diff --git a/app/src/main/java/be/lepl1509group13/workoutwarrior/ProgramDetailActivity.java b/app/src/main/java/be/lepl1509group13/workoutwarrior/ProgramDetailActivity.java index 01810455af67658aa2ea5f73786a4565cee2c802..e438158f55b11d7c3fb18cda8ebbda4cc1f90397 100644 --- a/app/src/main/java/be/lepl1509group13/workoutwarrior/ProgramDetailActivity.java +++ b/app/src/main/java/be/lepl1509group13/workoutwarrior/ProgramDetailActivity.java @@ -1,11 +1,15 @@ package be.lepl1509group13.workoutwarrior; +import android.app.Dialog; import android.content.Intent; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.widget.ImageButton; import android.widget.ImageView; +import android.widget.LinearLayout; +import android.widget.ListView; +import android.widget.SimpleAdapter; import android.widget.TextView; import android.widget.Toast; @@ -42,6 +46,10 @@ public class ProgramDetailActivity extends AppCompatActivity implements ProgramA TextView start_workout, delete_workout, show_workout; private boolean isLocalProgram = false; private String[][] exercisesData = null; + private ArrayList<ArrayList<String>> allExercices = new ArrayList<ArrayList<String>>(); + Map<String, ArrayList<Exercise>> all_ex_all_days = new HashMap<>(); + String program_name = ""; + ArrayList<String> all_days_exos = new ArrayList<String>(); @Override protected void onCreate(Bundle savedInstanceState) { @@ -51,6 +59,7 @@ public class ProgramDetailActivity extends AppCompatActivity implements ProgramA //get the id of the workout && launch the workout Intent this_intent = this.getIntent(); + program_name = this_intent.getStringExtra("name"); int id = this_intent.getIntExtra("id", 0); //finish activity of there is no id if (id == 0){ this.finish(); } @@ -86,7 +95,64 @@ public class ProgramDetailActivity extends AppCompatActivity implements ProgramA } private void showWorkout() { - //todo + + Dialog dialog = new Dialog(ProgramDetailActivity.this); + dialog.setContentView(R.layout.detail_program_popup); + + TextView program_name_popup = dialog.findViewById(R.id.program_name); + program_name_popup.setText(program_name); + + ImageView closeButton = dialog.findViewById(R.id.close_btn); + closeButton.setOnClickListener(w -> dialog.dismiss()); + + ListView listView = dialog.findViewById(R.id.list_exo_program); + // Création tableau avec nom d'exo + String[] exo_name = new String[exercisesData.length]; + for (int i = 0; i < exercisesData.length; i++) { + exo_name[i] = exercisesData[i][0]; + } + + String[] days_exos = new String[exercisesData.length]; + for (int i = 0; i < exercisesData.length; i++) { + String globalString = ""; + for (String key : all_ex_all_days.keySet()) { + ArrayList<Exercise> values = all_ex_all_days.get(key); + for (Exercise ex : values) { + if (ex.name.equals(exercisesData[i][0])) { + globalString += key + ", "; + break; + } + } + } + globalString = globalString.replaceAll(", $", " "); + days_exos[i] = globalString; + } + + // Création tableau avec description d'exo + String[] exo_description = new String[exercisesData.length]; + for (int i = 0; i < exercisesData.length; i++) { + exo_description[i] = exercisesData[i][1]; + } + + ArrayList<HashMap<String, String>> list = new ArrayList<>(); + for (int i = 0; i < exo_name.length; i++) { + HashMap<String, String> map = new HashMap<>(); + map.put("title", exo_name[i]); + map.put("subtitle", exo_description[i]); + map.put("days", days_exos[i]); + list.add(map); + } + + SimpleAdapter adapter = new SimpleAdapter( + ProgramDetailActivity.this, + list, + R.layout.exo_in_program_item, + new String[]{"title", "subtitle", "days"}, + new int[]{R.id.title_textview, R.id.subtitle_textview, R.id.day_item}); + + listView.setAdapter(adapter); + + dialog.show(); } private void deleteWorkout() { @@ -155,9 +221,12 @@ public class ProgramDetailActivity extends AppCompatActivity implements ProgramA for (String filename : fileNames){ if (filename.equals(name + ".ser")){ + ArrayList<String> exo = new ArrayList<String>(); + //update the title of the program TextView title = findViewById(R.id.title); title.setText(name); + exo.add(name); FileInputStream fileInputStream = openFileInput(filename); ObjectInputStream objectInputStream = new ObjectInputStream(fileInputStream); @@ -165,10 +234,23 @@ public class ProgramDetailActivity extends AppCompatActivity implements ProgramA // ici tu peux utiliser entry comme programme perso HashMap<String, ArrayList<Exercise>> entry = exerciseEntry.getEntry(); + for (Map.Entry<String, ArrayList<Exercise>> entrySet : entry.entrySet()) { + String key = entrySet.getKey(); // Récupération de la clé + ArrayList<Exercise> value = entrySet.getValue(); // Récupération de la valeur correspondante + all_ex_all_days.put(key, value); + } for (Map.Entry<String, ArrayList<Exercise>> set : entry.entrySet()) { + + for (Exercise values : set.getValue()){ + String customName = values.name; + exo.add(customName); + String description = values.description; + exo.add(description); + } String dayOfTheWeek = new SimpleDateFormat("EEEE", Locale.FRENCH).format(date.getTime()); String day = set.getKey(); + if(Objects.equals(dayOfTheWeek, day)){ //Get the data from the day of the week only int totalExercises = 0; @@ -196,6 +278,16 @@ public class ProgramDetailActivity extends AppCompatActivity implements ProgramA recyclerView.setAdapter(adapter); } } + boolean axo_in_program = false; + for (ArrayList<String> element : allExercices) { + if (element.equals(exo)) { + axo_in_program = true; + break; + } + } + if(!axo_in_program) { + allExercices.add(exo); + } objectInputStream.close(); fileInputStream.close(); } diff --git a/app/src/main/res/layout/detail_program_popup.xml b/app/src/main/res/layout/detail_program_popup.xml new file mode 100644 index 0000000000000000000000000000000000000000..570c1e3e420e8f887bd03bd7ef17e157bdf24649 --- /dev/null +++ b/app/src/main/res/layout/detail_program_popup.xml @@ -0,0 +1,76 @@ +<?xml version="1.0" encoding="utf-8"?> +<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:app="http://schemas.android.com/apk/res-auto" + xmlns:tools="http://schemas.android.com/tools" + android:layout_width="match_parent" + android:layout_height="match_parent"> + + <LinearLayout + android:id="@+id/linearLayout" + android:layout_width="match_parent" + android:layout_marginTop="40dp" + android:layout_height="wrap_content" + android:gravity="center_horizontal" + android:orientation="vertical" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toTopOf="parent"> + + <TextView + android:id="@+id/program_name" + android:layout_width="200dp" + android:layout_height="wrap_content" + android:layout_marginTop="30dp" + android:fontFamily="@font/poppins_semibold" + android:gravity="center" + android:textColor="@color/orange" + android:textSize="28sp" + android:textStyle="bold" + app:layout_constraintBottom_toTopOf="@+id/constraintLayout2" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toTopOf="parent" /> + + </LinearLayout> + + + <androidx.constraintlayout.widget.ConstraintLayout + android:id="@+id/constraintLayout2" + android:layout_width="387dp" + android:layout_height="524dp" + android:layout_marginBottom="50dp" + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintTop_toBottomOf="@+id/linearLayout"> + + <RelativeLayout + android:layout_width="290dp" + android:layout_height="wrap_content" + android:layout_marginTop="30dp" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toTopOf="parent"> + + <ListView + android:id="@+id/list_exo_program" + android:layout_width="match_parent" + android:layout_height="wrap_content"> + + </ListView> + + </RelativeLayout> + + + </androidx.constraintlayout.widget.ConstraintLayout> + + <ImageView + android:id="@+id/close_btn" + android:layout_width="35dp" + android:layout_height="35dp" + android:layout_marginTop="10dp" + android:layout_marginEnd="10dp" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintTop_toTopOf="parent" + app:srcCompat="@drawable/close_btn" /> + +</androidx.constraintlayout.widget.ConstraintLayout> \ No newline at end of file diff --git a/app/src/main/res/layout/exo_in_program_item.xml b/app/src/main/res/layout/exo_in_program_item.xml new file mode 100644 index 0000000000000000000000000000000000000000..22673a0dcf6c9fb04d42a6866b9dfa3145d32541 --- /dev/null +++ b/app/src/main/res/layout/exo_in_program_item.xml @@ -0,0 +1,38 @@ +<?xml version="1.0" encoding="utf-8"?> +<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:padding="16dp"> + + <TextView + android:id="@+id/title_textview" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:textSize="18sp" /> + + <TextView + android:id="@+id/subtitle_textview" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_below="@id/title_textview" + android:layout_marginTop="8dp" + android:textSize="16sp" /> + + <TextView + android:id="@+id/info_textview" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_below="@id/subtitle_textview" + android:layout_marginTop="8dp" + android:text="Vous devez effectuer cet exercice au(x) jour(s) suivant(s) :" + android:textSize="14sp" /> + + <TextView + android:id="@+id/day_item" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_below="@id/info_textview" + android:layout_marginTop="8dp" + android:textSize="14sp"/> + +</RelativeLayout> \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 2442df26381513a76c96b329db7368438f546378..d2a07cc7c0be22f3fe005c9be3496ad0c614c846 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -9,7 +9,7 @@ <string name="entrainement_badminton">Entrainement Badminton</string> <string name="launch_workout">Démarrer</string> <string name="delete_workout">Supprimer le programme</string> - <string name="show_workout">Afficher / Modifier le programme</string> + <string name="show_workout">Afficher le programme</string> <string name="title_activity_account">AccountActivity</string> <string name="prompt_email">Email</string> <string name="prompt_password">Password</string>