diff --git a/app/src/main/java/be/lepl1509group13/workoutwarrior/ProgramCreationActivity.java b/app/src/main/java/be/lepl1509group13/workoutwarrior/ProgramCreationActivity.java index afc46f0498fbae167d71437acc8481073ca21734..8e26276743f48b58c41d429e1bf450a2a77c7893 100644 --- a/app/src/main/java/be/lepl1509group13/workoutwarrior/ProgramCreationActivity.java +++ b/app/src/main/java/be/lepl1509group13/workoutwarrior/ProgramCreationActivity.java @@ -220,87 +220,96 @@ public class ProgramCreationActivity extends AppCompatActivity { Toast.makeText(ProgramCreationActivity.this, "Veuillez entrer un exercice avant de vouloir l'ajouter !", Toast.LENGTH_SHORT).show(); }else{ - Dialog dialog = new Dialog(ProgramCreationActivity.this); - dialog.setContentView(R.layout.modify_exercice_popup); - dialog.show(); - // Ajouter un listener à chaque checkBox - cb_lundi = dialog.findViewById(R.id.checkbox_monday); - cb_mardi = dialog.findViewById(R.id.checkbox_tuesday); - cb_mercredi = dialog.findViewById(R.id.checkbox_wednesday); - cb_jeudi = dialog.findViewById(R.id.checkbox_thursday); - cb_vendredi = dialog.findViewById(R.id.checkbox_friday); - cb_samedi = dialog.findViewById(R.id.checkbox_saturday); - cb_dimanche = dialog.findViewById(R.id.checkbox_sunday); - - cb_list.add(cb_lundi); - cb_list.add(cb_mardi); - cb_list.add(cb_mercredi); - cb_list.add(cb_jeudi); - cb_list.add(cb_vendredi); - cb_list.add(cb_samedi); - cb_list.add(cb_dimanche); - - for (CheckBox cb : cb_list) cb.setOnCheckedChangeListener(myCheckBoxListener); - - DatabaseReference workoutsDb = firebaseDb.getReference("Workouts"); - Query query = workoutsDb.orderByChild("name").equalTo(exercise_searched); - query.addValueEventListener(new ValueEventListener() { - @Override - public void onDataChange(DataSnapshot dataSnapshot) { - for (DataSnapshot snapshot : dataSnapshot.getChildren()) { - Long timer = (snapshot.child("timer").getValue(Long.class))/1000; - img_actual_exo = snapshot.child("image_url").getValue(String.class); - break_time = (snapshot.child("break").getValue(Long.class))/1000; - String description = snapshot.child("description").getValue(String.class); - - EditText description_text = dialog.findViewById(R.id.exercise_description); - EditText timer_edit = dialog.findViewById(R.id.exercise_timer); - TextView timer_text = dialog.findViewById(R.id.timer_text); - TextView break_text = dialog.findViewById(R.id.exercice_break); - - ConstraintLayout form_layout = dialog.findViewById(R.id.constraintLayout2); - form_layout.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - if (description_text.hasFocus()) { - description_text.clearFocus(); + if(!EXOS.contains(exercise_searched)){ + Toast.makeText(ProgramCreationActivity.this, "Cet exercice n'est pas connu dans notre système !", + Toast.LENGTH_SHORT).show(); + } + else{ + Dialog dialog = new Dialog(ProgramCreationActivity.this); + dialog.setContentView(R.layout.modify_exercice_popup); + dialog.show(); + // Ajouter un listener à chaque checkBox + cb_lundi = dialog.findViewById(R.id.checkbox_monday); + cb_mardi = dialog.findViewById(R.id.checkbox_tuesday); + cb_mercredi = dialog.findViewById(R.id.checkbox_wednesday); + cb_jeudi = dialog.findViewById(R.id.checkbox_thursday); + cb_vendredi = dialog.findViewById(R.id.checkbox_friday); + cb_samedi = dialog.findViewById(R.id.checkbox_saturday); + cb_dimanche = dialog.findViewById(R.id.checkbox_sunday); + + cb_list.add(cb_lundi); + cb_list.add(cb_mardi); + cb_list.add(cb_mercredi); + cb_list.add(cb_jeudi); + cb_list.add(cb_vendredi); + cb_list.add(cb_samedi); + cb_list.add(cb_dimanche); + + for (CheckBox cb : cb_list) cb.setOnCheckedChangeListener(myCheckBoxListener); + + DatabaseReference workoutsDb = firebaseDb.getReference("Workouts"); + Query query = workoutsDb.orderByChild("name").equalTo(exercise_searched); + query.addValueEventListener(new ValueEventListener() { + @Override + public void onDataChange(DataSnapshot dataSnapshot) { + for (DataSnapshot snapshot : dataSnapshot.getChildren()) { + Long timer = (snapshot.child("timer").getValue(Long.class))/1000; + img_actual_exo = snapshot.child("image_url").getValue(String.class); + break_time = (snapshot.child("break").getValue(Long.class))/1000; + String description = snapshot.child("description").getValue(String.class); + + EditText description_text = dialog.findViewById(R.id.exercise_description); + EditText timer_edit = dialog.findViewById(R.id.exercise_timer); + TextView timer_text = dialog.findViewById(R.id.timer_text); + TextView break_text = dialog.findViewById(R.id.exercice_break); + TextView text_break = dialog.findViewById(R.id.text_break); + + break_text.setVisibility(View.INVISIBLE); + text_break.setVisibility(View.INVISIBLE); + + ConstraintLayout form_layout = dialog.findViewById(R.id.constraintLayout2); + form_layout.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (description_text.hasFocus()) { + description_text.clearFocus(); + } } - } - }); - - description_text.setOnFocusChangeListener(new View.OnFocusChangeListener() { - @Override - public void onFocusChange(View v, boolean hasFocus) { - if (!hasFocus) { - description_text.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_CAP_SENTENCES); - } else { - description_text.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_MULTI_LINE | InputType.TYPE_TEXT_FLAG_CAP_SENTENCES); + }); + + description_text.setOnFocusChangeListener(new View.OnFocusChangeListener() { + @Override + public void onFocusChange(View v, boolean hasFocus) { + if (!hasFocus) { + description_text.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_CAP_SENTENCES); + } else { + description_text.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_MULTI_LINE | InputType.TYPE_TEXT_FLAG_CAP_SENTENCES); + } } - } - }); + }); - if(description != null){ - description_text.setText(description); - } - if(timer == 0){ - timer_edit.setVisibility(View.INVISIBLE); - timer_edit.setEnabled(false); - timer_text.setText(""); - }else{ - timer_edit.setText(timer.toString()); - } - if(break_time != null){ - break_text.setText(break_time.toString()); + if(description != null){ + description_text.setText(description); + } + if(timer == 0){ + timer_edit.setVisibility(View.INVISIBLE); + timer_edit.setEnabled(false); + timer_text.setText(""); + }else{ + timer_edit.setText(timer.toString()); + } + if(break_time != null){ + break_text.setText(break_time.toString()); + } + int resId = getResources().getIdentifier(img_actual_exo, "drawable", getPackageName()); + ImageView image = dialog.findViewById(R.id.exercice_to_modify_image); + image.setImageResource(resId); } - int resId = getResources().getIdentifier(img_actual_exo, "drawable", getPackageName()); - ImageView image = dialog.findViewById(R.id.exercice_to_modify_image); - image.setImageResource(resId); } - } - @Override - public void onCancelled(@NonNull DatabaseError databaseError) { - System.out.println(databaseError); + @Override + public void onCancelled(@NonNull DatabaseError databaseError) { + System.out.println(databaseError); } }); @@ -312,33 +321,34 @@ public class ProgramCreationActivity extends AppCompatActivity { Button save_btn = dialog.findViewById(R.id.btn_save_modif); save_btn.setOnClickListener(w -> { - if(nbre_day > 0){ - EditText description_text = dialog.findViewById(R.id.exercise_description); - String description_str = description_text.getText().toString(); - - EditText break_text = dialog.findViewById(R.id.exercice_break); - String string_break = break_text.getText().toString(); - Integer break_time = Integer.parseInt(string_break); - - EditText timer_edit = dialog.findViewById(R.id.exercise_timer); - String string_timer = timer_edit.getText().toString(); - String img = "@drawable/"+img_actual_exo; - if(string_timer.equals("")){ - actual_exo = new Exercise(exercise_searched, description_str, break_time, img, 0); - }else{ - Integer timer_int = Integer.parseInt(string_timer); - actual_exo = new Exercise(exercise_searched, description_str, break_time, img, timer_int); + if(nbre_day > 0){ + EditText description_text = dialog.findViewById(R.id.exercise_description); + String description_str = description_text.getText().toString(); + + EditText break_text = dialog.findViewById(R.id.exercice_break); + String string_break = break_text.getText().toString(); + Integer break_time = Integer.parseInt(string_break); + + EditText timer_edit = dialog.findViewById(R.id.exercise_timer); + String string_timer = timer_edit.getText().toString(); + String img = "@drawable/"+img_actual_exo; + if(string_timer.equals("")){ + actual_exo = new Exercise(exercise_searched, description_str, break_time, img, 0); + }else{ + Integer timer_int = Integer.parseInt(string_timer); + actual_exo = new Exercise(exercise_searched, description_str, break_time, img, timer_int); + } + addToProgram(actual_exo, new ArrayList<>(current_days_checked)); + dialog.dismiss(); + // Effacer le champ de texte AutoCompleteTextView + input_exo.setText(""); } - addToProgram(actual_exo, new ArrayList<>(current_days_checked)); - dialog.dismiss(); - // Effacer le champ de texte AutoCompleteTextView - input_exo.setText(""); - } - else{ - Toast.makeText(ProgramCreationActivity.this, "Veuillez sélectionner au moins un jour !", - Toast.LENGTH_SHORT).show(); - } - }); + else{ + Toast.makeText(ProgramCreationActivity.this, "Veuillez sélectionner au moins un jour !", + Toast.LENGTH_SHORT).show(); + } + }); + } } }); } @@ -437,8 +447,6 @@ public class ProgramCreationActivity extends AppCompatActivity { /** * Add the new exercise to the program */ - System.out.println(exercise.description); - System.out.println(exercise.timer); if (exoInProgram(exercise)) { Toast.makeText(this, "Exercice déjà dans le programme !", Toast.LENGTH_SHORT).show(); diff --git a/app/src/main/java/be/lepl1509group13/workoutwarrior/ProgramDetailActivity.java b/app/src/main/java/be/lepl1509group13/workoutwarrior/ProgramDetailActivity.java index f21fca412aa62be7e77a1950d014d1244dd9eb32..0453250131c76f649ccdac9bd2c30989a6072203 100644 --- a/app/src/main/java/be/lepl1509group13/workoutwarrior/ProgramDetailActivity.java +++ b/app/src/main/java/be/lepl1509group13/workoutwarrior/ProgramDetailActivity.java @@ -33,6 +33,7 @@ import java.io.IOException; import java.io.ObjectInputStream; import java.text.SimpleDateFormat; import java.util.ArrayList; +import java.util.Arrays; import java.util.Calendar; import java.util.Date; import java.util.HashMap; @@ -51,6 +52,9 @@ public class ProgramDetailActivity extends AppCompatActivity implements ProgramA private Button start_workout, delete_workout, show_workout, share_workout; private boolean isLocalProgram = false; private String[][] exercisesData = null; + private String[][] exercices_data_all = null; + int total_Exercises = 0; + int totalExercises = 0; private ArrayList<ArrayList<String>> allExercices = new ArrayList<ArrayList<String>>(); Map<String, ArrayList<Exercise>> all_ex_all_days = new HashMap<>(); String program_name = ""; @@ -186,19 +190,14 @@ public class ProgramDetailActivity extends AppCompatActivity implements ProgramA 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[] days_exos = new String[exercices_data_all.length]; + for (int i = 0; i < exercices_data_all.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])) { + if (ex.name.equals(exercices_data_all[i][0])) { globalString += key + ", "; break; } @@ -208,10 +207,16 @@ public class ProgramDetailActivity extends AppCompatActivity implements ProgramA days_exos[i] = globalString; } + // Création tableau avec nom d'exo + String[] exo_name = new String[exercices_data_all.length]; + for (int i = 0; i < exercices_data_all.length; i++) { + exo_name[i] = exercices_data_all[i][0]; + } + // 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]; + String[] exo_description = new String[exercices_data_all.length]; + for (int i = 0; i < exercices_data_all.length; i++) { + exo_description[i] = exercices_data_all[i][1]; } ArrayList<HashMap<String, String>> list = new ArrayList<>(); @@ -324,12 +329,6 @@ public class ProgramDetailActivity extends AppCompatActivity implements ProgramA 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(); @@ -352,23 +351,29 @@ public class ProgramDetailActivity extends AppCompatActivity implements ProgramA exercisesData[exerciseId] = new String[]{customName, description, image_url, String.valueOf(timer)}; exerciseId ++; } - RecyclerView recyclerView = findViewById(R.id.program_view_recycler); recyclerView.setLayoutManager(new LinearLayoutManager(ProgramDetailActivity.this)); ProgramAdapter adapter = new ProgramAdapter(exercisesData); adapter.setOnItemClickListener(ProgramDetailActivity.this); recyclerView.setAdapter(adapter); } - } - boolean axo_in_program = false; - for (ArrayList<String> element : allExercices) { - if (element.equals(exo)) { - axo_in_program = true; - break; + + int totalExercicesAll = 0; + for (Exercise values : set.getValue()){totalExercicesAll ++;} + + int exercise_Id = 0; + if(exercise_Id != totalExercicesAll){ + exercices_data_all = new String[totalExercicesAll][]; + } + + for (Exercise values : set.getValue()){ + String customName = values.name; + String description = values.description; + String image_url = values.image_url; + Integer timer = values.timer; + exercices_data_all[exercise_Id] = new String[]{customName, description, image_url, String.valueOf(timer)}; + exercise_Id ++; } - } - if(!axo_in_program) { - allExercices.add(exo); } objectInputStream.close(); fileInputStream.close(); diff --git a/app/src/main/res/drawable/border.xml b/app/src/main/res/drawable/border.xml new file mode 100644 index 0000000000000000000000000000000000000000..bf43bfb46f0b37dbf8647a1efe9539755849b2a7 --- /dev/null +++ b/app/src/main/res/drawable/border.xml @@ -0,0 +1,12 @@ +<?xml version="1.0" encoding="utf-8"?> + +<shape xmlns:android="http://schemas.android.com/apk/res/android" + android:shape="rectangle"> + <stroke android:width="2dp" + android:color="@color/orange" /> + <corners android:radius="20dp" /> + <padding android:left="30dp" + android:top="15dp" + android:right="30dp" + android:bottom="15dp" /> +</shape> diff --git a/app/src/main/res/layout/detail_program_popup.xml b/app/src/main/res/layout/detail_program_popup.xml index 570c1e3e420e8f887bd03bd7ef17e157bdf24649..b1c50d1fc12aa3db94db03a9c299853ef2de4d4c 100644 --- a/app/src/main/res/layout/detail_program_popup.xml +++ b/app/src/main/res/layout/detail_program_popup.xml @@ -18,9 +18,9 @@ <TextView android:id="@+id/program_name" - android:layout_width="200dp" + android:layout_width="280dp" android:layout_height="wrap_content" - android:layout_marginTop="30dp" + android:layout_marginTop="5dp" android:fontFamily="@font/poppins_semibold" android:gravity="center" android:textColor="@color/orange" @@ -34,34 +34,41 @@ </LinearLayout> - <androidx.constraintlayout.widget.ConstraintLayout - android:id="@+id/constraintLayout2" - android:layout_width="387dp" - android:layout_height="524dp" - android:layout_marginBottom="50dp" + <ScrollView + android:layout_width="380dp" + android:layout_height="550dp" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/linearLayout"> - <RelativeLayout - android:layout_width="290dp" + <androidx.constraintlayout.widget.ConstraintLayout + android:id="@+id/constraintLayout2" + android:layout_width="match_parent" android:layout_height="wrap_content" - android:layout_marginTop="30dp" - app:layout_constraintEnd_toEndOf="parent" - app:layout_constraintStart_toStartOf="parent" - app:layout_constraintTop_toTopOf="parent"> + android:layout_marginBottom="50dp"> + + <RelativeLayout + android:layout_width="290dp" + android:layout_height="450dp" + app:layout_constraintBottom_toBottomOf="parent" + 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 - android:id="@+id/list_exo_program" - android:layout_width="match_parent" - android:layout_height="wrap_content"> + </ListView> - </ListView> + </RelativeLayout> - </RelativeLayout> + </androidx.constraintlayout.widget.ConstraintLayout> - </androidx.constraintlayout.widget.ConstraintLayout> + </ScrollView> <ImageView android:id="@+id/close_btn" diff --git a/app/src/main/res/layout/exo_in_program_item.xml b/app/src/main/res/layout/exo_in_program_item.xml index 22673a0dcf6c9fb04d42a6866b9dfa3145d32541..5638a6b0281cba5b954fad71f65b7fb429ba9ca5 100644 --- a/app/src/main/res/layout/exo_in_program_item.xml +++ b/app/src/main/res/layout/exo_in_program_item.xml @@ -4,35 +4,46 @@ android:layout_height="wrap_content" android:padding="16dp"> - <TextView - android:id="@+id/title_textview" + <!-- Conteneur pour les TextViews avec une bordure --> + <RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content" - android:textSize="18sp" /> + android:background="@drawable/border"> - <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 pour le titre --> + <TextView + android:id="@+id/title_textview" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:textSize="18sp" + android:textStyle="bold"/> - <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 pour le sous-titre --> + <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/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"/> + <!-- TextView pour l'information --> + <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 pour l'élément de jour --> + <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> </RelativeLayout> \ No newline at end of file diff --git a/app/src/main/res/layout/modify_exercice_popup.xml b/app/src/main/res/layout/modify_exercice_popup.xml index 9722d04f05a01a842c0f1de26c2d25ff4081f840..b21434816fd6d82a3c43c24ea10125f2a2b26c9d 100644 --- a/app/src/main/res/layout/modify_exercice_popup.xml +++ b/app/src/main/res/layout/modify_exercice_popup.xml @@ -170,6 +170,7 @@ android:text=""/> <TextView + android:id="@+id/text_break" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Gérez votre temps de pause en secondes"/>