Commit dac8b0cd authored by Alutulu's avatar Alutulu

fix virgule

parent 8395ef26
import android.content.Context
import android.net.Uri
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.BaseAdapter
import android.widget.ImageView
import android.widget.TextView
import com.example.elbuenopeso.R
import com.example.elbuenopeso.models.AdModel
class AdAdapter(private val context: Context, private val adModelArrayList: List<AdModel>) : BaseAdapter() {
private val inflater: LayoutInflater = LayoutInflater.from(context)
override fun getCount(): Int = adModelArrayList.size
override fun getItem(i: Int): Any = adModelArrayList[i]
override fun getItemId(i: Int): Long = i.toLong()
fun usingJavaStringFormat(input: Double, scale: Int) = String.format("%.${scale}f", input)
override fun getView(i: Int, view: View?, viewGroup: ViewGroup): View {
val ad = adModelArrayList[i]
val convertView: View = inflater.inflate(R.layout.item_listview_ad, viewGroup, false)
val imageIV: ImageView = convertView.findViewById(R.id.itemListViewImageView)
val titleTV: TextView = convertView.findViewById(R.id.itemListViewTitleView)
val addressTV: TextView = convertView.findViewById(R.id.itemListViewTextView)
val prixTV: TextView = convertView.findViewById(R.id.itemListViewPrixView)
imageIV.setImageURI(Uri.parse(ad.image))
titleTV.text = ad.title
addressTV.text = ad.address
prixTV.text = "${usingJavaStringFormat(ad.prix, 2)} €"
return convertView
}
}
\ No newline at end of file
......@@ -18,25 +18,23 @@ class DbAdapter(context: Context, c: Cursor, layout: Int): CursorAdapter(context
return LayoutInflater.from(context).inflate(item_layout, viewGroup, false)
}
fun usingJavaStringFormat(input: Double, scale: Int) = String.format("%.${scale}f", input)
override fun bindView(view: View, context: Context, cursor: Cursor) {
val titleTextView: TextView = view.findViewById(R.id.itemListViewTitleView)
val addressTextView: TextView = view.findViewById(R.id.itemListViewTextView)
val imageView: ImageView = view.findViewById(R.id.itemListViewImageView)
val prixView: TextView = view.findViewById(R.id.itemListViewPrixView)
val _id: String = cursor.getString(cursor.getColumnIndexOrThrow(DBHelper._ID))
val title: String = cursor.getString(cursor.getColumnIndexOrThrow(DBHelper.TITLE))
val address: String = cursor.getString(cursor.getColumnIndexOrThrow(DBHelper.ADDRESS))
val prix: Double = cursor.getDouble(cursor.getColumnIndexOrThrow(DBHelper.PRIX))
val image: String = cursor.getString(cursor.getColumnIndexOrThrow(DBHelper.IMAGE))
titleTextView.setText(title)
addressTextView.setText(address)
prixView.setText(prix.toString())
titleTextView.text = title
addressTextView.text = address
prixView.text = "${usingJavaStringFormat(prix, 2)} €"
imageView.setImageURI(Uri.parse(image))
//with(Glide)
//TODO: trouver une alternative !!!
}
}
\ No newline at end of file
......@@ -113,7 +113,7 @@ class AddFragment : Fragment() {
binding.title.text.toString(),
binding.address.text.toString(),
this.filePath,
binding.price.text.toString().toDouble()
binding.price.text.toString().replace(',', '.').toDouble()
)
dbManager.insert(ad);
......
package com.example.elbuenopeso.ui.market
import AdAdapter
import android.database.Cursor
import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.GridView
import android.widget.CursorAdapter
import android.widget.ListView
import android.widget.ToggleButton
import androidx.fragment.app.Fragment
import androidx.lifecycle.ViewModelProvider
import com.example.elbuenopeso.databinding.FragmentMarketBinding
import com.example.elbuenopeso.models.AdModel
import com.example.elbuenopeso.R
import com.example.elbuenopeso.adapters.DbAdapter
import com.example.elbuenopeso.database.DBManager
......@@ -49,18 +44,6 @@ class MarketFragment : Fragment() {
toggleButton = binding.toggleButton
val listView: ListView = binding.listView
// seed market items
var annonces: List<AdModel> = listOf<AdModel>(
AdModel("Poutre", "1 rue Jean-Pierre", R.drawable.pichu.toString(), 25.0),
AdModel("Briques", "2 rue Jean-Michel", R.drawable.pichu.toString(), 16.0),
AdModel("Mur en bois", "4 rue Alain-Juju", R.drawable.pichu.toString(), 7.2),
AdModel("Maison de pierre", "7 rue Joris Belhomme", R.drawable.pichu.toString(), 3.99),
AdModel("Téléphone de Timothé", "8 rue de Timothé", R.drawable.pichu.toString(), 0.85),
AdModel("Oridnateur", "10 rue Jean-Charles", R.drawable.pichu.toString(), 104.98),
AdModel("Charnières", "22 rue Jeanne-Marie", R.drawable.pichu.toString(), 2648.97),
AdModel("Porte en marbre", "1 rue Jean-Pierre", R.drawable.pichu.toString(), 480.0),
AdModel("Cheminée", "33 rue du Gouvernement", R.drawable.pichu.toString(), 800.0),
)
toggleButton.setOnCheckedChangeListener { _, isChecked ->
isGridViewEnabled = isChecked
......@@ -68,7 +51,6 @@ class MarketFragment : Fragment() {
}
val dbManager: DBManager? = DBManager.getDBManager(requireContext())
//dbManager!!.init()
dbManager!!.open()
val cursor = dbManager.fetch()
adapter = DbAdapter(requireContext(), cursor!!, R.layout.item_listview_ad)
......
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