Compare commits
No commits in common. "devoir" and "master" have entirely different histories.
6 changed files with 21 additions and 121 deletions
|
|
@ -18,28 +18,27 @@ public class HelperApi {
|
||||||
return api;
|
return api;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T> void call(Call<ResponseApi<T>> call, ICallbackApi<T> callback) {
|
public static <T> void call(Call<ResponseApi<T>> call, ICallbackApi<T> callback)
|
||||||
|
{
|
||||||
call.enqueue(new Callback<ResponseApi<T>>() {
|
call.enqueue(new Callback<ResponseApi<T>>() {
|
||||||
@Override
|
@Override
|
||||||
public void onResponse(Call<ResponseApi<T>> call, Response<ResponseApi<T>> response) {
|
public void onResponse(Call<ResponseApi<T>> call, Response<ResponseApi<T>> response) {
|
||||||
// 1. On vérifie si la requête HTTP a réussi ET si on a un corps de réponse
|
Log.d("API", "code : " + response.body().getCode() +
|
||||||
|
" message : " + response.body().getMessage() +
|
||||||
|
" result : " + response.body().getResult()
|
||||||
|
);
|
||||||
if (response.isSuccessful() && response.body() != null) {
|
if (response.isSuccessful() && response.body() != null) {
|
||||||
// On peut maintenant logger sans risque
|
|
||||||
Log.d("API", "code : " + response.body().getCode() +
|
|
||||||
" message : " + response.body().getMessage());
|
|
||||||
|
|
||||||
callback.onSuccess(response.body().getResult());
|
callback.onSuccess(response.body().getResult());
|
||||||
} else {
|
} else {
|
||||||
// Cas d'erreur HTTP (ex: 404) ou body null
|
|
||||||
callback.onError();
|
callback.onError();
|
||||||
Log.e("API", "Erreur HTTP ou Body null. Code: " + response.code());
|
Log.e("API", "Erreur API: " + response.code());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFailure(Call<ResponseApi<T>> call, Throwable throwable) {
|
public void onFailure(Call<ResponseApi<T>> call, Throwable throwable) {
|
||||||
callback.onError();
|
callback.onError();
|
||||||
Log.e("API", "Erreur réseau / désérialisation", throwable);
|
Log.e("API", "Erreur API", throwable);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,4 @@ public interface IRequestApi {
|
||||||
|
|
||||||
@DELETE("profil/{champs}")
|
@DELETE("profil/{champs}")
|
||||||
Call<ResponseApi<Integer>> supprProfil(@Path(value = "champs", encoded = true) String profilJson);
|
Call<ResponseApi<Integer>> supprProfil(@Path(value = "champs", encoded = true) String profilJson);
|
||||||
|
|
||||||
@DELETE("profil/{keep}")
|
|
||||||
Call<ResponseApi<Integer>> purgeProfils(@Path(value = "keep", encoded = true) String profilJson);
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +0,0 @@
|
||||||
package com.example.coach.contract;
|
|
||||||
|
|
||||||
public interface IMainView extends IAllView{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,35 +0,0 @@
|
||||||
package com.example.coach.presenter;
|
|
||||||
|
|
||||||
import com.example.coach.api.HelperApi;
|
|
||||||
import com.example.coach.api.ICallbackApi;
|
|
||||||
import com.example.coach.api.IRequestApi;
|
|
||||||
import com.example.coach.contract.IMainView;
|
|
||||||
|
|
||||||
public class MainPresenter {
|
|
||||||
private IMainView vue;
|
|
||||||
public void purgeBDD(Integer nb, ICallbackApi<Void> callback)
|
|
||||||
{
|
|
||||||
String json = "{\"keep\":\"" + nb + "\"}";
|
|
||||||
HelperApi.call(HelperApi.getApi().purgeProfils(json), new ICallbackApi<Integer>() {
|
|
||||||
@Override
|
|
||||||
public void onSuccess(Integer result) {
|
|
||||||
if (result >= 1) {
|
|
||||||
vue.afficherMessage("profils supprimés : " + result);
|
|
||||||
callback.onSuccess(null);
|
|
||||||
}else{
|
|
||||||
vue.afficherMessage("BDD déjà purgée");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onError() {
|
|
||||||
vue.afficherMessage("échec suppression profils");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public MainPresenter(IMainView vue)
|
|
||||||
{
|
|
||||||
this.vue = vue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -2,10 +2,7 @@ package com.example.coach.view;
|
||||||
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.util.Log;
|
|
||||||
import android.widget.Button;
|
|
||||||
import android.widget.ImageButton;
|
import android.widget.ImageButton;
|
||||||
import android.widget.Toast;
|
|
||||||
|
|
||||||
import androidx.activity.EdgeToEdge;
|
import androidx.activity.EdgeToEdge;
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
|
|
@ -14,16 +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.api.ICallbackApi;
|
|
||||||
import com.example.coach.contract.IMainView;
|
|
||||||
import com.example.coach.presenter.MainPresenter;
|
|
||||||
|
|
||||||
public class MainActivity extends AppCompatActivity implements IMainView {
|
public class MainActivity extends AppCompatActivity {
|
||||||
|
|
||||||
private ImageButton btnMonIMG;
|
private ImageButton btnMonIMG;
|
||||||
private ImageButton btnMonHistorique;
|
private ImageButton btnMonHistorique;
|
||||||
private Button btnPurge;
|
|
||||||
private MainPresenter presenter;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
|
@ -42,14 +34,12 @@ public class MainActivity extends AppCompatActivity implements IMainView {
|
||||||
{
|
{
|
||||||
chargeObjetsGraphiques();
|
chargeObjetsGraphiques();
|
||||||
creerMenu();
|
creerMenu();
|
||||||
presenter = new MainPresenter(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void chargeObjetsGraphiques()
|
private void chargeObjetsGraphiques()
|
||||||
{
|
{
|
||||||
btnMonIMG = (ImageButton) findViewById(R.id.btnMonIMG);
|
btnMonIMG = (ImageButton) findViewById(R.id.btnMonIMG);
|
||||||
btnMonHistorique = (ImageButton) findViewById(R.id.btnMonHistorique);
|
btnMonHistorique = (ImageButton) findViewById(R.id.btnMonHistorique);
|
||||||
btnPurge = (Button) findViewById(R.id.btnPurge);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ecouteMenu(Class classe)
|
private void ecouteMenu(Class classe)
|
||||||
|
|
@ -62,30 +52,5 @@ public class MainActivity extends AppCompatActivity implements IMainView {
|
||||||
{
|
{
|
||||||
btnMonIMG.setOnClickListener(v -> ecouteMenu(CalculActivity.class));
|
btnMonIMG.setOnClickListener(v -> ecouteMenu(CalculActivity.class));
|
||||||
btnMonHistorique.setOnClickListener(v -> ecouteMenu(HistoActivity.class));
|
btnMonHistorique.setOnClickListener(v -> ecouteMenu(HistoActivity.class));
|
||||||
btnPurge.setOnClickListener(v -> btnPurge_clic());
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private void btnPurge_clic()
|
|
||||||
{
|
|
||||||
presenter.purgeBDD(5, new ICallbackApi<Void>() {
|
|
||||||
@Override
|
|
||||||
public void onSuccess(Void result) {
|
|
||||||
//
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onError() {
|
|
||||||
//
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param message
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void afficherMessage(String message) {
|
|
||||||
Toast.makeText(this, message, Toast.LENGTH_SHORT).show();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -54,41 +54,20 @@
|
||||||
android:layout_weight="1"
|
android:layout_weight="1"
|
||||||
android:orientation="vertical">
|
android:orientation="vertical">
|
||||||
|
|
||||||
<LinearLayout
|
<TextView
|
||||||
|
android:id="@+id/textView5"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="wrap_content"
|
||||||
android:layout_weight="1"
|
android:gravity="center_horizontal"
|
||||||
android:orientation="vertical">
|
android:text="mon historique"
|
||||||
|
android:textSize="34sp" />
|
||||||
<TextView
|
|
||||||
android:id="@+id/textView5"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
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" />
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
android:layout_weight="1"
|
|
||||||
android:orientation="vertical">
|
|
||||||
|
|
||||||
<Button
|
|
||||||
android:id="@+id/btnPurge"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:text="Purger BDD" />
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
|
<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>
|
||||||
Loading…
Reference in a new issue