mirror of
https://github.com/LucasVbr/OutilCuisson.git
synced 2026-05-13 17:11:53 +00:00
Finition des méthodes dans le fichier AfficherFragment + Création fichier CuissonAdapter pour afficher les trois arguments de la liste
This commit is contained in:
@@ -14,11 +14,20 @@ import android.view.MenuItem;
|
|||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.AdapterView;
|
import android.widget.AdapterView;
|
||||||
|
import android.widget.ArrayAdapter;
|
||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.Fragment;
|
||||||
|
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.ObjectInputStream;
|
||||||
|
import java.io.ObjectOutputStream;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
public class AfficherFragment extends Fragment {
|
public class AfficherFragment extends Fragment {
|
||||||
@@ -26,9 +35,13 @@ public class AfficherFragment extends Fragment {
|
|||||||
/**
|
/**
|
||||||
* Liste des cuissons enregistré dans l'application
|
* Liste des cuissons enregistré dans l'application
|
||||||
*/
|
*/
|
||||||
public static ArrayList<Cuisson> cuissonAffichees = new ArrayList<>();
|
public static ArrayList<com.example.outilcuisson.Cuisson> cuissonAffichees = new ArrayList<>();
|
||||||
|
|
||||||
ListView listeCuisson;
|
static View listeCuisson1;
|
||||||
|
static ArrayList listeCuisson;
|
||||||
|
|
||||||
|
private ArrayAdapter<String> adaptateur;
|
||||||
|
private ArrayList<String> cuissonAAfficher;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ajouter une cuisson
|
* Ajouter une cuisson
|
||||||
@@ -46,15 +59,20 @@ public class AfficherFragment extends Fragment {
|
|||||||
private static void updateSaveFile() {
|
private static void updateSaveFile() {
|
||||||
// TODO Il faut creer un fichier cuisson.txt si il n'existe pas
|
// TODO Il faut creer un fichier cuisson.txt si il n'existe pas
|
||||||
|
|
||||||
// try {
|
File file;
|
||||||
// FileOutputStream fos = new FileOutputStream("dataCuisson.txt", false);
|
FileOutputStream fos = null;
|
||||||
// ObjectOutputStream oos = new ObjectOutputStream(fos);
|
try {
|
||||||
// oos.writeObject(listeCuisson);
|
file = new File("dataCuisson.txt");
|
||||||
// oos.close();
|
fos = new FileOutputStream(file);
|
||||||
// fos.close();
|
if(!file.exists()){
|
||||||
// } catch (IOException ioe) {
|
file.createNewFile();
|
||||||
// ioe.printStackTrace();
|
}
|
||||||
// }
|
ObjectOutputStream oos = new ObjectOutputStream(fos);
|
||||||
|
oos.writeObject(listeCuisson1);
|
||||||
|
oos.close(); fos.close();
|
||||||
|
} catch (IOException ioe) {
|
||||||
|
ioe.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -63,21 +81,20 @@ public class AfficherFragment extends Fragment {
|
|||||||
private static void loadSaveFile() {
|
private static void loadSaveFile() {
|
||||||
// TODO à décommenter lorsque updateSaveFile() sera terminé
|
// TODO à décommenter lorsque updateSaveFile() sera terminé
|
||||||
|
|
||||||
// try {
|
try {
|
||||||
// FileInputStream fis = new FileInputStream("dataCuisson.txt");
|
FileInputStream fis = new FileInputStream("dataCuisson.txt");
|
||||||
// ObjectInputStream ois = new ObjectInputStream(fis);
|
ObjectInputStream ois = new ObjectInputStream(fis);
|
||||||
//
|
|
||||||
// listeCuisson = (ArrayList) ois.readObject();
|
listeCuisson = (ArrayList) ois.readObject();
|
||||||
//
|
ois.close();
|
||||||
// ois.close();
|
fis.close();
|
||||||
// fis.close();
|
} catch (FileNotFoundException ignored) {
|
||||||
// } catch (FileNotFoundException ignored) {
|
} catch (IOException ioe) {
|
||||||
// } catch (IOException ioe) {
|
ioe.printStackTrace();
|
||||||
// ioe.printStackTrace();
|
} catch (ClassNotFoundException c) {
|
||||||
// } catch (ClassNotFoundException c) {
|
System.out.println("Class not found");
|
||||||
// System.out.println("Class not found");
|
c.printStackTrace();
|
||||||
// c.printStackTrace();
|
}
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public AfficherFragment() {
|
public AfficherFragment() {
|
||||||
@@ -97,8 +114,8 @@ public class AfficherFragment extends Fragment {
|
|||||||
Bundle savedInstanceState) {
|
Bundle savedInstanceState) {
|
||||||
View view = inflater.inflate(R.layout.afficher_fragment, container, false);
|
View view = inflater.inflate(R.layout.afficher_fragment, container, false);
|
||||||
loadSaveFile();
|
loadSaveFile();
|
||||||
listeCuisson = view.findViewById(R.id.listeCuisson);
|
listeCuisson1 = view.findViewById(R.id.listeCuisson);
|
||||||
registerForContextMenu(listeCuisson);
|
registerForContextMenu(listeCuisson1);
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,7 +16,8 @@ import android.widget.TimePicker;
|
|||||||
|
|
||||||
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.Fragment;
|
||||||
|
|
||||||
import com.exercice.onglet.outilcuisson2021.OutilCuisson;
|
import com.example.outilcuisson.OutilCuisson;
|
||||||
|
import com.example.outilcuisson.Cuisson;
|
||||||
|
|
||||||
public class AjouterFragment extends Fragment {
|
public class AjouterFragment extends Fragment {
|
||||||
|
|
||||||
|
|||||||
@@ -31,4 +31,4 @@ public class Cuisson implements Serializable {
|
|||||||
public int getDegree() {
|
public int getDegree() {
|
||||||
return degree;
|
return degree;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,57 @@
|
|||||||
|
package com.example.outilcuisson;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.ArrayAdapter;
|
||||||
|
import android.widget.LinearLayout;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class CuissonAdapter extends ArrayAdapter<Cuisson> {
|
||||||
|
|
||||||
|
private int identifiantVueItem;
|
||||||
|
|
||||||
|
|
||||||
|
public CuissonAdapter(@NonNull Context context, int vueItem, List<Cuisson> lesCuissons) {
|
||||||
|
super(context, vueItem,lesCuissons);
|
||||||
|
this.identifiantVueItem = vueItem;
|
||||||
|
}
|
||||||
|
|
||||||
|
public View getView(int position, View uneVue, ViewGroup parent){
|
||||||
|
Cuisson unPlat = getItem(position);
|
||||||
|
LinearLayout vueItemListe;
|
||||||
|
|
||||||
|
if (uneVue == null) {
|
||||||
|
|
||||||
|
/*
|
||||||
|
* la vue décrivant chaque item de la liste n'est pas encore créée
|
||||||
|
* Il faut désérialiser le layout correspondant à cette vue.
|
||||||
|
*/
|
||||||
|
LayoutInflater outil;
|
||||||
|
outil = (LayoutInflater)getContext()
|
||||||
|
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||||
|
vueItemListe = (LinearLayout) outil.inflate(identifiantVueItem,
|
||||||
|
parent, false);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
vueItemListe = (LinearLayout) uneVue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// on accède aux 2 widgets présents sur la vue
|
||||||
|
TextView vuePlat = vueItemListe.findViewById(R.id.item_plat);
|
||||||
|
TextView vueDuree = vueItemListe.findViewById(R.id.item_duree);
|
||||||
|
TextView vueDegres = vueItemListe.findViewById(R.id.item_degres);
|
||||||
|
|
||||||
|
// on place dans les 2 widgets les valeurs de l'item à afficher
|
||||||
|
vuePlat.setText(unPlat.getPlat());
|
||||||
|
vueDuree.setText(unPlat.getHeure());
|
||||||
|
vueDegres.setText(Integer.toString(unPlat.getDegree()));
|
||||||
|
return vueItemListe;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -17,7 +17,7 @@
|
|||||||
/* A priori de fichier ne doit pas être modifié. Vous restez libre de le modifier si
|
/* A priori de fichier ne doit pas être modifié. Vous restez libre de le modifier si
|
||||||
besoin
|
besoin
|
||||||
*/
|
*/
|
||||||
package com.exercice.onglet.outilcuisson2021;
|
package com.example.outilcuisson;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -2,28 +2,37 @@
|
|||||||
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:stretchColumns="1">
|
android:stretchColumns="3">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_gravity="center"
|
android:layout_gravity="center"
|
||||||
android:gravity="center"
|
android:gravity="center"
|
||||||
android:text="@string/afficher_titre" />
|
android:text="@string/afficher_titre"
|
||||||
|
android:layout_marginBottom="15dp"/>
|
||||||
|
|
||||||
<TableRow>
|
<TableRow>
|
||||||
<TextView
|
<TextView
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="@string/afficher_label_plat" />
|
android:text="@string/afficher_label_plat"
|
||||||
|
android:layout_column="1"
|
||||||
|
android:layout_span="1"/>
|
||||||
|
<TextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/afficher_label_duree"
|
||||||
|
android:layout_column="2"
|
||||||
|
android:layout_span="1"
|
||||||
|
android:layout_marginLeft="100dp"
|
||||||
|
android:layout_marginRight="100dp"/>
|
||||||
<TextView
|
<TextView
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="@string/afficher_label_duree" />
|
android:text="@string/afficher_label_temperature"
|
||||||
<TextView
|
android:layout_column="3"
|
||||||
android:layout_width="match_parent"
|
android:layout_span="1"/>
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:text="@string/afficher_label_temperature" />
|
|
||||||
</TableRow>
|
</TableRow>
|
||||||
|
|
||||||
<ListView
|
<ListView
|
||||||
|
|||||||
@@ -5,13 +5,29 @@
|
|||||||
température soient bien alignées)
|
température soient bien alignées)
|
||||||
Un padding est ajouté autour du texte
|
Un padding est ajouté autour du texte
|
||||||
fichier ligne_liste.xml 12/21 -->
|
fichier ligne_liste.xml 12/21 -->
|
||||||
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:id="@android:id/text1"
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:orientation="horizontal">
|
||||||
|
|
||||||
|
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:id="@+id/item_plat"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:typeface="monospace"
|
android:typeface="monospace"
|
||||||
android:textStyle="bold"/>
|
android:textStyle="bold"/>
|
||||||
<!--android:textSize="@dimen/taille_texte_liste"
|
|
||||||
android:paddingTop="@dimen/padding_liste"
|
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:paddingBottom="@dimen/padding_liste"
|
android:id="@+id/item_duree"
|
||||||
android:textColor="@color/couleur_item_liste"-->
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:typeface="monospace"
|
||||||
|
android:textStyle="bold"/>
|
||||||
|
|
||||||
|
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:id="@+id/item_degres"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:typeface="monospace"
|
||||||
|
android:textStyle="bold"/>
|
||||||
|
</LinearLayout>
|
||||||
Reference in New Issue
Block a user