1 |
gabriel |
1 |
package com.cesams.twogetskills.inconcert.adapter;
|
|
|
2 |
|
|
|
3 |
|
|
|
4 |
import android.content.Context;
|
|
|
5 |
import android.graphics.Color;
|
|
|
6 |
import android.view.LayoutInflater;
|
|
|
7 |
import android.view.View;
|
|
|
8 |
import android.view.ViewGroup;
|
|
|
9 |
import android.widget.Button;
|
|
|
10 |
import android.widget.TextView;
|
|
|
11 |
import androidx.annotation.NonNull;
|
|
|
12 |
import androidx.cardview.widget.CardView;
|
|
|
13 |
import androidx.recyclerview.widget.RecyclerView;
|
|
|
14 |
import com.cesams.twogetskills.inconcert.R;
|
|
|
15 |
import com.cesams.twogetskills.inconcert.skeleton.ITwoGetSkills;
|
|
|
16 |
import java.util.ArrayList;
|
|
|
17 |
import java.util.HashMap;
|
|
|
18 |
|
|
|
19 |
public class CardViewAdapter extends RecyclerView.Adapter<CardViewAdapter.MyViewHolder> {
|
|
|
20 |
|
|
|
21 |
private ArrayList<HashMap<String, String>> mDataSet;
|
|
|
22 |
|
|
|
23 |
private ClickListener clickListener;
|
|
|
24 |
private View.OnFocusChangeListener focusChangeListener;
|
|
|
25 |
private Context mContext;
|
|
|
26 |
private ITwoGetSkills iTwoGetSkills;
|
|
|
27 |
|
|
|
28 |
public CardViewAdapter(Context context, ArrayList<HashMap<String, String>> mDataSet) {
|
|
|
29 |
this.mDataSet = mDataSet;
|
|
|
30 |
this.mContext = context;
|
|
|
31 |
this.iTwoGetSkills = (ITwoGetSkills) context;
|
|
|
32 |
}
|
|
|
33 |
|
|
|
34 |
@NonNull
|
|
|
35 |
@Override
|
|
|
36 |
public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
|
|
37 |
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.notification_item, parent, false);
|
|
|
38 |
return new MyViewHolder(v);
|
|
|
39 |
}
|
|
|
40 |
|
|
|
41 |
@Override
|
|
|
42 |
public void onBindViewHolder(@NonNull MyViewHolder holder, int position) {
|
|
|
43 |
HashMap<String, String> data = mDataSet.get(position);
|
|
|
44 |
holder.bindData(data);
|
|
|
45 |
}
|
|
|
46 |
|
|
|
47 |
@Override
|
|
|
48 |
public int getItemCount() {
|
|
|
49 |
return (mDataSet != null) ? mDataSet.size() : 0;
|
|
|
50 |
}
|
|
|
51 |
|
|
|
52 |
public String getItem(int position) {
|
|
|
53 |
return (mDataSet != null) ? String.valueOf(mDataSet.get(position)) : null;
|
|
|
54 |
}
|
|
|
55 |
|
|
|
56 |
void setOnFocusChangeListener(View.OnFocusChangeListener focusChangeListener){
|
|
|
57 |
this.focusChangeListener = focusChangeListener;
|
|
|
58 |
}
|
|
|
59 |
|
|
|
60 |
|
|
|
61 |
|
|
|
62 |
public class MyViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
|
|
|
63 |
|
|
|
64 |
private TextView titulo;
|
|
|
65 |
private TextView descripcion;
|
|
|
66 |
private Button cerrar;
|
|
|
67 |
private CardView card;
|
|
|
68 |
|
|
|
69 |
|
|
|
70 |
public MyViewHolder(@NonNull View itemView) {
|
|
|
71 |
super(itemView);
|
|
|
72 |
titulo = itemView.findViewById(R.id.titlenotifi);
|
|
|
73 |
descripcion = itemView.findViewById(R.id.description);
|
|
|
74 |
cerrar = itemView.findViewById(R.id.button);
|
|
|
75 |
card = itemView.findViewById(R.id.card_notifi);
|
|
|
76 |
|
|
|
77 |
if (clickListener != null) {
|
|
|
78 |
card.setFocusable(true);
|
|
|
79 |
card.setOnClickListener(this);
|
|
|
80 |
|
|
|
81 |
|
|
|
82 |
}
|
|
|
83 |
}
|
|
|
84 |
|
|
|
85 |
public void bindData(final HashMap<String, String> data) {
|
|
|
86 |
|
|
|
87 |
data.entrySet();
|
|
|
88 |
|
|
|
89 |
String title, descripciones,color;
|
|
|
90 |
|
|
|
91 |
title= data.get("titulo");
|
|
|
92 |
descripciones=data.get("descripcion");
|
|
|
93 |
color=data.get("color");
|
|
|
94 |
|
|
|
95 |
|
|
|
96 |
|
|
|
97 |
if (!color.equals(""))
|
|
|
98 |
{
|
|
|
99 |
card.setCardBackgroundColor(Color.WHITE);
|
|
|
100 |
}
|
|
|
101 |
|
|
|
102 |
|
|
|
103 |
if(titulo != null)
|
|
|
104 |
{
|
|
|
105 |
titulo.setText(title);
|
|
|
106 |
|
|
|
107 |
}
|
|
|
108 |
|
|
|
109 |
if(descripciones != null)
|
|
|
110 |
{
|
|
|
111 |
descripcion.setText(descripciones);
|
|
|
112 |
}
|
|
|
113 |
|
|
|
114 |
}
|
|
|
115 |
|
|
|
116 |
@Override
|
|
|
117 |
public void onClick(View v) {
|
|
|
118 |
if (clickListener != null) {
|
|
|
119 |
clickListener.onItemClick(getBindingAdapterPosition(), v);
|
|
|
120 |
}
|
|
|
121 |
}
|
|
|
122 |
|
|
|
123 |
|
|
|
124 |
|
|
|
125 |
}
|
|
|
126 |
|
|
|
127 |
// allows clicks events to be caught
|
|
|
128 |
public void setClickListener(ClickListener itemClickListener) {
|
|
|
129 |
this.clickListener = itemClickListener;
|
|
|
130 |
}
|
|
|
131 |
|
|
|
132 |
public interface ClickListener {
|
|
|
133 |
void onItemClick(int position, View v);
|
|
|
134 |
}
|
|
|
135 |
|
|
|
136 |
}
|