Commit 7a6069e4 authored by Inès EL HADRI's avatar Inès EL HADRI 💤

add layout for grid

parent b3ae2038
......@@ -16,6 +16,7 @@ public class HomeAdapter extends RecyclerView.Adapter<HomeAdapter.ViewHolder> {
private static final String TAG = "CustomAdapter";
private Annonce[] mDataSet;
private boolean mIsGrid;
// BEGIN_INCLUDE(recyclerViewSampleViewHolder)
/**
......@@ -52,8 +53,9 @@ public class HomeAdapter extends RecyclerView.Adapter<HomeAdapter.ViewHolder> {
*
* @param dataSet String[] containing the data to populate views to be used by RecyclerView.
*/
public HomeAdapter(Annonce[] dataSet) {
public HomeAdapter(Annonce[] dataSet, boolean isGrid) {
mDataSet = dataSet;
mIsGrid = isGrid;
}
// BEGIN_INCLUDE(recyclerViewOnCreateViewHolder)
......@@ -61,8 +63,15 @@ public class HomeAdapter extends RecyclerView.Adapter<HomeAdapter.ViewHolder> {
@Override
public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
// Create a new view.
View v = LayoutInflater.from(viewGroup.getContext())
.inflate(R.layout.annonces_liste, viewGroup, false);
View v;
if (mIsGrid) {
v = LayoutInflater.from(viewGroup.getContext())
.inflate(R.layout.annonces_grid, viewGroup, false);
}
else {
v = LayoutInflater.from(viewGroup.getContext())
.inflate(R.layout.annonces_liste, viewGroup, false);
}
return new ViewHolder(v);
}
......
......@@ -69,7 +69,7 @@ public class HomeFragment extends Fragment {
}
setRecyclerViewLayoutManager(mCurrentLayoutManagerType);
mAdapter = new HomeAdapter(mDataset);
mAdapter = new HomeAdapter(mDataset, false);
// Set CustomAdapter as the adapter for RecyclerView.
mRecyclerView.setAdapter(mAdapter);
// END_INCLUDE(initializeRecyclerView)
......@@ -111,10 +111,16 @@ public class HomeFragment extends Fragment {
case GRID_LAYOUT_MANAGER:
mLayoutManager = new GridLayoutManager(getActivity(), SPAN_COUNT);
mCurrentLayoutManagerType = LayoutManagerType.GRID_LAYOUT_MANAGER;
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;
mAdapter = new HomeAdapter(mDataset, false);
// Set CustomAdapter as the adapter for RecyclerView.
mRecyclerView.setAdapter(mAdapter);
break;
default:
mLayoutManager = new LinearLayoutManager(getActivity());
......
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:minHeight="50dp">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp">
<TextView
android:id="@+id/adresse_annonce"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/prix_annonce"
android:text="Adresse, 59000 Douai" />
<ImageView
android:id="@+id/imageView"
android:layout_width="80dp"
android:layout_height="80dp"
android:src="@drawable/ic_launcher_background" />
<TextView
android:id="@+id/titre_annonce"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/imageView"
android:fontFamily="sans-serif-medium"
android:text="Titre annonce de test"
android:textAppearance="@style/TextAppearance.AppCompat.Medium" />
<TextView
android:id="@+id/prix_annonce"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/titre_annonce"
android:layout_weight="1"
android:fontFamily="sans-serif-black"
android:text="12.99€"
android:textAppearance="@style/TextAppearance.AppCompat.Medium" />
</RelativeLayout>
</FrameLayout>
......@@ -5,60 +5,46 @@
android:gravity="center_vertical"
android:minHeight="50dp">
<LinearLayout
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:baselineAligned="false"
android:gravity="center_vertical"
android:orientation="horizontal"
android:padding="8dp">
android:layout_height="match_parent"
android:padding="10dp">
<LinearLayout
<ImageView
android:id="@+id/imageView"
android:layout_width="80dp"
android:layout_height="80dp"
android:src="@drawable/ic_launcher_background" />
<TextView
android:id="@+id/titre_annonce"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:id="@+id/imageView"
android:layout_width="40dp"
android:layout_height="40dp"
android:src="@drawable/ic_launcher_background" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/titre_annonce"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-medium"
android:paddingLeft="8dp"
android:text="Titre annonce de test"
android:textAppearance="@style/TextAppearance.AppCompat.Medium" />
<TextView
android:id="@+id/adresse_annonce"
android:layout_width="148dp"
android:layout_height="wrap_content"
android:paddingLeft="8dp"
android:text="Adresse, 59000 Douai" />
</LinearLayout>
android:fontFamily="sans-serif-medium"
android:text="Titre annonce de test"
android:layout_below="@+id/imageView"
android:textAppearance="@style/TextAppearance.AppCompat.Medium" />
</LinearLayout>
<TextView
android:id="@+id/adresse_annonce"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Adresse, 59000 Douai"
android:layout_toEndOf="@id/titre_annonce"
android:layout_alignTop="@id/titre_annonce"
android:textAlignment="viewEnd"
/>
<TextView
android:id="@+id/prix_annonce"
android:layout_width="wrap_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:fontFamily="sans-serif-black"
android:text="12.99€"
android:textAlignment="viewEnd"
android:layout_toRightOf="@id/imageView"
android:textAppearance="@style/TextAppearance.AppCompat.Medium" />
</LinearLayout>
</RelativeLayout>
</FrameLayout>
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