public void updateExerciseDetail(Exercise exercise) { SQLiteDatabase db = this.getWritableDatabase(); ContentValues values = new ContentValues(); values.put(KEY_DESCRIPTION, exercise.getDescription()); db.update(TABLE_EXERCISE_DETAIL, values, KEY_NAME + " = ?", new String[] {exercise.getName()}); deleteExerciseDetailCategory(exercise.getId()); for (Category category : exercise.getCategories()) { createExerciseDetailCategory(exercise.getId(), category); } }
public Exercise getExerciseDetail(int id) { SQLiteDatabase db = this.getWritableDatabase(); String selectQuery = "SELECT * FROM " + TABLE_EXERCISE_DETAIL + " WHERE " + KEY_ID + " = " + id; Cursor c = db.rawQuery(selectQuery, null); if (c != null) c.moveToFirst(); Exercise exercise = new Exercise(); exercise.setId(c.getInt(c.getColumnIndex(KEY_ID))); exercise.setName(c.getString(c.getColumnIndex(KEY_NAME))); exercise.setDescription(c.getString(c.getColumnIndex(KEY_DESCRIPTION))); selectQuery = "SELECT * FROM " + TABLE_EXERCISE_DETAIL_CATEGORY + " WHERE " + TABLE_EXERCISE_DETAIL + KEY_ID + " = " + exercise.getId(); c.close(); c = db.rawQuery(selectQuery, null); while (c.moveToNext()) { exercise.addCategory( Category.valueOf(c.getString(c.getColumnIndex(TABLE_EXERCISE_CATEGORY + KEY_NAME)))); } c.close(); return exercise; }
public void createExerciseDetail(Exercise exercise) { SQLiteDatabase db = this.getWritableDatabase(); ContentValues values = new ContentValues(); values.put(KEY_NAME, exercise.getName()); values.put(KEY_DESCRIPTION, exercise.getDescription()); exercise.setId((int) db.insert(TABLE_EXERCISE_DETAIL, null, values)); for (Category category : exercise.getCategories()) { createExerciseDetailCategory(exercise.getId(), category); } }
public void saveExerciseSet(List<Exercise> exrcises) { SQLiteDatabase db = this.getWritableDatabase(); ContentValues values; for (Exercise exercise : exrcises) { for (ExeciseSet exerciseSet : exercise.getAllSets()) { SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Date date = new Date(); values = new ContentValues(); values.put(TABLE_EXERCISE_DETAIL + KEY_ID, exercise.getId()); values.put(KEY_WEIGHT, exerciseSet.getWeight()); values.put(KEY_REPETITIONS, exerciseSet.getRepetition()); values.put(KEY_DATE, dateFormat.format(date)); db.insert(TABLE_EXERCISE_SET_REPETITIONS, null, values); } } }