S5 : menu et liste adapter interactive

This commit is contained in:
Erwann PHILIPPE 2026-02-05 15:30:42 +01:00
parent bf3797f5d8
commit 55912c0679
26 changed files with 889 additions and 281 deletions

View file

@ -3,8 +3,8 @@
<component name="deploymentTargetSelector"> <component name="deploymentTargetSelector">
<selectionStates> <selectionStates>
<SelectionState runConfigName="app"> <SelectionState runConfigName="app">
<option name="selectionMode" value="DIALOG" /> <option name="selectionMode" value="DROPDOWN" />
<DropdownSelection timestamp="2026-02-04T13:11:46.468249700Z"> <DropdownSelection timestamp="2026-02-05T11:33:42.096254600Z">
<Target type="DEFAULT_BOOT"> <Target type="DEFAULT_BOOT">
<handle> <handle>
<DeviceId pluginId="PhysicalDevice" identifier="serial=QGP7K78LKBMVZTRC" /> <DeviceId pluginId="PhysicalDevice" identifier="serial=QGP7K78LKBMVZTRC" />
@ -27,7 +27,28 @@
</DialogSelection> </DialogSelection>
</SelectionState> </SelectionState>
<SelectionState runConfigName="testCalculIMG()"> <SelectionState runConfigName="testCalculIMG()">
<option name="selectionMode" value="DROPDOWN" /> <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>
</SelectionState> </SelectionState>
</selectionStates> </selectionStates>
</component> </component>

View file

@ -8,7 +8,7 @@ android {
defaultConfig { defaultConfig {
applicationId "com.example.coach" applicationId "com.example.coach"
minSdk 16 minSdk 21
targetSdk 36 targetSdk 36
versionCode 1 versionCode 1
versionName "1.0" versionName "1.0"
@ -34,6 +34,7 @@ dependencies {
implementation libs.material implementation libs.material
implementation libs.activity implementation libs.activity
implementation libs.constraintlayout implementation libs.constraintlayout
implementation libs.recyclerview
testImplementation libs.junit testImplementation libs.junit
androidTestImplementation libs.ext.junit androidTestImplementation libs.ext.junit
androidTestImplementation libs.espresso.core androidTestImplementation libs.espresso.core

View file

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

View file

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

View file

@ -0,0 +1,45 @@
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

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

View file

@ -5,10 +5,12 @@ import com.example.coach.model.Profil;
import java.util.List; import java.util.List;
import retrofit2.Call; import retrofit2.Call;
import retrofit2.http.DELETE;
import retrofit2.http.Field; import retrofit2.http.Field;
import retrofit2.http.FormUrlEncoded; import retrofit2.http.FormUrlEncoded;
import retrofit2.http.GET; import retrofit2.http.GET;
import retrofit2.http.POST; import retrofit2.http.POST;
import retrofit2.http.Path;
public interface IRequestApi { public interface IRequestApi {
@GET("profil") @GET("profil")
@ -17,4 +19,7 @@ public interface IRequestApi {
@FormUrlEncoded @FormUrlEncoded
@POST("profil") @POST("profil")
Call<ResponseApi<Integer>> creerProfil(@Field("champs") String profilJson); Call<ResponseApi<Integer>> creerProfil(@Field("champs") String profilJson);
@DELETE("profil/{champs}")
Call<ResponseApi<Integer>> supprProfil(@Path(value = "champs", encoded = true) String profilJson);
} }

View file

@ -0,0 +1,5 @@
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 * Contrat pour que le CalculPresenter puisse envoyer des infos à la vue
*/ */
public interface ICalculView { public interface ICalculView extends IAllView{
/** /**
* Méthode permettant le transfert des résultats vers la vue * Méthode permettant le transfert des résultats vers la vue
* @param image nom du fichier du smiley * @param image nom du fichier du smiley

View file

@ -0,0 +1,10 @@
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,11 +1,12 @@
package com.example.coach.model; package com.example.coach.model;
import java.io.Serializable;
import java.util.Date; import java.util.Date;
/** /**
* Classe métier contenant les informations d'un profil * Classe métier contenant les informations d'un profil
*/ */
public class Profil { public class Profil implements Serializable {
private static final int MIN_FEMME = 25; private static final int MIN_FEMME = 25;
private static final int MAX_FEMME = 30; private static final int MAX_FEMME = 30;
private static final int MIN_HOMME = 15; private static final int MIN_HOMME = 15;
@ -83,7 +84,7 @@ public class Profil {
* @return Valeur de l'img * @return Valeur de l'img
*/ */
public double getImg(){ public double getImg(){
return this.img; return calculImg();
} }
/** /**

View file

@ -5,6 +5,8 @@ import android.util.Log;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import com.example.coach.api.CoachApi; 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.IRequestApi;
import com.example.coach.api.ResponseApi; import com.example.coach.api.ResponseApi;
import com.example.coach.contract.ICalculView; import com.example.coach.contract.ICalculView;
@ -43,53 +45,51 @@ public class CalculPresenter {
public void creerProfil(Integer sexe, Integer poids, Integer taille, Integer age) public void creerProfil(Integer sexe, Integer poids, Integer taille, Integer age)
{ {
Profil profil = new Profil(poids, taille, age, sexe, new Date()); Profil profil = new Profil(poids, taille, age, sexe, new Date());
String profilJson = CoachApi.getGson().toJson(profil);
IRequestApi api = CoachApi.getRetrofit().create(IRequestApi.class);
Call<ResponseApi<Integer>> call = api.creerProfil(profilJson);
call.enqueue(new Callback<ResponseApi<Integer>>() {
@Override
public void onResponse(Call<ResponseApi<Integer>> call, Response<ResponseApi<Integer>> response) {
Log.d("API", "code : " + response.body().getCode() +
" message : " + response.body().getMessage() +
" result : " + response.body().getResult()
);
if(response.isSuccessful() && response.body().getResult() == 1){
vue.AfficherResultat(profil.getImage(), profil.getImg(), profil.getMessage(), profil.normal()); 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{ }else{
Log.e("API", "Erreur API: " + response.code()); vue.afficherMessage("échec enregistrement profil");
} }
} }
@Override @Override
public void onFailure(Call<ResponseApi<Integer>> call, @NonNull Throwable throwable) { public void onError() {
Log.e("API", "Échec d'accès à l'api", throwable); vue.afficherMessage("échec enregistrement profil");
} }
}); });
} }
public void chargerDernierProfil() public void chargerDernierProfil()
{ {
IRequestApi api = CoachApi.getRetrofit().create(IRequestApi.class); IRequestApi api = HelperApi.getApi();
Call<ResponseApi<List<Profil>>> call = api.getProfils(); HelperApi.call(api.getProfils(), new ICallbackApi<List<Profil>>() {
call.enqueue(new Callback<ResponseApi<List<Profil>>>() {
@Override @Override
public void onResponse(Call<ResponseApi<List<Profil>>> call, Response<ResponseApi<List<Profil>>> response) { public void onSuccess(List<Profil> result) {
List<Profil> profils = response.body().getResult(); if(result != null){
List<Profil> profils = result;
if (profils != null && !profils.isEmpty()) { if (profils != null && !profils.isEmpty()) {
Profil dernier = Collections.max( // récupérer le plus récent
profils, Profil dernier = Collections.max(profils,
(p1, p2) -> p1.getDateMesure().compareTo(p2.getDateMesure()) (p1, p2) -> p1.getDateMesure().compareTo(p2.getDateMesure())
); );
vue.remplirChamps(dernier.getPoids(), dernier.getTaille(), dernier.getAge(), dernier.getSexe()); 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");
} }
} }
@Override @Override
public void onFailure(Call<ResponseApi<List<Profil>>> call, Throwable throwable) { public void onError() {
Log.e("API", "Échec d'accès à l'api", throwable); vue.afficherMessage("échec récupération dernier profil");
} }
}); });
} }

View file

@ -0,0 +1,74 @@
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

@ -0,0 +1,167 @@
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

@ -0,0 +1,74 @@
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

@ -0,0 +1,128 @@
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,13 +1,8 @@
package com.example.coach.view; package com.example.coach.view;
import android.graphics.Color; import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.widget.Button; import android.widget.ImageButton;
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.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
@ -16,24 +11,11 @@ import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat; import androidx.core.view.WindowInsetsCompat;
import com.example.coach.R; 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 EditText txtPoids; private ImageButton btnMonIMG;
private EditText txtTaille; private ImageButton btnMonHistorique;
private EditText txtAge;
private RadioButton rdHomme;
private RadioButton rdFemme;
private TextView lblIMG;
private ImageView imgSmiley;
private Button btnCalc;
private CalculPresenter presenter;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
@ -43,107 +25,32 @@ public class MainActivity extends AppCompatActivity implements ICalculView {
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> { ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars()); Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom); v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
init();
return insets; 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(false);
}
}
/**
* Traitements à réaliser lors du lancement de l'application
*/
private void init() private void init()
{ {
chargeObjetsGraphiques(); chargeObjetsGraphiques();
presenter = new CalculPresenter(this); creerMenu();
btnCalc.setOnClickListener(v -> btnCalcClic());
presenter.chargerDernierProfil();
} }
/**
* Récupère les objets graphiques
*/
private void chargeObjetsGraphiques() private void chargeObjetsGraphiques()
{ {
txtPoids = (EditText) findViewById(R.id.txtPoids); btnMonIMG = (ImageButton) findViewById(R.id.btnMonIMG);
txtTaille = (EditText) findViewById(R.id.txtTaille); btnMonHistorique = (ImageButton) findViewById(R.id.btnMonHistorique);
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()
{ {
int poids = 0, taille = 0, age = 0, sexe = 0; Intent intent = new Intent(MainActivity.this, classe);
startActivity(intent);
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){ private void creerMenu()
Toast.makeText(this, "Veuillez remplir tous les champs", Toast.LENGTH_SHORT).show(); {
}else{ btnMonIMG.setOnClickListener(v -> ecouteMenu(CalculActivity.class));
presenter.creerProfil(sexe, poids, taille, age); btnMonHistorique.setOnClickListener(v -> ecouteMenu(HistoActivity.class));
}
} }
} }

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.2 KiB

View file

@ -0,0 +1,173 @@
<?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

@ -0,0 +1,22 @@
<?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,164 +10,64 @@
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="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"> 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 <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_gravity="center_horizontal"
android:layout_weight="1" android:layout_weight="1"
android:orientation="vertical"> android:orientation="vertical">
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_gravity="center_horizontal"
android:layout_weight="1" android:layout_weight="1"
android:gravity="center_horizontal|center_vertical" android:orientation="vertical"></LinearLayout>
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 <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_gravity="center_horizontal"
android:layout_weight="1" android:layout_weight="1"
android:gravity="center_horizontal|center_vertical" android:orientation="vertical">
android:orientation="horizontal">
<TextView <TextView
android:id="@+id/textView2" android:id="@+id/textView4"
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_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center_horizontal" android:gravity="center_horizontal"
android:layout_weight="0" android:text="mon IMG"
android:gravity="center_horizontal|center_vertical" android:textSize="34sp" />
android:orientation="horizontal">
<Button <ImageButton
android:id="@+id/btnCalc" android:id="@+id/btnMonIMG"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1" android:layout_gravity="center_horizontal"
android:text="Calculer" /> app:srcCompat="@drawable/normal" />
</LinearLayout>
</LinearLayout> </LinearLayout>
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_gravity="center_horizontal"
android:layout_weight="1" android:layout_weight="1"
android:gravity="center_horizontal|center_vertical" android:orientation="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 <TextView
android:id="@+id/lblResultat" android:id="@+id/textView5"
android:layout_width="0dp" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1" /> 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" />
</LinearLayout> </LinearLayout>
</LinearLayout> </LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>

View file

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

View file

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

View file

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