Commit 09c2c76b authored by Lucas NAURY's avatar Lucas NAURY

Ajout numéro téléphone et adresse mail

parent 171ed8c0
......@@ -21,6 +21,8 @@ public class DBHelper extends SQLiteOpenHelper {
public static final String IMAGE = "image";
public static final String PRICE = "prix";
public static final String DESCRIPTION = "description";
public static final String TELEPHONE = "telephone";
public static final String EMAIL = "email";
// Database Information
static final String DB_NAME = "LEBONCOIN.DB";
......@@ -30,7 +32,7 @@ public class DBHelper extends SQLiteOpenHelper {
// Creating table query
private static final String CREATE_TABLE = "create table " + TABLE_NAME + "(" + _ID
+ " INTEGER PRIMARY KEY AUTOINCREMENT, " + TITLE + " TEXT NOT NULL, " + ADDRESS + " TEXT NOT NULL, " + IMAGE + " BLOB, " + PRICE + " DOUBLE NOT NULL, " + DESCRIPTION + " TEXT);";
+ " INTEGER PRIMARY KEY AUTOINCREMENT, " + TITLE + " TEXT NOT NULL, " + ADDRESS + " TEXT NOT NULL, " + IMAGE + " BLOB, " + PRICE + " DOUBLE NOT NULL, " + DESCRIPTION + " TEXT, " + TELEPHONE + " TEXT, " + EMAIL + " TEXT);";
public DBHelper(Context context) {
super(context,
......@@ -67,7 +69,9 @@ public class DBHelper extends SQLiteOpenHelper {
byte[] image = data.getBlob(data.getColumnIndexOrThrow(IMAGE));
double price = data.getDouble(data.getColumnIndexOrThrow(PRICE));
String description = data.getString(data.getColumnIndexOrThrow(DESCRIPTION));
String telephone = data.getString(data.getColumnIndexOrThrow(TELEPHONE));
String email = data.getString(data.getColumnIndexOrThrow(EMAIL));
return new Annonce(title, address, image, price, description);
return new Annonce(title, address, image, price, description, telephone, email);
}
}
......@@ -18,20 +18,25 @@ public class Annonce implements Parcelable {
private double prix;
private byte[] image;
private String description;
private String numeroTelephone;
private String email;
// Constructeur
public Annonce(String titre, String adresse, byte[] image, double prix, String description) {
public Annonce(String titre, String adresse, byte[] image, double prix, String description, String numTel, String email) {
this.titre = titre;
this.adresse = adresse;
this.image = image;
this.prix = prix;
this.description = description;
this.numeroTelephone = numTel;
this.email = email;
// Génération d'un id automatique
this.id = Annonce.nbAnnonces;
Annonce.nbAnnonces++;
}
// Getter et Setter
public String getTitre() {
return titre;
......@@ -55,6 +60,8 @@ public class Annonce implements Parcelable {
return bmpImage;
}
public String getDescription(){return description;}
public String getNumeroTelephone(){return numeroTelephone;}
public String getEmail(){return email;}
// Parcelable
......@@ -78,6 +85,9 @@ public class Annonce implements Parcelable {
parcel.writeString(description);
parcel.writeInt(id);
parcel.writeString(numeroTelephone);
parcel.writeString(email);
}
public static final Parcelable.Creator<Annonce> CREATOR
= new Parcelable.Creator<Annonce>() {
......@@ -107,5 +117,8 @@ public class Annonce implements Parcelable {
description = in.readString();
id = in.readInt();
numeroTelephone = in.readString();
email = in.readString();
}
}
......@@ -54,6 +54,8 @@ public class AjoutAnnonceFragment extends Fragment {
final EditText adresseAnnonce = binding.adresseAnnonce;
final EditText prixAnnonce = binding.prixAnnonce;
final EditText descriptionAnnonce = binding.descriptionAnnonce;
final EditText telephoneAnnonce = binding.telephoneAnnonce;
final EditText emailAnnonce = binding.emailAnnonce;
final ImageView imageAnnonce = binding.imageAnnonce;
final Button boutonCreation = binding.boutonAjoutAnnonce;
......@@ -65,10 +67,10 @@ public class AjoutAnnonceFragment extends Fragment {
boutonCreation.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
// On vérifie si les informations sont correctement remplies
// On vérifie si les informations obligatoires sont correctement remplies
if(titreAnnonce.getText().toString().equals("") || adresseAnnonce.getText().toString().equals("") || prixAnnonce.getText().toString().equals("")){
Snackbar.make(view, "Veuillez remplir les champs pour créer l'annonce", Snackbar.LENGTH_LONG).show();
Snackbar.make(view, "Veuillez remplir les champs marqués d'un * pour créer l'annonce", Snackbar.LENGTH_LONG).show();
return;
}
......@@ -86,7 +88,7 @@ public class AjoutAnnonceFragment extends Fragment {
// On créé l'objet de la nouvelle annonce
Annonce nouvelleAnnonce = new Annonce(titreAnnonce.getText().toString(), adresseAnnonce.getText().toString(), imageInByte, Double.parseDouble(prixAnnonce.getText().toString()), descriptionAnnonce.getText().toString());
Annonce nouvelleAnnonce = new Annonce(titreAnnonce.getText().toString(), adresseAnnonce.getText().toString(), imageInByte, Double.parseDouble(prixAnnonce.getText().toString()), descriptionAnnonce.getText().toString(), telephoneAnnonce.getText().toString(), emailAnnonce.getText().toString());
//On ajoute la nouvelle annonce à la DB
dbManager.insert(nouvelleAnnonce);
......
......@@ -153,11 +153,56 @@
android:layout_height="wrap_content"
android:minHeight="@dimen/activity_vertical_margin" />
<TextView
android:id="@+id/labelTelephone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-medium"
android:text="Téléphone : "
android:textAppearance="@style/TextAppearance.AppCompat.Medium" />
<EditText
android:id="@+id/telephoneAnnonce"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="ex: 0123456789"
android:inputType="text"
android:textColorHint="#4D000000" />
<Space
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="@dimen/activity_vertical_margin" />
<TextView
android:id="@+id/labelEmail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-medium"
android:text="Email : "
android:textAppearance="@style/TextAppearance.AppCompat.Medium" />
<EditText
android:id="@+id/emailAnnonce"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="ex: john.doe@mail.com"
android:inputType="text"
android:textColorHint="#4D000000" />
<Space
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="@dimen/activity_vertical_margin" />
<TextView
android:id="@+id/warningObligatoire"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Les champs marqués d'un * sont obligatoires"
android:textAlignment="viewStart"
android:textAppearance="@style/TextAppearance.AppCompat.Body1"
android:textColor="#52000000" />
......@@ -165,7 +210,9 @@
android:id="@+id/boutonAjoutAnnonce"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:text="ajouter" />
</LinearLayout>
</ScrollView>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment