Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
U
uv-amse-android
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
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
Lucas NAURY
uv-amse-android
Commits
a9c71840
Commit
a9c71840
authored
Feb 17, 2024
by
Inès EL HADRI
💤
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix add annonce on home page
parent
9d8f582b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
14 deletions
+21
-14
HomeAdapter.java
...ain/java/com/example/tpleboncoin/ui/home/HomeAdapter.java
+7
-5
HomeFragment.java
...in/java/com/example/tpleboncoin/ui/home/HomeFragment.java
+14
-9
No files found.
app/src/main/java/com/example/tpleboncoin/ui/home/HomeAdapter.java
View file @
a9c71840
...
...
@@ -11,11 +11,13 @@ import androidx.recyclerview.widget.RecyclerView;
import
com.example.tpleboncoin.R
;
import
com.example.tpleboncoin.models.Annonce
;
import
java.util.ArrayList
;
public
class
HomeAdapter
extends
RecyclerView
.
Adapter
<
HomeAdapter
.
ViewHolder
>
{
private
static
final
String
TAG
=
"CustomAdapter"
;
private
A
nnonce
[]
mDataSet
;
private
A
rrayList
<
Annonce
>
mDataSet
;
private
boolean
mIsGrid
;
/**
...
...
@@ -53,7 +55,7 @@ public class HomeAdapter extends RecyclerView.Adapter<HomeAdapter.ViewHolder> {
* @param dataSet String[] containing the data to populate views to be used by RecyclerView.
* @param isGrid boolean = le layout actuel (grille ou linéaire)
*/
public
HomeAdapter
(
A
nnonce
[]
dataSet
,
boolean
isGrid
)
{
public
HomeAdapter
(
A
rrayList
<
Annonce
>
dataSet
,
boolean
isGrid
)
{
mDataSet
=
dataSet
;
mIsGrid
=
isGrid
;
}
...
...
@@ -82,14 +84,14 @@ public class HomeAdapter extends RecyclerView.Adapter<HomeAdapter.ViewHolder> {
// Get element from dataset at this position and replace the contents of the view
// with that element
viewHolder
.
getTitreTextView
().
setText
(
mDataSet
[
position
]
.
getTitre
());
viewHolder
.
getAdresseTextView
().
setText
(
mDataSet
[
position
]
.
getAdresse
());
viewHolder
.
getTitreTextView
().
setText
(
mDataSet
.
get
(
position
)
.
getTitre
());
viewHolder
.
getAdresseTextView
().
setText
(
mDataSet
.
get
(
position
)
.
getAdresse
());
}
// Return the size of dataset (invoked by the layout manager)
@Override
public
int
getItemCount
()
{
return
mDataSet
.
length
;
return
mDataSet
.
toArray
().
length
;
}
}
...
...
app/src/main/java/com/example/tpleboncoin/ui/home/HomeFragment.java
View file @
a9c71840
...
...
@@ -19,6 +19,9 @@ import com.example.tpleboncoin.R;
import
com.example.tpleboncoin.models.Annonce
;
import
com.example.tpleboncoin.databinding.FragmentHomeBinding
;
import
java.util.ArrayList
;
import
java.util.List
;
public
class
HomeFragment
extends
Fragment
{
private
static
final
String
TAG
=
"RecyclerViewFragment"
;
...
...
@@ -39,7 +42,7 @@ public class HomeFragment extends Fragment {
protected
RecyclerView
mRecyclerView
;
protected
HomeAdapter
mAdapter
;
protected
RecyclerView
.
LayoutManager
mLayoutManager
;
protected
A
nnonce
[]
mDataset
;
protected
A
rrayList
<
Annonce
>
mDataset
;
@Override
public
void
onCreate
(
Bundle
savedInstanceState
)
{
...
...
@@ -72,6 +75,14 @@ public class HomeFragment extends Fragment {
}
setRecyclerViewLayoutManager
(
mCurrentLayoutManagerType
);
// On récupère l'annonce qui vient d'être créée s'il y en a une
if
(
getArguments
()
!=
null
&&
getArguments
().
getParcelable
(
"nouvelleAnnonce"
)
!=
null
){
Annonce
newAnnonce
=
getArguments
().
getParcelable
(
"nouvelleAnnonce"
);
Log
.
d
(
"HomeFragment"
,
newAnnonce
.
getTitre
());
mDataset
.
add
(
newAnnonce
);
}
// adapter pour gérer le visu de l'annonce
mAdapter
=
new
HomeAdapter
(
mDataset
,
false
);
mRecyclerView
.
setAdapter
(
mAdapter
);
...
...
@@ -93,12 +104,6 @@ public class HomeFragment extends Fragment {
}
});
// On récupère l'annonce qui vient d'être créée s'il y en a une
if
(
getArguments
()
!=
null
&&
getArguments
().
getParcelable
(
"nouvelleAnnonce"
)
!=
null
){
Annonce
newAnnonce
=
getArguments
().
getParcelable
(
"nouvelleAnnonce"
);
Log
.
d
(
"HomeFragment"
,
newAnnonce
.
getTitre
());
}
return
rootView
;
}
...
...
@@ -155,10 +160,10 @@ public class HomeFragment extends Fragment {
* from a local content provider or remote server.
*/
private
void
initDataset
()
{
mDataset
=
new
A
nnonce
[
DATASET_COUNT
]
;
mDataset
=
new
A
rrayList
<
Annonce
>()
;
for
(
int
i
=
0
;
i
<
DATASET_COUNT
;
i
++)
{
Annonce
annonce
=
new
Annonce
(
"Titre "
+
i
,
"Adresse "
+
i
,
0
,
12.99
);
mDataset
[
i
]
=
annonce
;
mDataset
.
add
(
annonce
)
;
}
}
}
\ 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