Skip to content

Commit

Permalink
Visual Notification for workout selection
Browse files Browse the repository at this point in the history
  • Loading branch information
avalax committed Dec 6, 2017
1 parent 2f7d123 commit adaf407
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package de.avalax.fitbuddy.presentation.welcome_screen;

import android.support.v7.widget.CardView;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
Expand All @@ -17,6 +18,7 @@ public class WorkoutAdapter extends RecyclerView.Adapter<WorkoutAdapter.ViewHold
private EditWorkoutApplicationService workoutSession;
private List<Workout> workouts;
private MainActivity activity;
private int selectedPosition = RecyclerView.NO_POSITION;

WorkoutAdapter(MainActivity activity, EditWorkoutApplicationService workoutSession, List<Workout> workouts) {
super();
Expand All @@ -37,6 +39,7 @@ public void onBindViewHolder(WorkoutAdapter.ViewHolder holder, int position) {
Workout workout = workouts.get(position);
holder.getTitleTextView().setText(workout.getName());
holder.getSubtitleTextView().setText("Executed 0 times");
holder.setSelected(selectedPosition == position);
if (workoutSession.isActiveWorkout(workout)) {
holder.getStatusTextView().setText(R.string.workout_active);
} else {
Expand All @@ -46,6 +49,13 @@ public void onBindViewHolder(WorkoutAdapter.ViewHolder holder, int position) {
activity.selectWorkout(workout);
});
holder.getView().setOnLongClickListener(view -> {
int oldSelectedPosition = selectedPosition;
selectedPosition = position;
if (oldSelectedPosition != RecyclerView.NO_POSITION) {
notifyItemChanged(oldSelectedPosition);
}
notifyItemChanged(position);

activity.updateEditToolbar(position, workout);
return true;
});
Expand All @@ -66,9 +76,11 @@ static class ViewHolder extends RecyclerView.ViewHolder {
private final TextView dateTextView;
private final TextView subtitleTextView;
private final TextView statusTextView;
private final CardView cardView;

ViewHolder(View v) {
super(v);
cardView = v.findViewById(R.id.card);
titleTextView = v.findViewById(R.id.card_title);
subtitleTextView = v.findViewById(R.id.card_subtitle);
dateTextView = v.findViewById(R.id.card_date);
Expand All @@ -94,5 +106,14 @@ public View getView() {
public TextView getStatusTextView() {
return statusTextView;
}


public void setSelected(boolean selected) {
int backgroundColor = itemView.getResources().getColor(R.color.cardsColor);
if (selected) {
backgroundColor = itemView.getResources().getColor(R.color.primaryLightColor);
}
cardView.setCardBackgroundColor(backgroundColor);
}
}
}
5 changes: 3 additions & 2 deletions src/main/res/layout/card_workout.xml
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/card"
android:layout_width="match_parent"
android:layout_height="120dp"
android:layout_margin="8dp"
card_view:cardBackgroundColor="@color/cardsColor"
card_view:cardCornerRadius="2dp"
card_view:cardElevation="2dp"
android:layout_margin="8dp">
card_view:cardElevation="2dp">

<RelativeLayout
android:layout_width="match_parent"
Expand Down

0 comments on commit adaf407

Please sign in to comment.