diff --git a/app/src/main/java/be/lepl1509group13/workoutwarrior/ListExercicesAdapter.java b/app/src/main/java/be/lepl1509group13/workoutwarrior/ListExercicesAdapter.java index 6664021069e027fc8953eadc620a254db9304903..03444fc8485092defb92ac82c5724f00b32db637 100644 --- a/app/src/main/java/be/lepl1509group13/workoutwarrior/ListExercicesAdapter.java +++ b/app/src/main/java/be/lepl1509group13/workoutwarrior/ListExercicesAdapter.java @@ -1,13 +1,17 @@ package be.lepl1509group13.workoutwarrior; +import static android.content.ContentValues.TAG; + import android.content.Context; import android.content.Intent; import android.graphics.drawable.Drawable; +import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ArrayAdapter; import android.widget.Button; +import android.widget.EditText; import android.widget.ImageView; import android.widget.ListView; import android.widget.TextView; @@ -23,6 +27,7 @@ import com.google.firebase.database.ValueEventListener; import java.util.ArrayList; import java.util.HashMap; +import java.util.Objects; public class ListExercicesAdapter extends ArrayAdapter<String> { @@ -33,7 +38,6 @@ public class ListExercicesAdapter extends ArrayAdapter<String> { super(context, R.layout.exercice, values); this.context = context; this.values = values; - } @Override @@ -48,53 +52,75 @@ public class ListExercicesAdapter extends ArrayAdapter<String> { // Récupérez l'image et le texte pour chaque élément de la liste en fonction de la position if (this.values.size() > 0) { System.out.println("values : " + values); - String exercice = values.get(position); + String exercise = values.get(position); Drawable delete_cross = context.getResources().getDrawable(R.drawable.cross_mark); Drawable pen = context.getResources().getDrawable(R.drawable.edit); // Afficher l'image et le texte dans les vues correspondantes delete_button.setImageDrawable(delete_cross); edit_button.setImageDrawable(pen); - exercice_name.setText(exercice); + exercice_name.setText(exercise); ProgramCreationActivity activity = (ProgramCreationActivity) context; - String current_day_displayed = activity.current_day_displayed; - HashMap<String, ArrayList<String>> exos_per_days = activity.exos_per_days; + // Ecouteur de clics pour chaque élément de la ListView edit_button.setOnClickListener(view -> { + System.out.println("details : " + activity.exoDetailsForEachDay); AlertDialog.Builder builder = new AlertDialog.Builder(view.getContext()); View dialogView = inflater.inflate(R.layout.edit_workout, null); builder.setView(dialogView); + AlertDialog dialog = builder.create(); + dialog.show(); - TextView exerciceName = dialogView.findViewById(R.id.exercise_name); - exerciceName.setText(exercice); + TextView exerciseName = dialogView.findViewById(R.id.exercise_name); + exerciseName.setText(exercise); - Query query = activity.db.orderByChild("name").equalTo(exercice); - query.addListenerForSingleValueEvent(new ValueEventListener() { - @Override - public void onDataChange(DataSnapshot dataSnapshot) { - for (DataSnapshot snapshot : dataSnapshot.getChildren()) { + // Rechercher l'exercice dans la HashMap + ArrayList<Exercise> exercises = activity.exoDetailsForEachDay.get(activity.current_day_displayed); + String imageUrl; + String description; + for (Exercise exo : exercises) { + if (Objects.equals(exo.name, exercise)) { - // Récupération de la description - String description = snapshot.child("description").getValue(String.class); + // Afficher les détails de l'exo + imageUrl = exo.image_url; + ImageView imageView = dialogView.findViewById(R.id.exercise_image); + int resourceId = context.getResources().getIdentifier(imageUrl, "drawable", context.getPackageName()); + imageView.setImageResource(resourceId); - TextView descriptionTextView = dialogView.findViewById(R.id.description_edit); - descriptionTextView.setText(description); - } + TextView descriptionTextView = dialogView.findViewById(R.id.description_edit); + descriptionTextView.setText(exo.description); + + + TextView break_time_TextView = dialogView.findViewById(R.id.pause_edit); + break_time_TextView.setText(String.valueOf(exo.breakVal/1000)); } + } + + // Enregistrer les modifications de l'exercice + Button save_btn = dialogView.findViewById(R.id.save_modif_button); + save_btn.setOnClickListener(v -> { + EditText description_edit = dialogView.findViewById(R.id.description_edit); + EditText break_time_edit = dialogView.findViewById(R.id.pause_edit); + + String new_description = description_edit.getText().toString(); + int new_break_time = Integer.parseInt(break_time_edit.getText().toString()); + + // Rechercher l'exercice dans la HashMap et modifier ces paramètres - @Override - public void onCancelled(DatabaseError databaseError) { - // Gestion de l'erreur - // ... + for (Exercise exo : exercises) { + if (Objects.equals(exo.name, exercise)) { + exo.description = new_description; + exo.breakVal = new_break_time * 1000; + } } + activity.exoDetailsForEachDay.put(activity.current_day_displayed, exercises); + System.out.println("details : " + activity.exoDetailsForEachDay); + Toast.makeText(context, "Modifications sauvegardées", Toast.LENGTH_SHORT).show(); + dialog.dismiss(); }); - - - AlertDialog dialog = builder.create(); - dialog.show(); ImageView closeButton = dialogView.findViewById(R.id.close_btn); closeButton.setOnClickListener(v -> { @@ -106,13 +132,15 @@ public class ListExercicesAdapter extends ArrayAdapter<String> { // Ajouter un OnClickListener à l'image delete_button.setOnClickListener(v -> { // Code à exécuter lors du clic - Toast.makeText(context, exercice + " supprimé", Toast.LENGTH_SHORT).show(); + Toast.makeText(context, exercise + " supprimé", Toast.LENGTH_SHORT).show(); - ArrayList<String> exercicesList = exos_per_days.get(current_day_displayed); - exercicesList.remove(position); - exos_per_days.put(current_day_displayed, exercicesList); - updateValues(exercicesList); + activity.exoDetailsForEachDay.get(activity.current_day_displayed).remove(position); + ArrayList<String> exosDisplay = new ArrayList<>(); + for (Exercise exo : activity.exoDetailsForEachDay.get(activity.current_day_displayed)) { + exosDisplay.add(exo.name); + } + updateValues(exosDisplay); notifyDataSetChanged(); }); } @@ -126,6 +154,12 @@ public class ListExercicesAdapter extends ArrayAdapter<String> { notifyDataSetChanged(); System.out.println("values : " + values); } + + private void save_workout_details() { + + } + + } diff --git a/app/src/main/java/be/lepl1509group13/workoutwarrior/ProgramCreationActivity.java b/app/src/main/java/be/lepl1509group13/workoutwarrior/ProgramCreationActivity.java index b556da7d8b5fde954671645fc8d91ba818ec5216..f298eaa635572931f6cc8d4792fded2070ea0a28 100644 --- a/app/src/main/java/be/lepl1509group13/workoutwarrior/ProgramCreationActivity.java +++ b/app/src/main/java/be/lepl1509group13/workoutwarrior/ProgramCreationActivity.java @@ -20,6 +20,7 @@ import android.widget.Toast; import android.view.View; import android.widget.AutoCompleteTextView; +import androidx.annotation.NonNull; import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AppCompatActivity; @@ -27,9 +28,8 @@ import com.google.firebase.database.DataSnapshot; import com.google.firebase.database.DatabaseError; import com.google.firebase.database.DatabaseReference; import com.google.firebase.database.FirebaseDatabase; +import com.google.firebase.database.Query; import com.google.firebase.database.ValueEventListener; -import com.google.gson.Gson; -import com.google.gson.reflect.TypeToken; import java.io.BufferedReader; import java.io.FileInputStream; @@ -39,7 +39,6 @@ import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.PrintWriter; -import java.lang.reflect.Type; import java.util.ArrayList; import java.util.HashMap; import java.util.Map; @@ -63,11 +62,13 @@ public class ProgramCreationActivity extends AppCompatActivity { private ImageButton help_creation_program; - public HashMap<String, ArrayList<String>> exos_per_days = new HashMap<>(); + HashMap<String, ArrayList<Exercise>> exoDetailsForEachDay = new HashMap<>(); ListExercicesAdapter exercisesListAdapter; public static int lastCheckedPosition = -1; + ArrayList<String> currentExoList = new ArrayList<>(); + @Override protected void onCreate(Bundle savedInstanceState) { @@ -126,29 +127,18 @@ public class ProgramCreationActivity extends AppCompatActivity { testbtn.setOnClickListener(v -> { System.out.println("EXO SAVED: \n"); try { - // il suffit de changer le nom du fichier pour recuperer les valeurs - // HashMap<String, ArrayList<String>> testHashMap aura alors par exemple: - // (si HashMapExos) Squat0, break description image name timer - // (si HashMapJours) Lundi, Squat0 Soulevé de terre0 etc - FileInputStream fis = openFileInput("HashMapExos.json"); + FileInputStream fis = openFileInput("data.txt"); InputStreamReader isr = new InputStreamReader(fis); BufferedReader br = new BufferedReader(isr); - StringBuilder sb = new StringBuilder(); String line; while ((line = br.readLine()) != null) { - sb.append(line); - } - String jsonString = sb.toString(); - Type type = new TypeToken<HashMap<String, ArrayList<String>>>(){}.getType(); - HashMap<String, ArrayList<String>> testHashMap = new Gson().fromJson(jsonString, type); - fis.close(); - - for (Map.Entry<String, ArrayList<String>> set : testHashMap.entrySet()){ - System.out.println(set.getKey() + " : " + set.getValue()); + System.out.println(line); } - + br.close(); + } catch (FileNotFoundException e) { + throw new RuntimeException(e); } catch (IOException e) { - e.printStackTrace(); + throw new RuntimeException(e); } }); } @@ -171,66 +161,22 @@ public class ProgramCreationActivity extends AppCompatActivity { private void saveProgramListener(){ Button save_btn = findViewById((R.id.save_button)); - HashMap<String, ArrayList<String>> HashMapExos = new HashMap<>(); // contains Squat0, break description image name timer - HashMap<String, ArrayList<String>> HashMapJours = new HashMap<>(); // contains Lundi, Squat0 Soulevé de terre0 etc - save_btn.setOnClickListener(v -> { System.out.println("Voici la liste des exos pour ce programme : \n"); - for (Map.Entry<String, ArrayList<String>> set : exos_per_days.entrySet()) { + for (Map.Entry<String, ArrayList<Exercise>> set : exoDetailsForEachDay.entrySet()) { System.out.println(set.getKey() + " = " + set.getValue()); } try { - db = firebaseDb.getReference("Workouts"); - - db.addListenerForSingleValueEvent(new ValueEventListener() { - @Override - public void onDataChange(DataSnapshot dataSnapshot) { - for (Map.Entry<String, ArrayList<String>> set : exos_per_days.entrySet()) { - ArrayList<String> tmp_joursArrayList = new ArrayList<>(); - for (String exo : set.getValue()) { - - ArrayList<String> tmp_arrayList = new ArrayList<>(); - for (DataSnapshot snapshot : dataSnapshot.getChildren()) { - // Retrieve the data from each child node - String name = snapshot.child("name").getValue(String.class); - if (exo.equals(name)) { - tmp_arrayList.add(snapshot.child("break").getValue().toString()); - tmp_arrayList.add(snapshot.child("description").getValue(String.class)); - tmp_arrayList.add(snapshot.child("image_url").getValue(String.class)); - tmp_arrayList.add(name); - // if timer is set by default - String timer = snapshot.child("timer").getValue().toString(); - tmp_arrayList.add(timer); - tmp_joursArrayList.add(name+timer); - if (!HashMapExos.containsKey(name+timer)){ HashMapExos.put(name+timer,tmp_arrayList);} - break; - } - ; - - } - } - HashMapJours.put(set.getKey(),tmp_joursArrayList); - } - - } - - @Override - public void onCancelled(DatabaseError databaseError) { - System.out.println("error"); - } - }); - - // write both HashMap in separate json files - String jsonStringJours = new Gson().toJson(HashMapJours); - String jsonStringExos = new Gson().toJson(HashMapExos); - FileOutputStream fos = openFileOutput("HashMapJours.json", Context.MODE_PRIVATE); - fos.write(jsonStringJours.getBytes()); - fos.close(); - FileOutputStream fos2 = openFileOutput("HashMapExos.json", Context.MODE_PRIVATE); - fos2.write(jsonStringExos.getBytes()); - fos2.close(); + FileOutputStream fos = openFileOutput("data.txt", Context.MODE_PRIVATE); + PrintWriter writer = new PrintWriter(new OutputStreamWriter(fos)); + for (Map.Entry<String, ArrayList<Exercise>> set : exoDetailsForEachDay.entrySet()) { + String key = set.getKey(); + ArrayList<Exercise> value = set.getValue(); + writer.println(key + " = " + value.toString()); + } + writer.close(); } catch (Exception e) { e.printStackTrace(); } @@ -262,58 +208,80 @@ public class ProgramCreationActivity extends AppCompatActivity { } private void init_day_lists() { - exos_per_days.put("lundi", new ArrayList<>()); - exos_per_days.put("mardi", new ArrayList<>()); - exos_per_days.put("mercredi", new ArrayList<>()); - exos_per_days.put("jeudi", new ArrayList<>()); - exos_per_days.put("vendredi", new ArrayList<>()); - exos_per_days.put("samedi", new ArrayList<>()); - exos_per_days.put("dimanche", new ArrayList<>()); - - System.out.println(exos_per_days); + exoDetailsForEachDay.put("lundi", new ArrayList<>()); + exoDetailsForEachDay.put("mardi", new ArrayList<>()); + exoDetailsForEachDay.put("mercredi", new ArrayList<>()); + exoDetailsForEachDay.put("jeudi", new ArrayList<>()); + exoDetailsForEachDay.put("vendredi", new ArrayList<>()); + exoDetailsForEachDay.put("samedi", new ArrayList<>()); + exoDetailsForEachDay.put("dimanche", new ArrayList<>()); + + System.out.println(exoDetailsForEachDay); } private void addExerciceListener() { /** - * Ajoute un exercice au jour courant dans la HashMap exos_per_days et dans la ListView exos_current_day + * Ajoute un exercice au jour courant dans la HashMap exoDetailsForEachDay et dans la ListView exos_current_day */ Button add_exo_button = findViewById(R.id.add_exo_button); add_exo_button.setOnClickListener(v -> { // Récupérer la valeur du champ de texte AutoCompleteTextView - String exercice_searched = input_exo.getText().toString(); + String exercise_searched = input_exo.getText().toString(); - System.out.println("current_days_checked : " + current_days_checked); // Récupérer la liste courante et ajouter l'exo aux jours correspondants dans la liste - for(int i=0; i < current_days_checked.size(); i++){ - + for(int i = 0; i < current_days_checked.size(); i++){ String current_day = current_days_checked.get(i); - ArrayList<String> exos_current_days = exos_per_days.get(current_day); - assert exos_current_days != null; - if (!exos_current_days.contains(exercice_searched)) exos_current_days.add(exercice_searched); - exos_per_days.put(current_day, exos_current_days); - System.out.println("exos_per_days"); - System.out.println(exos_per_days); - - System.out.println("current day : " + current_day); - System.out.println("current day displayed : " + current_day_displayed); - if (Objects.equals(current_day, current_day_displayed)) { - exercisesListAdapter.updateValues(exos_current_days); + ArrayList<Exercise> currentDayExercices = exoDetailsForEachDay.get(current_day); + assert currentDayExercices != null; + + // Rechercher dans la HashMap si l'exo n'est pas déjà dedans + boolean exoAlreadyIn = false; + for (Exercise exo : currentDayExercices) { + if (Objects.equals(exo.name, exercise_searched)) exoAlreadyIn = true; + } + + if (!exoAlreadyIn) { + Query query = db.orderByChild("name").equalTo(exercise_searched); + query.addListenerForSingleValueEvent(new ValueEventListener() { + @Override + public void onDataChange(DataSnapshot dataSnapshot) { + for (DataSnapshot snapshot : dataSnapshot.getChildren()) { + String description = snapshot.child("description").getValue(String.class); + String imageUrl = snapshot.child("image_url").getValue(String.class); + int timer = snapshot.child("timer").getValue(Integer.class); + int breakVal = snapshot.child("break").getValue(Integer.class); + Exercise newExo = new Exercise(exercise_searched, description, breakVal, imageUrl, timer); + exoDetailsForEachDay.get(current_day).add(newExo); + System.out.println("exoDetailsForEachDay : " + exoDetailsForEachDay); + + // Si le jour affiché est le jour où l'exercice a été ajouté, mettre à jour la liste via l'adaptateur + if (Objects.equals(current_day, current_day_displayed)) { + currentExoList.clear(); + for (Exercise exo : exoDetailsForEachDay.get(current_day_displayed)) currentExoList.add(exo.name); + //currentExoList.add(newExo.name); + exercisesListAdapter.updateValues(currentExoList); + System.out.println("currentExoList : " + currentExoList); + } + // print dans la console juste pour vérifier que les listes sont correctes + for (Map.Entry<String, ArrayList<Exercise>> set : exoDetailsForEachDay.entrySet()) { + System.out.println(set.getKey() + " = " + set.getValue()); + } + } + } + + @Override + public void onCancelled(DatabaseError error) { + + } + }); } } // Effacer le champ de texte AutoCompleteTextView input_exo.setText(""); - - // Ajouter la valeur à l'adaptateur pour l'afficher dans la ListView - //exercisesListAdapter.addExercice(exercice_searched); - - // print dans la console juste pour vérifier que les listes sont correctes - for (Map.Entry<String, ArrayList<String>> set : exos_per_days.entrySet()) { - System.out.println(set.getKey() + " = " + set.getValue()); - } }); } @@ -321,8 +289,6 @@ public class ProgramCreationActivity extends AppCompatActivity { new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { - System.out.println("checkbox listening"); - // Si la CheckBox est cochée, décocher les autres CheckBox if (buttonView == cb_lundi) { if(current_days_checked.contains("lundi")){ current_days_checked.remove("lundi"); @@ -380,11 +346,11 @@ public class ProgramCreationActivity extends AppCompatActivity { db.addValueEventListener(new ValueEventListener() { @Override public void onDataChange(DataSnapshot snapshot) { - DataSnapshot exercice; + DataSnapshot exercise; int i = 1; while (snapshot.hasChild(Integer.toString(i))) { - exercice = snapshot.child(Integer.toString(i)); - EXOS.add(exercice.child("name").getValue(String.class)); + exercise = snapshot.child(Integer.toString(i)); + EXOS.add(exercise.child("name").getValue(String.class)); i++; } for (String ex : EXOS) System.out.println("ex : " + ex); @@ -397,13 +363,40 @@ public class ProgramCreationActivity extends AppCompatActivity { } public void onNewDayTextClick(View view){ - String day = (String) view.getTag(); - current_day_displayed = day; - ArrayList<String> exos_to_display; - exos_to_display = exos_per_days.get(day); - - System.out.println("day : " + day); - System.out.println("exos to display : " + exos_to_display); - exercisesListAdapter.updateValues(exos_to_display); + current_day_displayed = (String) view.getTag(); + + ArrayList<Exercise> exoList = exoDetailsForEachDay.get(current_day_displayed); + + currentExoList.clear(); + for (Exercise exo : exoList) { + currentExoList.add(exo.name); + } + exercisesListAdapter.updateValues(currentExoList); + System.out.println("currentExoList : " + currentExoList); + System.out.println("day : " + current_day_displayed); + System.out.println("exos to display : " + exoList); } } + +class Exercise { + String name; + String description; + int breakVal; + String image_url; + int timer; + + public Exercise(String n, String desc, int b, String im, int t) { + this.name = n; + this.description = desc; + this.breakVal = b; + this.image_url = im; + this.timer = t; + } + + @NonNull + @Override + public String toString() { + return name + ", " + description + ", temps de pause : " + breakVal; + } +} + diff --git a/app/src/main/res/drawable/biceps_curl_marteau.png b/app/src/main/res/drawable/biceps_curl_marteau.png new file mode 100644 index 0000000000000000000000000000000000000000..68cb3712b04205f5a229447f6c5fd9d93b7ed30c Binary files /dev/null and b/app/src/main/res/drawable/biceps_curl_marteau.png differ diff --git a/app/src/main/res/drawable/developpe_incline_halteres.png b/app/src/main/res/drawable/developpe_incline_halteres.png new file mode 100644 index 0000000000000000000000000000000000000000..13387f864e29518fc99d7285845fbd935aa3e19d Binary files /dev/null and b/app/src/main/res/drawable/developpe_incline_halteres.png differ diff --git a/app/src/main/res/drawable/extension_triceps.png b/app/src/main/res/drawable/extension_triceps.png new file mode 100644 index 0000000000000000000000000000000000000000..8c0aaee265d51b5c5cb9eb44b630ce8ce7b11a33 Binary files /dev/null and b/app/src/main/res/drawable/extension_triceps.png differ diff --git a/app/src/main/res/drawable/pec_fly.png b/app/src/main/res/drawable/pec_fly.png new file mode 100644 index 0000000000000000000000000000000000000000..534077324beaf230bd43b8e07787cc219b8e947b Binary files /dev/null and b/app/src/main/res/drawable/pec_fly.png differ diff --git a/app/src/main/res/drawable/tractions.jpg b/app/src/main/res/drawable/tractions.jpg new file mode 100644 index 0000000000000000000000000000000000000000..4e14272be0aa5a8b0b956fdd632e7f31638fa4fb Binary files /dev/null and b/app/src/main/res/drawable/tractions.jpg differ diff --git a/app/src/main/res/layout/edit_workout.xml b/app/src/main/res/layout/edit_workout.xml index 8fbe13c055cdb5b6516aaaa6b40ae2dbc971b503..e5b2ba141fe6980df9c2634b3067a2fda21e9f09 100644 --- a/app/src/main/res/layout/edit_workout.xml +++ b/app/src/main/res/layout/edit_workout.xml @@ -26,17 +26,17 @@ android:text="Nom de l'exo" android:textSize="22sp" app:layout_constraintBottom_toBottomOf="parent" - app:layout_constraintEnd_toStartOf="@+id/imageView" + app:layout_constraintEnd_toStartOf="@+id/exercise_image" app:layout_constraintHorizontal_bias="0.0" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" /> <ImageView - android:id="@+id/imageView" + android:id="@+id/exercise_image" android:layout_width="164dp" android:layout_height="122dp" android:scaleType="fitCenter" - android:src="@drawable/developpe_couche_barre" + android:src="@drawable/ic_launcher_background" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintHorizontal_bias="0.977" diff --git a/app/src/main/res/layout/program_creation.xml b/app/src/main/res/layout/program_creation.xml index 47e6867bb8973519b14c68af341a2eb0608439ff..c8817a52811e97564af9ad66ffe270f31aebfbfb 100644 --- a/app/src/main/res/layout/program_creation.xml +++ b/app/src/main/res/layout/program_creation.xml @@ -174,7 +174,7 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:fontFamily="@font/poppins" - android:text="Sélectionnez les jours de votre programme :" /> + android:text="Sélectionnez les jours pour lesquels l'exercice sera ajouté :" /> <LinearLayout android:layout_width="match_parent"