Skip to content
Extraits de code Groupes Projets

Comparer les révisions

Les modifications sont affichées comme si la révision source était fusionnée avec la révision cible. En savoir plus sur la comparaison des révisions.

Source

Sélectionner le projet cible
No results found

Cible

Sélectionner le projet cible
  • schamrotha/LEPL1509-Projet
1 résultat
Afficher les modifications
Validations sur la source (26)
Affichage de
avec 1061 ajouts et 295 suppressions
......@@ -48,5 +48,5 @@ dependencies {
implementation 'com.google.firebase:firebase-crashlytics:18.2.9'
implementation 'com.google.firebase:firebase-analytics:20.1.2'
implementation 'com.google.code.gson:gson:2.8.9'
}
}
\ No newline at end of file
......@@ -124,11 +124,13 @@ public class AccountActivity extends AppCompatActivity implements FriendsAdapter
}
public void onItemClick(String friend_pseudo) {
//todo when a friend is clicked to be deleted
//When a friend is clicked to be deleted
db = firebaseDb.getReference("Friends");
db.child(userPseudo).child(friend_pseudo).removeValue()
.addOnSuccessListener(aVoid -> Toast.makeText(AccountActivity.this, friend_pseudo + " supprimé de vos amis !", Toast.LENGTH_SHORT).show())
.addOnFailureListener(e -> Toast.makeText(AccountActivity.this, "Une erreur est survenue !", Toast.LENGTH_SHORT).show());
db.child(friend_pseudo).child(userPseudo).removeValue()
.addOnFailureListener(e -> Toast.makeText(AccountActivity.this, "Une erreur est survenue !", Toast.LENGTH_SHORT).show());
}
private void getFriends(String pseudo) {
......
......@@ -134,13 +134,19 @@ public class AddFriendActivity extends AppCompatActivity {
}
private void addFriendship(String userPseudo, String newFriendPseudo) {
//adding friendship to the actual user
db = firebaseDb.getReference("Friends").child(userPseudo);
Map<String, Object> updateFriendship = new HashMap<>();
updateFriendship.put(newFriendPseudo, "");
Map<String, Object> updates = new HashMap<>();
updates.put(newFriendPseudo, "");
//adding friendship to the other user
DatabaseReference db2 = firebaseDb.getReference("Friends").child(newFriendPseudo);
Map<String, Object> updateFriendshipToNewFriend = new HashMap<>();
updateFriendshipToNewFriend.put(userPseudo, "");
try {
db.updateChildren(updates);
db.updateChildren(updateFriendship);
db2.updateChildren(updateFriendshipToNewFriend);
Toast.makeText(AddFriendActivity.this, "Ami ajouté !", Toast.LENGTH_SHORT).show();
resetFirebaseQuery();
finish();
......
package be.lepl1509group13.workoutwarrior;
import be.lepl1509group13.workoutwarrior.ProgramCreationActivity;
import android.app.Dialog;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.text.InputType;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import androidx.constraintlayout.widget.ConstraintLayout;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import be.lepl1509group13.workoutwarrior.ProgramCreationActivity;
public class ListExercicesAdapter extends ArrayAdapter<String> {
private final Context context;
private ArrayList<String> values;
public Exercise actual_exo ;
public String img_actual_exo;
HashMap<Exercise, ArrayList<String>> program = new HashMap<>();
String name_exo;
String description_exo;
Long timer_exo;
Long break_exo;
ArrayList<String> days_exo = new ArrayList<String>();
CheckBox cb_lundi, cb_mardi, cb_mercredi, cb_jeudi, cb_vendredi, cb_samedi, cb_dimanche;
private ArrayList<CheckBox> cb_list = new ArrayList<>();
private ArrayList<String> current_days_checked = new ArrayList<>();
Integer nbre_day = 0;
public ListExercicesAdapter(Context context, ArrayList<String> values) {
super(context, R.layout.exercises_list_row, values);
this.context = context;
......@@ -40,102 +67,198 @@ public class ListExercicesAdapter extends ArrayAdapter<String> {
ProgramCreationActivity activity = (ProgramCreationActivity) context;
System.out.println("values : " + values);
String exercise = values.get(position);
String training_days = "";
final String[] training_days = {""};
Drawable delete_cross = context.getResources().getDrawable(R.drawable.cross_mark);
Drawable pen = context.getResources().getDrawable(R.drawable.edit);
// Get training days for this exercise
for (Map.Entry<Exercise, ArrayList<String>> set : activity.program.entrySet()) {
System.out.println(set.getKey().name);
if (set.getKey().name == exercise) {
training_days = "";
training_days[0] = "";
for (String day : set.getValue()) {
training_days += getShortDayName(day) + ", ";
training_days[0] += getShortDayName(day) + " ";
}
}
}
training_days = training_days.substring(0, training_days.length() - 2);
System.out.println("training days : " + training_days);
training_days[0] = training_days[0].substring(0, training_days[0].length() - 2);
// Display texts and images in Views
delete_button.setImageDrawable(delete_cross);
edit_button.setImageDrawable(pen);
exercise_name.setText(exercise);
training_daysView.setText(training_days);
training_daysView.setText(training_days[0]);
// Ecouteur de clics pour chaque élément de la ListView
edit_button.setOnClickListener(view -> {
/*
System.out.println("details : " + activity.program);
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 exerciseName = dialogView.findViewById(R.id.exercise_name);
exerciseName.setText(exercise);
// 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)) {
// 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(exo.description);
TextView break_time_TextView = dialogView.findViewById(R.id.pause_edit);
break_time_TextView.setText(String.valueOf(exo.breakVal/1000));
current_days_checked = new ArrayList<String>();
nbre_day = 0;
days_exo = new ArrayList<>();
for (Map.Entry<Exercise, ArrayList<String>> set : activity.program.entrySet()) {
if (set.getKey().name == exercise) {
for (String day : set.getValue()) {
if(!days_exo.contains(day)){
days_exo.add(day);
}
}
name_exo = set.getKey().name;
description_exo = set.getKey().description;
timer_exo = Long.valueOf(set.getKey().timer);
break_exo = Long.valueOf(set.getKey().breakVal);
img_actual_exo = set.getKey().image_url;
}
}
Dialog dialog = new Dialog(this.context);
dialog.setContentView(R.layout.modify_exercice_popup);
ImageView closeButton = dialog.findViewById(R.id.close_btn);
closeButton.setOnClickListener(w -> dialog.dismiss());
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(int i = 0; i < days_exo.size(); i++){
if(days_exo.get(i).equals("lundi")){
cb_lundi.setChecked(true);
current_days_checked.add(days_exo.get(i));
nbre_day += 1;
}
if(days_exo.get(i).equals("mardi")){
cb_mardi.setChecked(true);
current_days_checked.add(days_exo.get(i));
nbre_day += 1;
}
if(days_exo.get(i).equals("mercredi")){
cb_mercredi.setChecked(true);
current_days_checked.add(days_exo.get(i));
nbre_day += 1;
}
if(days_exo.get(i).equals("jeudi")){
cb_jeudi.setChecked(true);
current_days_checked.add(days_exo.get(i));
nbre_day += 1;
}
if(days_exo.get(i).equals("vendredi")){
cb_vendredi.setChecked(true);
current_days_checked.add(days_exo.get(i));
nbre_day += 1;
}
if(days_exo.get(i).equals("samedi")){
cb_samedi.setChecked(true);
current_days_checked.add(days_exo.get(i));
nbre_day += 1;
}
if(days_exo.get(i).equals("dimanche")){
cb_dimanche.setChecked(true);
current_days_checked.add(days_exo.get(i));
nbre_day += 1;
}
}
// 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());
for (CheckBox cb : cb_list) cb.setOnCheckedChangeListener(myCheckBoxListener);
ConstraintLayout form_layout = dialog.findViewById(R.id.constraintLayout2);
// Rechercher l'exercice dans la HashMap et modifier ces paramètres
EditText description_text = dialog.findViewById(R.id.exercise_description);
EditText timer_edit = dialog.findViewById(R.id.exercise_timer);
EditText break_edit = dialog.findViewById(R.id.exercice_break);
TextView timer_text = dialog.findViewById(R.id.timer_text);
if(description_exo != null){
description_text.setText(description_exo);
}
if(timer_exo == 0){
timer_edit.setVisibility(View.INVISIBLE);
timer_edit.setEnabled(false);
timer_text.setText("");
}else{
timer_edit.setText(timer_exo.toString());
}
if(break_exo != null){
break_edit.setText(break_exo.toString());
}
for (Exercise exo : exercises) {
if (Objects.equals(exo.name, exercise)) {
exo.description = new_description;
exo.breakVal = new_break_time * 1000;
dialog.show();
Button save_btn = dialog.findViewById(R.id.btn_save_modif);
save_btn.setOnClickListener(w -> {
if(nbre_day > 0){
String description_str = description_text.getText().toString();
String string_break = break_edit.getText().toString();
Integer break_time = Integer.parseInt(string_break);
String string_timer = timer_edit.getText().toString();
if(string_timer.equals("")){
actual_exo = new Exercise(name_exo, description_str, break_time, "@drawable/developpe_couche_barre", 0);
}else{
Integer timer_int = Integer.parseInt(string_timer);
actual_exo = new Exercise(name_exo, description_str, break_time, "@drawable/developpe_couche_barre", timer_int);
}
Iterator<Map.Entry<Exercise, ArrayList<String>>> iterator = activity.program.entrySet().iterator();
while (iterator.hasNext()) {
Map.Entry<Exercise, ArrayList<String>> entry = iterator.next();
Exercise key = entry.getKey();
if (key.name.equals(exercise)) {
key.description = description_str;
key.breakVal = break_time;
key.timer = Math.toIntExact(timer_exo);
}
for (Map.Entry<Exercise, ArrayList<String>> set : activity.program.entrySet()) {
if (set.getKey().name == exercise) {
set.setValue(current_days_checked);
}
}
}
for (Map.Entry<Exercise, ArrayList<String>> set : activity.program.entrySet()) {
if (set.getKey().name == exercise) {
training_days[0] = "";
for (String day : set.getValue()) {
training_days[0] += getShortDayName(day) + " ";
}
}
}
training_daysView.setText(training_days[0]);
dialog.dismiss();
}
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();
else{
Toast.makeText(this.context, "Veuillez sélectionner au moins un jour !",
Toast.LENGTH_SHORT).show();
}
});
form_layout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (description_text.hasFocus()) {
description_text.clearFocus();
}
}
});
ImageView closeButton = dialogView.findViewById(R.id.close_btn);
closeButton.setOnClickListener(v -> {
// Fermer la pop-up
dialog.dismiss();
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);
}
}
});
*/
TextView name_exercice = dialog.findViewById(R.id.exercice_to_modify_name);
name_exercice.setText(name_exo);
int resId = context.getResources().getIdentifier(img_actual_exo, "drawable", context.getPackageName());
ImageView image = dialog.findViewById(R.id.exercice_to_modify_image);
image.setImageResource(resId);
});
// Ajouter un OnClickListener à l'image
......@@ -152,8 +275,6 @@ public class ListExercicesAdapter extends ArrayAdapter<String> {
}
}
ArrayList<String> updatedExercicesList = new ArrayList<>();
for (Map.Entry<Exercise, ArrayList<String>> set : activity.program.entrySet()) {
updatedExercicesList.add(set.getKey().name);
......@@ -171,11 +292,6 @@ public class ListExercicesAdapter extends ArrayAdapter<String> {
this.values.clear();
this.values.addAll(exercices);
notifyDataSetChanged();
System.out.println("values : " + values);
}
private void save_workout_details() {
}
String getShortDayName(String day) {
......@@ -189,7 +305,71 @@ public class ListExercicesAdapter extends ArrayAdapter<String> {
else throw new IllegalArgumentException();
}
public CompoundButton.OnCheckedChangeListener myCheckBoxListener =
new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (buttonView == cb_lundi) {
if(current_days_checked.contains("lundi")){
current_days_checked.remove("lundi");
nbre_day -= 1;
}else{
current_days_checked.add("lundi");
nbre_day += 1;
}
} else if (buttonView == cb_mardi) {
if(current_days_checked.contains("mardi")){
current_days_checked.remove("mardi");
nbre_day -= 1;
}else{
current_days_checked.add("mardi");
nbre_day += 1;
}
} else if (buttonView == cb_mercredi) {
if(current_days_checked.contains("mercredi")){
current_days_checked.remove("mercredi");
nbre_day -= 1;
}else{
current_days_checked.add("mercredi");
nbre_day += 1;
}
} else if (buttonView == cb_jeudi) {
if(current_days_checked.contains("jeudi")){
current_days_checked.remove("jeudi");
nbre_day -= 1;
}else{
current_days_checked.add("jeudi");
nbre_day += 1;
}
} else if (buttonView == cb_vendredi) {
if(current_days_checked.contains("vendredi")){
current_days_checked.remove("vendredi");
nbre_day -= 1;
}else{
current_days_checked.add("vendredi");
nbre_day += 1;
}
} else if (buttonView == cb_samedi) {
if(current_days_checked.contains("samedi")){
current_days_checked.remove("samedi");
nbre_day -= 1;
}else{
current_days_checked.add("samedi");
nbre_day += 1;
}
} else if (buttonView == cb_dimanche) {
if(current_days_checked.contains("dimanche")){
current_days_checked.remove("dimanche");
nbre_day -= 1;
}else{
current_days_checked.add("dimanche");
nbre_day += 1;
}
//for (CheckBox cb : cb_list) if (!Objects.equals(cb, cb_dimanche)) cb.setChecked(false);
}
System.out.println(current_days_checked);
}
};
}
......
package be.lepl1509group13.workoutwarrior;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.TextView;
import android.widget.Toast;
import androidx.activity.result.ActivityResultLauncher;
import androidx.activity.result.contract.ActivityResultContracts;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.view.GravityCompat;
import androidx.drawerlayout.widget.DrawerLayout;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageButton;
import android.widget.TextView;
import android.widget.Toast;
import com.google.android.material.navigation.NavigationView;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
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.ValueEventListener;
import com.google.gson.Gson;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
......@@ -41,6 +52,7 @@ public class MainActivity extends AppCompatActivity implements MainAdapter.OnIte
private final FirebaseDatabase firebaseDb = FirebaseDatabase.getInstance();
private DatabaseReference db;
private FirebaseAuth mAuth;
private Integer numberOfProgramsToDisplay = 0, totalNumberOfCustomPrograms = 0;
private boolean needsRefresh = false;
......@@ -51,6 +63,9 @@ public class MainActivity extends AppCompatActivity implements MainAdapter.OnIte
setContentView(R.layout.activity_main);
getSupportActionBar().hide();
mAuth = FirebaseAuth.getInstance();
FirebaseUser currentUser = mAuth.getCurrentUser();
db = firebaseDb.getReference("Programs");
getProgramData();
......@@ -74,6 +89,9 @@ public class MainActivity extends AppCompatActivity implements MainAdapter.OnIte
drawerLayout.closeDrawer(GravityCompat.START);
return false;
});
//check if any programs were shared by friends
getUserPseudo(currentUser);
}
@Override
......@@ -242,4 +260,176 @@ public class MainActivity extends AppCompatActivity implements MainAdapter.OnIte
});
}
private void getSharedPrograms(String currentUser) {
db = firebaseDb.getReference("Shared_program");
db.addValueEventListener(new ValueEventListener() {
@SuppressLint("SetTextI18n")
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
DataSnapshot firstChild = dataSnapshot.child(currentUser);
for (DataSnapshot childData: firstChild.getChildren()) {
for(DataSnapshot realData : firstChild.child(childData.getKey()).getChildren()){
//aled
String dataFromDB = realData.getValue(String.class);
Gson gson = new Gson();
HashMap<String, ArrayList<Exercise>> programByDay = gson.fromJson(dataFromDB, HashMap.class);
androidx.appcompat.app.AlertDialog.Builder builder = new androidx.appcompat.app.AlertDialog.Builder(MainActivity.this);
LayoutInflater inflater = getLayoutInflater();
View dialogView = inflater.inflate(R.layout.shared_workout_popup, null);
TextView title = dialogView.findViewById(R.id.share_popup_title);
title.setText(childData.getKey() + " a partagé avec vous son programme personnel.");
TextView description = dialogView.findViewById(R.id.share_popup_description);
description.setText("Voulez-vous l'accepter ?");
builder.setView(dialogView);
builder.setPositiveButton("J'accepte", (dialog, which) ->
addNewCustomWorkout(childData.getKey(), programByDay));
builder.setNegativeButton("Je refuse", (dialog, which) ->
Log.d("MainActivity", "Cancel workout share with: " + childData.getKey()));
AlertDialog dialog = builder.create();
dialog.setOnShowListener(new DialogInterface.OnShowListener() {
@Override
public void onShow(DialogInterface dialog) {
Button positiveButton = ((AlertDialog) dialog).getButton(DialogInterface.BUTTON_POSITIVE);
positiveButton.setTextColor(getResources().getColor(R.color.green));
Button negativeButton = ((AlertDialog) dialog).getButton(DialogInterface.BUTTON_NEGATIVE);
negativeButton.setTextColor(getResources().getColor(R.color.black));
}
});
dialog.show();
}
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
Toast.makeText(MainActivity.this, "Une erreur est survenue !", Toast.LENGTH_SHORT).show();
}
});
}
private void getUserPseudo(FirebaseUser currentUser) {
if(currentUser != null){
db = firebaseDb.getReference("Account_pseudo");
db.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
for (DataSnapshot childSnapshot: dataSnapshot.getChildren()) {
String userKey = childSnapshot.getKey();
String pseudo = childSnapshot.getValue(String.class);
if(Objects.equals(userKey, currentUser.getUid())){
db = firebaseDb.getReference("Friends");
getSharedPrograms(pseudo);
return;
}
}
}
@Override
public void onCancelled(@NonNull DatabaseError error) {
Toast.makeText(MainActivity.this, "Une erreur est survenue !", Toast.LENGTH_SHORT).show();
}
});
}
}
private void addNewCustomWorkout(String username, HashMap<String, ArrayList<Exercise>> programByDay) {
/*
Log.d("NOP", "user: " + username);
Log.d("NOP", "data: " + programByDay);
Log.d("TAG", "addNewCustomWorkout: " + programByDay.get("lundi"));
String lundiString = null, lundiSubstring, mardiString = null, mardiSubstring, mercrediString = null, mercrediSubstring, jeudiString = null, jeudiSubstring,
vendrediString = null, vendrediSubstring, samediString = null, samediSubstring, dimancheString = null, dimancheSubstring;
ArrayList<Exercise> lundi = programByDay.get("lundi");
if(!lundi.isEmpty()){
lundiSubstring = lundi.toString().substring(lundi.toString().indexOf("name=") + 5, lundi.toString().indexOf(", timer"));
lundiString = lundiSubstring.trim().replaceAll("^\"|\"$", "");
}
ArrayList<Exercise> mardi = programByDay.get("mardi");
if(!mardi.isEmpty()){
mardiSubstring = mardi.toString().substring(mardi.toString().indexOf("name=") + 5, mardi.toString().indexOf(", timer"));
mardiString = mardiSubstring.trim().replaceAll("^\"|\"$", "");
}
ArrayList<Exercise> mercredi = programByDay.get("mercredi");
if(!mercredi.isEmpty()){
mercrediSubstring = mercredi.toString().substring(mercredi.toString().indexOf("name=") + 5, mercredi.toString().indexOf(", timer"));
mercrediString = mercrediSubstring.trim().replaceAll("^\"|\"$", "");
}
ArrayList<Exercise> jeudi = programByDay.get("jeudi");
if(!jeudi.isEmpty()){
jeudiSubstring = jeudi.toString().substring(jeudi.toString().indexOf("name=") + 5, jeudi.toString().indexOf(", timer"));
jeudiString = jeudiSubstring.trim().replaceAll("^\"|\"$", "");
}
ArrayList<Exercise> vendredi = programByDay.get("vendredi");
if(!vendredi.isEmpty()){
vendrediSubstring = vendredi.toString().substring(vendredi.toString().indexOf("name=") + 5, vendredi.toString().indexOf(", timer"));
vendrediString = vendrediSubstring.trim().replaceAll("^\"|\"$", "");
}
ArrayList<Exercise> samedi = programByDay.get("samedi");
if(!samedi.isEmpty()){
samediSubstring = samedi.toString().substring(samedi.toString().indexOf("name=") + 5, samedi.toString().indexOf(", timer"));
samediString = samediSubstring.trim().replaceAll("^\"|\"$", "");
}
ArrayList<Exercise> dimanche = programByDay.get("dimanche");
if(dimanche.isEmpty()){
dimancheSubstring = dimanche.toString().substring(dimanche.toString().indexOf("name=") + 5, dimanche.toString().indexOf(", timer"));
dimancheString = dimancheSubstring.trim().replaceAll("^\"|\"$", "");
}
//String inputString = "[{breakVal=60.0, description=Répétitions : 4x10, image_url=@drawable/developpe_couche_barre, name=Développé couché, timer=0.0, workingDays=[]}]";
System.out.println(lundiString); // Output: Développé couché
System.out.println(mardiString); // Output: Développé couché
System.out.println(mercrediString); // Output: Développé couché
System.out.println(jeudiString); // Output: Développé couché
System.out.println(vendrediString); // Output: Développé couché
System.out.println(samediString); // Output: Développé couché
System.out.println(dimancheString); // Output: Développé couché
ArrayList<Exercise> newLundi = new ArrayList<>();
newLundi.add(new Exercise(lundiString, "fff", 10, "ah oue", 10));
programByDay.clear();
programByDay.put("lundi", newLundi);
try {
String programpath = username + ".ser";
HashMap<String, ArrayList<Exercise>> entry = programByDay;
ExerciseEntry exerciseEntry = new ExerciseEntry(entry);
FileOutputStream fileOutputStream = openFileOutput(programpath, Context.MODE_PRIVATE);
ObjectOutputStream objectOutputStream = new ObjectOutputStream(fileOutputStream);
objectOutputStream.writeObject(exerciseEntry);
objectOutputStream.close();
fileOutputStream.close();
//todo
//Tell the mainActivity to refresh, to add the new program
//setResult(1);
Toast.makeText(MainActivity.this, "Programme enregistré !",
Toast.LENGTH_SHORT).show();
} catch (Exception e) {
e.printStackTrace();
}
*/
}
}
\ No newline at end of file
......@@ -7,6 +7,7 @@ import android.graphics.Color;
import android.graphics.Typeface;
import android.os.Bundle;
import android.provider.ContactsContract;
import android.text.InputType;
import android.widget.AdapterView;
import android.content.Context;
import android.os.Bundle;
......@@ -30,6 +31,7 @@ import android.widget.AutoCompleteTextView;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
......@@ -55,6 +57,7 @@ import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
......@@ -66,9 +69,11 @@ public class ProgramCreationActivity extends AppCompatActivity {
// Déclaration variables
AutoCompleteTextView input_exo; // Champ de texte pour rechercher les exercices
Integer nbre_day = 0;
// Liste d'exos dynamique à remplir depuis la DB
public Exercise actual_exo ;
public String img_actual_exo;
private static ArrayList<String> EXOS = new ArrayList<>(); // Liste des exercices de la base de données
CheckBox cb_lundi, cb_mardi, cb_mercredi, cb_jeudi, cb_vendredi, cb_samedi, cb_dimanche;
private ArrayList<CheckBox> cb_list = new ArrayList<>();
......@@ -83,7 +88,8 @@ public class ProgramCreationActivity extends AppCompatActivity {
ListExercicesAdapter exercisesListAdapter;
String descriptionText;
Long break_time;
@Override
protected void onCreate(Bundle savedInstanceState) {
......@@ -92,9 +98,6 @@ public class ProgramCreationActivity extends AppCompatActivity {
getSupportActionBar().hide();
//init_days_TextView();
db = firebaseDb.getReference("Workouts");
get_DB_Exercices();
......@@ -130,12 +133,11 @@ public class ProgramCreationActivity extends AppCompatActivity {
// Ajoute l'exo dans la HashMap (en mémoire) et dans la ListView (sur la page) quand l'utilisateur appuie sur le bouton "ajouter"
addExerciceListener();
// Sauvegarde du programme
saveProgramListener();
}
private void helpButtonListener(){
public void helpButtonListener(){
help_creation_program = findViewById(R.id.help_program_creation);
help_creation_program.setOnClickListener(v -> {
AlertDialog.Builder builder = new AlertDialog.Builder(ProgramCreationActivity.this);
......@@ -151,47 +153,65 @@ public class ProgramCreationActivity extends AppCompatActivity {
});
}
private void saveProgramListener(){
public void saveProgramListener(){
Button save_btn = findViewById((R.id.save_button));
save_btn.setOnClickListener(v -> {
convertToProgramByDay();
try {
// recup le nom de programme comme nom de fichier -> nomdeprogramme.ser
EditText programNameEditText = findViewById(R.id.program_name);
String programName = programNameEditText.getText().toString();
String programpath = programName + ".ser";
// place le HashMap du programme dans nomdeprogramme.ser
HashMap<String, ArrayList<Exercise>> entry = programByDay;
ExerciseEntry exerciseEntry = new ExerciseEntry(entry);
FileOutputStream fileOutputStream = openFileOutput(programpath, Context.MODE_PRIVATE);
ObjectOutputStream objectOutputStream = new ObjectOutputStream(fileOutputStream);
objectOutputStream.writeObject(exerciseEntry);
objectOutputStream.close();
fileOutputStream.close();
//Tell the mainActivity to refresh, to add the new program
setResult(1);
Toast.makeText(ProgramCreationActivity.this, "Programme enregistré !",
EditText program_name = findViewById(R.id.program_name);
String program_name_str = program_name.getText().toString();
if(program_name_str.equals("")){
Toast.makeText(ProgramCreationActivity.this, "Veuillez entrer un nom à votre programme !",
Toast.LENGTH_SHORT).show();
} catch (Exception e) {
e.printStackTrace();
}
else{
convertToProgramByDay();
boolean all_empty = true;
for (ArrayList<Exercise> valeurs : programByDay.values()) {
if (!valeurs.isEmpty()) {
all_empty = false;
break;
}
}
if(all_empty){
Toast.makeText(ProgramCreationActivity.this, "Veuillez entrer au moins un exercice à votre programme !",
Toast.LENGTH_SHORT).show();
}else{
try {
// recup le nom de programme comme nom de fichier -> nomdeprogramme.ser
EditText programNameEditText = findViewById(R.id.program_name);
String programName = programNameEditText.getText().toString();
String programpath = programName + ".ser";
// place le HashMap du programme dans nomdeprogramme.ser
HashMap<String, ArrayList<Exercise>> entry = programByDay;
ExerciseEntry exerciseEntry = new ExerciseEntry(entry);
FileOutputStream fileOutputStream = openFileOutput(programpath, Context.MODE_PRIVATE);
ObjectOutputStream objectOutputStream = new ObjectOutputStream(fileOutputStream);
objectOutputStream.writeObject(exerciseEntry);
objectOutputStream.close();
fileOutputStream.close();
//Tell the mainActivity to refresh, to add the new program
setResult(1);
Toast.makeText(ProgramCreationActivity.this, "Programme enregistré !",
Toast.LENGTH_SHORT).show();
} catch (Exception e) {
e.printStackTrace();
}
}
}
});
}
private void addExerciceListener() {
public void addExerciceListener() {
/**
* Ajoute un exercice au jour courant dans la HashMap programByDay et dans la ListView exos_current_day
*/
Button add_exo_button = findViewById(R.id.add_exo_button);
add_exo_button.setOnClickListener(v -> {
current_days_checked.clear();
nbre_day = 0;
// Récupérer la valeur du champ de texte AutoCompleteTextView
String exercise_searched = input_exo.getText().toString();
......@@ -230,7 +250,7 @@ public class ProgramCreationActivity extends AppCompatActivity {
for (DataSnapshot snapshot : dataSnapshot.getChildren()) {
Long timer = (snapshot.child("timer").getValue(Long.class))/1000;
img_actual_exo = snapshot.child("image_url").getValue(String.class);
Long break_time = (snapshot.child("break").getValue(Long.class))/1000;
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);
......@@ -238,6 +258,27 @@ public class ProgramCreationActivity extends AppCompatActivity {
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();
}
}
});
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);
}
......@@ -260,93 +301,110 @@ public class ProgramCreationActivity extends AppCompatActivity {
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
System.out.println(databaseError);
}
});
}
});
ImageView closeButton = dialog.findViewById(R.id.close_btn);
closeButton.setOnClickListener(w -> dialog.dismiss());
ImageView closeButton = dialog.findViewById(R.id.close_btn);
closeButton.setOnClickListener(w -> dialog.dismiss());
TextView name_exercice = dialog.findViewById(R.id.exercice_to_modify_name);
name_exercice.setText(exercise_searched);
TextView name_exercice = dialog.findViewById(R.id.exercice_to_modify_name);
name_exercice.setText(exercise_searched);
Button save_btn = dialog.findViewById(R.id.btn_save_modif);
save_btn.setOnClickListener(w -> {
EditText description_text = dialog.findViewById(R.id.exercise_description);
String description_str = description_text.getText().toString();
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 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();
if(string_timer.equals("")){
actual_exo = new Exercise(exercise_searched, description_str, break_time, "@drawable/developpe_couche_barre", 0);
}else{
Integer timer_int = Integer.parseInt(string_timer);
actual_exo = new Exercise(exercise_searched, description_str, break_time, "@drawable/developpe_couche_barre", timer_int);
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("");
}
else{
Toast.makeText(ProgramCreationActivity.this, "Veuillez sélectionner au moins un jour !",
Toast.LENGTH_SHORT).show();
}
addToProgram(actual_exo, new ArrayList<>(current_days_checked));
dialog.dismiss();
});
// Effacer le champ de texte AutoCompleteTextView
input_exo.setText("");
}
});
}
private CompoundButton.OnCheckedChangeListener myCheckBoxListener =
public CompoundButton.OnCheckedChangeListener myCheckBoxListener =
new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (buttonView == cb_lundi) {
if(current_days_checked.contains("lundi")){
current_days_checked.remove("lundi");
nbre_day -= 1;
}else{
current_days_checked.add("lundi");
nbre_day += 1;
}
} else if (buttonView == cb_mardi) {
if(current_days_checked.contains("mardi")){
current_days_checked.remove("mardi");
nbre_day -= 1;
}else{
current_days_checked.add("mardi");
nbre_day += 1;
}
} else if (buttonView == cb_mercredi) {
if(current_days_checked.contains("mercredi")){
current_days_checked.remove("mercredi");
nbre_day -= 1;
}else{
current_days_checked.add("mercredi");
nbre_day += 1;
}
} else if (buttonView == cb_jeudi) {
if(current_days_checked.contains("jeudi")){
current_days_checked.remove("jeudi");
nbre_day -= 1;
}else{
current_days_checked.add("jeudi");
nbre_day += 1;
}
} else if (buttonView == cb_vendredi) {
if(current_days_checked.contains("vendredi")){
current_days_checked.remove("vendredi");
nbre_day -= 1;
}else{
current_days_checked.add("vendredi");
nbre_day += 1;
}
} else if (buttonView == cb_samedi) {
if(current_days_checked.contains("samedi")){
current_days_checked.remove("samedi");
nbre_day -= 1;
}else{
current_days_checked.add("samedi");
nbre_day += 1;
}
} else if (buttonView == cb_dimanche) {
if(current_days_checked.contains("dimanche")){
current_days_checked.remove("dimanche");
nbre_day -= 1;
}else{
current_days_checked.add("dimanche");
nbre_day += 1;
}
//for (CheckBox cb : cb_list) if (!Objects.equals(cb, cb_dimanche)) cb.setChecked(false);
}
System.out.println(current_days_checked);
}
};
......@@ -375,10 +433,12 @@ public class ProgramCreationActivity extends AppCompatActivity {
});
}
private void addToProgram(Exercise exercise, ArrayList<String> trainingDays) {
public void addToProgram(Exercise exercise, ArrayList<String> trainingDays) {
/**
* 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();
......@@ -416,8 +476,6 @@ public class ProgramCreationActivity extends AppCompatActivity {
}
}
System.out.println("program : " + program);
System.out.println("programByDay : " + programByDay);
}
}
......
package be.lepl1509group13.workoutwarrior;
import android.app.Dialog;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
......@@ -7,6 +8,8 @@ import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TextView;
import android.widget.Toast;
......@@ -30,7 +33,6 @@ 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;
......@@ -45,12 +47,14 @@ public class ProgramDetailActivity extends AppCompatActivity implements ProgramA
private FirebaseAuth mAuth;
private HashMap<String, ArrayList<Exercise>> programHash;
ImageButton return_btn;
TextView start_workout, delete_workout, show_workout, share_workout;
private Button start_workout, delete_workout, show_workout, share_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) {
......@@ -60,6 +64,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(); }
......@@ -70,15 +75,15 @@ public class ProgramDetailActivity extends AppCompatActivity implements ProgramA
show_workout = findViewById(R.id.show_workout);
show_workout.setOnClickListener(view -> showWorkout());
share_workout = findViewById(R.id.share_workout);
share_workout.setOnClickListener(view -> shareWorkout());
db = firebaseDb.getReference("Programs");
getProgramData(id, this_intent.getStringExtra("name"));
return_btn = findViewById(R.id.return_btn2);
return_btn.setOnClickListener(view -> finish());
share_workout = findViewById(R.id.share_workout);
share_workout.setOnClickListener(view -> {shareWorkout();});
start_workout = findViewById(R.id.start_workout);
start_workout.setOnClickListener(view -> {
Intent intent = new Intent(ProgramDetailActivity.this, WorkoutActivity.class);
......@@ -162,7 +167,6 @@ public class ProgramDetailActivity extends AppCompatActivity implements ProgramA
}
});
AlertDialog dialog = builder.create();
dialog.show();
ImageView closeShareButton = dialogView.findViewById(R.id.close_share_btn);
......@@ -170,10 +174,65 @@ public class ProgramDetailActivity extends AppCompatActivity implements ProgramA
}
}
private void showWorkout() {
Dialog dialog = new Dialog(ProgramDetailActivity.this);
dialog.setContentView(R.layout.detail_program_popup);
private void showWorkout() {
//todo
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() {
......@@ -228,7 +287,6 @@ public class ProgramDetailActivity extends AppCompatActivity implements ProgramA
public void onItemClick(String[] exercise) {display_popup_content(exercise);}
private void getProgramData(int id, String name){
if(id == -1){
//It's a custom program
......@@ -243,9 +301,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);
......@@ -255,9 +316,23 @@ public class ProgramDetailActivity extends AppCompatActivity implements ProgramA
HashMap<String, ArrayList<Exercise>> entry = exerciseEntry.getEntry();
programHash = entry;
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;
......@@ -285,6 +360,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();
}
......@@ -296,6 +381,7 @@ public class ProgramDetailActivity extends AppCompatActivity implements ProgramA
isLocalProgram = false;
delete_workout.setVisibility(View.INVISIBLE);
show_workout.setVisibility(View.INVISIBLE);
share_workout.setVisibility(View.INVISIBLE);
db.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot snapshot) {
......
......@@ -65,7 +65,6 @@ public class SharingAdapter extends RecyclerView.Adapter<SharingAdapter.MyViewHo
writeOnDatabase(sender,friend_data[0],programHash);
}
});
}
public void writeOnDatabase(String from, String to, HashMap<String, ArrayList<Exercise>> sharedProgram){
......@@ -98,9 +97,6 @@ public class SharingAdapter extends RecyclerView.Adapter<SharingAdapter.MyViewHo
System.out.println("HashMap<String, ArrayList<Exercise>>: " + testProgram);
System.out.println(testProgram);
}
@Override
......@@ -128,5 +124,3 @@ public class SharingAdapter extends RecyclerView.Adapter<SharingAdapter.MyViewHo
}
}
}
......@@ -3,11 +3,9 @@ package be.lepl1509group13.workoutwarrior;
import androidx.appcompat.app.AppCompatActivity;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.os.Vibrator;
import android.util.Log;
import android.view.View;
import android.widget.Button;
......@@ -22,6 +20,7 @@ import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;
import java.util.Arrays;
import java.util.Objects;
public class WorkoutActivity extends AppCompatActivity {
......@@ -32,20 +31,15 @@ public class WorkoutActivity extends AppCompatActivity {
private DatabaseReference db;
private Integer numberOfWorkouts;
private int[] workout_id = new int[25];
private int timer;
Button set_break_btn;
TextView set_break_timer_text;
private CountDownTimer set_countDownTimer;
long set_break_timer; // temps de pause entre les séries
private boolean set_break_timer_counting = false; // vrai si le timer de pause est en train de décompter
private Button btn_exercise_timer;
private Button btn_next_during_break;
private TextView countdown_text;
private TextView text_little_timer;
private boolean workout_timer_counting = false; // vrai si le timer de l'exo est en train de décompter
private boolean workout_timer_started = false; // vrai si le timer de l'exo a déjà été démarré (qu'il soit sur pause ou non)
private long timeLeftInMillis; // temps restant sur le timer du workout
Button next_btn;
private Button next_btn;
private int exerciseIndexToDisplay = 0;
@Override
......@@ -57,6 +51,11 @@ public class WorkoutActivity extends AppCompatActivity {
next_btn = findViewById(R.id.next_btn);
next_btn.setOnClickListener(v -> onNextClick());
btn_exercise_timer = findViewById(R.id.btn_exercise_timer);
btn_next_during_break = findViewById(R.id.btn_next_during_break);
countdown_text = findViewById(R.id.workout_timer);
text_little_timer = findViewById(R.id.text_little_timer);
//get the id of the workout && launch the workout
Intent intent = this.getIntent();
int id = intent.getIntExtra("id", 0);
......@@ -64,6 +63,10 @@ public class WorkoutActivity extends AppCompatActivity {
if (id == 0){
String[][] exercisesData = (String[][]) intent.getSerializableExtra("exercisesData");
//todo pour Killian
System.out.println("custom : " + Arrays.deepToString(exercisesData));
next_btn.setOnClickListener(v -> onNextClickCustomProgram(exercisesData));
displayCustomExercise(exercisesData);
}else{
//it's a program from the database
db = firebaseDb.getReference("Programs");
......@@ -73,27 +76,145 @@ public class WorkoutActivity extends AppCompatActivity {
ImageButton return_btn = findViewById(R.id.return_btn);
return_btn.setOnClickListener(view -> {
if (countdown != null) countdown.cancel();
if (set_countDownTimer != null) set_countDownTimer.cancel();
finish();
});
// Timer de pause entre les séries
set_break_btn = findViewById(R.id.set_break_btn);
set_break_timer_text = findViewById(R.id.set_break_timer);
//Check if the user click on "start timer"
Button launch_timer = findViewById(R.id.launch_timer);
launch_timer.setOnClickListener(view -> {
countdown = workout_timer(timer);
countdown.start();
launch_timer.setVisibility(View.INVISIBLE);
workout_timer_started = true;
workout_timer_counting = true;
//Check if the user click on the timer button
btn_exercise_timer.setOnClickListener(view -> {
Log.d("TAG", "onCreate: time left " + timeLeftInMillis);
if(btn_exercise_timer.getText() == "Pause"){
Log.d("TAG", "onCreate: COUNTDOWN CANCEL");
countdown.cancel();
btn_exercise_timer.setText("Reprendre");
}else if(btn_exercise_timer.getText() == "Reprendre") {
Log.d("TAG", "onCreate: COUNTDOWN RESTART");
countdown = workout_timer((int) timeLeftInMillis);
countdown.start();
btn_exercise_timer.setText("Pause");
}else{
Log.d("TAG", "onCreate: COUNTDOWN START");
countdown = workout_timer(timer);
countdown.start();
btn_exercise_timer.setText("Pause");
countdown_text.setVisibility(View.VISIBLE);
workout_timer_counting = true;
}
});
timeLeftInMillis = timer;
}
// Lauch custom program
void onNextClickCustomProgram(String[][] exercises) {
/**
* For custom programs: when the button "Suivant" is pressed
*/
exerciseIndexToDisplay++;
countdown_text.setVisibility(View.INVISIBLE);
if (countdown != null) countdown.cancel();
if (exerciseIndexToDisplay >= exercises.length) {
finish();
} else {
TextView name = findViewById(R.id.workout_todo);
TextView description = findViewById(R.id.workout_detail);
ImageView image = findViewById(R.id.workout_image);
btn_exercise_timer.setVisibility(View.INVISIBLE);
name.setText(exercises[exerciseIndexToDisplay][0]);
name.setVisibility(View.INVISIBLE);
description.setText(exercises[exerciseIndexToDisplay][1]);
description.setVisibility(View.INVISIBLE);
int resourceId = getResources().getIdentifier(exercises[exerciseIndexToDisplay][2], "drawable", getPackageName());
image.setImageResource(resourceId);
image.setVisibility(View.INVISIBLE);
TextView timer_break = findViewById(R.id.timer_break);
CountDownTimer countDownBreak = new CountDownTimer(3000, 1000) {
@Override
public void onTick(long l) {
timer_break.setText("");
name.setText("");
description.setText("");
image.setVisibility(View.INVISIBLE);
timer_break.setText("" + l / 1000);
next_btn.setVisibility(View.INVISIBLE);
btn_next_during_break.setVisibility(View.VISIBLE);
text_little_timer.setText("Il est temps de prendre une pause...");
}
@Override
public void onFinish() {
text_little_timer.setText("");
timer_break.setText("");
next_btn.setVisibility(View.VISIBLE);
btn_next_during_break.setVisibility(View.INVISIBLE);
displayCustomExercise(exercises);
}
};
countDownBreak.start();
//button to pass the break between 2 exercises
btn_next_during_break.setOnClickListener(view -> {
countDownBreak.cancel();
countDownBreak.onFinish();
});
}
}
void displayCustomExercise(String[][] exercises) {
/**
* For custom programs : display the exercise
*/
if (exerciseIndexToDisplay >= exercises.length) finish();
next_btn.setOnClickListener(v1 -> onNextClickCustomProgram(exercises));
TextView name = findViewById(R.id.workout_todo);
name.setText(exercises[exerciseIndexToDisplay][0]);
name.setVisibility(View.VISIBLE);
TextView description = findViewById(R.id.workout_detail);
description.setText(exercises[exerciseIndexToDisplay][1]);
description.setVisibility(View.VISIBLE);
ImageView image = findViewById(R.id.workout_image);
int resourceId = getResources().getIdentifier(exercises[exerciseIndexToDisplay][2], "drawable", getPackageName());
image.setImageResource(resourceId);
image.setVisibility(View.VISIBLE);
timer = Integer.parseInt(exercises[exerciseIndexToDisplay][3]) * 1000;
System.out.println("timer = " + timer);
if(timer != 0){
//Show the button to start the timer
btn_exercise_timer.setVisibility(View.VISIBLE);
}else{
btn_exercise_timer.setVisibility(View.INVISIBLE);
if (countdown != null) {
countdown.cancel();
}
}
/*
if (timer > 0) {
//Check if the user click on "start timer"
btn_exercise_timer.setVisibility(View.VISIBLE);
btn_exercise_timer.setOnClickListener(view -> {
countdown_text.setVisibility(View.VISIBLE);
countdown = workout_timer(timer);
countdown.start();
btn_exercise_timer.setVisibility(View.INVISIBLE);
workout_timer_counting = true;
});
timeLeftInMillis = timer;
}
*/
}
// Timer entre les séries
/*
CountDownTimer workout_break_timer() {
CountDownTimer timer = new CountDownTimer(set_break_timer, 1000) {
public void onTick(long millisUntilFinished) {
......@@ -118,7 +239,7 @@ public class WorkoutActivity extends AppCompatActivity {
};
return timer;
}
*/
private void getProgramData(int id){
db.addValueEventListener(new ValueEventListener() {
......@@ -177,46 +298,16 @@ public class WorkoutActivity extends AppCompatActivity {
int resourceId = getResources().getIdentifier(workout.child("image_url").getValue(String.class), "drawable", getPackageName());
image.setImageResource(resourceId);
set_break_timer = workout.child("break").getValue(Integer.class);
set_break_timer_text.setText(String.valueOf(set_break_timer/1000) + " secondes");
set_countDownTimer = workout_break_timer();
set_break_btn.setOnClickListener(view -> {
if (set_break_timer_counting) {
set_countDownTimer.cancel();
set_break_timer_text.setText(String.valueOf(set_break_timer/1000) + " secondes");
set_break_timer_counting = false;
// Si le timer avait déjà été actionné, on reprend le décompte
if (workout_timer_started) {
countdown = workout_timer((int) timeLeftInMillis);
countdown.start();
workout_timer_counting = true;
}
}
else {
set_countDownTimer.start();
set_break_timer_counting = true;
if (workout_timer_counting && countdown != null) {
countdown.cancel();
workout_timer_counting = false;
}
}
});
Button launch_timer = findViewById(R.id.launch_timer);
timer = workout.child("timer").getValue(Integer.class);
if(timer != 0){
//Show the button to start the timer
launch_timer.setVisibility(View.VISIBLE);
btn_exercise_timer.setVisibility(View.VISIBLE);
}else{
launch_timer.setVisibility(View.INVISIBLE);
btn_exercise_timer.setVisibility(View.INVISIBLE);
if (countdown != null) {
countdown.cancel();
countdown.onFinish();
}
}
}
@Override
......@@ -228,28 +319,17 @@ public class WorkoutActivity extends AppCompatActivity {
@SuppressLint("SetTextI18n")
private void onNextClick() {
try {
if(countdown != null){
countdown.cancel();
TextView countdown_text = findViewById(R.id.workout_timer);
countdown_text.setText("");
} catch (Exception e){
Log.d("Exception", "onNextClick: " + e);
}
if (set_countDownTimer != null) {
set_countDownTimer.cancel();
//set_countDownTimer.onFinish();
workout_timer_started = false;
countdown_text.setVisibility(View.INVISIBLE);
}
TextView name = findViewById(R.id.workout_todo);
TextView description = findViewById(R.id.workout_detail);
ImageView image = findViewById(R.id.workout_image);
Button launch_timer = findViewById(R.id.launch_timer);
launch_timer.setVisibility(View.INVISIBLE);
btn_exercise_timer.setVisibility(View.INVISIBLE);
btn_exercise_timer.setText("Démarrer le timer");
if(step == 0){
finish();
......@@ -258,48 +338,44 @@ public class WorkoutActivity extends AppCompatActivity {
else if(!Objects.equals(numberOfWorkouts, step)){
TextView timer_break = findViewById(R.id.timer_break);
CountDownTimer countDownBreak = new CountDownTimer(10000, 1000) {
CountDownTimer countDownBreak = new CountDownTimer(3000, 1000) {
@Override
public void onTick(long l) {
timer_break.setText("");
name.setText("");
description.setText("");
image.setVisibility(View.INVISIBLE);
next_btn.setVisibility(View.INVISIBLE);
btn_next_during_break.setVisibility(View.VISIBLE);
timer_break.setText("" + l/1000);
//btn_next.setVisibility(View.INVISIBLE);
set_break_timer_text.setText("Il est temps de prendre une pause...");
set_break_btn.setVisibility(View.INVISIBLE);
text_little_timer.setText("Il est temps de prendre une pause...");
}
@Override
public void onFinish() {
text_little_timer.setText("");
timer_break.setText("");
image.setVisibility(View.VISIBLE);
next_btn.setVisibility(View.VISIBLE);
set_break_btn.setVisibility(View.VISIBLE);
btn_next_during_break.setVisibility(View.INVISIBLE);
db = firebaseDb.getReference("Workouts");
getWorkoutData(Integer.toString(workout_id[step - 1]));
step ++;
}
};
countDownBreak.start();
next_btn.setText("Passer");
next_btn.setOnClickListener(v -> {
//button to pass the break between 2 exercises
btn_next_during_break.setOnClickListener(view -> {
countDownBreak.cancel();
countDownBreak.onFinish();
next_btn.setText("Suivant");
next_btn.setOnClickListener(v1 -> onNextClick());
});
} else if (numberOfWorkouts.equals(step)) {
name.setText("Entrainement terminé!");
description.setText("");
next_btn.setText("Retour à l'accueil");
image.setImageResource(0);
set_break_timer_text.setText("");
set_break_btn.setVisibility(View.INVISIBLE);
step = 0;
}
System.out.println("countdown = " + countdown);
}
CountDownTimer workout_timer(Integer millis){
......
......@@ -36,12 +36,12 @@
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/delete_workout"
android:id="@+id/share_workout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/orange"
android:backgroundTint="@color/orange"
android:text="@string/delete_workout"
android:text="@string/share_workout"
android:textColor="@color/black"
app:iconTint="@color/orange"
android:layout_marginEnd="15dp"
......@@ -127,18 +127,34 @@
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<Button
android:id="@+id/show_workout"
android:layout_width="wrap_content"
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/orange"
android:backgroundTint="@color/orange"
android:text="@string/show_workout"
android:textColor="@color/black"
app:iconTint="@color/orange"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/start_workout" />
app:layout_constraintTop_toBottomOf="@+id/start_workout"
android:gravity="center">
<Button
android:id="@+id/show_workout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/orange"
android:backgroundTint="@color/orange"
android:text="@string/show_workout"
android:textColor="@color/black"
app:iconTint="@color/orange"
android:layout_marginRight="35dp"/>
<Button
android:id="@+id/delete_workout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/orange"
android:backgroundTint="@color/orange"
android:text="@string/delete_workout"
android:textColor="@color/black"
app:iconTint="@color/orange" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
......@@ -109,7 +109,7 @@
app:layout_constraintStart_toStartOf="parent" />
<Button
android:id="@+id/launch_timer"
android:id="@+id/btn_exercise_timer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="35dp"
......@@ -119,27 +119,16 @@
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<Button
android:id="@+id/set_break_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Pause"
android:layout_marginTop="20dp"
app:layout_constraintTop_toBottomOf="@id/workout_detail"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>
<TextView
android:id="@+id/set_break_timer"
android:id="@+id/text_little_timer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@android:color/black"
app:layout_constraintBottom_toTopOf="@+id/set_break_btn"
app:layout_constraintEnd_toEndOf="@id/set_break_btn"
app:layout_constraintStart_toStartOf="@id/set_break_btn"
app:layout_constraintTop_toBottomOf="@+id/workout_detail" />
app:layout_constraintBottom_toTopOf="@+id/btn_exercise_timer"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/workout_detail"
tools:text="textview" />
<Button
android:id="@+id/next_btn"
......@@ -152,4 +141,16 @@
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
<Button
android:id="@+id/btn_next_during_break"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="25dp"
android:layout_marginBottom="25dp"
android:backgroundTint="@color/orange"
android:text="Passer"
android:visibility="invisible"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
<?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
<?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
......@@ -179,7 +179,8 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Pause"
android:text=""/>
android:text=""
android:maxLines="5"/>
<TextView
android:id="@+id/timer_text"
......
......@@ -47,6 +47,4 @@
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/close_btn" />
</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
</androidx.constraintlayout.widget.ConstraintLayout>
<?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"
android:background="@color/white">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/share_popup"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginTop="20dp"
android:layout_marginBottom="60dp"
android:padding="15dp">
<TextView
android:id="@+id/share_popup_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="@font/poppins_semibold"
android:textSize="20sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:text="test" />
<TextView
android:id="@+id/share_popup_description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="@font/poppins"
android:layout_marginTop="20dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/share_popup_title"
tools:text="test"
android:textSize="20sp" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content">
......@@ -39,4 +39,4 @@
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
</androidx.constraintlayout.widget.ConstraintLayout>
......@@ -8,9 +8,8 @@
<string name="entrainement_foot">Entrainement Foot</string>
<string name="entrainement_badminton">Entrainement Badminton</string>
<string name="launch_workout">Démarrer</string>
<string name="share_workout">Partager</string>
<string name="delete_workout">Supprimer le programme</string>
<string name="show_workout">Afficher / Modifier le programme</string>
<string name="delete_workout">Supprimer</string>
<string name="show_workout">Afficher</string>
<string name="title_activity_account">AccountActivity</string>
<string name="prompt_email">Email</string>
<string name="prompt_password">Password</string>
......@@ -25,4 +24,5 @@
<string name="add_friend_activity_title">Entrez le pseudo de l\'ami à ajouter</string>
<string name="add_friend_activity_btn_text">Ajouter</string>
<string name="login_title">Veuillez d\'abord vous connecter</string>
<string name="share_workout">Partager ce programme</string>
</resources>
......@@ -7,6 +7,7 @@ buildscript {
dependencies {
classpath "com.android.tools.build:gradle:7.0.0"
classpath 'com.google.gms:google-services:4.3.10'
classpath 'com.google.gms:google-services:4.3.15'
classpath 'com.google.firebase:firebase-crashlytics-gradle:2.8.1'
// NOTE: Do not place your application dependencies here; they belong
......