use of com.se491.chef_ly.model.RecipeInformation in project chefly_android by chef-ly.
the class DatabaseHandler method getRecipes.
public ArrayList<RecipeInformation> getRecipes() {
SQLiteDatabase db = null;
Cursor cursor = null;
ArrayList<RecipeInformation> list = new ArrayList<>();
String[] columns = { RecipeDetailTable.COLUMN_RECIPE_DETAIL_ID, RecipeDetailTable.COLUMN_RECIPE_DETAIL_NAME, RecipeDetailTable.COLUMN_RECIPE_DETAIL_AUTHOR, RecipeDetailTable.COLUMN_RECIPE_DETAIL_CATEGORIES, RecipeDetailTable.COLUMN_RECIPE_DETAIL_LEVEL, RecipeDetailTable.COLUMN_RECIPE_DETAIL_TIME, RecipeDetailTable.COLUMN_RECIPE_DETAIL_RATING, RecipeDetailTable.COLUMN_RECIPE_DETAIL_IMAGE };
try {
db = this.getWritableDatabase();
cursor = db.query(RecipeDetailTable.RECIPE_DETAIL_TABLE_ITEMS, columns, null, null, null, null, RecipeDetailTable.COLUMN_RECIPE_DETAIL_NAME);
if (cursor.moveToFirst()) {
do {
String id = cursor.getString(cursor.getColumnIndex(RecipeDetailTable.COLUMN_RECIPE_DETAIL_ID));
String name = cursor.getString(cursor.getColumnIndex(RecipeDetailTable.COLUMN_RECIPE_DETAIL_NAME));
String author = cursor.getString(cursor.getColumnIndex(RecipeDetailTable.COLUMN_RECIPE_DETAIL_AUTHOR));
String cats = cursor.getString(cursor.getColumnIndex(RecipeDetailTable.COLUMN_RECIPE_DETAIL_CATEGORIES));
String level = cursor.getString(cursor.getColumnIndex(RecipeDetailTable.COLUMN_RECIPE_DETAIL_LEVEL));
int time = cursor.getInt(cursor.getColumnIndex(RecipeDetailTable.COLUMN_RECIPE_DETAIL_TIME));
int rating = cursor.getInt(cursor.getColumnIndex(RecipeDetailTable.COLUMN_RECIPE_DETAIL_RATING));
String image = cursor.getString(cursor.getColumnIndex(RecipeDetailTable.COLUMN_RECIPE_DETAIL_IMAGE));
Gson gson = new Gson();
String[] categories = gson.fromJson(cats, String[].class);
// list.add(new RecipeInformation(id,name,author,image, rating, time, categories, level));
} while (cursor.moveToNext());
}
} finally {
if (cursor != null)
cursor.close();
if (db != null)
db.close();
}
return list;
}
use of com.se491.chef_ly.model.RecipeInformation in project chefly_android by chef-ly.
the class RecipeListActivity method onActivityResult.
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// Check which request we're responding to
if (requestCode == CREATE_RECIPE_CODE) {
// Make sure the request was successful
if (resultCode == RESULT_OK) {
Log.d(TAG, "Result from CreateRecipe");
RecipeInformation r = data.getParcelableExtra("recipe");
favoriteRecipes.add(r);
favs.updateListAdapter(favoriteRecipes);
}
}
}
use of com.se491.chef_ly.model.RecipeInformation in project chefly_android by chef-ly.
the class ListViewFragment method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_list_view, container, false);
listView = (ListView) v.findViewById(R.id.list);
emptyView = v.findViewById(R.id.emptyList);
if (title.equals("Favorites")) {
emptyView.setBackground(ContextCompat.getDrawable(getContext(), R.drawable.emptylist));
} else {
emptyView.setBackground(ContextCompat.getDrawable(getContext(), R.drawable.emptylistwelcome));
}
listView.setAdapter(new ListViewFragment.RecipeAdapter(getContext(), list, mListener));
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView l, View v, int position, long id) {
Intent intent = new Intent(getContext(), RecipeDetailActivity.class);
RecipeInformation recipe = ((RecipeInformation) l.getAdapter().getItem(position));
// intent.putExtra("recipe", String.valueOf(recipeID));
intent.putExtra("recipeDetail", recipe);
Log.d(TAG + "/" + title, "Recipe Clicked: id -> " + recipe.getId());
startActivity(intent);
}
});
final LoaderManager.LoaderCallbacks callbacks = this;
listView.setOnScrollListener(new AbsListView.OnScrollListener() {
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
}
@Override
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
if (title.equals(RECIPES)) {
// TODO remove limit and or wait for user to scroll past end of list to load more
if (firstVisibleItem + visibleItemCount + 2 == totalItemCount && totalItemCount != 0 && totalItemCount < 25) {
if (!isLoading.get()) {
Log.d(TAG + "/" + title, "Getting more recipes from server");
isLoading.set(true);
RequestMethod requestPackage = new RequestMethod();
if (searchText.length() == 0) {
// requestPackage.setEndPoint(urlString + qMark + urlRequestNumber + requestNumRandom);
requestPackage.setEndPoint(urlString + urlQ + urlPageNum + requestNumRandom);
requestNumRandom++;
} else {
// requestPackage.setEndPoint(urlStringSearch + searchText + urlRequestNumber + requestNumSearch);
requestPackage.setEndPoint(urlStringSearch + searchText + urlA + urlPageNum + requestNumSearch);
requestNumSearch++;
}
requestPackage.setMethod("GET");
Log.d(TAG, "Get more recipes from -> " + requestPackage.getEndpoint());
Bundle bundle = new Bundle();
bundle.putParcelable("requestPackage", requestPackage);
// Log.d(TAG, "onScroll: SearchQuery -> " + searchText);
getLoaderManager().initLoader((new Date()).hashCode(), bundle, callbacks).forceLoad();
}
}
}
}
});
final Handler h = new Handler();
h.postDelayed(new Runnable() {
@Override
public void run() {
listView.setEmptyView(emptyView);
}
}, 500);
// Inflate the layout for this fragment
return v;
}
use of com.se491.chef_ly.model.RecipeInformation in project chefly_android by chef-ly.
the class ListViewFragment method onLoadFinished.
// LoaderManager callback method
@Override
public void onLoadFinished(Loader<RecipeList> loader, RecipeList data) {
Log.d(TAG + "/" + title, "Loader - OnLoadFinish");
for (RecipeInformation recipe : data) {
list.add(recipe);
}
((BaseAdapter) listView.getAdapter()).notifyDataSetChanged();
isLoading.set(false);
Log.d(TAG, "Getting more recipes from server --- Done");
}
Aggregations