mirror of
https://github.com/LucasVbr/OutilCuisson.git
synced 2026-05-13 17:11:53 +00:00
ajout AlertDialog
This commit is contained in:
@@ -6,6 +6,7 @@
|
|||||||
|
|
||||||
package com.example.outilcuisson;
|
package com.example.outilcuisson;
|
||||||
|
|
||||||
|
import android.app.AlertDialog;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
@@ -100,8 +101,18 @@ public class AjouterFragment extends Fragment {
|
|||||||
|
|
||||||
/* Cas ou les valeurs sont valides : on ajoute une nouvelle
|
/* Cas ou les valeurs sont valides : on ajoute une nouvelle
|
||||||
cuisson dans la liste a afficher */
|
cuisson dans la liste a afficher */
|
||||||
activiteQuiMEcoute.recevoirCuisson(
|
try {
|
||||||
new Cuisson(txtPlat, hDuree, mDuree, temperature));
|
activiteQuiMEcoute.recevoirCuisson(
|
||||||
|
new Cuisson(txtPlat, hDuree, mDuree, temperature));
|
||||||
|
} catch (Exception e) {
|
||||||
|
new AlertDialog.Builder(getContext()).setTitle("Erreur")
|
||||||
|
.setMessage(e.getMessage())
|
||||||
|
.setPositiveButton(
|
||||||
|
R.string.btn_valider,
|
||||||
|
null)
|
||||||
|
.show(); // TODO modif
|
||||||
|
System.out.println(e.getMessage());
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -31,7 +31,12 @@ public class Cuisson implements Serializable {
|
|||||||
private int minute;
|
private int minute;
|
||||||
private int degree;
|
private int degree;
|
||||||
|
|
||||||
public Cuisson(String plat, int heure, int minute, int degree) {
|
public Cuisson(String plat, int heure, int minute, int degree) throws
|
||||||
|
Exception {
|
||||||
|
if (!platValide(plat) || !heureCuissonValide(heure)
|
||||||
|
|| !minuteCuissonValide(minute) || !temperatureValide(degree)) {
|
||||||
|
throw new Exception(CHAINE_DEFAUT);
|
||||||
|
}
|
||||||
this.plat = plat;
|
this.plat = plat;
|
||||||
this.heure = heure;
|
this.heure = heure;
|
||||||
this.minute = minute;
|
this.minute = minute;
|
||||||
@@ -105,36 +110,31 @@ public class Cuisson implements Serializable {
|
|||||||
public String toString() {
|
public String toString() {
|
||||||
StringBuilder aRenvoyer = new StringBuilder();
|
StringBuilder aRenvoyer = new StringBuilder();
|
||||||
|
|
||||||
if (platValide(this.plat) && heureCuissonValide(this.heure)
|
|
||||||
&& minuteCuissonValide(this.minute) && temperatureValide(this.degree)) {
|
|
||||||
|
|
||||||
// on insère le nom du plat
|
// on insère le nom du plat
|
||||||
aRenvoyer.append(plat);
|
aRenvoyer.append(plat);
|
||||||
aRenvoyer.append(chaineEspace(LG_MAX_PLAT - plat.length()));
|
aRenvoyer.append(chaineEspace(LG_MAX_PLAT - plat.length()));
|
||||||
aRenvoyer.append(" | ");
|
aRenvoyer.append(" | ");
|
||||||
|
|
||||||
// on insère la durée
|
// on insère la durée
|
||||||
aRenvoyer.append(String.valueOf(heure));
|
aRenvoyer.append(String.valueOf(heure));
|
||||||
aRenvoyer.append(" h ");
|
aRenvoyer.append(" h ");
|
||||||
if (minute < 10) {
|
if (minute < 10) {
|
||||||
aRenvoyer.append("0");
|
aRenvoyer.append("0");
|
||||||
}
|
|
||||||
aRenvoyer.append(String.valueOf(minute));
|
|
||||||
aRenvoyer.append(" | ");
|
|
||||||
|
|
||||||
// on insère la température
|
|
||||||
aRenvoyer.append(String.format("%3d", degree));
|
|
||||||
} else {
|
|
||||||
|
|
||||||
// l'un des arguments est invalide
|
|
||||||
aRenvoyer.append(CHAINE_DEFAUT);
|
|
||||||
}
|
}
|
||||||
|
aRenvoyer.append(String.valueOf(minute));
|
||||||
|
aRenvoyer.append(" | ");
|
||||||
|
|
||||||
|
// on insère la température
|
||||||
|
aRenvoyer.append(String.format("%3d", degree));
|
||||||
return aRenvoyer.toString();
|
return aRenvoyer.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extrait d'une chaîne le nom du plat. On suppose que la chaîne est correctement
|
* Extrait d'une chaîne le nom du plat. On suppose que la chaîne est
|
||||||
* formatée dans le format de la description d'une cuisson gérée par cette classe
|
* correctement
|
||||||
|
* formatée dans le format de la description d'une cuisson gérée par
|
||||||
|
* cette classe
|
||||||
* (les 20 premiers caractères de la chaîne sont extraits)
|
* (les 20 premiers caractères de la chaîne sont extraits)
|
||||||
*
|
*
|
||||||
* @param source chaîne source de l'extraction
|
* @param source chaîne source de l'extraction
|
||||||
@@ -161,11 +161,13 @@ public class Cuisson implements Serializable {
|
|||||||
*/
|
*/
|
||||||
public static int extraireTemperature(String source) {
|
public static int extraireTemperature(String source) {
|
||||||
int temperature; // température extraite
|
int temperature; // température extraite
|
||||||
String chaineTemperature; // température extraite en tant que chaîne
|
String
|
||||||
|
chaineTemperature; // température extraite en tant que chaîne
|
||||||
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
chaineTemperature = source.substring(source.length() - 3, source.length());
|
chaineTemperature = source.substring(source.length() - 3,
|
||||||
|
source.length());
|
||||||
temperature = Integer.parseInt(chaineTemperature);
|
temperature = Integer.parseInt(chaineTemperature);
|
||||||
} catch (NumberFormatException | IndexOutOfBoundsException erreur) {
|
} catch (NumberFormatException | IndexOutOfBoundsException erreur) {
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user