Commit 03d8e6b7 authored by m-spi's avatar m-spi

Corrected all known bugs

parent d7ce9e22
......@@ -3,7 +3,20 @@
<component name="deploymentTargetDropDown">
<value>
<entry key="app">
<State />
<State>
<targetSelectedWithDropDown>
<Target>
<type value="QUICK_BOOT_TARGET" />
<deviceKey>
<Key>
<type value="VIRTUAL_DEVICE_PATH" />
<value value="$USER_HOME$/.android/avd/Pixel_3a_API_34_extension_level_7_x86_64.avd" />
</Key>
</deviceKey>
</Target>
</targetSelectedWithDropDown>
<timeTargetWasSelectedWithDropDown value="2024-02-22T20:04:40.258703061Z" />
</State>
</entry>
</value>
</component>
......
......@@ -39,15 +39,13 @@ class DbAdapter(context: Context, c: Cursor, layout: Int): CursorAdapter(context
addressTextView.text = address
prixView.text = "${usingJavaStringFormat(prix, 2)} €"
val Bouton: Button =view.findViewById(R.id.buttonCall)
Bouton.setOnClickListener{
Bouton.setOnClickListener {
Log.d("TAG", "TEST")
val callIntent = Intent(Intent.ACTION_DIAL)
callIntent.data = Uri.parse("tel:$num")
context.startActivity(callIntent)
}
val button: Button = view.findViewById(R.id.buttonCall)
button.setOnClickListener {
Log.d("TAG", "TEST")
val callIntent = Intent(Intent.ACTION_DIAL)
callIntent.data = Uri.parse("tel:$num")
context.startActivity(callIntent)
}
......
......@@ -14,11 +14,11 @@ class DBHelper(context: Context) : SQLiteOpenHelper(context, DB_NAME, null, DB_V
const val ADDRESS = "address"
const val IMAGE = "image_url"
const val PRIX = "price"
const val NUM = "123456789"
const val NUM = "num"
private const val DB_NAME = "LEBONCOIN.DB"
private const val DB_VERSION = 1
const val CREATE_TABLE = "CREATE TABLE $TABLE_NAME ($_ID INTEGER PRIMARY KEY AUTOINCREMENT, $TITLE TEXT NOT NULL, $ADDRESS TEXT, $IMAGE TEXT, $PRIX REAL NOT NULL);"
const val CREATE_TABLE = "CREATE TABLE $TABLE_NAME ($_ID INTEGER PRIMARY KEY AUTOINCREMENT, $TITLE TEXT NOT NULL, $ADDRESS TEXT, $IMAGE TEXT, $PRIX REAL NOT NULL, $NUM TEXT);"
}
override fun onCreate(db: SQLiteDatabase) {
......@@ -40,8 +40,9 @@ class DBHelper(context: Context) : SQLiteOpenHelper(context, DB_NAME, null, DB_V
val address = data.getString(data.getColumnIndexOrThrow(ADDRESS))
val image = data.getString(data.getColumnIndexOrThrow(IMAGE))
val prix = data.getDouble(data.getColumnIndexOrThrow(PRIX))
val num = data.getString(data.getColumnIndexOrThrow(NUM))
data.close()
AdModel(title, address, image, prix)
AdModel(title, address, image, prix, num)
} else {
data.close()
null
......
......@@ -25,35 +25,34 @@ private constructor(private val context: Context) {
}
// Add ads manually.
fun init() {
this.open()
this.insert(
AdModel("Poutre", "1 rue Jean-Pierre", "drawable/pichu.png", 25.0)
AdModel("Poutre", "1 rue Jean-Pierre", "drawable/pichu.png", 25.0, "0123456789")
)
this.insert(
AdModel("Briques", "2 rue Jean-Michel", "drawable/pichu.png", 16.0)
AdModel("Briques", "2 rue Jean-Michel", "drawable/pichu.png", 16.0, "0123456789")
)
this.insert(
AdModel("Maison de pierre", "7 rue Joris Belhomme", "drawable/pichu.png", 3.99)
AdModel("Maison de pierre", "7 rue Joris Belhomme", "drawable/pichu.png", 3.99, "0123456789")
)
this.insert(
AdModel("Mur en bois", "4 rue Alain-Juju", "drawable/pichu.png", 7.2)
AdModel("Mur en bois", "4 rue Alain-Juju", "drawable/pichu.png", 7.2, "0123456789")
)
this.insert(
AdModel("Téléphone de Timothé", "8 rue de Timothé", "drawable/pichu.png", 0.85)
AdModel("Téléphone de Timothé", "8 rue de Timothé", "drawable/pichu.png", 0.85, "0123456789")
)
this.insert(
AdModel("Oridnateur", "10 rue Jean-Charles", "drawable/pichu.png", 104.98)
AdModel("Oridnateur", "10 rue Jean-Charles", "drawable/pichu.png", 104.98,"0123456789")
)
this.insert(
AdModel("Charnières", "22 rue Jeanne-Marie", "drawable/pichu.png", 2648.97)
AdModel("Charnières", "22 rue Jeanne-Marie", "drawable/pichu.png", 2648.97, "0123456789")
)
this.insert(
AdModel("Porte en marbre", "1 rue Jean-Pierre", "drawable/pichu.png", 480.0)
AdModel("Porte en marbre", "1 rue Jean-Pierre", "drawable/pichu.png", 480.0, "0123456789")
)
this.insert(
AdModel("Cheminée", "33 rue du Gouvernement", "drawable/pichu.png", 800.0)
AdModel("Cheminée", "33 rue du Gouvernement", "drawable/pichu.png", 800.0, "0123456789")
)
}
......@@ -63,12 +62,13 @@ private constructor(private val context: Context) {
contentValue.put(DBHelper.ADDRESS, ad.address)
contentValue.put(DBHelper.IMAGE, ad.image)
contentValue.put(DBHelper.PRIX, ad.prix)
contentValue.put(DBHelper.NUM, ad.num)
this.database!!.insert(DBHelper.TABLE_NAME, null, contentValue)
}
fun fetch(): Cursor? {
val columns: Array<String> =
arrayOf(DBHelper._ID, DBHelper.TITLE, DBHelper.ADDRESS, DBHelper.IMAGE, DBHelper.PRIX)
arrayOf(DBHelper._ID, DBHelper.TITLE, DBHelper.ADDRESS, DBHelper.IMAGE, DBHelper.PRIX, DBHelper.NUM)
val cursor = this.database!!.query(DBHelper.TABLE_NAME, columns, null, null, null, null, null)
cursor?.moveToFirst()
return cursor
......@@ -79,6 +79,8 @@ private constructor(private val context: Context) {
contentValues.put(DBHelper.TITLE, ad.title)
contentValues.put(DBHelper.ADDRESS, ad.address)
contentValues.put(DBHelper.IMAGE, ad.image)
contentValues.put(DBHelper.PRIX, ad.prix)
contentValues.put(DBHelper.NUM, ad.num)
return this.database!!.update(
DBHelper.TABLE_NAME,
contentValues,
......
package com.example.elbuenopeso.models
public class AdModel(var title: String, var address: String, var image: String, var prix: Double) {
public class AdModel(var title: String, var address: String, var image: String, var prix: Double, var num: String) {
}
\ No newline at end of file
package com.example.elbuenopeso.ui.add
import android.app.Activity
import android.content.ContentResolver
import android.content.Context
import android.content.ContextWrapper
import android.content.Intent
import android.graphics.Bitmap
import android.graphics.BitmapFactory
import android.net.Uri
import android.os.Bundle
import android.provider.MediaStore
......@@ -25,9 +27,11 @@ import com.example.elbuenopeso.models.AdModel
import java.io.File
import java.io.FileOutputStream
import java.io.IOException
import java.io.InputStream
import java.io.OutputStream
import java.lang.NumberFormatException
@Suppress("DEPRECATION")
class AddFragment : Fragment() {
private var _binding: FragmentAddBinding? = null
......@@ -45,20 +49,39 @@ class AddFragment : Fragment() {
registerForActivityResult(ActivityResultContracts.StartActivityForResult()) {
result -> run {
if (result.resultCode == Activity.RESULT_OK) {
val image = result?.data?.data as Uri
this.filePath = image.path!!
val image: Uri = result?.data?.data as Uri
val cw = ContextWrapper(requireContext())
val directory: File = cw.getDir("imageDir", Context.MODE_PRIVATE)
val tsLong = System.currentTimeMillis() / 1000
val ts = tsLong.toString()
val file = File(directory, "$ts.jpg")
val in_stream: InputStream? = requireContext().contentResolver.openInputStream(image)
val out_stream: OutputStream = FileOutputStream(file)
val buf = ByteArray(1024)
var len: Int
while (in_stream!!.read(buf).also { len = it } > 0) {
out_stream.write(buf, 0, len)
}
out_stream.flush()
out_stream.close()
in_stream.close()
this.filePath = file.toString()
this.image.setImageURI(image)
}
}
}
@Suppress("DEPRECATION")
private val cameraActivityResultLauncher: ActivityResultLauncher<Intent> =
registerForActivityResult(ActivityResultContracts.StartActivityForResult()) {
result -> if (result.resultCode == Activity.RESULT_OK) {
val data = result.data
val bitmap = data!!.extras!!["data"] as Bitmap?
val cw = ContextWrapper(requireContext())
val directory = cw.getDir("imageDir", Context.MODE_PRIVATE)
val directory: File = cw.getDir("imageDir", Context.MODE_PRIVATE)
val tsLong = System.currentTimeMillis() / 1000
val ts = tsLong.toString()
val file = File(directory, "$ts.jpg")
......@@ -109,11 +132,20 @@ class AddFragment : Fragment() {
return@setOnClickListener
}
Log.d(null, this.filePath)
val ad = AdModel(
binding.title.text.toString(),
binding.address.text.toString(),
this.filePath,
binding.price.text.toString().replace(',', '.').toDouble()
prix = run {
try {
binding.price.text.toString().replace(',', '.').toDouble()
} catch (e: NumberFormatException) {
Double.NaN
}
},
binding.num.text.toString()
)
dbManager.insert(ad);
......@@ -122,6 +154,7 @@ class AddFragment : Fragment() {
binding.title.setText("")
binding.address.setText("")
binding.price.setText("")
binding.num.setText("")
this.filePath = ""
// Je sais pas trop ce que c'est mais dans le doute je laisse ça là...
......
......@@ -96,6 +96,26 @@
android:paddingHorizontal="36dp" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/numLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginHorizontal="20dp"
android:layout_marginVertical="10dp"
android:hint="@string/phone_number"
android:textColorHint="#6E6E6E"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/priceLayout"
tools:ignore="MissingConstraints">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/num"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingHorizontal="36dp" />
</com.google.android.material.textfield.TextInputLayout>
<Button
android:id="@+id/sendButton"
android:layout_width="wrap_content"
......@@ -107,7 +127,7 @@
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/priceLayout"
app:layout_constraintTop_toBottomOf="@+id/numLayout"
tools:ignore="MissingConstraints" />
</androidx.constraintlayout.widget.ConstraintLayout>
......
......@@ -10,7 +10,7 @@
android:id="@+id/toggleButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Toggle View"
android:text="@string/toggle_view"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
......
......@@ -10,4 +10,6 @@
<string name="title">Title</string>
<string name="gallery">Gallery</string>
<string name="price">Price</string>
<string name="phone_number">Phone number</string>
<string name="toggle_view">Toggle View</string>
</resources>
\ 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