Commit 354a4136 authored by donia's avatar donia

detailActivity

parent ab902137
......@@ -12,6 +12,9 @@
android:supportsRtl="true"
android:theme="@style/Theme.TPLeBonCoin"
tools:targetApi="31">
<activity
android:name=".ui.DetailScreen"
android:exported="false" />
<activity
android:name=".MainActivity"
android:exported="true"
......
......@@ -7,6 +7,7 @@ import android.content.Intent;
import android.os.Bundle;
import com.example.tpleboncoin.R;
import com.example.tpleboncoin.models.Annonce;
public class DetailScreen extends AppCompatActivity {
ActivityDetailScreenBinding binding;
......@@ -18,12 +19,12 @@ public class DetailScreen extends AppCompatActivity {
setContentView(binding.getRoot());
Intent intent = this.getIntent();
if (intent != null){
Annonce annonce = intent.getParcelableExtra("annonce");
String titre = intent.getStringExtra("titre");
String adresse = intent.getStringExtra("adresse");
String description = intent.getStringExtra("description");
Double prix = intent.getDoubleExtra("prix",999);
binding.adresseTextView.setText(adresse);
binding.prixTextView.setText(prix.toString()+" €");
binding.imageView.setImageResource(R.drawable.ic_account_circle_black_24dp);
......
package com.example.tpleboncoin.ui.home;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import androidx.activity.result.contract.ActivityResultContracts;
import androidx.recyclerview.widget.RecyclerView;
import com.example.tpleboncoin.R;
import com.example.tpleboncoin.models.Annonce;
import com.example.tpleboncoin.ui.DetailScreen;
import java.util.ArrayList;
......@@ -19,6 +25,7 @@ public class HomeAdapter extends RecyclerView.Adapter<HomeAdapter.ViewHolder> {
private ArrayList<Annonce> mDataSet;
private boolean mIsGrid;
private static Context mContext;
/**
* 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> {
@Override
public void onClick(View v) {
// 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.");
}
});
......@@ -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 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;
mIsGrid = isGrid;
mContext = context;
}
// Create new views (invoked by the layout manager)
......
......@@ -86,7 +86,7 @@ public class HomeFragment extends Fragment {
}
// adapter pour gérer le visu de l'annonce
mAdapter = new HomeAdapter(mDataset, false);
mAdapter = new HomeAdapter(mDataset, false, this.getContext());
mRecyclerView.setAdapter(mAdapter);
// bouton pour changer de layout
......@@ -130,7 +130,7 @@ public class HomeFragment extends Fragment {
mCurrentLayoutManagerType = LayoutManagerType.GRID_LAYOUT_MANAGER;
// redéfinition de l'adapter
mAdapter = new HomeAdapter(mDataset, true);
mAdapter = new HomeAdapter(mDataset, true, this.getContext());
mRecyclerView.setAdapter(mAdapter);
break;
case LINEAR_LAYOUT_MANAGER:
......@@ -138,7 +138,7 @@ public class HomeFragment extends Fragment {
mCurrentLayoutManagerType = LayoutManagerType.LINEAR_LAYOUT_MANAGER;
// redéfinition de l'adapter
mAdapter = new HomeAdapter(mDataset, false);
mAdapter = new HomeAdapter(mDataset, false, this.getContext());
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