Compare commits

..

1 commit

Author SHA1 Message Date
eb93410553 S3b : sérialisation 2026-02-03 16:42:38 +01:00
28 changed files with 275 additions and 1003 deletions

View file

@ -4,7 +4,7 @@
<selectionStates>
<SelectionState runConfigName="app">
<option name="selectionMode" value="DROPDOWN" />
<DropdownSelection timestamp="2026-02-05T11:33:42.096254600Z">
<DropdownSelection timestamp="2026-02-03T14:43:08.366675Z">
<Target type="DEFAULT_BOOT">
<handle>
<DeviceId pluginId="PhysicalDevice" identifier="serial=QGP7K78LKBMVZTRC" />
@ -27,28 +27,7 @@
</DialogSelection>
</SelectionState>
<SelectionState runConfigName="testCalculIMG()">
<option name="selectionMode" value="DIALOG" />
<DropdownSelection timestamp="2026-02-04T16:57:48.611512800Z">
<Target type="DEFAULT_BOOT">
<handle>
<DeviceId pluginId="PhysicalDevice" identifier="serial=QGP7K78LKBMVZTRC" />
</handle>
</Target>
</DropdownSelection>
<DialogSelection>
<targets>
<Target type="DEFAULT_BOOT">
<handle>
<DeviceId pluginId="PhysicalDevice" identifier="serial=QGP7K78LKBMVZTRC" />
</handle>
</Target>
<Target type="DEFAULT_BOOT">
<handle>
<DeviceId pluginId="LocalEmulator" identifier="path=C:\Users\erwan\.android\avd\Medium_Phone.avd" />
</handle>
</Target>
</targets>
</DialogSelection>
<option name="selectionMode" value="DROPDOWN" />
</SelectionState>
</selectionStates>
</component>

View file

@ -8,7 +8,7 @@ android {
defaultConfig {
applicationId "com.example.coach"
minSdk 21
minSdk 16
targetSdk 36
versionCode 1
versionName "1.0"
@ -34,11 +34,8 @@ dependencies {
implementation libs.material
implementation libs.activity
implementation libs.constraintlayout
implementation libs.recyclerview
testImplementation libs.junit
androidTestImplementation libs.ext.junit
androidTestImplementation libs.espresso.core
implementation 'com.google.code.gson:gson:2.11.0'
implementation 'com.squareup.retrofit2:retrofit:2.11.0'
implementation 'com.squareup.retrofit2:converter-gson:2.11.0'
}

View file

@ -12,14 +12,15 @@ import static androidx.test.espresso.action.ViewActions.click;
import static androidx.test.espresso.action.ViewActions.typeText;
import static androidx.test.espresso.action.ViewActions.closeSoftKeyboard;
import static androidx.test.espresso.matcher.ViewMatchers.withId;
import static androidx.test.espresso.assertion.ViewAssertions.matches;
import static androidx.test.espresso.matcher.ViewMatchers.withText;
import com.example.coach.R;
@RunWith(AndroidJUnit4.class)
public class CalculActivityTest {
public class MainActivityTest {
@Rule
public ActivityScenarioRule activityRule = new ActivityScenarioRule<>(CalculActivity.class);
public ActivityScenarioRule activityRule = new ActivityScenarioRule<>(MainActivity.class);
@Test
public void testCalculIMG(){

View file

@ -2,8 +2,6 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
@ -12,26 +10,16 @@
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.Coach"
android:usesCleartextTraffic="true">
<activity
android:name=".view.HistoActivity"
android:parentActivityName=".view.MainActivity"
android:exported="false" />
android:theme="@style/Theme.Coach">
<activity
android:name=".view.MainActivity"
android:exported="true"
android:launchMode="singleTop">
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".view.CalculActivity"
android:exported="false"
android:parentActivityName=".view.MainActivity"></activity>
</application>
</manifest>

View file

@ -1,30 +0,0 @@
package com.example.coach.api;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;
public class CoachApi {
private static final String API_URL = "http://10.0.2.2/rest_coach/";
private static Retrofit retrofit = null;
private static Gson gson = new GsonBuilder()
.setDateFormat("yyyy-MM-dd HH:mm:ss")
.create();
public static Retrofit getRetrofit()
{
if(retrofit == null){
retrofit = new Retrofit.Builder()
.baseUrl(API_URL)
.addConverterFactory(GsonConverterFactory.create(gson))
.build();
}
return retrofit;
}
public static Gson getGson() {
return gson;
}
}

View file

@ -1,45 +0,0 @@
package com.example.coach.api;
import android.util.Log;
import com.example.coach.model.Profil;
import java.util.List;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
public class HelperApi {
private static final IRequestApi api = CoachApi.getRetrofit().create(IRequestApi.class);
public static IRequestApi getApi()
{
return api;
}
public static <T> void call(Call<ResponseApi<T>> call, ICallbackApi<T> callback)
{
call.enqueue(new Callback<ResponseApi<T>>() {
@Override
public void onResponse(Call<ResponseApi<T>> call, Response<ResponseApi<T>> response) {
Log.d("API", "code : " + response.body().getCode() +
" message : " + response.body().getMessage() +
" result : " + response.body().getResult()
);
if (response.isSuccessful() && response.body() != null) {
callback.onSuccess(response.body().getResult());
} else {
callback.onError();
Log.e("API", "Erreur API: " + response.code());
}
}
@Override
public void onFailure(Call<ResponseApi<T>> call, Throwable throwable) {
callback.onError();
Log.e("API", "Erreur API", throwable);
}
});
}
}

View file

@ -1,6 +0,0 @@
package com.example.coach.api;
public interface ICallbackApi<T> {
void onSuccess(T result);
void onError();
}

View file

@ -1,25 +0,0 @@
package com.example.coach.api;
import com.example.coach.model.Profil;
import java.util.List;
import retrofit2.Call;
import retrofit2.http.DELETE;
import retrofit2.http.Field;
import retrofit2.http.FormUrlEncoded;
import retrofit2.http.GET;
import retrofit2.http.POST;
import retrofit2.http.Path;
public interface IRequestApi {
@GET("profil")
Call<ResponseApi<List<Profil>>> getProfils();
@FormUrlEncoded
@POST("profil")
Call<ResponseApi<Integer>> creerProfil(@Field("champs") String profilJson);
@DELETE("profil/{champs}")
Call<ResponseApi<Integer>> supprProfil(@Path(value = "champs", encoded = true) String profilJson);
}

View file

@ -1,31 +0,0 @@
package com.example.coach.api;
public class ResponseApi<T> {
private int code;
private String message;
private T result;
public int getCode() {
return code;
}
public void setCode(int code) {
this.code = code;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public T getResult() {
return result;
}
public void setResult(T result) {
this.result = result;
}
}

View file

@ -1,5 +0,0 @@
package com.example.coach.contract;
public interface IAllView {
void afficherMessage(String message);
}

View file

@ -3,7 +3,7 @@ package com.example.coach.contract;
/**
* Contrat pour que le CalculPresenter puisse envoyer des infos à la vue
*/
public interface ICalculView extends IAllView{
public interface ICalculView {
/**
* Méthode permettant le transfert des résultats vers la vue
* @param image nom du fichier du smiley

View file

@ -1,10 +0,0 @@
package com.example.coach.contract;
import com.example.coach.model.Profil;
import java.util.List;
public interface IHistoView extends IAllView {
void afficherListe(List profils);
void transfertProfil(Profil profil);
}

View file

@ -1,12 +1,11 @@
package com.example.coach.model;
import java.io.Serializable;
import java.util.Date;
/**
* Classe métier contenant les informations d'un profil
*/
public class Profil implements Serializable {
public class Profil {
private static final int MIN_FEMME = 25;
private static final int MAX_FEMME = 30;
private static final int MIN_HOMME = 15;
@ -19,8 +18,8 @@ public class Profil implements Serializable {
private Integer taille;
private Integer age;
private Integer sexe;
private transient double img;
private transient int indice;
private double img;
private int indice;
private Date dateMesure;
/**
@ -84,7 +83,7 @@ public class Profil implements Serializable {
* @return Valeur de l'img
*/
public double getImg(){
return calculImg();
return this.img;
}
/**

View file

@ -1,37 +1,32 @@
package com.example.coach.presenter;
import android.util.Log;
import android.content.Context;
import android.content.SharedPreferences;
import androidx.annotation.NonNull;
import com.example.coach.api.CoachApi;
import com.example.coach.api.HelperApi;
import com.example.coach.api.ICallbackApi;
import com.example.coach.api.IRequestApi;
import com.example.coach.api.ResponseApi;
import com.example.coach.contract.ICalculView;
import com.example.coach.model.Profil;
import com.google.gson.Gson;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
/**
* 'presenter' dédié à la vue affichant le calcul de l'img
*/
public class CalculPresenter {
private ICalculView vue;
private static final String NOM_FIC = "coach_records";
private static final String PROFIL_CLE = "profil_json";
private Gson gson;
private SharedPreferences prefs;
/**
* Constructeur : valorise la propriété permettant d'accéder à la vue
* @param vue
*/
public CalculPresenter(ICalculView vue) {
public CalculPresenter(ICalculView vue, Context context) {
this.vue = vue;
this.prefs = context.getSharedPreferences(NOM_FIC, Context.MODE_PRIVATE);
this.gson = new Gson();
}
/**
@ -45,52 +40,22 @@ public class CalculPresenter {
public void creerProfil(Integer sexe, Integer poids, Integer taille, Integer age)
{
Profil profil = new Profil(poids, taille, age, sexe, new Date());
sauvegarderProfil(profil);
vue.AfficherResultat(profil.getImage(), profil.getImg(), profil.getMessage(), profil.normal());
String profilJson = CoachApi.getGson().toJson(profil);
HelperApi.call(HelperApi.getApi().creerProfil(profilJson), new ICallbackApi<Integer>() {
@Override
public void onSuccess(Integer result) {
if (result == 1) {
vue.afficherMessage("profil enregistré");
}else{
vue.afficherMessage("échec enregistrement profil");
}
}
@Override
public void onError() {
vue.afficherMessage("échec enregistrement profil");
}
});
}
public void chargerDernierProfil()
private void sauvegarderProfil(Profil profil)
{
IRequestApi api = HelperApi.getApi();
HelperApi.call(api.getProfils(), new ICallbackApi<List<Profil>>() {
@Override
public void onSuccess(List<Profil> result) {
if(result != null){
List<Profil> profils = result;
if (profils != null && !profils.isEmpty()) {
// récupérer le plus récent
Profil dernier = Collections.max(profils,
(p1, p2) -> p1.getDateMesure().compareTo(p2.getDateMesure())
);
vue.remplirChamps(dernier.getPoids(), dernier.getTaille(),
dernier.getAge(), dernier.getSexe());
}else{
vue.afficherMessage("échec récupération dernier profil");
}
}else{
vue.afficherMessage("échec récupération dernier profil");
}
}
String json = gson.toJson(profil);
prefs.edit().putString(PROFIL_CLE, json).apply();
}
@Override
public void onError() {
vue.afficherMessage("échec récupération dernier profil");
}
});
public void chargerProfil()
{
String json = prefs.getString(PROFIL_CLE, null);
if(json != null){
Profil profil = gson.fromJson(json, Profil.class);
vue.remplirChamps(profil.getPoids(), profil.getTaille(), profil.getAge(), profil.getSexe());
}
}
}

View file

@ -1,74 +0,0 @@
package com.example.coach.presenter;
import android.util.Log;
import com.example.coach.api.CoachApi;
import com.example.coach.api.HelperApi;
import com.example.coach.api.ICallbackApi;
import com.example.coach.api.IRequestApi;
import com.example.coach.api.ResponseApi;
import com.example.coach.contract.IHistoView;
import com.example.coach.model.Profil;
import java.util.Collections;
import java.util.List;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
public class HistoPresenter {
private IHistoView vue;
public HistoPresenter(IHistoView vue)
{
this.vue = vue;
}
public void chargerProfils()
{
HelperApi.call(HelperApi.getApi().getProfils(), new ICallbackApi<List<Profil>>() {
@Override
public void onSuccess(List<Profil> result) {
if(result != null){
List<Profil> profils = result;
Collections.sort(profils, (p1, p2) -> p2.getDateMesure().compareTo(p1.getDateMesure()));
vue.afficherListe(profils);
}else{
vue.afficherMessage("échec récupération des derniers profils");
}
}
@Override
public void onError() {
vue.afficherMessage("échec récupération des derniers profils");
}
});
}
public void supprProfil(Profil profil, ICallbackApi<Void> callback)
{
String profilJson = CoachApi.getGson().toJson(profil);
HelperApi.call(HelperApi.getApi().supprProfil(profilJson), new ICallbackApi<Integer>() {
@Override
public void onSuccess(Integer result) {
if (result == 1) {
vue.afficherMessage("profil supprimé");
callback.onSuccess(null);
}else{
vue.afficherMessage("échec suppression profil");
}
}
@Override
public void onError() {
vue.afficherMessage("échec suppression profil");
}
});
}
public void transfertProfil(Profil profil)
{
vue.transfertProfil(profil);
}
}

View file

@ -1,167 +0,0 @@
package com.example.coach.view;
import android.graphics.Color;
import android.os.Bundle;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.TextView;
import android.widget.Toast;
import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
import com.example.coach.R;
import com.example.coach.contract.ICalculView;
import com.example.coach.model.Profil;
import com.example.coach.presenter.CalculPresenter;
/**
* Activity qui permet le calcul de l'img
*/
public class CalculActivity extends AppCompatActivity implements ICalculView {
private EditText txtPoids;
private EditText txtTaille;
private EditText txtAge;
private RadioButton rdHomme;
private RadioButton rdFemme;
private TextView lblIMG;
private ImageView imgSmiley;
private Button btnCalc;
private CalculPresenter presenter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
EdgeToEdge.enable(this);
setContentView(R.layout.activity_calcul);
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
return insets;
});
init();
}
/**
* Méthode permettant l'affichage du résultat du calcul de l'img
* @param image nom du fichier drawable pour le smiley
* @param img valeur de l'img
* @param message message à afficher
* @param normal faux si l'img n'est pas normal, vrai dans le cas inverse
*/
@Override
public void AfficherResultat(String image, double img, String message, boolean normal) {
int iamgeId = getResources().getIdentifier(image, "drawable", getPackageName());
String texte = String.format("%.01f", img) + " : IMG " + message;
if(iamgeId == 0){
imgSmiley.setImageResource(R.drawable.normal);
}else{
imgSmiley.setImageResource(iamgeId);
}
lblIMG.setText(texte);
if(!normal){
lblIMG.setTextColor(Color.RED);
}else{
lblIMG.setTextColor(Color.GREEN);
}
}
/**
* @param poids poids stocké
* @param taille taille stockée
* @param age âge stocké
* @param sexe sexe stocké
*/
@Override
public void remplirChamps(Integer poids, Integer taille, Integer age, Integer sexe) {
txtPoids.setText(poids.toString());
txtTaille.setText(taille.toString());
txtAge.setText(age.toString());
if(sexe == 1){
rdHomme.setChecked(true);
}else{
rdFemme.setChecked(true);
}
}
/**
* Traitements à réaliser lors du lancement de l'application
*/
private void init()
{
chargeObjetsGraphiques();
presenter = new CalculPresenter(this);
btnCalc.setOnClickListener(v -> btnCalcClic());
recupProfil();
}
/**
* Récupère les objets graphiques
*/
private void chargeObjetsGraphiques()
{
txtPoids = (EditText) findViewById(R.id.txtPoids);
txtTaille = (EditText) findViewById(R.id.txtTaille);
txtAge = (EditText) findViewById(R.id.txtAge);
rdHomme = (RadioButton) findViewById(R.id.rdHomme);
rdFemme = (RadioButton) findViewById(R.id.rdFemme);
lblIMG = (TextView) findViewById(R.id.lblResultat);
imgSmiley = (ImageView) findViewById(R.id.imgSmiley);
btnCalc = (Button) findViewById(R.id.btnCalc);
}
/**
* Traitements à réaliser lors du clic sur le bouton
*/
private void btnCalcClic()
{
int poids = 0, taille = 0, age = 0, sexe = 0;
try {
poids = Integer.parseInt(txtPoids.getText().toString());
taille = Integer.parseInt(txtTaille.getText().toString());
age = Integer.parseInt(txtAge.getText().toString());
}catch (Exception ignored){}
if(rdHomme.isChecked()){
sexe = 1;
}
if(poids == 0 || taille == 0 || age == 0){
Toast.makeText(this, "Veuillez remplir tous les champs", Toast.LENGTH_SHORT).show();
}else{
presenter.creerProfil(sexe, poids, taille, age);
}
}
/**
* @param message
*/
@Override
public void afficherMessage(String message) {
Toast.makeText(this, message, Toast.LENGTH_SHORT).show();
}
private void recupProfil()
{
Profil profil = (Profil) getIntent().getSerializableExtra("profil");
if(profil != null){
remplirChamps(profil.getPoids(), profil.getTaille(), profil.getAge(), profil.getSexe());
}else{
presenter.chargerDernierProfil();
}
}
}

View file

@ -1,74 +0,0 @@
package com.example.coach.view;
import android.content.Intent;
import android.os.Bundle;
import android.widget.Toast;
import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.example.coach.R;
import com.example.coach.contract.IHistoView;
import com.example.coach.model.Profil;
import com.example.coach.presenter.HistoPresenter;
import java.util.List;
public class HistoActivity extends AppCompatActivity implements IHistoView {
HistoPresenter presenter;
private void init()
{
presenter = new HistoPresenter(this);
presenter.chargerProfils();
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
EdgeToEdge.enable(this);
setContentView(R.layout.activity_histo);
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
init();
return insets;
});
}
/**
* @param profils
*/
@Override
public void afficherListe(List profils) {
if(profils != null){
RecyclerView lstHisto = (RecyclerView) findViewById(R.id.lstHisto);
HistoListAdapter adapter = new HistoListAdapter(profils, HistoActivity.this);
lstHisto.setAdapter(adapter);
lstHisto.setLayoutManager(new LinearLayoutManager(HistoActivity.this));
}
}
/**
* @param profil
*/
@Override
public void transfertProfil(Profil profil) {
Intent intent = new Intent(HistoActivity.this, CalculActivity.class);
intent.putExtra("profil", profil);
startActivity(intent);
}
/**
* @param message
*/
@Override
public void afficherMessage(String message) {
Toast.makeText(this, message, Toast.LENGTH_SHORT).show();
}
}

View file

@ -1,128 +0,0 @@
package com.example.coach.view;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import com.example.coach.R;
import com.example.coach.api.ICallbackApi;
import com.example.coach.contract.IHistoView;
import com.example.coach.model.Profil;
import com.example.coach.presenter.HistoPresenter;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Locale;
public class HistoListAdapter extends RecyclerView.Adapter<HistoListAdapter.ViewHolder> {
private List<Profil> profils;
private IHistoView vue;
/**
* Retourne une ligne de la liste
* @param parent The ViewGroup into which the new View will be added after it is bound to
* an adapter position.
* @param viewType The view type of the new View.
* @return
*/
@NonNull
@Override
public HistoListAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
Context parentContext = parent.getContext();
LayoutInflater layout = LayoutInflater.from(parentContext);
View view = layout.inflate(R.layout.layout_list_histo, parent, false);
return new HistoListAdapter.ViewHolder(view);
}
/**
* Rempli une ligne
* @param holder The ViewHolder which should be updated to represent the contents of the
* item at the given position in the data set.
* @param position The position of the item within the adapter's data set.
*/
@Override
public void onBindViewHolder(@NonNull HistoListAdapter.ViewHolder holder, int position) {
Double img = profils.get(position).getImg();
String img1desimal = String.format("%.01f", img);
holder.txtListIMG.setText(img1desimal);
Date dateMesure = profils.get(position).getDateMesure();
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss", Locale.getDefault());
String dateFormatee = sdf.format(dateMesure);
holder.txtListDate.setText(dateFormatee);
}
/**
* Compte le nombre de lignes
* @return int
*/
@Override
public int getItemCount() {
return profils.size();
}
public HistoListAdapter(List<Profil> profils, IHistoView vue)
{
this.profils = profils;
this.vue = vue;
}
public class ViewHolder extends RecyclerView.ViewHolder{
final TextView txtListDate;
final TextView txtListIMG;
final ImageButton btnListSuppr;
HistoPresenter presenter;
public ViewHolder(@NonNull View itemView) {
super(itemView);
txtListDate = (TextView) itemView.findViewById(R.id.txtListDate);
txtListIMG = (TextView) itemView.findViewById(R.id.txtListIMG);
btnListSuppr = (ImageButton) itemView.findViewById(R.id.btnListSuppr);
init();
}
private void btnListSuppr_clic()
{
int position = getBindingAdapterPosition();
presenter.supprProfil(profils.get(position), new ICallbackApi<Void>() {
@Override
public void onSuccess(Void result) {
profils.remove(position);
notifyItemRemoved(position);
}
@Override
public void onError() {
}
});
}
private void init()
{
btnListSuppr.setOnClickListener(v -> btnListSuppr_clic());
txtListDate.setOnClickListener(v -> txtListDateOrImg_clic());
txtListIMG.setOnClickListener(v -> txtListDateOrImg_clic());
presenter = new HistoPresenter(vue);
}
private void txtListDateOrImg_clic()
{
int position = getBindingAdapterPosition();
presenter.transfertProfil(profils.get(position));
}
}
}

View file

@ -1,8 +1,13 @@
package com.example.coach.view;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.widget.ImageButton;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.TextView;
import android.widget.Toast;
import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
@ -11,11 +16,24 @@ import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
import com.example.coach.R;
import com.example.coach.contract.ICalculView;
import com.example.coach.presenter.CalculPresenter;
public class MainActivity extends AppCompatActivity {
/**
* Activity qui permet le calcul de l'img
*/
public class MainActivity extends AppCompatActivity implements ICalculView {
private ImageButton btnMonIMG;
private ImageButton btnMonHistorique;
private EditText txtPoids;
private EditText txtTaille;
private EditText txtAge;
private RadioButton rdHomme;
private RadioButton rdFemme;
private TextView lblIMG;
private ImageView imgSmiley;
private Button btnCalc;
private CalculPresenter presenter;
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -25,32 +43,106 @@ public class MainActivity extends AppCompatActivity {
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
init();
return insets;
});
init();
}
/**
* Méthode permettant l'affichage du résultat du calcul de l'img
* @param image nom du fichier drawable pour le smiley
* @param img valeur de l'img
* @param message message à afficher
* @param normal faux si l'img n'est pas normal, vrai dans le cas inverse
*/
@Override
public void AfficherResultat(String image, double img, String message, boolean normal) {
int iamgeId = getResources().getIdentifier(image, "drawable", getPackageName());
String texte = String.format("%.01f", img) + " : IMG " + message;
if(iamgeId == 0){
imgSmiley.setImageResource(R.drawable.normal);
}else{
imgSmiley.setImageResource(iamgeId);
}
lblIMG.setText(texte);
if(!normal){
lblIMG.setTextColor(Color.RED);
}else{
lblIMG.setTextColor(Color.GREEN);
}
}
/**
* @param poids poids stocké
* @param taille taille stockée
* @param age âge stocké
* @param sexe sexe stocké
*/
@Override
public void remplirChamps(Integer poids, Integer taille, Integer age, Integer sexe) {
txtPoids.setText(poids.toString());
txtTaille.setText(taille.toString());
txtAge.setText(age.toString());
if(sexe == 1){
rdHomme.setChecked(true);
}else{
rdFemme.setChecked(true);
}
}
/**
* Traitements à réaliser lors du lancement de l'application
*/
private void init()
{
chargeObjetsGraphiques();
creerMenu();
presenter = new CalculPresenter(this, this);
btnCalc.setOnClickListener(v -> btnCalcClic());
presenter.chargerProfil();
}
/**
* Récupère les objets graphiques
*/
private void chargeObjetsGraphiques()
{
btnMonIMG = (ImageButton) findViewById(R.id.btnMonIMG);
btnMonHistorique = (ImageButton) findViewById(R.id.btnMonHistorique);
txtPoids = (EditText) findViewById(R.id.txtPoids);
txtTaille = (EditText) findViewById(R.id.txtTaille);
txtAge = (EditText) findViewById(R.id.txtAge);
rdHomme = (RadioButton) findViewById(R.id.rdHomme);
rdFemme = (RadioButton) findViewById(R.id.rdFemme);
lblIMG = (TextView) findViewById(R.id.lblResultat);
imgSmiley = (ImageView) findViewById(R.id.imgSmiley);
btnCalc = (Button) findViewById(R.id.btnCalc);
}
private void ecouteMenu(Class classe)
/**
* Traitements à réaliser lors du clic sur le bouton
*/
private void btnCalcClic()
{
Intent intent = new Intent(MainActivity.this, classe);
startActivity(intent);
}
int poids = 0, taille = 0, age = 0, sexe = 0;
private void creerMenu()
{
btnMonIMG.setOnClickListener(v -> ecouteMenu(CalculActivity.class));
btnMonHistorique.setOnClickListener(v -> ecouteMenu(HistoActivity.class));
try {
poids = Integer.parseInt(txtPoids.getText().toString());
taille = Integer.parseInt(txtTaille.getText().toString());
age = Integer.parseInt(txtAge.getText().toString());
}catch (Exception ignored){}
if(rdHomme.isChecked()){
sexe = 1;
}
if(poids == 0 || taille == 0 || age == 0){
Toast.makeText(this, "Veuillez remplir tous les champs", Toast.LENGTH_SHORT).show();
}else{
presenter.creerProfil(sexe, poids, taille, age);
}
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.2 KiB

View file

@ -1,173 +0,0 @@
<?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:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".view.CalculActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:layout_editor_absoluteX="1dp"
tools:layout_editor_absoluteY="1dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal"
android:layout_weight="1"
android:orientation="horizontal">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal"
android:layout_weight="1"
android:gravity="center_horizontal|center_vertical"
android:orientation="vertical">
<RadioGroup
android:id="@+id/grpRadioSexe"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RadioButton
android:id="@+id/rdHomme"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:checked="true"
android:text="Homme" />
<RadioButton
android:id="@+id/rdFemme"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:text="Femme" />
</RadioGroup>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal"
android:layout_weight="1"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal"
android:layout_weight="1"
android:gravity="center_horizontal|center_vertical"
android:orientation="horizontal">
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Poids :" />
<EditText
android:id="@+id/txtPoids"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:inputType="number" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal"
android:layout_weight="1"
android:gravity="center_horizontal|center_vertical"
android:orientation="horizontal">
<TextView
android:id="@+id/textView2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Taille :" />
<EditText
android:id="@+id/txtTaille"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:inputType="number" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal"
android:layout_weight="1"
android:gravity="center_horizontal|center_vertical"
android:orientation="horizontal">
<TextView
android:id="@+id/textView3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Age :" />
<EditText
android:id="@+id/txtAge"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:inputType="number" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_weight="0"
android:gravity="center_horizontal|center_vertical"
android:orientation="horizontal">
<Button
android:id="@+id/btnCalc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Calculer" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal"
android:layout_weight="1"
android:gravity="center_horizontal|center_vertical"
android:orientation="horizontal">
<ImageView
android:id="@+id/imgSmiley"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
app:srcCompat="@drawable/normal" />
<TextView
android:id="@+id/lblResultat"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
</LinearLayout>
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

View file

@ -1,22 +0,0 @@
<?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:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".view.HistoActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/lstHisto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="?attr/actionBarSize"
android:scrollbars="vertical" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

View file

@ -10,64 +10,164 @@
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
android:orientation="vertical"
tools:layout_editor_absoluteX="1dp"
tools:layout_editor_absoluteY="1dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal"
android:layout_weight="1"
android:orientation="vertical">
android:orientation="horizontal">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal"
android:layout_weight="1"
android:orientation="vertical"></LinearLayout>
android:gravity="center_horizontal|center_vertical"
android:orientation="vertical">
<RadioGroup
android:id="@+id/grpRadioSexe"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RadioButton
android:id="@+id/rdHomme"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:checked="true"
android:text="Homme" />
<RadioButton
android:id="@+id/rdFemme"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:text="Femme" />
</RadioGroup>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:id="@+id/textView4"
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="mon IMG"
android:textSize="34sp" />
<ImageButton
android:id="@+id/btnMonIMG"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal"
app:srcCompat="@drawable/normal" />
</LinearLayout>
android:layout_weight="1"
android:gravity="center_horizontal|center_vertical"
android:orientation="horizontal">
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Poids :" />
<EditText
android:id="@+id/txtPoids"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:inputType="number" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal"
android:layout_weight="1"
android:gravity="center_horizontal|center_vertical"
android:orientation="horizontal">
<TextView
android:id="@+id/textView2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Taille :" />
<EditText
android:id="@+id/txtTaille"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:inputType="number" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal"
android:layout_weight="1"
android:gravity="center_horizontal|center_vertical"
android:orientation="horizontal">
<TextView
android:id="@+id/textView3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Age :" />
<EditText
android:id="@+id/txtAge"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:inputType="number" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_weight="0"
android:gravity="center_horizontal|center_vertical"
android:orientation="horizontal">
<Button
android:id="@+id/btnCalc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Calculer" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal"
android:layout_weight="1"
android:orientation="vertical">
android:gravity="center_horizontal|center_vertical"
android:orientation="horizontal">
<ImageView
android:id="@+id/imgSmiley"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
app:srcCompat="@drawable/normal" />
<TextView
android:id="@+id/textView5"
android:layout_width="match_parent"
android:id="@+id/lblResultat"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="mon historique"
android:textSize="34sp" />
<ImageButton
android:id="@+id/btnMonHistorique"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
app:srcCompat="@drawable/historique" />
android:layout_weight="1" />
</LinearLayout>
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

View file

@ -1,57 +0,0 @@
<?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"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="0"
android:gravity="clip_vertical"
android:orientation="vertical">
<ImageButton
android:id="@+id/btnListSuppr"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:srcCompat="@drawable/suppr" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="clip_vertical"
android:orientation="vertical">
<TextView
android:id="@+id/txtListDate"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="TextView" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="clip_vertical"
android:orientation="vertical">
<TextView
android:id="@+id/txtListIMG"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="end"
android:text="TextView"
android:textSize="24sp"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

View file

@ -1,6 +1,6 @@
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="Base.Theme.Coach" parent="Theme.AppCompat.DayNight.DarkActionBar">
<style name="Base.Theme.Coach" parent="Theme.Material3.DayNight.NoActionBar">
<!-- Customize your dark theme here. -->
<!-- <item name="colorPrimary">@color/my_dark_primary</item> -->
</style>

View file

@ -1,6 +1,6 @@
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="Base.Theme.Coach" parent="Theme.AppCompat.DayNight">
<style name="Base.Theme.Coach" parent="Theme.Material3.DayNight.NoActionBar">
<!-- Customize your light theme here. -->
<!-- <item name="colorPrimary">@color/my_light_primary</item> -->
</style>

View file

@ -7,7 +7,6 @@ appcompat = "1.6.1"
material = "1.10.0"
activity = "1.8.0"
constraintlayout = "2.1.4"
recyclerview = "1.4.0"
[libraries]
junit = { group = "junit", name = "junit", version.ref = "junit" }
@ -17,7 +16,6 @@ appcompat = { group = "androidx.appcompat", name = "appcompat", version.ref = "a
material = { group = "com.google.android.material", name = "material", version.ref = "material" }
activity = { group = "androidx.activity", name = "activity", version.ref = "activity" }
constraintlayout = { group = "androidx.constraintlayout", name = "constraintlayout", version.ref = "constraintlayout" }
recyclerview = { group = "androidx.recyclerview", name = "recyclerview", version.ref = "recyclerview" }
[plugins]
android-application = { id = "com.android.application", version.ref = "agp" }