Commit 354a4136 authored by donia's avatar donia

detailActivity

parent ab902137
...@@ -12,6 +12,9 @@ ...@@ -12,6 +12,9 @@
android:supportsRtl="true" android:supportsRtl="true"
android:theme="@style/Theme.TPLeBonCoin" android:theme="@style/Theme.TPLeBonCoin"
tools:targetApi="31"> tools:targetApi="31">
<activity
android:name=".ui.DetailScreen"
android:exported="false" />
<activity <activity
android:name=".MainActivity" android:name=".MainActivity"
android:exported="true" android:exported="true"
......
...@@ -7,6 +7,7 @@ import android.content.Intent; ...@@ -7,6 +7,7 @@ import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import com.example.tpleboncoin.R; import com.example.tpleboncoin.R;
import com.example.tpleboncoin.models.Annonce;
public class DetailScreen extends AppCompatActivity { public class DetailScreen extends AppCompatActivity {
ActivityDetailScreenBinding binding; ActivityDetailScreenBinding binding;
...@@ -18,12 +19,12 @@ public class DetailScreen extends AppCompatActivity { ...@@ -18,12 +19,12 @@ public class DetailScreen extends AppCompatActivity {
setContentView(binding.getRoot()); setContentView(binding.getRoot());
Intent intent = this.getIntent(); Intent intent = this.getIntent();
if (intent != null){ if (intent != null){
Annonce annonce = intent.getParcelableExtra("annonce");
String titre = intent.getStringExtra("titre"); String titre = intent.getStringExtra("titre");
String adresse = intent.getStringExtra("adresse"); String adresse = intent.getStringExtra("adresse");
String description = intent.getStringExtra("description"); String description = intent.getStringExtra("description");
Double prix = intent.getDoubleExtra("prix",999); Double prix = intent.getDoubleExtra("prix",999);
binding.adresseTextView.setText(adresse); binding.adresseTextView.setText(adresse);
binding.prixTextView.setText(prix.toString()+" €"); binding.prixTextView.setText(prix.toString()+" €");
binding.imageView.setImageResource(R.drawable.ic_account_circle_black_24dp); binding.imageView.setImageResource(R.drawable.ic_account_circle_black_24dp);
......
package com.example.tpleboncoin.ui.home; package com.example.tpleboncoin.ui.home;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.util.Log; import android.util.Log;
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.TextView; import android.widget.TextView;
import androidx.activity.result.contract.ActivityResultContracts;
import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView;
import com.example.tpleboncoin.R; import com.example.tpleboncoin.R;
import com.example.tpleboncoin.models.Annonce; import com.example.tpleboncoin.models.Annonce;
import com.example.tpleboncoin.ui.DetailScreen;
import java.util.ArrayList; import java.util.ArrayList;
public class HomeAdapter extends RecyclerView.Adapter<HomeAdapter.ViewHolder> { public class HomeAdapter extends RecyclerView.Adapter<HomeAdapter.ViewHolder> {
private static final String TAG = "CustomAdapter"; private static final String TAG = "CustomAdapter";
private ArrayList<Annonce> mDataSet; private ArrayList<Annonce> mDataSet;
private boolean mIsGrid; private boolean mIsGrid;
private static Context mContext;
/** /**
* Provide a reference to the type of views that you are using (custom ViewHolder) * Provide a reference to the type of views that you are using (custom ViewHolder)
...@@ -34,6 +41,11 @@ public class HomeAdapter extends RecyclerView.Adapter<HomeAdapter.ViewHolder> { ...@@ -34,6 +41,11 @@ public class HomeAdapter extends RecyclerView.Adapter<HomeAdapter.ViewHolder> {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
// TODO : mettre la page de Donia // TODO : mettre la page de Donia
Intent detailIntent = new Intent(mContext, DetailScreen.class);
detailIntent.putExtra("titre", titreTextView.getText());
detailIntent.putExtra("adresse", adresseTextView.getText());
v.getContext().startActivity(detailIntent);
//detailIntent.putExtra("prix", prix);
Log.d(TAG, "Element " + getAdapterPosition() + " clicked."); Log.d(TAG, "Element " + getAdapterPosition() + " clicked.");
} }
}); });
...@@ -55,9 +67,10 @@ public class HomeAdapter extends RecyclerView.Adapter<HomeAdapter.ViewHolder> { ...@@ -55,9 +67,10 @@ public class HomeAdapter extends RecyclerView.Adapter<HomeAdapter.ViewHolder> {
* @param dataSet String[] containing the data to populate views to be used by RecyclerView. * @param dataSet String[] containing the data to populate views to be used by RecyclerView.
* @param isGrid boolean = le layout actuel (grille ou linéaire) * @param isGrid boolean = le layout actuel (grille ou linéaire)
*/ */
public HomeAdapter(ArrayList<Annonce> dataSet, boolean isGrid) { public HomeAdapter(ArrayList<Annonce> dataSet, boolean isGrid, Context context) {
mDataSet = dataSet; mDataSet = dataSet;
mIsGrid = isGrid; mIsGrid = isGrid;
mContext = context;
} }
// Create new views (invoked by the layout manager) // Create new views (invoked by the layout manager)
......
...@@ -86,7 +86,7 @@ public class HomeFragment extends Fragment { ...@@ -86,7 +86,7 @@ public class HomeFragment extends Fragment {
} }
// adapter pour gérer le visu de l'annonce // adapter pour gérer le visu de l'annonce
mAdapter = new HomeAdapter(mDataset, false); mAdapter = new HomeAdapter(mDataset, false, this.getContext());
mRecyclerView.setAdapter(mAdapter); mRecyclerView.setAdapter(mAdapter);
// bouton pour changer de layout // bouton pour changer de layout
...@@ -130,7 +130,7 @@ public class HomeFragment extends Fragment { ...@@ -130,7 +130,7 @@ public class HomeFragment extends Fragment {
mCurrentLayoutManagerType = LayoutManagerType.GRID_LAYOUT_MANAGER; mCurrentLayoutManagerType = LayoutManagerType.GRID_LAYOUT_MANAGER;
// redéfinition de l'adapter // redéfinition de l'adapter
mAdapter = new HomeAdapter(mDataset, true); mAdapter = new HomeAdapter(mDataset, true, this.getContext());
mRecyclerView.setAdapter(mAdapter); mRecyclerView.setAdapter(mAdapter);
break; break;
case LINEAR_LAYOUT_MANAGER: case LINEAR_LAYOUT_MANAGER:
...@@ -138,7 +138,7 @@ public class HomeFragment extends Fragment { ...@@ -138,7 +138,7 @@ public class HomeFragment extends Fragment {
mCurrentLayoutManagerType = LayoutManagerType.LINEAR_LAYOUT_MANAGER; mCurrentLayoutManagerType = LayoutManagerType.LINEAR_LAYOUT_MANAGER;
// redéfinition de l'adapter // redéfinition de l'adapter
mAdapter = new HomeAdapter(mDataset, false); mAdapter = new HomeAdapter(mDataset, false, this.getContext());
mRecyclerView.setAdapter(mAdapter); mRecyclerView.setAdapter(mAdapter);
break; break;
default: 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