Skip to content

Commit

Permalink
notifyItemRemoved on delete workout
Browse files Browse the repository at this point in the history
  • Loading branch information
avalax committed Jan 12, 2018
1 parent 8b50710 commit 9e15c3a
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -297,14 +297,21 @@ public void doWorkout_shouldFinishAfterLastExercise() throws Exception {

@Test
public void aWorkout_shouldBeDeleted() throws Exception {
persistence.addWorkout(aWorkout().withExercise(anExercise()));
persistence.addWorkout(aWorkout().withName("first").withExercise(anExercise()));
persistence.addWorkout(aWorkout().withName("second").withExercise(anExercise()));
persistence.addWorkout(aWorkout().withName("third").withExercise(anExercise()));

activityRule.launchActivity(null);

application.deleteWorkout(1);
application.hasShownWorkoutDetails(0, "first", "Never", "Executed 0 times");
application.hasShownWorkoutDetails(1, "third", "Never", "Executed 0 times");

application.deleteWorkout(0);
application.hasShownWorkoutDetails(0, "third", "Never", "Executed 0 times");

application.deleteWorkout(0);
application.hasShownAddNewWorkoutHint();
application.showsSupportMenuItem();
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public void finishWorkout(Workout workout) throws ResourceException {
public void deleteWorkouts() throws ResourceException {
List<Workout> workouts = activityRule.editWorkoutService.loadAllWorkouts();
for (Workout workout : workouts) {
activityRule.editWorkoutService.deleteWorkout(workout);
activityRule.editWorkoutService.deleteWorkout(workout.getWorkoutId());
}

if (activityRule.workoutService.hasActiveWorkout()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

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.WorkoutRepository;

public class EditWorkoutService {
Expand All @@ -15,8 +16,8 @@ public EditWorkoutService(
this.workoutRepository = workoutRepository;
}

public void deleteWorkout(Workout workout) {
workoutRepository.delete(workout.getWorkoutId());
public void deleteWorkout(WorkoutId workoutId) {
workoutRepository.delete(workoutId);
}

public void saveWorkout(Workout workout) throws WorkoutException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
}
if (item.getItemId() == R.id.toolbar_delete_workout) {
Workout workout = (Workout) item.getIntent().getSerializableExtra("workout");
editWorkoutService.deleteWorkout(workout);
editWorkoutService.deleteWorkout(workout.getWorkoutId());
removeWorkoutFromList(workout);
mainToolbar();
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,9 @@ public void removeSelection() {

public void removeWorkout(Workout workout) {
removeSelection();
workouts.remove(workout);
int index = workouts.indexOf(workout);
workouts.remove(index);
workoutAdapter.notifyItemRemoved(index);
recyclerView.updateEmptyView();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public void saveWorkout_shouldSaveWorkoutInRepository() throws Exception {

@Test
public void deleteWorkout_shouldRemoveTheWorkoutFromThePersistence() throws Exception {
editWorkoutService.deleteWorkout(workout);
editWorkoutService.deleteWorkout(workoutId);

verify(workoutRepository).delete(workoutId);
}
Expand Down

0 comments on commit 9e15c3a

Please sign in to comment.