use of com.se491.chef_ly.model.ShoppingListItem in project chefly_android by chef-ly.
the class DatabaseHandler method getShoppingList.
public ArrayList<ShoppingListItem> getShoppingList() {
SQLiteDatabase db = null;
Cursor cursor = null;
ArrayList<ShoppingListItem> listItems = new ArrayList<>();
try {
db = this.getReadableDatabase();
cursor = db.query(ShoppingList.TABLE_LIST_ITEMS, ShoppingList.ALL_COLUMNS, null, null, null, null, ShoppingList.COLUMN_NAME);
if (cursor.moveToFirst()) {
do {
int id = cursor.getInt(cursor.getColumnIndex(ShoppingList.COLUMN_LIST_ID));
String name = cursor.getString(cursor.getColumnIndex(ShoppingList.COLUMN_NAME));
boolean purchased = cursor.getInt(cursor.getColumnIndex(ShoppingList.COLUMN_PURCHASED)) > 0;
listItems.add(new ShoppingListItem(id, name, purchased));
} while (cursor.moveToNext());
return listItems;
}
} finally {
if (cursor != null) {
cursor.close();
}
if (db != null) {
db.close();
}
}
return listItems;
}
Aggregations