Example #1
0
 /**
  * Updates or insert a new a category
  *
  * @param category Category to be updated or inserted
  * @return Rows affected or new inserted category id
  */
 public Category updateCategory(Category category) {
   ContentValues values = new ContentValues();
   values.put(
       KEY_CATEGORY_ID,
       category.getId() != null ? category.getId() : Calendar.getInstance().getTimeInMillis());
   values.put(KEY_CATEGORY_NAME, category.getName());
   values.put(KEY_CATEGORY_DESCRIPTION, category.getDescription());
   values.put(KEY_CATEGORY_COLOR, category.getColor());
   getDatabase(true)
       .insertWithOnConflict(
           TABLE_CATEGORY, KEY_CATEGORY_ID, values, SQLiteDatabase.CONFLICT_REPLACE);
   return category;
 }