Commit d95f8def authored by Timothé KOBAK's avatar Timothé KOBAK

grid view implemented

parent b2bc3455
...@@ -5,7 +5,9 @@ import android.os.Bundle ...@@ -5,7 +5,9 @@ import android.os.Bundle
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import android.widget.GridView
import android.widget.ListView import android.widget.ListView
import android.widget.ToggleButton
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import androidx.lifecycle.ViewModelProvider import androidx.lifecycle.ViewModelProvider
import com.example.elbuenopeso.databinding.FragmentMarketBinding import com.example.elbuenopeso.databinding.FragmentMarketBinding
...@@ -15,25 +17,30 @@ import com.example.elbuenopeso.R ...@@ -15,25 +17,30 @@ import com.example.elbuenopeso.R
class MarketFragment : Fragment() { class MarketFragment : Fragment() {
private var _binding: FragmentMarketBinding? = null private var _binding: FragmentMarketBinding? = null
// This property is only valid between onCreateView and
// onDestroyView.
private val binding get() = _binding!! private val binding get() = _binding!!
private lateinit var listView: ListView
private lateinit var gridView: GridView
private lateinit var toggleButton: ToggleButton
private lateinit var adAdapter: AdAdapter
private var isGridViewEnabled = false
override fun onCreateView( override fun onCreateView(
inflater: LayoutInflater, inflater: LayoutInflater,
container: ViewGroup?, container: ViewGroup?,
savedInstanceState: Bundle? savedInstanceState: Bundle?
): View { ): View {
val marketViewModel =
ViewModelProvider(this)[MarketViewModel::class.java]
_binding = FragmentMarketBinding.inflate(inflater, container, false) _binding = FragmentMarketBinding.inflate(inflater, container, false)
val root: View = binding.root val root: View = binding.root
val listView: ListView = binding.listView listView = binding.listView
// seed market items gridView = binding.gridView
var annonces: List<AdModel> = listOf<AdModel>( toggleButton = binding.toggleButton
val annonces: List<AdModel> = listOf(
AdModel("Poutre", "1 rue Jean-Pierre", R.drawable.pichu, 25.0),
AdModel("Briques", "2 rue Jean-Michel", R.drawable.pichu, 16.0),
AdModel("Poutre", "1 rue Jean-Pierre", R.drawable.pichu, 25.0), AdModel("Poutre", "1 rue Jean-Pierre", R.drawable.pichu, 25.0),
AdModel("Briques", "2 rue Jean-Michel", R.drawable.pichu, 16.0), AdModel("Briques", "2 rue Jean-Michel", R.drawable.pichu, 16.0),
AdModel("Mur en bois", "4 rue Alain-Juju", R.drawable.pichu, 7.2), AdModel("Mur en bois", "4 rue Alain-Juju", R.drawable.pichu, 7.2),
...@@ -43,19 +50,43 @@ class MarketFragment : Fragment() { ...@@ -43,19 +50,43 @@ class MarketFragment : Fragment() {
AdModel("Charnières", "22 rue Jeanne-Marie", R.drawable.pichu, 2648.97), AdModel("Charnières", "22 rue Jeanne-Marie", R.drawable.pichu, 2648.97),
AdModel("Porte en marbre", "1 rue Jean-Pierre", R.drawable.pichu, 480.0), AdModel("Porte en marbre", "1 rue Jean-Pierre", R.drawable.pichu, 480.0),
AdModel("Cheminée", "33 rue du Gouvernement", R.drawable.pichu, 800.0), AdModel("Cheminée", "33 rue du Gouvernement", R.drawable.pichu, 800.0),
AdModel("Poutre", "1 rue Jean-Pierre", R.drawable.pichu, 25.0),
AdModel("Briques", "2 rue Jean-Michel", R.drawable.pichu, 16.0),
AdModel("Mur en bois", "4 rue Alain-Juju", R.drawable.pichu, 7.2),
AdModel("Maison de pierre", "7 rue Joris Belhomme", R.drawable.pichu, 3.99),
AdModel("Téléphone de Timothé", "8 rue de Timothé", R.drawable.pichu, 0.85),
AdModel("Oridnateur", "10 rue Jean-Charles", R.drawable.pichu, 104.98),
AdModel("Charnières", "22 rue Jeanne-Marie", R.drawable.pichu, 2648.97),
AdModel("Porte en marbre", "1 rue Jean-Pierre", R.drawable.pichu, 480.0),
AdModel("Cheminée", "33 rue du Gouvernement", R.drawable.pichu, 800.0),
// Add more AdModel items as needed
) )
var adAdapter: AdAdapter = AdAdapter(requireContext(), annonces) adAdapter = AdAdapter(requireContext(), annonces)
listView.adapter = adAdapter listView.adapter = adAdapter
/*marketViewModel.text.observe(viewLifecycleOwner) {
textView.text = it toggleButton.setOnCheckedChangeListener { _, isChecked ->
}*/ isGridViewEnabled = isChecked
updateView()
}
return root return root
} }
private fun updateView() {
if (isGridViewEnabled) {
listView.visibility = View.GONE
gridView.visibility = View.VISIBLE
gridView.adapter = adAdapter
} else {
gridView.visibility = View.GONE
listView.visibility = View.VISIBLE
listView.adapter = adAdapter
}
}
override fun onDestroyView() { override fun onDestroyView() {
super.onDestroyView() super.onDestroyView()
_binding = null _binding = null
} }
} }
\ No newline at end of file
...@@ -6,12 +6,37 @@ ...@@ -6,12 +6,37 @@
android:layout_height="match_parent" android:layout_height="match_parent"
tools:context=".ui.market.MarketFragment"> tools:context=".ui.market.MarketFragment">
<ToggleButton
android:id="@+id/toggleButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Toggle View"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ListView <ListView
android:id="@+id/listView" android:id="@+id/listView"
android:layout_width="409dp" android:layout_width="0dp"
android:layout_height="681dp" android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" /> app:layout_constraintTop_toBottomOf="@id/toggleButton" />
<GridView
android:id="@+id/gridView"
android:layout_width="0dp"
android:layout_height="0dp"
android:numColumns="2"
android:stretchMode="columnWidth"
android:gravity="center"
android:horizontalSpacing="8dp"
android:verticalSpacing="8dp"
android:padding="8dp"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/toggleButton" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="wrap_content"
android:orientation="vertical"
<TextView android:padding="8dp">
android:id="@+id/itemListViewTitleView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
android:textSize="20sp"
app:layout_constraintStart_toEndOf="@+id/itemListViewImageView"
app:layout_constraintTop_toTopOf="parent" />
<ImageView <ImageView
android:id="@+id/itemListViewImageView" android:id="@+id/itemListViewImageView"
android:layout_width="117dp" android:layout_width="117dp"
android:layout_height="94dp" android:layout_height="94dp"
app:layout_constraintStart_toStartOf="parent" android:layout_gravity="center_horizontal"
app:layout_constraintTop_toTopOf="parent" android:src="@drawable/pichu" />
tools:srcCompat="@drawable/pichu" />
<TextView <TextView
android:id="@+id/itemListViewTextView" android:id="@+id/itemListViewTitleView"
android:layout_width="wrap_content" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="TextView" android:textSize="20sp"
app:layout_constraintBottom_toBottomOf="@+id/itemListViewImageView" android:textStyle="bold"
app:layout_constraintStart_toEndOf="@+id/itemListViewImageView" /> android:maxLines="2"
android:ellipsize="end"
android:paddingTop="8dp"
android:paddingBottom="4dp" />
<TextView <TextView
android:id="@+id/itemListViewPrixView" android:id="@+id/itemListViewPrixView"
android:layout_width="wrap_content" android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="16sp"
android:paddingBottom="4dp" />
<TextView
android:id="@+id/itemListViewTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="TextView" android:textSize="14sp"
app:layout_constraintBottom_toTopOf="@+id/itemListViewTextView" android:maxLines="3"
app:layout_constraintStart_toEndOf="@+id/itemListViewImageView" android:ellipsize="end" />
app:layout_constraintTop_toBottomOf="@+id/itemListViewTitleView" />
</androidx.constraintlayout.widget.ConstraintLayout> </LinearLayout>
\ 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