Skip to content

Instantly share code, notes, and snippets.

@jezinka
Created May 12, 2017 08:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jezinka/3acb9d7411d2f07c6241ad372a79c2ad to your computer and use it in GitHub Desktop.
Save jezinka/3acb9d7411d2f07c6241ad372a79c2ad to your computer and use it in GitHub Desktop.
public String getShoppingList(List<Meal> meals, SQLiteOpenHelper helper) {
ArrayList<String> array_list = new ArrayList<>();
String[] queryArgs = getMealIds(meals);
String query = getShoppingListQuery(meals);
SQLiteDatabase db = helper.getReadableDatabase();
Cursor res = db.rawQuery(query, queryArgs);
if (res != null && res.getCount() > 0) {
res.moveToFirst();
do {
String name = res.getString(0);
int count = res.getInt(1);
array_list.add(count + " x " + name + "\n");
} while (res.moveToNext());
}
db.close();
return TextUtils.join("\n", array_list);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment