Permalink
Browse files

delete workout

  • Loading branch information...
avalax committed Oct 15, 2017
1 parent db714e0 commit 002f175d4690ce05dda6804f590e68a0da19fc95
Showing with 223 additions and 247 deletions.
  1. BIN doc/prototype.epgz
  2. BIN doc/prototype/start.png
  3. +23 −6 src/androidTest/java/de/avalax/fitbuddy/FitbuddyAcceptanceTest.java
  4. +16 −7 src/androidTest/java/de/avalax/fitbuddy/runner/ApplicationRunner.java
  5. +3 −3 src/androidTest/java/de/avalax/fitbuddy/runner/FitbuddyActivityTestRule.java
  6. +0 −6 src/main/java/de/avalax/fitbuddy/application/edit/workout/EditWorkoutApplicationService.java
  7. +0 −30 src/main/java/de/avalax/fitbuddy/domain/model/workout/WorkoutListEntry.java
  8. +1 −1 src/main/java/de/avalax/fitbuddy/domain/model/workout/WorkoutRepository.java
  9. +4 −7 src/main/java/de/avalax/fitbuddy/port/adapter/persistence/SQLiteWorkoutRepository.java
  10. +44 −2 src/main/java/de/avalax/fitbuddy/presentation/MainActivity.java
  11. +1 −1 src/main/java/de/avalax/fitbuddy/presentation/edit/exercise/EditExerciseActivity.java
  12. +1 −1 src/main/java/de/avalax/fitbuddy/presentation/edit/set/EditSetActivity.java
  13. +1 −1 src/main/java/de/avalax/fitbuddy/presentation/edit/workout/EditWorkoutActivity.java
  14. +81 −0 src/main/java/de/avalax/fitbuddy/presentation/welcome_screen/WorkoutAdapter.java
  15. +10 −94 src/main/java/de/avalax/fitbuddy/presentation/welcome_screen/WorkoutListFragment.java
  16. +9 −0 src/main/res/drawable/ic_action_edit.xml
  17. +1 −1 src/main/res/layout/activity_edit_exercise.xml
  18. +1 −1 src/main/res/layout/activity_edit_set.xml
  19. +1 −1 src/main/res/layout/activity_edit_workout.xml
  20. +1 −25 src/main/res/layout/card_workout.xml
  21. +17 −0 src/main/res/menu/menu_main_edit_workout.xml
  22. +0 −10 src/test/java/de/avalax/fitbuddy/application/edit/workout/EditWorkoutApplicationServiceTest.java
  23. +0 −41 src/test/java/de/avalax/fitbuddy/domain/model/workout/WorkoutListEntryTest.java
  24. +8 −9 src/test/java/de/avalax/fitbuddy/port/adapter/persistence/SQLiteWorkoutRepositoryTest.java
View
BIN -1.08 KB (99%) doc/prototype.epgz
Binary file not shown.
View
BIN -1.25 KB (96%) doc/prototype/start.png
Binary file not shown.
@@ -26,6 +26,7 @@
public void initialStart_shouldShowEmptyStartFragment() throws Exception {
application.showsStartBottomNavAsActive();
application.hasShownAddNewWorkoutHint();
application.showsSupportMenuItem();
}
@Test
@@ -59,15 +60,15 @@ public void existingWorkout_shouldDisplayChanges() throws Exception {
application.saveExercise();
application.saveWorkout();
application.selectWorkout(0);
application.editWorkout(0);
application.hasShownOldWorkoutNameInEditView("old workout");
application.changeWorkout("new workout");
application.selectExercise(0);
application.editExercise(0);
application.hasShownOldExerciseNameInEditView("old exercise");
application.changeExercise("new exercise");
application.selectSet(0);
application.editSet(0);
application.hasShownOldSetDetails("15", "42.5");
application.changeSet("12", "47.5");
@@ -92,8 +93,8 @@ public void existingWorkoutWithTwoSets_shouldInteractWithSetListAndDisplaySaveNo
application.saveExercise();
application.saveWorkout();
application.selectWorkout(0);
application.selectExercise(0);
application.editWorkout(0);
application.editExercise(0);
application.enterSetSelectionMode(0);
application.selectSets(1);
@@ -122,7 +123,7 @@ public void existingWorkoutWithTwoExercises_shouldInteractWithExerciseListAndDis
application.saveExercise();
application.saveWorkout();
application.selectWorkout(0);
application.editWorkout(0);
application.enterExerciseSelectionMode(0);
application.selectExercises(1);
@@ -137,6 +138,22 @@ public void existingWorkoutWithTwoExercises_shouldInteractWithExerciseListAndDis
application.hasShownCantSaveWorkoutWithoutExercices();
}
@Test
public void existingWorkout_shouldBeDeleted() throws Exception {
//TODO: use provider for arrange
application.addWorkout("a workout");
application.addExercise("an exercise");
application.addSet("12", "42.0");
application.saveSet();
application.saveExercise();
application.saveWorkout();
application.deleteWorkout(0);
application.hasShownAddNewWorkoutHint();
application.showsSupportMenuItem();
}
@After
public void tearDown() throws Exception {
activityRule.deleteWorkouts();
@@ -44,6 +44,11 @@ public void showsStartBottomNavAsActive() {
onView(withId(R.id.navigation_statistics_item)).check(matches(bottomNavItemIsNotChecked()));
}
public void showsSupportMenuItem() {
onView(withId(R.id.toolbar_support)).check(matches(isDisplayed()));
}
public void hasShownAddNewWorkoutHint() {
onView(withId(android.R.id.empty)).check(matches(withText(R.string.empty_workout_list)));
onView(withId(android.R.id.list)).check(matches(not(isDisplayed())));
@@ -64,16 +69,22 @@ public void addWorkout(String name) {
onView(withId(R.id.edit_text_workout_name)).perform(typeText(name), closeSoftKeyboard());
}
public void selectWorkout(int position) {
public void editWorkout(int position) {
onView(withId(android.R.id.list)).perform(
actionOnItemAtPosition(position, clickChildButtonWithId(R.id.btn_edit_workout)));
actionOnItemAtPosition(position, longClick()));
onView(withId(R.id.toolbar_edit_workout)).perform(click());
}
public void changeWorkout(String name) {
onView(withId(R.id.edit_text_workout_name)).perform(replaceText(name), closeSoftKeyboard());
}
public void deleteWorkout(int position) {
onView(withId(android.R.id.list)).perform(actionOnItemAtPosition(position, longClick()));
onView(withId(R.id.toolbar_delete_workout)).perform(click());
}
public void hasShownOldWorkoutNameInEditView(String name) {
onView(withId(R.id.edit_text_workout_name)).check(matches(withText(name)));
}
@@ -83,7 +94,7 @@ public void addExercise(String name) {
onView(withId(R.id.edit_text_exercise_name)).perform(typeText(name), closeSoftKeyboard());
}
public void selectExercise(int position) {
public void editExercise(int position) {
onView(withId(android.R.id.list)).perform(
actionOnItemAtPosition(position, click()));
}
@@ -112,7 +123,7 @@ public void addSet(String reps, String weight) {
onView(withId(R.id.done_button)).perform(click());
}
public void selectSet(int position) {
public void editSet(int position) {
onView(withId(android.R.id.list)).perform(
actionOnItemAtPosition(position, click()));
}
@@ -219,9 +230,7 @@ public void hasShownWorkoutDetails(int position, String name) {
.check(matches(itemAtPosition(position, withText(name), R.id.card_title)))
.check(matches(itemAtPosition(position, withText("Executed 0 times"), R.id.card_subtitle)))
.check(matches(itemAtPosition(position, withText("never"), R.id.card_date)))
.check(matches(itemAtPosition(position, withText(R.string.btn_start_workout), R.id.btn_start_workout)))
.check(matches(itemAtPosition(position, withText(R.string.btn_edit_workout), R.id.btn_edit_workout)))
.check(matches(itemAtPosition(position, isDisplayed(), R.id.btn_share_workout)));
.check(matches(itemAtPosition(position, withText(R.string.btn_start_workout), R.id.btn_start_workout)));
}
public void hasShownSetDetails(String reps, String weight) {
@@ -6,7 +6,7 @@
import javax.inject.Inject;
import de.avalax.fitbuddy.domain.model.workout.WorkoutListEntry;
import de.avalax.fitbuddy.domain.model.workout.Workout;
import de.avalax.fitbuddy.domain.model.workout.WorkoutRepository;
import de.avalax.fitbuddy.presentation.MainActivity;
@@ -28,8 +28,8 @@ protected void afterActivityLaunched() {
}
public void deleteWorkouts() {
List<WorkoutListEntry> workoutList = workoutRepository.getWorkoutList();
for (WorkoutListEntry workoutListEntry : workoutList) {
List<Workout> workoutList = workoutRepository.getWorkouts();
for (Workout workoutListEntry : workoutList) {
workoutRepository.delete(workoutListEntry.getWorkoutId());
}
}
@@ -1,7 +1,6 @@
package de.avalax.fitbuddy.application.edit.workout;
import java.util.Collection;
import java.util.List;
import de.avalax.fitbuddy.application.workout.WorkoutSession;
import de.avalax.fitbuddy.domain.model.ResourceException;
@@ -16,7 +15,6 @@
import de.avalax.fitbuddy.domain.model.workout.Workout;
import de.avalax.fitbuddy.domain.model.workout.WorkoutException;
import de.avalax.fitbuddy.domain.model.workout.WorkoutId;
import de.avalax.fitbuddy.domain.model.workout.WorkoutListEntry;
import de.avalax.fitbuddy.domain.model.workout.WorkoutParseException;
import de.avalax.fitbuddy.domain.model.workout.WorkoutParserService;
import de.avalax.fitbuddy.domain.model.workout.WorkoutRepository;
@@ -81,10 +79,6 @@ public void switchWorkout(Workout workout) throws WorkoutException {
setUnsavedChanges(false);
}
public List<WorkoutListEntry> getWorkoutList() {
return workoutRepository.getWorkoutList();
}
public Workout createWorkout() {
Workout workout = new BasicWorkout();
workoutRepository.save(workout);

This file was deleted.

Oops, something went wrong.
@@ -7,7 +7,7 @@
Workout load(WorkoutId id) throws WorkoutException;
List<WorkoutListEntry> getWorkoutList();
List<Workout> getWorkouts();
void delete(WorkoutId id);
}
@@ -14,7 +14,6 @@
import de.avalax.fitbuddy.domain.model.workout.Workout;
import de.avalax.fitbuddy.domain.model.workout.WorkoutException;
import de.avalax.fitbuddy.domain.model.workout.WorkoutId;
import de.avalax.fitbuddy.domain.model.workout.WorkoutListEntry;
import de.avalax.fitbuddy.domain.model.workout.WorkoutRepository;
public class SQLiteWorkoutRepository implements WorkoutRepository {
@@ -80,17 +79,15 @@ private Workout createWorkout(Cursor cursor) {
}
@Override
public List<WorkoutListEntry> getWorkoutList() {
List<WorkoutListEntry> workoutList = new ArrayList<>();
public List<Workout> getWorkouts() {
List<Workout> workoutList = new ArrayList<>();
SQLiteDatabase database = sqLiteOpenHelper.getReadableDatabase();
Cursor cursor = database.query(TABLE_WORKOUT, new String[]{"id", "name"},
null, null, null, null, null);
if (cursor.moveToFirst()) {
do {
WorkoutId workoutId = new WorkoutId(cursor.getString(0));
String name = cursor.getString(1);
WorkoutListEntry entry = new WorkoutListEntry(workoutId, name);
workoutList.add(entry);
Workout workout = createWorkout(cursor);
workoutList.add(workout);
} while (cursor.moveToNext());
}
cursor.close();
@@ -6,6 +6,7 @@
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import javax.inject.Inject;
@@ -23,6 +24,7 @@
public static final int EDIT_WORKOUT = 2;
@Inject
protected WorkoutRepository workoutRepository;
private Menu menu;
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -37,6 +39,7 @@ protected void onCreate(Bundle savedInstanceState) {
@Override
public boolean onCreateOptionsMenu(Menu menu) {
this.menu = menu;
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@@ -47,6 +50,22 @@ public void onAddWorkoutButtonClick(View view) {
startActivityForResult(intent, ADD_WORKOUT);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == R.id.toolbar_edit_workout) {
startActivityForResult(item.getIntent(), EDIT_WORKOUT);
return true;
}
if (item.getItemId() == R.id.toolbar_delete_workout) {
Workout workout = (Workout) item.getIntent().getSerializableExtra("workout");
workoutRepository.delete(workout.getWorkoutId());
removeWorkoutFromList(workout);
mainToolbar();
return true;
}
return false;
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
@@ -57,11 +76,11 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == EDIT_WORKOUT && resultCode == Activity.RESULT_OK) {
Workout workout = (Workout) data.getSerializableExtra("workout");
Integer position = data.getIntExtra("position", -1);
updateWorkout(position, workout);
updateWorkoutInList(position, workout);
}
}
private void updateWorkout(Integer position, Workout workout) {
private void updateWorkoutInList(Integer position, Workout workout) {
WorkoutListFragment workoutListFragment = (WorkoutListFragment)
getSupportFragmentManager().findFragmentById(R.id.toolbar_fragment);
workoutListFragment.updateWorkout(position, workout);
@@ -72,4 +91,27 @@ private void addWorkoutToList(Workout workout) {
getSupportFragmentManager().findFragmentById(R.id.toolbar_fragment);
workoutListFragment.addWorkout(workout);
}
private void removeWorkoutFromList(Workout workout) {
WorkoutListFragment workoutListFragment = (WorkoutListFragment)
getSupportFragmentManager().findFragmentById(R.id.toolbar_fragment);
workoutListFragment.removeWorkout(workout);
}
public void updateEditToolbar(int position, Workout workout) {
menu.clear();
getMenuInflater().inflate(R.menu.menu_main_edit_workout, menu);
Intent intent = new Intent(this, EditWorkoutActivity.class);
intent.putExtra("workout", workout);
intent.putExtra("position", position);
MenuItem item = menu.findItem(R.id.toolbar_edit_workout);
item.setIntent(intent);
MenuItem itemDelete = menu.findItem(R.id.toolbar_delete_workout);
itemDelete.setIntent(intent);
}
private void mainToolbar() {
menu.clear();
getMenuInflater().inflate(R.menu.menu_main, menu);
}
}
@@ -33,7 +33,7 @@
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_edit_exercise);
Toolbar toolbar = findViewById(R.id.toolbar_edit_exercise);
Toolbar toolbar = findViewById(R.id.toolbar_exercise_edit);
setSupportActionBar(toolbar);
nameEditText = findViewById(R.id.edit_text_exercise_name);
exercise = (Exercise) getIntent().getSerializableExtra("exercise");
@@ -30,7 +30,7 @@ public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_edit_set);
Toolbar toolbar = findViewById(R.id.toolbar_edit_set);
Toolbar toolbar = findViewById(R.id.toolbar_set_edit);
setSupportActionBar(toolbar);
set = (Set) getIntent().getSerializableExtra("set");
repsTextView = findViewById(R.id.set_reps_text_view);
@@ -41,7 +41,7 @@ public void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.activity_edit_workout);
((FitbuddyApplication) getApplication()).getComponent().inject(this);
Toolbar toolbar = findViewById(R.id.toolbar_edit_workout);
Toolbar toolbar = findViewById(R.id.toolbar_workout_edit);
setSupportActionBar(toolbar);
nameEditText = findViewById(R.id.edit_text_workout_name);
workout = (Workout) getIntent().getSerializableExtra("workout");
Oops, something went wrong.

0 comments on commit 002f175

Please sign in to comment.