Beispiel #1
0
 public void setFridge(Set<Ingredient> ingredients) {
   db.delete(DBHelper.fridgeTableName, null, null);
   ContentValues cv = new ContentValues();
   for (Ingredient ingredient : ingredients) {
     cv.put(DBHelper.ingredientIdColName, ingredient.getId());
     cv.put(DBHelper.ingredientNameColName, ingredient.getName());
     db.insert(DBHelper.fridgeTableName, null, cv);
   }
 }
Beispiel #2
0
 public Set<Ingredient> getFridge() {
   Set<Ingredient> fridge = null;
   Cursor cursor = db.rawQuery("select * from " + DBHelper.fridgeTableName, null);
   if (cursor.moveToFirst()) {
     fridge = new HashSet<Ingredient>();
     int ingredientIdColIndex = cursor.getColumnIndex(DBHelper.ingredientIdColName);
     int ingredientNameColIndex = cursor.getColumnIndex(DBHelper.ingredientNameColName);
     do {
       String ingedientId = cursor.getString(ingredientIdColIndex);
       String ingredientName = cursor.getString(ingredientNameColIndex);
       Ingredient ingredient = new Ingredient();
       ingredient.setId(ingedientId);
       ingredient.setName(ingredientName);
       fridge.add(ingredient);
     } while (cursor.moveToNext());
   }
   cursor.close();
   return fridge;
 }