Projet Bee-Honey't (Mobile)  0.2
BTS SNIR LaSalle Avignon 2020
RucheAdapter.java
Aller à la documentation de ce fichier.
1 package com.lasalle.beehoneyt;
2 
9 import android.content.Context;
10 import android.content.Intent;
11 import android.util.Log;
12 import android.view.ContextThemeWrapper;
13 import android.view.LayoutInflater;
14 import android.view.View;
15 import android.view.ViewGroup;
16 import android.widget.Toast;
17 
18 import androidx.annotation.NonNull;
19 import androidx.recyclerview.widget.RecyclerView;
20 
21 import java.io.Serializable;
22 import java.lang.reflect.Array;
23 import java.util.List;
24 
30 public class RucheAdapter extends RecyclerView.Adapter<RuchesViewHolder>
31 {
32  private static final String TAG = "RucheAdapter";
33  private Context mContext;
34  private List<Ruche> ruches = null;
35 
36  public RucheAdapter(Context context, List<Ruche> ruches)
37  {
38  if(ruches != null)
39  {
40  this.ruches = ruches;
41  mContext = context;
42  }
43  }
44 
45  @Override
46  public RuchesViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType)
47  {
48  LayoutInflater inflater = LayoutInflater.from(parent.getContext());
49  View view = inflater.inflate(R.layout.ruche, parent, false);
50  return new RuchesViewHolder(view);
51  }
52 
53  @Override
54  public void onBindViewHolder(@NonNull RuchesViewHolder holder, final int position)
55  {
56  Log.d(TAG, "onBindViewHolder: appel.");
57 
58  final Ruche ruche = ruches.get(position);
59  holder.afficher(ruche);
60 
61  holder.cardview.setOnClickListener(new View.OnClickListener(){
62  @Override
63  public void onClick(View view) {
64  Log.d(TAG, "onClick: click sur : " + ruche);
65  Toast.makeText(mContext, ruche.getNom(), Toast.LENGTH_SHORT).show();
66 
67  ruche.souscrireTopic();
68  Intent intent = new Intent(mContext, RucheActivity.class);
69  intent.putExtra("Ruche", (Serializable) ruche);
70  mContext.startActivity(intent);
71  }
72  });
73  }
74 
75  @Override
76  public int getItemCount()
77  {
78  if(ruches != null)
79  return ruches.size();
80  return 0;
81  }
82 }
Déclaration de la classe RuchesViewHolder.
Déclaration de la classe Ruche.
Definition: Ruche.java:16
String getNom()
Accesseur get du nom de la ruche.
Definition: Ruche.java:94
Déclaration de la classe RucheAdapter.
void souscrireTopic()
Permet de s&#39;abonner au topic TTN du deviceID de la ruche.
Definition: Ruche.java:146
void onBindViewHolder(@NonNull RuchesViewHolder holder, final int position)
RuchesViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType)
Déclaration de la classe RucheActivity.
RucheAdapter(Context context, List< Ruche > ruches)