Skip to content

Commit

Permalink
Styling for edit sets
Browse files Browse the repository at this point in the history
  • Loading branch information
avalax committed Dec 18, 2017
1 parent 76a64c3 commit baf24bb
Show file tree
Hide file tree
Showing 7 changed files with 102 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public void newWorkout_shouldBeDisplayed() throws Exception {
application.hasShownAddNewSetHint();

application.addSet("15", "42.5");
application.hasShownSetDetails("15", "42.5");
application.hasShownSetDetails("15 reps", "42.5 kg");

application.saveSet();
application.hasShownSetAddedToExercise("15 reps", "42.5 kg");
Expand Down Expand Up @@ -90,7 +90,7 @@ public void existingWorkout_shouldDisplayChanges() throws Exception {
application.changeExercise("new exercise");

application.editSet(0);
application.hasShownOldSetDetails("15", "42.5");
application.hasShownOldSetDetails("15 reps", "42.5 kg");
application.changeSet("12", "47.5");

application.saveSet();
Expand Down Expand Up @@ -142,7 +142,7 @@ public void existingWorkout_shouldNotSaveWorkoutOnBack() throws Exception {
}

@Test
public void existingWorkout_shouldNotSaveExerciseOnBack() throws Exception {
public void existingExercise_shouldNotSaveExerciseOnBack() throws Exception {
BasicSetBuilder set = aSet().withMaxReps(12).withWeight(0);
BasicExerciseBuilder exercise = anExercise().withName("old exercise name").withSet(set);
BasicWorkoutBuilder workout = aWorkout().withExercise(exercise);
Expand All @@ -157,6 +157,23 @@ public void existingWorkout_shouldNotSaveExerciseOnBack() throws Exception {
application.hasShownExerciseDetails("old exercise name", "1 x 12", "no weight");
}

@Test
public void existingSet_shouldNotSaveExerciseOnBack() throws Exception {
BasicSetBuilder set = aSet().withMaxReps(12).withWeight(0);
BasicExerciseBuilder exercise = anExercise().withSet(set);
BasicWorkoutBuilder workout = aWorkout().withExercise(exercise);
persistence.addWorkout(workout);
activityRule.launchActivity(null);
application.editWorkout(0);
application.editExercise(0);

application.editSet(0);
application.changeSet("15", "100.0");
application.cancelAction();

application.hasShownSetAddedToExercise("12 reps", "no weight");
}

@Test
public void existingWorkout_shouldNotSaveWorkoutWithoutExercises() throws Exception {
BasicWorkoutBuilder workout = aWorkout().withExercise(anExercise()).withExercise(anExercise());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import dagger.Component;
import de.avalax.fitbuddy.presentation.edit.exercise.SetListFragment;
import de.avalax.fitbuddy.presentation.edit.set.EditSetActivity;
import de.avalax.fitbuddy.presentation.edit.set.EditSetFragment;
import de.avalax.fitbuddy.presentation.edit.workout.EditWorkoutActivity;
import de.avalax.fitbuddy.presentation.edit.workout.ExerciseListFragment;
Expand Down Expand Up @@ -54,5 +55,7 @@ public interface ApplicationComponent {
void inject(EditSetFragment editSetFragment);

void inject(FinishedWorkoutDetailFragment finishedWorkoutDetailFragment);

void inject(EditSetActivity editSetActivity);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,17 @@
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.TextView;

import javax.inject.Inject;

import de.avalax.fitbuddy.R;
import de.avalax.fitbuddy.domain.model.set.Set;
import de.avalax.fitbuddy.presentation.FitbuddyApplication;
import de.avalax.fitbuddy.presentation.dialog.EditRepsDialogFragment;
import de.avalax.fitbuddy.presentation.dialog.EditWeightDialogFragment;

import static java.lang.Double.parseDouble;
import static java.lang.Integer.parseInt;
import static java.lang.String.valueOf;
import de.avalax.fitbuddy.presentation.edit.exercise.EditExerciseViewHelper;

public class EditSetActivity extends AppCompatActivity implements
EditWeightDialogFragment.DialogListener,
Expand All @@ -25,13 +26,18 @@ public class EditSetActivity extends AppCompatActivity implements
private TextView repsTextView;
private Set set;

@Inject
protected EditExerciseViewHelper editExerciseViewHelper;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_edit_set);
((FitbuddyApplication) getApplication()).getComponent().inject(this);

Toolbar toolbar = findViewById(R.id.toolbar_set_edit);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayShowTitleEnabled(false);
set = (Set) getIntent().getSerializableExtra("set");
repsTextView = findViewById(R.id.set_reps_text_view);
weightTextView = findViewById(R.id.set_weight_text_view);
Expand All @@ -48,8 +54,6 @@ public boolean onCreateOptionsMenu(Menu menu) {
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == R.id.toolbar_save_set) {
Intent intent = new Intent();
set.setMaxReps(parseInt(repsTextView.getText().toString()));
set.setWeight(parseDouble(weightTextView.getText().toString()));
int position = getIntent().getIntExtra("position", -1);
intent.putExtra("position", position);
intent.putExtra("set", set);
Expand All @@ -63,12 +67,19 @@ public boolean onOptionsItemSelected(MenuItem item) {
@Override
public void onDialogPositiveClick(EditRepsDialogFragment editRepsDialogFragment) {
int reps = editRepsDialogFragment.getReps();
repsTextView.setText(valueOf(reps));
set.setMaxReps(reps);
repsTextView.setText(editExerciseViewHelper.title(set));
}

@Override
public void onDialogPositiveClick(EditWeightDialogFragment editWeightDialogFragment) {
double weight = editWeightDialogFragment.getWeight();
weightTextView.setText(valueOf(weight));
set.setWeight(weight);
weightTextView.setText(editExerciseViewHelper.subtitle(set));
}

public void onCancelButtonClick(View view) {
setResult(RESULT_CANCELED);
finish();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
view.findViewById(R.id.set_reps).setOnClickListener(v -> changeMaxReps());
set = (Set) getActivity().getIntent().getSerializableExtra("set");
TextView repsTextView = view.findViewById(R.id.set_reps_text_view);
repsTextView.setText(editExerciseViewHelper.titleValue(set));
repsTextView.setText(editExerciseViewHelper.title(set));
TextView weightTextView = view.findViewById(R.id.set_weight_text_view);
weightTextView.setText(editExerciseViewHelper.subtitleValue(set));
weightTextView.setText(editExerciseViewHelper.subtitle(set));
return view;
}

Expand Down
27 changes: 24 additions & 3 deletions src/main/res/layout/activity_edit_set.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,30 @@
android:id="@+id/toolbar_set_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_set_toolbar_title"
android:textColor="@color/primaryTextColor" />
</android.support.v7.widget.Toolbar>

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

Expand Down
51 changes: 33 additions & 18 deletions src/main/res/layout/fragment_edit_set.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,60 +8,75 @@
<RelativeLayout
android:id="@+id/set_reps"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_height="72dp"
android:background="?android:attr/selectableItemBackground"
android:paddingTop="6dp"
android:paddingBottom="4dp"
android:clickable="true"
android:focusable="true">
android:focusable="true"
android:paddingEnd="16dp"
android:paddingStart="16dp"
android:paddingTop="20dp">

<TextView
android:id="@+id/set_reps_label_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:fadingEdge="horizontal"
android:singleLine="true"
android:text="@string/label_exercise_repetitions"
android:textAppearance="?android:attr/textAppearanceLarge"
android:singleLine="true" />
android:textColor="?android:textColorPrimary"
android:textSize="16sp" />

<TextView
android:id="@+id/set_reps_text_view"
android:layout_width="fill_parent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/set_reps_label_text_view"
android:text="@string/default_set_reps"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="?android:attr/textColorSecondary"/>
android:textColor="?android:textColorSecondary"
android:textSize="14sp" />
</RelativeLayout>

<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#1f000000" />

<RelativeLayout
android:id="@+id/set_weight"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="6dp"
android:paddingBottom="4dp"
android:layout_height="72dp"
android:background="?android:attr/selectableItemBackground"
android:clickable="true"
android:focusable="true">
android:focusable="true"
android:paddingEnd="16dp"
android:paddingStart="16dp"
android:paddingTop="20dp">

<TextView
android:id="@+id/set_weight_label_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:fadingEdge="horizontal"
android:singleLine="true"
android:text="@string/label_exercise_weight"
android:textAppearance="?android:attr/textAppearanceLarge"
android:singleLine="true" />
android:textColor="?android:textColorPrimary"
android:textSize="16sp" />

<TextView
android:id="@+id/set_weight_text_view"
android:layout_width="fill_parent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/set_weight_label_text_view"
android:text="@string/default_set_weight"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="?android:attr/textColorSecondary"/>
android:textColor="?android:textColorSecondary"
android:textSize="14sp" />
</RelativeLayout>

<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#1f000000" />

</LinearLayout>
1 change: 1 addition & 0 deletions src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,5 @@
<string name="edit_text_workout_name_hint">Name</string>
<string name="reps_suffix">reps</string>
<string name="weight_suffix">kg</string>
<string name="edit_set_toolbar_title">Edit set</string>
</resources>

0 comments on commit baf24bb

Please sign in to comment.