mirror of
https://github.com/LucasVbr/OutilCuisson.git
synced 2026-05-14 01:21:52 +00:00
Ajout Cuisson, action Annuler, Valider
Ajout de la classe Cuisson (Sérialisable) // Classe AjouterFragment - Definition des valeurs par défaut du time picker - Ajout des actions Annuler et Valider (avec des tests qui creer un nouvel objet qui est stocké dans la liste de AfficherFragment) // Classe Afficher Fragment Ajout d'une arraylist qui contiens les cuissons Ajout de deux fonctions pour charger et sauvegarder les cuissons dans un fichier (ne fonctionne pas encore, a faire)
This commit is contained in:
@@ -13,9 +13,67 @@ import android.view.ViewGroup;
|
||||
|
||||
import androidx.fragment.app.Fragment;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class AfficherFragment extends Fragment {
|
||||
|
||||
public AfficherFragment() {}
|
||||
/**
|
||||
* Liste des cuissons enregistré dans l'application
|
||||
*/
|
||||
public static ArrayList<Cuisson> listeCuisson = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* Ajouter une cuisson
|
||||
*
|
||||
* @param cuisson La cuisson à ajouter
|
||||
*/
|
||||
public static void addCuisson(Cuisson cuisson) {
|
||||
listeCuisson.add(cuisson);
|
||||
updateSaveFile();
|
||||
}
|
||||
|
||||
/**
|
||||
* Met a jour le fichier dataCuisson.txt qui sauvegarde la liste des cuissons
|
||||
*/
|
||||
private static void updateSaveFile() {
|
||||
// TODO Il faut creer un fichier cuisson.txt si il n'existe pas
|
||||
|
||||
// try {
|
||||
// FileOutputStream fos = new FileOutputStream("dataCuisson.txt", false);
|
||||
// ObjectOutputStream oos = new ObjectOutputStream(fos);
|
||||
// oos.writeObject(listeCuisson);
|
||||
// oos.close();
|
||||
// fos.close();
|
||||
// } catch (IOException ioe) {
|
||||
// ioe.printStackTrace();
|
||||
// }
|
||||
}
|
||||
|
||||
/**
|
||||
* Charge la liste des cuissons contenue dans le fichier dataCuisson.txt
|
||||
*/
|
||||
private static void loadSaveFile() {
|
||||
// TODO à décommenter lorsque updateSaveFile() sera terminé
|
||||
|
||||
// try {
|
||||
// FileInputStream fis = new FileInputStream("dataCuisson.txt");
|
||||
// ObjectInputStream ois = new ObjectInputStream(fis);
|
||||
//
|
||||
// listeCuisson = (ArrayList) ois.readObject();
|
||||
//
|
||||
// ois.close();
|
||||
// fis.close();
|
||||
// } catch (FileNotFoundException ignored) {
|
||||
// } catch (IOException ioe) {
|
||||
// ioe.printStackTrace();
|
||||
// } catch (ClassNotFoundException c) {
|
||||
// System.out.println("Class not found");
|
||||
// c.printStackTrace();
|
||||
// }
|
||||
}
|
||||
|
||||
public AfficherFragment() {
|
||||
}
|
||||
|
||||
public static AfficherFragment newInstance() {
|
||||
return new AfficherFragment();
|
||||
@@ -29,6 +87,7 @@ public class AfficherFragment extends Fragment {
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
loadSaveFile();
|
||||
return inflater.inflate(R.layout.afficher_fragment, container, false);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user