Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
E
ElBuenoPeso
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Matis SPINELLI
ElBuenoPeso
Commits
d95f8def
Commit
d95f8def
authored
Feb 21, 2024
by
Timothé KOBAK
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
grid view implemented
parent
b2bc3455
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
100 additions
and
45 deletions
+100
-45
MarketFragment.kt
.../java/com/example/elbuenopeso/ui/market/MarketFragment.kt
+45
-14
fragment_market.xml
app/src/main/res/layout/fragment_market.xml
+29
-4
item_listview_ad.xml
app/src/main/res/layout/item_listview_ad.xml
+26
-27
No files found.
app/src/main/java/com/example/elbuenopeso/ui/market/MarketFragment.kt
View file @
d95f8def
...
@@ -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,39 @@ import com.example.elbuenopeso.R
...
@@ -15,25 +17,39 @@ 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
(
"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
),
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,17 +59,32 @@ class MarketFragment : Fragment() {
...
@@ -43,17 +59,32 @@ 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
),
// Add more AdModel items as needed
)
)
var
adAdapter
:
A
dAdapter
=
AdAdapter
(
requireContext
(),
annonces
)
a
dAdapter
=
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
...
...
app/src/main/res/layout/fragment_market.xml
View file @
d95f8def
...
@@ -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>
app/src/main/res/layout/item_listview_ad.xml
View file @
d95f8def
<?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"
>
<TextView
android:id=
"@+id/itemListViewTitleView"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_height=
"wrap_content"
android:text=
"TextView"
android:orientation=
"vertical"
android:textSize=
"20sp"
android:padding=
"8dp"
>
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/itemListViewT
ext
View"
android:id=
"@+id/itemListViewT
itle
View"
android:layout_width=
"
wrap_cont
ent"
android:layout_width=
"
match_par
ent"
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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment