-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
192 additions
and
127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
src/main/java/de/avalax/fitbuddy/presentation/edit/workout/EditWorkoutFragment.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package de.avalax.fitbuddy.presentation.edit.workout; | ||
|
||
import android.arch.lifecycle.ViewModelProviders; | ||
import android.databinding.DataBindingUtil; | ||
import android.os.Bundle; | ||
import android.support.annotation.NonNull; | ||
import android.support.annotation.Nullable; | ||
import android.support.v4.app.Fragment; | ||
import android.support.v7.widget.DividerItemDecoration; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
|
||
import de.avalax.fitbuddy.R; | ||
import de.avalax.fitbuddy.databinding.EditWorkoutBinding; | ||
import de.avalax.fitbuddy.domain.model.workout.Workout; | ||
|
||
import static android.support.v7.widget.DividerItemDecoration.VERTICAL; | ||
|
||
public class EditWorkoutFragment extends Fragment { | ||
|
||
private static final String KEY_WORKOUT = "workout"; | ||
private EditWorkoutViewModel viewModel; | ||
private EditWorkoutBinding binding; | ||
|
||
public static EditWorkoutFragment forWorkout(Workout workout) { | ||
EditWorkoutFragment fragment = new EditWorkoutFragment(); | ||
Bundle bundle = new Bundle(); | ||
bundle.putSerializable(KEY_WORKOUT, workout); | ||
fragment.setArguments(bundle); | ||
return fragment; | ||
} | ||
|
||
@Override | ||
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, | ||
Bundle savedInstanceState) { | ||
binding = DataBindingUtil.inflate(inflater, R.layout.edit_workout, container, false); | ||
viewModel = ViewModelProviders.of(getActivity()).get(EditWorkoutViewModel.class); | ||
binding.setEditWorkoutViewModel(viewModel); | ||
binding.setLifecycleOwner(this); | ||
|
||
binding.list.setEmptyView(binding.getRoot().findViewById(android.R.id.empty)); | ||
binding.list.addItemDecoration(new DividerItemDecoration(getActivity(), VERTICAL)); | ||
|
||
return binding.getRoot(); | ||
} | ||
|
||
@Override | ||
public void onActivityCreated(@Nullable Bundle savedInstanceState) { | ||
super.onActivityCreated(savedInstanceState); | ||
Workout workout = (Workout) getArguments().getSerializable(KEY_WORKOUT); | ||
viewModel.init(getActivity(), workout); | ||
binding.list.setAdapter(viewModel.getExerciseAdapter()); | ||
} | ||
|
||
public void notifyItemInserted() { | ||
viewModel.getExerciseAdapter().notifyItemInserted(viewModel.getExerciseAdapter().getItemCount() - 1); | ||
binding.list.updateEmptyView(); | ||
} | ||
|
||
public void notifyItemChanged(int position) { | ||
viewModel.getExerciseAdapter().notifyItemChanged(position); | ||
binding.list.updateEmptyView(); | ||
} | ||
|
||
public void removeSelections() { | ||
viewModel.getExerciseAdapter().removeSelections(); | ||
binding.list.updateEmptyView(); | ||
((EditWorkoutActivity) getActivity()).updateToolbar(0); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
src/main/java/de/avalax/fitbuddy/presentation/edit/workout/EditWorkoutViewModel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package de.avalax.fitbuddy.presentation.edit.workout; | ||
|
||
import android.app.Activity; | ||
import android.arch.lifecycle.ViewModel; | ||
|
||
import de.avalax.fitbuddy.domain.model.workout.Workout; | ||
|
||
public class EditWorkoutViewModel extends ViewModel { | ||
private ExerciseAdapter exerciseAdapter; | ||
private Workout workout; | ||
|
||
public void init(Activity activity, Workout workout) { | ||
exerciseAdapter = new ExerciseAdapter(activity, workout.getExercises()); | ||
this.workout = workout; | ||
} | ||
|
||
public ExerciseAdapter getExerciseAdapter() { | ||
return exerciseAdapter; | ||
} | ||
|
||
public String getName() { | ||
return workout.getName(); | ||
} | ||
} |
52 changes: 0 additions & 52 deletions
52
src/main/java/de/avalax/fitbuddy/presentation/edit/workout/ExerciseListFragment.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<layout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto"> | ||
|
||
<data> | ||
<variable | ||
name="editWorkoutViewModel" | ||
type="de.avalax.fitbuddy.presentation.edit.workout.EditWorkoutViewModel" /> | ||
</data> | ||
|
||
<LinearLayout | ||
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.EditWorkoutActivity"> | ||
|
||
<android.support.v7.widget.CardView | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:layout_margin="8dp" | ||
card_view:cardBackgroundColor="@color/cardsColor" | ||
card_view:cardCornerRadius="2dp" | ||
card_view:cardElevation="2dp"> | ||
|
||
<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:text="@{editWorkoutViewModel.name}"/> | ||
</android.support.design.widget.TextInputLayout> | ||
</android.support.v7.widget.CardView> | ||
|
||
<android.support.v7.widget.CardView | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
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> | ||
</layout> |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.