Permalink
Browse files

delete exercises

  • Loading branch information...
avalax committed Oct 12, 2017
1 parent aa86ff5 commit 1879c182647853f7d2cc2e20f7c75eb124202843
View
@@ -10,7 +10,7 @@ buildscript {
plugins {
id "org.standardout.versioneye" version "1.5.0"
id "com.github.ben-manes.versions" version "0.13.0"
id "com.github.ben-manes.versions" version "0.15.0"
id "com.github.kt3k.coveralls" version "2.8.1"
}
@@ -108,6 +108,35 @@ public void existingWorkoutWithTwoSets_shouldInteractWithSetListAndDisplaySaveNo
application.hasShownCantSaveExerciseWithoutSets();
}
@Test
public void existingWorkoutWithTwoExercises_shouldInteractWithExerciseListAndDisplaySaveNotPossibleMessage() throws Exception {
//TODO: use provider for arrange
application.addWorkout("old workout");
application.addExercise("first exercise");
application.addSet("1", "42.5");
application.saveSet();
application.saveExercise();
application.addExercise("second exercise");
application.addSet("1", "42.5");
application.saveSet();
application.saveExercise();
application.saveWorkout();
application.selectWorkout(0);
application.enterExerciseSelectionMode(0);
application.selectExercises(1);
application.hasShownDeleteExerciseCount(2);
application.selectExercises(0);
application.hasShownDeleteExerciseCount(1);
application.selectExercises(0);
application.hasShownDeleteExerciseCount(2);
application.deleteSelectedExercices();
application.hasShownAddNewExerciseHint();
application.saveWorkout();
application.hasShownCantSaveWorkoutWithoutExercices();
}
@After
public void tearDown() throws Exception {
activityRule.deleteWorkouts();
@@ -172,6 +172,31 @@ public void hasShownSetAddedToExercise(String reps, String weight) {
onView(withId(R.id.item_subtitle)).check(matches(withText(weight)));
}
public void enterExerciseSelectionMode(int position) {
onView(withId(android.R.id.list)).perform(
actionOnItemAtPosition(position, longClick()));
onView(withId(R.id.toolbar_delete_exercices)).check(matches(withtMenuTitle(valueOf(1))));
}
public void selectExercises(int... positions) {
for (int position : positions) {
onView(withId(android.R.id.list)).perform(
actionOnItemAtPosition(position, click()));
}
}
public void hasShownDeleteExerciseCount(int count) {
onView(withId(R.id.toolbar_delete_exercices)).check(matches(withtMenuTitle(valueOf(count))));
}
public void deleteSelectedExercices() {
onView(withId(R.id.toolbar_delete_exercices)).perform(click());
}
public void hasShownCantSaveWorkoutWithoutExercices() {
onView(withText(R.string.message_save_workout_without_exercices)).inRoot(isToast()).check(matches(isDisplayed()));
}
public void saveExercise() {
onView(withId(R.id.toolbar_save_exercise)).perform(click());
}
@@ -134,7 +134,7 @@ public void deleteExercises(Workout workout, Collection<Integer> positions)
for (Integer position : positions) {
Exercise exercise = workout.getExercises().get(position);
exerciseRepository.delete(exercise.getExerciseId());
workout.getExercises().delete(exercise);
workout.getExercises().removeAll(singleton(exercise));
}
}
@@ -1,5 +1,6 @@
package de.avalax.fitbuddy.domain.model.exercise;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
@@ -12,8 +13,8 @@ public BasicExercises(List<Exercise> exercises) {
}
@Override
public void delete(Exercise exercise) {
exercises.remove(exercise);
public void removeAll(Collection<Exercise> exercises) {
this.exercises.removeAll(exercises);
}
@Override
@@ -53,7 +54,7 @@ public boolean moveExerciseAtPositionUp(int index) throws ExerciseException {
return false;
}
Exercise exercise = get(index);
delete(exercise);
exercises.remove(exercise);
exercises.add(index - 1, exercise);
return true;
}
@@ -64,7 +65,7 @@ public boolean moveExerciseAtPositionDown(int index) throws ExerciseException {
return false;
}
Exercise exercise = get(index);
delete(exercise);
exercises.remove(exercise);
exercises.add(index + 1, exercise);
return true;
}
@@ -1,6 +1,8 @@
package de.avalax.fitbuddy.domain.model.exercise;
import java.io.Serializable;
import java.util.Collection;
import java.util.Set;
public interface Exercises extends Serializable, Iterable<Exercise> {
Exercise createExercise();
@@ -9,8 +11,6 @@
// Remove exception
Exercise get(int index) throws ExerciseException;
void delete(Exercise exercise);
int size();
void setCurrentExercise(int index) throws ExerciseException;
@@ -24,4 +24,6 @@
void add(Exercise exercise);
void set(int position, Exercise exercise);
void removeAll(Collection<Exercise> exercises);
}
@@ -60,8 +60,8 @@ public Set createSet() {
}
@Override
public void removeAll(Collection<Set> set) {
sets.removeAll(set);
public void removeAll(Collection<Set> sets) {
this.sets.removeAll(sets);
}
@Override
@@ -0,0 +1,41 @@
package de.avalax.fitbuddy.presentation.edit;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.TextView;
import de.avalax.fitbuddy.R;
import static android.graphics.Color.TRANSPARENT;
public class SelectableViewHolder extends RecyclerView.ViewHolder {
private final TextView titleTextView;
private final TextView subtitleTextView;
public SelectableViewHolder(View v) {
super(v);
titleTextView = v.findViewById(R.id.item_title);
subtitleTextView = v.findViewById(R.id.item_subtitle);
}
public TextView getTitleTextView() {
return titleTextView;
}
public TextView getSubtitleTextView() {
return subtitleTextView;
}
public View getView() {
return itemView;
}
public void select() {
int color = itemView.getResources().getColor(R.color.primaryDarkColor);
itemView.setBackgroundColor(color);
}
public void deselect() {
itemView.setBackgroundColor(TRANSPARENT);
}
}
@@ -81,7 +81,8 @@ public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == R.id.toolbar_save_exercise) {
if (exercise.getSets().size() == 0) {
Context context = getApplicationContext();
makeText(context, R.string.message_save_exercise_without_sets, LENGTH_SHORT).show();
makeText(context, R.string.message_save_exercise_without_sets, LENGTH_SHORT)
.show();
} else {
Intent intent = new Intent();
exercise.setName(nameEditText.getText().toString());
@@ -0,0 +1,124 @@
package de.avalax.fitbuddy.presentation.edit.exercise;
import android.app.Activity;
import android.content.Intent;
import android.support.v4.util.ArraySet;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import de.avalax.fitbuddy.R;
import de.avalax.fitbuddy.domain.model.set.Set;
import de.avalax.fitbuddy.domain.model.set.SetException;
import de.avalax.fitbuddy.domain.model.set.Sets;
import de.avalax.fitbuddy.presentation.edit.SelectableViewHolder;
import de.avalax.fitbuddy.presentation.edit.set.EditSetActivity;
import static de.avalax.fitbuddy.presentation.edit.exercise.EditExerciseActivity.EDIT_SET;
public class SetAdapter extends RecyclerView.Adapter<SelectableViewHolder> {
private Sets sets;
private EditExerciseApplicationService editExerciseApplicationService;
private Activity activity;
private java.util.Set<Set> selections;
public SetAdapter(Activity activity,
Sets sets,
EditExerciseApplicationService editExerciseApplicationService) {
super();
this.activity = activity;
this.sets = sets;
this.editExerciseApplicationService = editExerciseApplicationService;
this.selections = new ArraySet<>();
}
@Override
public SelectableViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
LayoutInflater inflater = LayoutInflater.from(activity);
View view = inflater.inflate(R.layout.item_set, parent, false);
return new SelectableViewHolder(view);
}
@Override
public void onBindViewHolder(SelectableViewHolder holder, int position) {
try {
Set set = sets.get(position);
String title = editExerciseApplicationService.title(set);
String subtitle = editExerciseApplicationService.subtitle(set);
holder.getTitleTextView().setText(title);
holder.getSubtitleTextView().setText(subtitle);
holder.deselect();
holder.getView().setOnClickListener(view -> {
if (selections.isEmpty()) {
Intent intent = new Intent(activity, EditSetActivity.class);
intent.putExtra("set", set);
intent.putExtra("position", holder.getAdapterPosition());
activity.startActivityForResult(intent, EDIT_SET);
} else {
if (isSelected(holder)) {
deselect(holder);
} else {
select(holder);
}
}
});
holder.getView().setOnLongClickListener(view -> {
select(holder);
return true;
});
} catch (SetException e) {
Log.e("SetException", e.getMessage(), e);
}
}
private boolean isSelected(SelectableViewHolder holder) {
boolean isSelected = false;
try {
isSelected = selections.contains(sets.get(holder.getAdapterPosition()));
} catch (SetException e) {
Log.e("SetException", e.getMessage(), e);
}
return isSelected;
}
private void deselect(SelectableViewHolder holder) {
try {
selections.remove(sets.get(holder.getAdapterPosition()));
holder.deselect();
((EditExerciseActivity) activity).updateToolbar(selections.size());
} catch (SetException e) {
Log.e("SetException", e.getMessage(), e);
}
}
private void select(SelectableViewHolder holder) {
try {
selections.add(sets.get(holder.getAdapterPosition()));
holder.select();
((EditExerciseActivity) activity).updateToolbar(selections.size());
} catch (SetException e) {
Log.e("SetException", e.getMessage(), e);
}
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public int getItemCount() {
return sets == null ? 0 : sets.size();
}
public void removeSelections() {
sets.removeAll(selections);
selections.clear();
notifyDataSetChanged();
}
}
Oops, something went wrong.

0 comments on commit 1879c18

Please sign in to comment.