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
f1704608
Commit
f1704608
authored
Feb 17, 2024
by
Inès EL HADRI
💤
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
clean code
parent
7a6069e4
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
17 deletions
+15
-17
HomeAdapter.java
...ain/java/com/example/tpleboncoin/ui/home/HomeAdapter.java
+5
-9
HomeFragment.java
...in/java/com/example/tpleboncoin/ui/home/HomeFragment.java
+10
-8
No files found.
app/src/main/java/com/example/tpleboncoin/ui/home/HomeAdapter.java
View file @
f1704608
...
...
@@ -18,7 +18,6 @@ public class HomeAdapter extends RecyclerView.Adapter<HomeAdapter.ViewHolder> {
private
Annonce
[]
mDataSet
;
private
boolean
mIsGrid
;
// BEGIN_INCLUDE(recyclerViewSampleViewHolder)
/**
* Provide a reference to the type of views that you are using (custom ViewHolder)
*/
...
...
@@ -32,6 +31,7 @@ public class HomeAdapter extends RecyclerView.Adapter<HomeAdapter.ViewHolder> {
v
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
@Override
public
void
onClick
(
View
v
)
{
// TODO : mettre la page de Donia
Log
.
d
(
TAG
,
"Element "
+
getAdapterPosition
()
+
" clicked."
);
}
});
...
...
@@ -46,23 +46,22 @@ public class HomeAdapter extends RecyclerView.Adapter<HomeAdapter.ViewHolder> {
return
adresseTextView
;
}
}
// END_INCLUDE(recyclerViewSampleViewHolder)
/**
* Initialize the dataset of the Adapter.
*
* @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
(
Annonce
[]
dataSet
,
boolean
isGrid
)
{
mDataSet
=
dataSet
;
mIsGrid
=
isGrid
;
}
// BEGIN_INCLUDE(recyclerViewOnCreateViewHolder)
// Create new views (invoked by the layout manager)
@Override
public
ViewHolder
onCreateViewHolder
(
ViewGroup
viewGroup
,
int
viewType
)
{
// Create a new view.
// Create a new view.
- Layout en fonction de la sélection
View
v
;
if
(
mIsGrid
)
{
v
=
LayoutInflater
.
from
(
viewGroup
.
getContext
())
...
...
@@ -75,22 +74,19 @@ public class HomeAdapter extends RecyclerView.Adapter<HomeAdapter.ViewHolder> {
return
new
ViewHolder
(
v
);
}
// END_INCLUDE(recyclerViewOnCreateViewHolder)
// BEGIN_INCLUDE(recyclerViewOnBindViewHolder)
// Replace the contents of a view (invoked by the layout manager)
@Override
public
void
onBindViewHolder
(
ViewHolder
viewHolder
,
final
int
position
)
{
Log
.
d
(
TAG
,
"Element "
+
position
+
" set."
);
// Get element from
your
dataset at this position and replace the contents of the view
// 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
());
}
// END_INCLUDE(recyclerViewOnBindViewHolder)
// Return the size of
your
dataset (invoked by the layout manager)
// Return the size of dataset (invoked by the layout manager)
@Override
public
int
getItemCount
()
{
return
mDataSet
.
length
;
...
...
app/src/main/java/com/example/tpleboncoin/ui/home/HomeFragment.java
View file @
f1704608
...
...
@@ -49,15 +49,14 @@ public class HomeFragment extends Fragment {
@Override
public
View
onCreateView
(
LayoutInflater
inflater
,
ViewGroup
container
,
Bundle
savedInstanceState
)
{
// vue de base :
View
rootView
=
inflater
.
inflate
(
R
.
layout
.
fragment_home
,
container
,
false
);
rootView
.
setTag
(
TAG
);
//
BEGIN_INCLUDE(initializeRecyclerView
)
//
Vue qui gère les éléments (annonces
)
mRecyclerView
=
(
RecyclerView
)
rootView
.
findViewById
(
R
.
id
.
recycler_view
);
// LinearLayoutManager is used here, this will layout the elements in a similar fashion
// to the way ListView would layout elements. The RecyclerView.LayoutManager defines how
// elements are laid out.
// pour gérer le layout (grille ou liste linéaire)
mLayoutManager
=
new
LinearLayoutManager
(
getActivity
());
mCurrentLayoutManagerType
=
LayoutManagerType
.
LINEAR_LAYOUT_MANAGER
;
...
...
@@ -69,11 +68,11 @@ public class HomeFragment extends Fragment {
}
setRecyclerViewLayoutManager
(
mCurrentLayoutManagerType
);
// adapter pour gérer le visu de l'annonce
mAdapter
=
new
HomeAdapter
(
mDataset
,
false
);
// Set CustomAdapter as the adapter for RecyclerView.
mRecyclerView
.
setAdapter
(
mAdapter
);
// END_INCLUDE(initializeRecyclerView)
// bouton pour changer de layout
mLinearLayoutRadioButton
=
(
RadioButton
)
rootView
.
findViewById
(
R
.
id
.
linear_layout_rb
);
mLinearLayoutRadioButton
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
@Override
...
...
@@ -107,19 +106,22 @@ public class HomeFragment extends Fragment {
.
findFirstCompletelyVisibleItemPosition
();
}
// on change de layout
switch
(
layoutManagerType
)
{
case
GRID_LAYOUT_MANAGER:
mLayoutManager
=
new
GridLayoutManager
(
getActivity
(),
SPAN_COUNT
);
mCurrentLayoutManagerType
=
LayoutManagerType
.
GRID_LAYOUT_MANAGER
;
// redéfinition de l'adapter
mAdapter
=
new
HomeAdapter
(
mDataset
,
true
);
// Set CustomAdapter as the adapter for RecyclerView.
mRecyclerView
.
setAdapter
(
mAdapter
);
break
;
case
LINEAR_LAYOUT_MANAGER:
mLayoutManager
=
new
LinearLayoutManager
(
getActivity
());
mCurrentLayoutManagerType
=
LayoutManagerType
.
LINEAR_LAYOUT_MANAGER
;
// redéfinition de l'adapter
mAdapter
=
new
HomeAdapter
(
mDataset
,
false
);
// Set CustomAdapter as the adapter for RecyclerView.
mRecyclerView
.
setAdapter
(
mAdapter
);
break
;
default
:
...
...
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