Commit f1704608 authored by Inès EL HADRI's avatar Inès EL HADRI 💤

clean code

parent 7a6069e4
......@@ -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;
......
......@@ -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:
......
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