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