Skip to content

Commit

Permalink
Merge pull request #20 from Bobbelty/copyifSomethinghappens
Browse files Browse the repository at this point in the history
UI done
  • Loading branch information
Bobbelty authored Oct 24, 2021
2 parents ad9e6a0 + 34a1d3a commit 75218ad
Show file tree
Hide file tree
Showing 23 changed files with 339 additions and 95 deletions.
10 changes: 10 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,16 @@
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".view.HistoryExercisesActivity"
android:exported="true"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,15 @@
public class EditScheduleRecyclerViewAdapter extends RecyclerView.Adapter<EditScheduleRecyclerViewAdapter.ListViewHolder> {


private Activity activity;
private Workout selectedWorkout;
private Plan selectedPlan;
private EditWorkoutViewModel editWorkoutViewModel = EditWorkoutViewModel.getInstance();

/**
* Constructor for adapter
*
* @param activity the current activity
*/
public EditScheduleRecyclerViewAdapter(Activity activity) {
public EditScheduleRecyclerViewAdapter() {
this.selectedWorkout = editWorkoutViewModel.getSelectedWorkout();
this.activity = activity;
this.selectedPlan = editWorkoutViewModel.getSelectedPlan();
}

Expand Down Expand Up @@ -126,7 +122,6 @@ public int getItemCount() {

static class ListViewHolder extends RecyclerView.ViewHolder{


private final EditText etbxExerciseName;
private final EditText etbxNoOfSets;
private final EditText etbxNoOfReps;
Expand All @@ -140,7 +135,6 @@ static class ListViewHolder extends RecyclerView.ViewHolder{
public ListViewHolder(@NonNull View itemView) {
super(itemView);


etbxExerciseName = itemView.findViewById(R.id.etbxExerciseName);
etbxNoOfSets = itemView.findViewById(R.id.etbxNoOfReps);
etbxNoOfReps = itemView.findViewById(R.id.etbxWeight);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,16 @@
public class EditWorkoutRecyclerViewAdapter extends RecyclerView.Adapter<EditWorkoutRecyclerViewAdapter.ListViewHolder> {


private Activity activity;
private Plan selectedPlan;
private EditWorkoutViewModel editWorkoutViewModel = EditWorkoutViewModel.getInstance();
private Workout selectedWorkout;
private ActiveWorkout activeWorkout;

/**
* Constructor for adapter
*
* @param activity the current activity
*/
public EditWorkoutRecyclerViewAdapter(Activity activity) {
public EditWorkoutRecyclerViewAdapter() {
this.selectedWorkout = editWorkoutViewModel.getSelectedWorkout();
this.activity = activity;
this.selectedPlan = editWorkoutViewModel.getSelectedPlan();
editWorkoutViewModel.createActiveWorkout(selectedPlan.getId(), selectedWorkout.getId());
this.activeWorkout = editWorkoutViewModel.getActiveWorkout();
Expand All @@ -63,7 +59,15 @@ public ListViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType
*/
@Override
public void onBindViewHolder(@NonNull ListViewHolder holder, @SuppressLint("RecyclerView") int position) {
holder.lblWorkoutExerciseName.setText(activeWorkout.getExercise(position).getName());
holder.lblWorkoutExerciseName.setText("");
if (position > 0) {
if (!(activeWorkout.getExercise(position).getName().equals(activeWorkout.getExercise(position-1).getName()))) {
holder.lblWorkoutExerciseName.setText(activeWorkout.getExercise(position).getName());
}
}
else {
holder.lblWorkoutExerciseName.setText(activeWorkout.getExercise(position).getName());
}
holder.etbxNoOfReps.setText(activeWorkout.getExercise(position).getNoOfReps() + "");
holder.etbxWeight.setText(0 + "");

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package com.example.trainingapp.view.Adapter;

import android.annotation.SuppressLint;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.trainingapp.R;
import com.example.trainingapp.model.activeComponents.ActiveWorkout;


public class HistoryExercisesRecyclerViewAdapter extends RecyclerView.Adapter<HistoryExercisesRecyclerViewAdapter.ListViewHolder>{

private ActiveWorkout selectedWorkout;

public HistoryExercisesRecyclerViewAdapter(ActiveWorkout selectedWorkout) {
this.selectedWorkout = selectedWorkout;
}

@NonNull
@Override
public ListViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {

return new HistoryExercisesRecyclerViewAdapter.ListViewHolder(LayoutInflater.from(parent.getContext())
.inflate(R.layout.fragment_exercise_history_list_item, parent, false));

}

@Override
public void onBindViewHolder(@NonNull ListViewHolder holder, @SuppressLint("RecyclerView") int position) {
if (position > 0) {
if (!(selectedWorkout.getExercise(position).getName().equals(selectedWorkout.getExercise(position-1).getName()))) {
holder.lblViewExerciseName.setText(selectedWorkout.getExercise(position).getName() + "");
}
}
else {
holder.lblViewExerciseName.setText(selectedWorkout.getExercise(position).getName() + "");
}
holder.lblViewExerciseReps.setText(selectedWorkout.getExercise(position).getNoOfReps() + "");
holder.lblViewExerciseWeight.setText(selectedWorkout.getExercise(position).getWeights() + "");
}

@Override
public int getItemCount() { return selectedWorkout.getExerciseList().size(); }

static class ListViewHolder extends RecyclerView.ViewHolder{

private final TextView lblViewExerciseName;
private final TextView lblViewExerciseReps;
private final TextView lblViewExerciseWeight;

public ListViewHolder(@NonNull View itemView) {
super(itemView);
lblViewExerciseName = itemView.findViewById(R.id.lblViewExerciseName);
lblViewExerciseReps = itemView.findViewById(R.id.lblViewExerciseReps);
lblViewExerciseWeight = itemView.findViewById(R.id.lblViewExerciseWeight);

}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;

import java.util.List;
Expand All @@ -15,6 +17,9 @@

import com.example.trainingapp.R;
import com.example.trainingapp.model.activeComponents.ActiveWorkout;
import com.example.trainingapp.view.EditScheduleActivity;
import com.example.trainingapp.view.HistoryExercisesActivity;
import com.example.trainingapp.viewModel.HistoryViewModel;

/**
* Adapter for the RecyclerView in the HistoryActivity, provides the correct information for
Expand All @@ -25,6 +30,7 @@ public class HistoryRecyclerViewAdapter extends RecyclerView.Adapter<HistoryRecy
private List<ActiveWorkout> completedWorkouts;
private Context context;
private Activity activity;
private HistoryViewModel historyViewModel = HistoryViewModel.getInstance();

/**
* Constructor for adapter
Expand All @@ -45,6 +51,7 @@ public ListViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType

return new HistoryRecyclerViewAdapter.ListViewHolder(LayoutInflater.from(parent.getContext())
.inflate(R.layout.fragment_history_list_item, parent, false));

}

/**
Expand All @@ -56,9 +63,19 @@ public ListViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType
@Override
public void onBindViewHolder(@NonNull ListViewHolder holder, @SuppressLint("RecyclerView") int position) {


holder.lblActiveWorkoutName.setText(completedWorkouts.get(position).getName());
holder.lblActiveWorkoutDate.setText(completedWorkouts.get(position).getTime());
holder.btnViewExercises.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
historyViewModel.setSelectedWorkout(completedWorkouts.get(position));

activity.onBackPressed();
Intent openActivity = new Intent(context, HistoryExercisesActivity.class);
context.startActivity(openActivity);
}
});


}

Expand All @@ -69,6 +86,7 @@ static class ListViewHolder extends RecyclerView.ViewHolder{

private final TextView lblActiveWorkoutName;
private final TextView lblActiveWorkoutDate;
private final Button btnViewExercises;

/**
* Binds elements in layout file to the variables in the ViewHolder
Expand All @@ -79,6 +97,7 @@ public ListViewHolder(@NonNull View itemView) {
super(itemView);
lblActiveWorkoutName= itemView.findViewById(R.id.lblActiveWorkoutName);
lblActiveWorkoutDate = itemView.findViewById(R.id.lblActiveWorkoutDate);
btnViewExercises = itemView.findViewById(R.id.btnViewExercises);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ public ListViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType
public void onBindViewHolder(@NonNull ListViewHolder holder, @SuppressLint("RecyclerView") int position) {

holder.lblWorkoutName.setText(plan.getWorkoutList().get(position).getName());
// set list views
holder.btnEditWorkout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick (View v) {
Expand All @@ -85,7 +84,6 @@ public int getItemCount() {

static class ListViewHolder extends RecyclerView.ViewHolder{


private final TextView lblWorkoutName;
private final Button btnEditWorkout;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

import com.example.trainingapp.R;
import com.example.trainingapp.model.components.Plan;
import com.example.trainingapp.view.EditScheduleActivity;
import com.example.trainingapp.view.EditWorkoutActivity;
import com.example.trainingapp.viewModel.EditWorkoutViewModel;

Expand Down Expand Up @@ -71,7 +70,6 @@ public void onBindViewHolder(@NonNull ListViewHolder holder, @SuppressLint("Recy
holder.btnWorkout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick (View v) {
//editScheduleViewModel.setSelectedPlanId(plan.getId());

editWorkoutViewModel.setSelectedWorkout(plan.getWorkoutList().get(position));
editWorkoutViewModel.setSelectedPlan(plan);
Expand All @@ -90,7 +88,6 @@ public int getItemCount() {

static class ListViewHolder extends RecyclerView.ViewHolder{


private final TextView lblWorkoutName;
private final Button btnWorkout;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import androidx.appcompat.app.AppCompatActivity;

import com.example.trainingapp.R;
//import com.example.trainingapp.databinding.ActivityMainBinding;

/**
* Activity for editing the workouts in plans
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,10 @@
import androidx.recyclerview.widget.RecyclerView;

import com.example.trainingapp.R;
import com.example.trainingapp.model.components.Plan;
import com.example.trainingapp.model.components.Workout;
import com.example.trainingapp.view.Adapter.EditScheduleRecyclerViewAdapter;
import com.example.trainingapp.viewModel.EditWorkoutViewModel;

import java.util.ArrayList;
import java.util.List;

/**
* Fragment for editing the workouts in plans
*/
Expand All @@ -34,9 +30,7 @@ public class EditScheduleFragment extends Fragment {
private EditScheduleRecyclerViewAdapter recyclerViewAdapter;
private EditWorkoutViewModel editWorkoutViewModel = EditWorkoutViewModel.getInstance();

private List<Plan> testPlans = new ArrayList<>();

Plan plan;
/**
* onCreateView creates and returns the view hierarchy associated with the fragment.
*
Expand All @@ -53,7 +47,6 @@ public class EditScheduleFragment extends Fragment {
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {

View v = LayoutInflater.from(getContext()).inflate(R.layout.fragment_edit_schedule,container,false);
initObjects();
selectedWorkout = editWorkoutViewModel.getSelectedWorkout();
initTitleText(v);
initRecyclerView(v);
Expand All @@ -75,7 +68,7 @@ private void initAddExerciseButton(View v) {
@Override
public void onClick(View view) {
editWorkoutViewModel.addExerciseToWorkout(editWorkoutViewModel.getSelectedPlan().getId(), selectedWorkout.getId());
recyclerViewAdapter = new EditScheduleRecyclerViewAdapter(getActivity());
recyclerViewAdapter = new EditScheduleRecyclerViewAdapter();
recyclerView.setAdapter(recyclerViewAdapter);
}
});
Expand Down Expand Up @@ -136,10 +129,10 @@ public void onClick(DialogInterface dialogInterface, int i) {
* @param v the current view used in the application.
*/
private void initRecyclerView(View v) {
recyclerView = (RecyclerView) v.findViewById(R.id.editScheduleRecyclerView);
recyclerView = (RecyclerView) v.findViewById(R.id.HistoryExerciseRecyclerView);
recyclerView.setLayoutManager(new LinearLayoutManager(this.getContext()));

recyclerViewAdapter = new EditScheduleRecyclerViewAdapter(this.getActivity());
recyclerViewAdapter = new EditScheduleRecyclerViewAdapter();
recyclerView.setAdapter(recyclerViewAdapter);
}

Expand All @@ -165,13 +158,4 @@ public void onFocusChange(View view, boolean b) {
}
});
}

/**
* initObjects gets the saved plans, used for testing and initial demo/presentation.
*/
private void initObjects() {
// setting up test objects
testPlans = editWorkoutViewModel.getSavedPlans();
plan = testPlans.get(0); // get active plan instead
}
}
Loading

0 comments on commit 75218ad

Please sign in to comment.