Permalink
Browse files

show set details in summary

  • Loading branch information...
avalax committed Jan 3, 2018
1 parent d988c8a commit e69a8f8ca6d4367ea40b789c2a8bea77b881eb9f
View
@@ -19,6 +19,7 @@ allprojects {
repositories {
jcenter()
google()
maven { url "https://jitpack.io" }
}
}
@@ -96,8 +97,8 @@ dependencies {
implementation 'com.android.support:cardview-v7:26.1.0'
implementation 'com.android.support:recyclerview-v7:26.1.0'
implementation 'com.google.android.gms:play-services-ads:11.6.2'
implementation 'com.google.dagger:dagger:2.12'
implementation 'com.github.PhilJay:MPAndroidChart:v3.0.3'
annotationProcessor 'com.google.dagger:dagger-compiler:2.12'
androidTestAnnotationProcessor 'com.google.dagger:dagger-compiler:2.12'
View
BIN +496 Bytes (100%) doc/prototype.epgz
Binary file not shown.
View
Binary file not shown.
@@ -320,6 +320,22 @@ public void aFinishedWorkout_shouldBeDeleted() throws Exception {
application.hasShownAddNoFinishedWorkoutsHint();
}
@Test
public void aFinishedWorkout_shouldShowExerciseDetails() throws Exception {
BasicSetBuilder set = aSet().withWeight(42).withMaxReps(12);
BasicExerciseBuilder exercise = anExercise().withName("an exercise").withSet(set);
BasicWorkoutBuilder workout = aWorkout().withName("a workout").withExercise(exercise);
Workout persistedWorkout = persistence.addWorkout(workout);
persistence.finishWorkout(persistedWorkout);
activityRule.launchActivity(null);
application.switchToSummary();
application.selectFinishedWorkout(0);
application.showsFinishedExerciseDetail(0, "an exercise", "1 x 12");
}
@After
public void tearDown() throws Exception {
persistence.deleteWorkouts();
@@ -385,11 +385,12 @@ public void showsFinishedWorkoutDetail(String name, String created, String execu
onView(withId(R.id.finished_workout_executed)).check(matches(withText(executed)));
}
public void showsFinishedExerciseDetail(int position, String name) {
public void showsFinishedExerciseDetail(int position, String name, String sets) {
onView(withId(android.R.id.empty)).check(matches(not(isDisplayed())));
onView(withId(android.R.id.list))
.perform(RecyclerViewActions.scrollToPosition(position))
.check(matches(itemAtPosition(position, withText(name), R.id.item_title)));
.check(matches(itemAtPosition(position, withText(name), R.id.item_title)))
.check(matches(itemAtPosition(position, withText(sets), R.id.item_subtitle)));
}
private static ViewAction setNumberPicker(final int value) {
@@ -30,6 +30,7 @@
import de.avalax.fitbuddy.presentation.edit.exercise.EditExerciseViewHelper;
import de.avalax.fitbuddy.presentation.edit.workout.EditWorkoutViewHelper;
import de.avalax.fitbuddy.presentation.helper.ExerciseViewHelper;
import de.avalax.fitbuddy.presentation.summary.FinishedExerciseViewHelper;
import de.avalax.fitbuddy.presentation.summary.FinishedWorkoutViewHelper;
import de.avalax.fitbuddy.presentation.welcome_screen.WorkoutViewHelper;
@@ -102,6 +103,12 @@ FinishedWorkoutViewHelper provideFinishedWorkoutViewHelper(WorkoutViewHelper wor
return new FinishedWorkoutViewHelper(context, workoutViewHelper, workoutRepository);
}
@Provides
@Singleton
FinishedExerciseViewHelper provideFinishedExerciseViewHelper() {
return new FinishedExerciseViewHelper();
}
@Provides
@Singleton
EditExerciseViewHelper provideEditExerciseApplicationService() {
@@ -7,34 +7,92 @@
import android.view.ViewGroup;
import android.widget.TextView;
import com.github.mikephil.charting.charts.BarChart;
import com.github.mikephil.charting.data.BarData;
import com.github.mikephil.charting.data.BarDataSet;
import com.github.mikephil.charting.data.BarEntry;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.formatter.IValueFormatter;
import com.github.mikephil.charting.utils.ViewPortHandler;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;
import de.avalax.fitbuddy.R;
import de.avalax.fitbuddy.domain.model.finished_exercise.FinishedExercise;
import de.avalax.fitbuddy.domain.model.finished_set.FinishedSet;
public class FinishedExerciseAdapter
extends RecyclerView.Adapter<FinishedExerciseAdapter.ExerciseViewHolder> {
private FinishedExerciseViewHelper finishedExerciseViewHelper;
private List<FinishedExercise> finishedExercises;
private Activity activity;
public FinishedExerciseAdapter(Activity activity, List<FinishedExercise> finishedExercises) {
public FinishedExerciseAdapter(Activity activity,
FinishedExerciseViewHelper finishedExerciseViewHelper,
List<FinishedExercise> finishedExercises) {
super();
this.activity = activity;
this.finishedExerciseViewHelper = finishedExerciseViewHelper;
this.finishedExercises = finishedExercises;
}
@Override
public void onBindViewHolder(ExerciseViewHolder holder, int position) {
FinishedExercise finishedExercise = finishedExercises.get(position);
String title = finishedExercise.getName();
holder.getTitleTextView().setText(title);
//TODO: FinishedExerciseViewHelper
holder.getSubtitleTextView().setText(finishedExerciseViewHelper.subtitle(finishedExercise));
BarData barData = getBarData(finishedExercise);
holder.getBarChart().setData(barData);
holder.getBarChart().getAxisLeft().setAxisMinimum(0);
holder.getBarChart().getAxisLeft().setAxisMaximum(getMaxReps(finishedExercise));
holder.getBarChart().invalidate();
}
private int getMaxReps(FinishedExercise finishedExercise) {
int maxReps = 0;
for (FinishedSet set : finishedExercise.getSets()) {
if (set.getMaxReps() > maxReps) {
maxReps = set.getMaxReps();
}
}
return maxReps;
}
@Override
public ExerciseViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
LayoutInflater inflater = LayoutInflater.from(activity);
View view = inflater.inflate(R.layout.card_finished_exercise, parent, false);
return new ExerciseViewHolder(view);
}
@Override
public void onBindViewHolder(ExerciseViewHolder holder, int position) {
FinishedExercise finishedExercise = finishedExercises.get(position);
String title = finishedExercise.getName();
holder.getTitleTextView().setText(title);
private BarData getBarData(FinishedExercise finishedExercise) {
List<FinishedSet> sets = finishedExercise.getSets();
List<BarEntry> entries = new ArrayList<>();
for (int i = 0; i < sets.size(); i++) {
int reps = sets.get(i).getReps();
int maxReps = sets.get(i).getMaxReps();
int openReps = maxReps - reps;
entries.add(new BarEntry(i, new float[]{reps, openReps}));
}
BarDataSet set = new BarDataSet(entries, "sets");
int textColor = activity.getResources().getColor(R.color.primaryTextColor);
set.setValueTextColor(textColor);
set.setValueTextSize(12);
set.setColors(getColors());
BarData barData = new BarData(set);
barData.setValueFormatter(new ZeroValueFormatter());
return barData;
}
private int[] getColors() {
return new int[]{
activity.getResources().getColor(R.color.primaryColor),
activity.getResources().getColor(R.color.secondaryColor)
};
}
@Override
@@ -49,14 +107,72 @@ public int getItemCount() {
static class ExerciseViewHolder extends RecyclerView.ViewHolder {
private final TextView titleTextView;
private final BarChart barChart;
private final TextView subtitleTextView;
ExerciseViewHolder(View v) {
super(v);
titleTextView = v.findViewById(R.id.item_title);
subtitleTextView = v.findViewById(R.id.item_subtitle);
barChart = v.findViewById(R.id.item_chart);
int backgroundColor = v.getResources().getColor(R.color.appBarColor);
initBarChart(backgroundColor);
}
private void initBarChart(int backgroundColor) {
barChart.setFitBars(true);
barChart.getLegend().setEnabled(false);
barChart.getDescription().setEnabled(false);
barChart.setDrawBarShadow(false);
barChart.setDrawValueAboveBar(false);
barChart.setHighlightFullBarEnabled(false);
barChart.setFocusable(false);
barChart.setDragEnabled(false);
barChart.setHighlightPerDragEnabled(false);
barChart.setHighlightPerTapEnabled(false);
barChart.setTouchEnabled(false);
barChart.setClickable(false);
barChart.setMinOffset(0);
barChart.setBackgroundColor(backgroundColor);
barChart.getAxisLeft().setEnabled(false);
barChart.getAxisRight().setEnabled(false);
barChart.getAxisRight().setLabelCount(2);
barChart.getXAxis().setEnabled(false);
barChart.setAutoScaleMinMaxEnabled(true);
}
TextView getTitleTextView() {
return titleTextView;
}
BarChart getBarChart() {
return barChart;
}
public TextView getSubtitleTextView() {
return subtitleTextView;
}
}
private class ZeroValueFormatter implements IValueFormatter {
private DecimalFormat mFormat;
ZeroValueFormatter() {
mFormat = new DecimalFormat("###.###");
}
@Override
public String getFormattedValue(
float value,
Entry entry,
int dataSetIndex,
ViewPortHandler viewPortHandler) {
if (value > 0) {
return mFormat.format(value);
} else {
return "";
}
}
}
}
@@ -0,0 +1,26 @@
package de.avalax.fitbuddy.presentation.summary;
import java.util.LinkedHashSet;
import de.avalax.fitbuddy.domain.model.finished_exercise.FinishedExercise;
import de.avalax.fitbuddy.domain.model.finished_set.FinishedSet;
import static android.text.TextUtils.join;
public class FinishedExerciseViewHelper {
public String subtitle(FinishedExercise exercise) {
java.util.Set<Integer> reps = repsFromExercise(exercise);
if (reps.size() == 1) {
return exercise.getSets().size() + " x " + reps.iterator().next();
}
return join(" - ", reps);
}
private java.util.Set<Integer> repsFromExercise(FinishedExercise exercise) {
java.util.Set<Integer> reps = new LinkedHashSet<>();
for (FinishedSet set : exercise.getSets()) {
reps.add(set.getMaxReps());
}
return reps;
}
}
@@ -25,6 +25,9 @@
@Inject
FinishedWorkoutViewHelper finishedWorkoutViewHelper;
@Inject
FinishedExerciseViewHelper finishedExerciseViewHelper;
private TextView createdTextView;
private TextView executedTextView;
private FinishedWorkout finishedWorkout;
@@ -43,7 +46,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
recyclerView.setEmptyView(view.findViewById(android.R.id.empty));
RecyclerView.Adapter adapter =
new FinishedExerciseAdapter(getActivity(), finishedWorkout.getFinishedExercises());
new FinishedExerciseAdapter(getActivity(), finishedExerciseViewHelper, finishedWorkout.getFinishedExercises());
recyclerView.setAdapter(adapter);
return view;
}
@@ -3,7 +3,7 @@
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/card"
android:layout_width="match_parent"
android:layout_height="120dp"
android:layout_height="300dp"
android:layout_margin="8dp"
card_view:cardBackgroundColor="@color/cardsColor"
card_view:cardCornerRadius="2dp"
@@ -19,11 +19,32 @@
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginTop="24dp"
android:hint="@string/placeholder_title"
android:textColor="?android:textColorPrimary"
android:textSize="14sp"
tools:ignore="RelativeOverlap" />
<TextView
android:layout_marginEnd="16dp"
android:layout_marginStart="16dp"
android:layout_marginBottom="16dp"
android:id="@+id/item_subtitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/item_title"
android:hint="@string/placeholder_subtitle"
android:textColor="?android:textColorSecondary"
android:textSize="14sp" />
<com.github.mikephil.charting.charts.BarChart
android:id="@+id/item_chart"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/item_subtitle"
android:layout_marginEnd="16dp"
android:layout_marginStart="16dp"
android:layout_marginBottom="24dp"/>
</RelativeLayout>
</android.support.v7.widget.CardView>
@@ -4,7 +4,9 @@
android:id="@+id/card"
android:layout_width="match_parent"
android:layout_height="120dp"
android:layout_margin="8dp"
android:layout_marginEnd="2dp"
android:layout_marginStart="2dp"
android:layout_marginTop="16dp"
card_view:cardBackgroundColor="@color/cardsColor"
card_view:cardCornerRadius="2dp"
card_view:cardElevation="2dp">
Oops, something went wrong.

0 comments on commit e69a8f8

Please sign in to comment.