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);
}
}
......@@ -58,12 +58,12 @@ public class DBManager {
// Add ads manually.
public void init(Context c){
insert(new Annonce("Wood", "Douai", imageToByteArray(R.drawable.mat1, c),24.99, "High-quality seasoned firewood for sale! Perfect for cozy nights by the fireplace or powering your wood-burning stove. Our carefully selected wood is sourced sustainably, ensuring both quality and environmental responsibility. Available for delivery to your doorstep, our firewood is split and ready to use, saving you time and effort. Whether you're a homeowner, camper, or outdoor enthusiast, our firewood is ideal for all your needs. Stock up now and enjoy the warmth and ambiance of natural wood burning. Don't miss out on this opportunity to elevate your fire experience. Contact us today to place your order!"));
insert(new Annonce("Steel", "Lille", imageToByteArray(R.drawable.mat2, c), 18.9, "Premium steel available for sale! Engineered for strength and durability, our high-grade steel is suitable for a wide range of applications. Whether you're a contractor, builder, or DIY enthusiast, our steel products are perfect for construction projects, fabrication, or repairs. With various sizes and shapes available, we cater to diverse needs and specifications. Our steel undergoes rigorous quality checks to ensure top-notch performance and reliability. Conveniently order online and have it delivered to your location. Upgrade your projects with our superior steel today. Contact us now to place your order and experience the difference!"));
insert(new Annonce("Clay", "Douai", imageToByteArray(R.drawable.mat3, c), 7.88, "Quality clay for sale! Ideal for pottery, sculpting, and crafting projects, our premium-grade clay offers versatility and excellent molding properties. Sourced from reliable suppliers, our clay is carefully processed to ensure consistency and workability. Whether you're a professional artist or a hobbyist, our clay is perfect for bringing your creative visions to life. Available in various quantities, we cater to both small-scale and large-scale projects. Order online for convenient delivery to your doorstep. Elevate your crafting experience with our top-quality clay. Contact us today to place your order and unleash your artistic potential!"));
insert(new Annonce("Metal", "Lyon", imageToByteArray(R.drawable.mat4, c), 12.99, "Discover the perfect metal for your projects! Our high-quality metal is meticulously crafted to meet the demands of various industries and applications. Whether you're in construction, manufacturing, or metalworking, our premium-grade metal offers unparalleled strength, durability, and versatility. From stainless steel to aluminum and everything in between, we provide a wide range of metal options to suit your specific needs. Our metals are sourced from trusted suppliers and undergo rigorous quality checks to ensure superior performance. Conveniently order online and have it delivered to your location. Elevate your projects with our exceptional metal products. Contact us today to place your order and experience the difference!"));
insert(new Annonce("Glass", "Valenciennes", imageToByteArray(R.drawable.mat5, c), 12.0, "Explore the brilliance of our premium glass products! Crafted with precision and quality in mind, our glass offerings are perfect for a variety of applications. Whether you're in need of durable windows for your home, sleek glass tabletops for your office, or intricate glassware for your dining table, we have you covered. Our extensive range includes tempered glass, laminated glass, decorative glass, and more, ensuring we meet your specific requirements. Sourced from trusted manufacturers, our glass products undergo stringent quality control measures to guarantee clarity, strength, and safety. Order online for hassle-free delivery to your desired location. Elevate your spaces with our exquisite glass solutions. Contact us today to place your order and bring sophistication to your projects!"));
insert(new Annonce("Wood", "Orchies", imageToByteArray(R.drawable.mat6, c), 3, "Experience the unparalleled warmth and charm of Orchies wood – the epitome of quality and elegance. Our carefully curated selection of Orchies wood is renowned for its superior craftsmanship and timeless appeal. Sourced from sustainably managed forests in the scenic city of Orchies, France, our wood exudes a unique character and richness that sets it apart. Whether you're crafting bespoke furniture or enhancing your living space with exquisite wood accents, Orchies wood promises unmatched beauty and durability. Elevate your projects with the finest Orchies wood and indulge in the rustic allure of this picturesque city. Transform your space with Orchies wood – where timeless elegance meets sustainable craftsmanship."));
insert(new Annonce("Wood", "Douai", imageToByteArray(R.drawable.mat1, c),24.99, "High-quality seasoned firewood for sale! Perfect for cozy nights by the fireplace or powering your wood-burning stove. Our carefully selected wood is sourced sustainably, ensuring both quality and environmental responsibility. Available for delivery to your doorstep, our firewood is split and ready to use, saving you time and effort. Whether you're a homeowner, camper, or outdoor enthusiast, our firewood is ideal for all your needs. Stock up now and enjoy the warmth and ambiance of natural wood burning. Don't miss out on this opportunity to elevate your fire experience. Contact us today to place your order!", "0123456789", "test@mail.com"));
insert(new Annonce("Steel", "Lille", imageToByteArray(R.drawable.mat2, c), 18.9, "Premium steel available for sale! Engineered for strength and durability, our high-grade steel is suitable for a wide range of applications. Whether you're a contractor, builder, or DIY enthusiast, our steel products are perfect for construction projects, fabrication, or repairs. With various sizes and shapes available, we cater to diverse needs and specifications. Our steel undergoes rigorous quality checks to ensure top-notch performance and reliability. Conveniently order online and have it delivered to your location. Upgrade your projects with our superior steel today. Contact us now to place your order and experience the difference!", "0123456789", "test@mail.com"));
insert(new Annonce("Clay", "Douai", imageToByteArray(R.drawable.mat3, c), 7.88, "Quality clay for sale! Ideal for pottery, sculpting, and crafting projects, our premium-grade clay offers versatility and excellent molding properties. Sourced from reliable suppliers, our clay is carefully processed to ensure consistency and workability. Whether you're a professional artist or a hobbyist, our clay is perfect for bringing your creative visions to life. Available in various quantities, we cater to both small-scale and large-scale projects. Order online for convenient delivery to your doorstep. Elevate your crafting experience with our top-quality clay. Contact us today to place your order and unleash your artistic potential!", "0123456789", "test@mail.com"));
insert(new Annonce("Metal", "Lyon", imageToByteArray(R.drawable.mat4, c), 12.99, "Discover the perfect metal for your projects! Our high-quality metal is meticulously crafted to meet the demands of various industries and applications. Whether you're in construction, manufacturing, or metalworking, our premium-grade metal offers unparalleled strength, durability, and versatility. From stainless steel to aluminum and everything in between, we provide a wide range of metal options to suit your specific needs. Our metals are sourced from trusted suppliers and undergo rigorous quality checks to ensure superior performance. Conveniently order online and have it delivered to your location. Elevate your projects with our exceptional metal products. Contact us today to place your order and experience the difference!", "0123456789", "test@mail.com"));
insert(new Annonce("Glass", "Valenciennes", imageToByteArray(R.drawable.mat5, c), 12.0, "Explore the brilliance of our premium glass products! Crafted with precision and quality in mind, our glass offerings are perfect for a variety of applications. Whether you're in need of durable windows for your home, sleek glass tabletops for your office, or intricate glassware for your dining table, we have you covered. Our extensive range includes tempered glass, laminated glass, decorative glass, and more, ensuring we meet your specific requirements. Sourced from trusted manufacturers, our glass products undergo stringent quality control measures to guarantee clarity, strength, and safety. Order online for hassle-free delivery to your desired location. Elevate your spaces with our exquisite glass solutions. Contact us today to place your order and bring sophistication to your projects!", "0123456789", "test@mail.com"));
insert(new Annonce("Wood", "Orchies", imageToByteArray(R.drawable.mat6, c), 3, "Experience the unparalleled warmth and charm of Orchies wood – the epitome of quality and elegance. Our carefully curated selection of Orchies wood is renowned for its superior craftsmanship and timeless appeal. Sourced from sustainably managed forests in the scenic city of Orchies, France, our wood exudes a unique character and richness that sets it apart. Whether you're crafting bespoke furniture or enhancing your living space with exquisite wood accents, Orchies wood promises unmatched beauty and durability. Elevate your projects with the finest Orchies wood and indulge in the rustic allure of this picturesque city. Transform your space with Orchies wood – where timeless elegance meets sustainable craftsmanship.", "0123456789", "test@mail.com"));
}
//Convert drawable image to byteArray
......@@ -85,11 +85,14 @@ public class DBManager {
contentValue.put(DBHelper.IMAGE, ad.getImage());
contentValue.put(DBHelper.PRICE, ad.getPrix());
contentValue.put(DBHelper.DESCRIPTION, ad.getDescription());
contentValue.put(DBHelper.TELEPHONE, ad.getNumeroTelephone());
contentValue.put(DBHelper.EMAIL, ad.getEmail());
database.insert(DBHelper.TABLE_NAME, null, contentValue);
}
public Cursor fetch() {
String[] columns = new String[] { DBHelper._ID, DBHelper.TITLE, DBHelper.ADDRESS, DBHelper.IMAGE, DBHelper.PRICE, DBHelper.DESCRIPTION};
String[] columns = new String[] { DBHelper._ID, DBHelper.TITLE, DBHelper.ADDRESS, DBHelper.IMAGE, DBHelper.PRICE, DBHelper.DESCRIPTION, DBHelper.TELEPHONE, DBHelper.EMAIL};
Cursor cursor = database.query(DBHelper.TABLE_NAME, columns, null, null, null, null, null);
if (cursor != null) {
cursor.moveToFirst();
......@@ -104,6 +107,8 @@ public class DBManager {
contentValues.put(DBHelper.IMAGE, ad.getImage());
contentValues.put(DBHelper.PRICE, ad.getPrix());
contentValues.put(DBHelper.DESCRIPTION, ad.getDescription());
contentValues.put(DBHelper.TELEPHONE, ad.getNumeroTelephone());
contentValues.put(DBHelper.EMAIL, ad.getEmail());
int i = database.update(DBHelper.TABLE_NAME, contentValues, DBHelper._ID + " = " + _id, null);
......@@ -133,8 +138,10 @@ public class DBManager {
byte[] image = cursor.getBlob(abs(cursor.getColumnIndex(DBHelper.IMAGE)));
double prix = cursor.getDouble(abs(cursor.getColumnIndex(DBHelper.PRICE)));
String description = cursor.getString(abs(cursor.getColumnIndex(DBHelper.DESCRIPTION)));
String telephone = cursor.getString(abs(cursor.getColumnIndex(DBHelper.TELEPHONE)));
String email = cursor.getString(abs(cursor.getColumnIndex(DBHelper.EMAIL)));
annonces.add(new Annonce(titre, adresse, image, prix, description));
annonces.add(new Annonce(titre, adresse, image, prix, description, telephone, email));
} while (cursor.moveToNext());
return annonces;
......
......@@ -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