Permalink
Browse files

Refactoring

  • Loading branch information...
avalax committed Jun 20, 2018
1 parent c22ac97 commit e33fe56a7737a5b9ea1bca3f136a031036dcea04
@@ -27,7 +27,7 @@
import static de.avalax.fitbuddy.presentation.FitbuddyApplication.ADD_SET;
import static de.avalax.fitbuddy.presentation.FitbuddyApplication.EDIT_SET;
public class EditExerciseFragment extends Fragment {
public class EditExerciseFragment extends Fragment implements SetViewHolderCallback {
private static final String KEY_EXERCISE = "exercise";
private EditExerciseViewModel viewModel;
@@ -47,26 +47,7 @@ public static EditExerciseFragment forExercise(Exercise exercise) {
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
viewModel = ViewModelProviders.of(getActivity()).get(EditExerciseViewModel.class);
setAdapter = new SetAdapter(new SetViewHolderCallback() {
@Override
public void onItemClick(View view, int position) {
try {
Set set = exercise.getSets().get(position);
Intent intent = new Intent(getActivity(), EditSetActivity.class);
intent.putExtra("set", set);
intent.putExtra("position", position);
getActivity().startActivityForResult(intent, EDIT_SET);
} catch (SetException e) {
Log.e("SetException", e.getMessage(), e);
}
}
@Override
public void onSelectionChange(int size) {
((EditExerciseActivity) getActivity()).onSelectionChange(size);
}
});
setAdapter = new SetAdapter(this);
binding = DataBindingUtil.inflate(inflater, R.layout.edit_exercise, container, false);
binding.setEditExerciseViewModel(viewModel);
binding.setLifecycleOwner(this);
@@ -123,4 +104,22 @@ public void removeSelections() {
((EditExerciseActivity) getActivity()).onSelectionChange(0);
}
@Override
public void onItemClick(View view, int position) {
try {
Set set = exercise.getSets().get(position);
Intent intent = new Intent(getActivity(), EditSetActivity.class);
intent.putExtra("set", set);
intent.putExtra("position", position);
getActivity().startActivityForResult(intent, EDIT_SET);
} catch (SetException e) {
Log.e("SetException", e.getMessage(), e);
}
}
@Override
public void onSelectionChange(int size) {
((EditExerciseActivity) getActivity()).onSelectionChange(size);
}
}
@@ -29,7 +29,7 @@
import static de.avalax.fitbuddy.presentation.FitbuddyApplication.EDIT_EXERCISE;
import static de.avalax.fitbuddy.presentation.edit.workout.ExerciseAdapter.ExerciseViewHolderCallback;
public class EditWorkoutFragment extends Fragment {
public class EditWorkoutFragment extends Fragment implements ExerciseViewHolderCallback {
private static final String KEY_WORKOUT = "workout";
private EditWorkoutViewModel viewModel;
@@ -49,25 +49,7 @@ public static EditWorkoutFragment forWorkout(Workout workout) {
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
viewModel = ViewModelProviders.of(getActivity()).get(EditWorkoutViewModel.class);
exerciseAdapter = new ExerciseAdapter(new ExerciseViewHolderCallback() {
@Override
public void onItemClick(View view, int position) {
try {
Exercise exercise = workout.getExercises().get(position);
Intent intent = new Intent(getActivity(), EditExerciseActivity.class);
intent.putExtra("exercise", exercise);
intent.putExtra("position", position);
getActivity().startActivityForResult(intent, EDIT_EXERCISE);
} catch (ExerciseException e) {
Log.e("ExerciseException", e.getMessage(), e);
}
}
@Override
public void onSelectionChange(int size) {
((EditWorkoutActivity) getActivity()).onSelectionChange(size);
}
});
exerciseAdapter = new ExerciseAdapter(this);
binding = DataBindingUtil.inflate(inflater, R.layout.edit_workout, container, false);
binding.setEditWorkoutViewModel(viewModel);
binding.setLifecycleOwner(this);
@@ -123,4 +105,21 @@ private void removeSelections() {
((EditWorkoutActivity) getActivity()).onSelectionChange(0);
}
@Override
public void onItemClick(View view, int position) {
try {
Exercise exercise = workout.getExercises().get(position);
Intent intent = new Intent(getActivity(), EditExerciseActivity.class);
intent.putExtra("exercise", exercise);
intent.putExtra("position", position);
getActivity().startActivityForResult(intent, EDIT_EXERCISE);
} catch (ExerciseException e) {
Log.e("ExerciseException", e.getMessage(), e);
}
}
@Override
public void onSelectionChange(int size) {
((EditWorkoutActivity) getActivity()).onSelectionChange(size);
}
}

0 comments on commit e33fe56

Please sign in to comment.