Skip to content

Commit

Permalink
Styling for edit workout
Browse files Browse the repository at this point in the history
  • Loading branch information
avalax committed Dec 18, 2017
1 parent 002ed60 commit 76a64c3
Show file tree
Hide file tree
Showing 13 changed files with 184 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public void newWorkout_shouldBeDisplayed() throws Exception {
application.hasShownSetAddedToExercise("15 reps", "42.5 kg");

application.saveExercise();
application.hasShownExerciseDetails("new exercise", "1 x 15");
application.hasShownExerciseDetails("new exercise", "1 x 15", "42.5 kg");

application.saveWorkout();
application.hasShownWorkoutDetails(0, "new workout");
Expand Down Expand Up @@ -97,7 +97,7 @@ public void existingWorkout_shouldDisplayChanges() throws Exception {
application.hasShownSetAddedToExercise("12 reps", "47.5 kg");

application.saveExercise();
application.hasShownExerciseDetails("new exercise", "1 x 12");
application.hasShownExerciseDetails("new exercise", "1 x 12", "47.5 kg");
application.saveWorkout();
application.hasShownWorkoutDetails(0, "new workout");
}
Expand Down Expand Up @@ -127,8 +127,23 @@ public void existingWorkout_shouldNotSaveExerciseWithoutSets() throws Exception
}

@Test
public void existingWorkout_shouldNotSaveExerciseOnBack() throws Exception {
public void existingWorkout_shouldNotSaveWorkoutOnBack() throws Exception {
BasicSetBuilder set = aSet().withMaxReps(12);
BasicExerciseBuilder exercise = anExercise().withSet(set);
BasicWorkoutBuilder workout = aWorkout().withName("old workout name").withExercise(exercise);
persistence.addWorkout(workout);
activityRule.launchActivity(null);
application.editWorkout(0);

application.changeWorkout("new workout name");
application.cancelAction();

application.hasShownWorkoutDetails(0, "old workout name");
}

@Test
public void existingWorkout_shouldNotSaveExerciseOnBack() throws Exception {
BasicSetBuilder set = aSet().withMaxReps(12).withWeight(0);
BasicExerciseBuilder exercise = anExercise().withName("old exercise name").withSet(set);
BasicWorkoutBuilder workout = aWorkout().withExercise(exercise);
persistence.addWorkout(workout);
Expand All @@ -139,7 +154,7 @@ public void existingWorkout_shouldNotSaveExerciseOnBack() throws Exception {
application.changeExercise("new exercise name");
application.cancelAction();

application.hasShownExerciseDetails("old exercise name", "1 x 12");
application.hasShownExerciseDetails("old exercise name", "1 x 12", "no weight");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,10 +271,11 @@ public void saveExercise() {
onView(withId(R.id.toolbar_save_exercise)).perform(click());
}

public void hasShownExerciseDetails(String name, String details) {
public void hasShownExerciseDetails(String name, String details, String weight) {
onView(withId(android.R.id.empty)).check(matches(not(isDisplayed())));
onView(withId(R.id.item_title)).check(matches(withText(name)));
onView(withId(R.id.item_subtitle)).check(matches(withText(details)));
onView(withId(R.id.item_weight)).check(matches(withText(weight)));
}

public void saveWorkout() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ EditWorkoutApplicationService provideManageWorkout() {

@Provides
@Singleton
EditWorkoutViewHelper provideEditWorkoutViewHelper() {
return new EditWorkoutViewHelper();
EditWorkoutViewHelper provideEditWorkoutViewHelper(EditExerciseViewHelper editExerciseViewHelper) {
return new EditWorkoutViewHelper(context, editExerciseViewHelper);
}

@Provides
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_edit_workout);
((FitbuddyApplication) getApplication()).getComponent().inject(this);

Toolbar toolbar = findViewById(R.id.toolbar_workout_edit);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayShowTitleEnabled(false);
nameEditText = findViewById(R.id.edit_text_workout_name);
workout = (Workout) getIntent().getSerializableExtra("workout");
nameEditText.setText(workout.getName());
Expand Down Expand Up @@ -121,4 +121,9 @@ public void updateToolbar(int selectionCount) {
getMenuInflater().inflate(R.menu.menu_edit_workout, menu);
}
}

public void onCancelButtonClick(View view) {
setResult(RESULT_CANCELED);
finish();
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
package de.avalax.fitbuddy.presentation.edit.workout;

import android.support.annotation.NonNull;
import android.content.Context;

import java.util.LinkedHashSet;

import de.avalax.fitbuddy.R;
import de.avalax.fitbuddy.domain.model.exercise.Exercise;
import de.avalax.fitbuddy.domain.model.set.Set;
import de.avalax.fitbuddy.presentation.edit.exercise.EditExerciseViewHelper;

import static android.text.TextUtils.join;

public class EditWorkoutViewHelper {

private final String defaultWeight;
private EditExerciseViewHelper editExerciseViewHelper;

public EditWorkoutViewHelper(Context context, EditExerciseViewHelper editExerciseViewHelper) {
this.editExerciseViewHelper = editExerciseViewHelper;
defaultWeight = context.getResources().getString(R.string.default_set_weight);
}

public String title(Exercise exercise) {
String name = exercise.getName();
if (name == null) {
Expand All @@ -27,12 +38,24 @@ public String subtitle(Exercise exercise) {
return join(" - ", reps);
}

@NonNull
private java.util.Set<Integer> repsFromExercise(Exercise exercise) {
java.util.Set<Integer> reps = new LinkedHashSet<>();
for (Set set : exercise.getSets()) {
reps.add(set.getMaxReps());
}
return reps;
}

public String weight(Exercise exercise) {
double exerciseWeight = 0;
String weight = defaultWeight;
for (Set set : exercise.getSets()) {
double setWeight = set.getWeight();
if (setWeight > exerciseWeight) {
exerciseWeight = setWeight;
weight = editExerciseViewHelper.subtitle(set);
}
}
return weight;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import java.util.Set;

Expand All @@ -20,7 +21,7 @@

import static de.avalax.fitbuddy.presentation.edit.workout.EditWorkoutActivity.EDIT_EXERCISE;

public class ExerciseAdapter extends RecyclerView.Adapter<SelectableViewHolder> {
public class ExerciseAdapter extends RecyclerView.Adapter<ExerciseAdapter.ExerciseViewHolder> {
private Exercises exercises;
private EditWorkoutViewHelper editWorkoutViewHelper;
private Activity activity;
Expand All @@ -37,21 +38,23 @@ public class ExerciseAdapter extends RecyclerView.Adapter<SelectableViewHolder>
}

@Override
public SelectableViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
public ExerciseViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
LayoutInflater inflater = LayoutInflater.from(activity);
View view = inflater.inflate(R.layout.item_exercise, parent, false);
return new SelectableViewHolder(view);
return new ExerciseViewHolder(view);
}

@Override
public void onBindViewHolder(SelectableViewHolder holder, int position) {
public void onBindViewHolder(ExerciseViewHolder holder, int position) {
try {
Exercise exercise = exercises.get(position);
String title = editWorkoutViewHelper.title(exercise);
String subtitle = editWorkoutViewHelper.subtitle(exercise);
String weight = editWorkoutViewHelper.weight(exercise);

holder.getTitleTextView().setText(title);
holder.getSubtitleTextView().setText(subtitle);
holder.getWeightTextView().setText(weight);
holder.setSelected(selections.contains(exercise));

holder.getView().setOnClickListener(view -> {
Expand Down Expand Up @@ -108,4 +111,17 @@ void removeSelections() {
selections.clear();
notifyDataSetChanged();
}

static class ExerciseViewHolder extends SelectableViewHolder {
private final TextView weightTextView;

public ExerciseViewHolder(View v) {
super(v);
weightTextView = v.findViewById(R.id.item_weight);
}

public TextView getWeightTextView() {
return weightTextView;
}
}
}
27 changes: 24 additions & 3 deletions src/main/res/layout/activity_edit_workout.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,30 @@
android:id="@+id/toolbar_workout_edit"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/primaryColor"
app:layout_collapseMode="pin"
app:titleTextColor="?android:textColorPrimaryInverse" />
android:theme="@style/AppTheme.ActionBar"
app:layout_collapseMode="pin">

<ImageButton
android:id="@+id/toolbar_cancel_action"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="start"
android:layout_marginEnd="30dp"
android:background="@color/primaryColor"
android:clickable="true"
android:contentDescription="@string/edit_exercise_toolbar_cancel"
android:focusable="true"
android:onClick="onCancelButtonClick"
android:src="@drawable/ic_action_close"
android:theme="@style/AppTheme.ActionBarButton" />

<TextView
style="@style/TextAppearance.AppCompat.Widget.ActionBar.Title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/edit_workout_toolbar_title"
android:textColor="@color/primaryTextColor" />
</android.support.v7.widget.Toolbar>

</android.support.design.widget.AppBarLayout>

Expand Down
7 changes: 3 additions & 4 deletions src/main/res/layout/fragment_edit_exercise.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,14 @@
card_view:cardElevation="2dp">

<android.support.design.widget.TextInputLayout
android:id="@+id/username_text_input_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<EditText
android:id="@+id/edit_text_exercise_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/edit_exercise_edt_text_hint"
android:hint="@string/edit_text_exercise_name_hint"
android:inputType="text" />
</android.support.design.widget.TextInputLayout>
</android.support.v7.widget.CardView>
Expand Down Expand Up @@ -56,7 +55,7 @@
android:layout_height="match_parent"
android:layout_gravity="center"
android:gravity="center"
android:text="@string/empty_set_list"
android:onClick="onAddSetButtonClick"/>
android:onClick="onAddSetButtonClick"
android:text="@string/empty_set_list" />
</android.support.v7.widget.CardView>
</LinearLayout>
67 changes: 47 additions & 20 deletions src/main/res/layout/fragment_edit_workout.xml
Original file line number Diff line number Diff line change
@@ -1,35 +1,62 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".presentation.edit.workout.ExerciseListFragment">

<EditText
android:id="@+id/edit_text_workout_name"
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content" />
android:layout_height="wrap_content"
android:layout_margin="8dp"
card_view:cardBackgroundColor="@color/cardsColor"
card_view:cardCornerRadius="2dp"
card_view:cardElevation="2dp">

<de.avalax.fitbuddy.presentation.welcome_screen.WorkoutRecyclerView
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="@dimen/shr_list_margin"
android:layout_marginRight="@dimen/shr_list_margin"
android:layout_marginBottom="54dp"
android:scrollbars="vertical"
app:layoutManager="GridLayoutManager"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
app:spanCount="@integer/list_columns" />
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">

<EditText
android:id="@+id/edit_text_workout_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/edit_text_workout_name_hint"
android:inputType="text" />
</android.support.design.widget.TextInputLayout>
</android.support.v7.widget.CardView>

<TextView
android:id="@android:id/empty"
style="?android:attr/textAppearanceMedium"
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:gravity="center"
android:text="@string/empty_exercise_list" />
android:layout_margin="8dp"
card_view:cardBackgroundColor="@color/cardsColor"
card_view:cardCornerRadius="2dp"
card_view:cardElevation="2dp">

<de.avalax.fitbuddy.presentation.welcome_screen.WorkoutRecyclerView
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="54dp"
android:layout_marginLeft="@dimen/shr_list_margin"
android:layout_marginRight="@dimen/shr_list_margin"
android:scrollbars="vertical"
app:layoutManager="GridLayoutManager"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
app:spanCount="@integer/list_columns" />

<TextView
android:id="@android:id/empty"
style="?android:attr/textAppearanceMedium"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:gravity="center"
android:onClick="onAddExerciseButtonClick"
android:text="@string/empty_exercise_list" />
</android.support.v7.widget.CardView>

</LinearLayout>
18 changes: 16 additions & 2 deletions src/main/res/layout/item_exercise.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="72dp"
android:paddingEnd="20dp"
android:paddingEnd="16dp"
android:paddingStart="16dp"
android:paddingTop="20dp">

Expand All @@ -22,4 +23,17 @@
android:text="@string/placeholder_subtitle"
android:textColor="?android:textColorSecondary"
android:textSize="14sp" />
</RelativeLayout>

<TextView
android:id="@+id/item_weight"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:text="@string/default_set_weight"
android:textColor="?android:textColorPrimary"
android:textSize="18sp"
tools:ignore="RelativeOverlap" />
</RelativeLayout>


Loading

0 comments on commit 76a64c3

Please sign in to comment.