1 |
gabriel |
1 |
package com.cesams.twogetskills.inconcert.adapter;
|
|
|
2 |
|
|
|
3 |
|
|
|
4 |
import android.content.Context;
|
|
|
5 |
import android.text.Html;
|
|
|
6 |
import android.view.LayoutInflater;
|
|
|
7 |
import android.view.View;
|
|
|
8 |
import android.view.ViewGroup;
|
|
|
9 |
import android.widget.Button;
|
|
|
10 |
import android.widget.ImageView;
|
|
|
11 |
import android.widget.TextView;
|
|
|
12 |
|
|
|
13 |
import androidx.annotation.NonNull;
|
|
|
14 |
import androidx.cardview.widget.CardView;
|
|
|
15 |
import androidx.recyclerview.widget.RecyclerView;
|
|
|
16 |
|
|
|
17 |
import com.bumptech.glide.Glide;
|
|
|
18 |
import com.bumptech.glide.load.engine.DiskCacheStrategy;
|
|
|
19 |
import com.bumptech.glide.load.model.GlideUrl;
|
|
|
20 |
import com.bumptech.glide.load.model.LazyHeaders;
|
|
|
21 |
import com.bumptech.glide.request.RequestOptions;
|
|
|
22 |
import com.cesams.twogetskills.inconcert.Constants;
|
|
|
23 |
import com.cesams.twogetskills.inconcert.R;
|
|
|
24 |
import com.cesams.twogetskills.inconcert.library.MD5;
|
|
|
25 |
import com.cesams.twogetskills.inconcert.skeleton.ITwoGetSkills;
|
|
|
26 |
|
|
|
27 |
import java.util.ArrayList;
|
|
|
28 |
import java.util.Calendar;
|
|
|
29 |
import java.util.HashMap;
|
|
|
30 |
import java.util.Random;
|
|
|
31 |
import java.util.TimeZone;
|
|
|
32 |
|
|
|
33 |
public class TabsCapsulesAdapter extends RecyclerView.Adapter<TabsCapsulesAdapter.MyViewHolder> {
|
|
|
34 |
|
|
|
35 |
private ArrayList<HashMap<String, String>> mDataSet;
|
|
|
36 |
|
|
|
37 |
private Context mContext;
|
|
|
38 |
private ITwoGetSkills iTwoGetSkills;
|
|
|
39 |
private ClickListener clickListener;
|
|
|
40 |
|
|
|
41 |
|
|
|
42 |
public TabsCapsulesAdapter(Context context, ArrayList<HashMap<String, String>> mDataSet) {
|
|
|
43 |
this.mDataSet = mDataSet;
|
|
|
44 |
this.mContext = context;
|
|
|
45 |
this.iTwoGetSkills = (ITwoGetSkills) context;
|
|
|
46 |
}
|
|
|
47 |
|
|
|
48 |
@NonNull
|
|
|
49 |
@Override
|
|
|
50 |
public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
|
|
51 |
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.capsuleitemcategory, parent, false);
|
|
|
52 |
|
|
|
53 |
MyViewHolder viewHolder = new MyViewHolder(v);
|
|
|
54 |
|
|
|
55 |
return viewHolder;
|
|
|
56 |
}
|
|
|
57 |
|
|
|
58 |
@Override
|
|
|
59 |
public void onBindViewHolder(@NonNull MyViewHolder holder, int position) {
|
|
|
60 |
HashMap<String, String> data = mDataSet.get(position);
|
|
|
61 |
holder.bindData(data);
|
|
|
62 |
}
|
|
|
63 |
|
|
|
64 |
@Override
|
|
|
65 |
public int getItemCount() {
|
|
|
66 |
return (mDataSet != null) ? mDataSet.size() : 0;
|
|
|
67 |
}
|
|
|
68 |
|
|
|
69 |
/* void setOnItemClickListener(ClickListener clickListener) {
|
|
|
70 |
this.clickListener = clickListener;
|
|
|
71 |
}
|
|
|
72 |
*/
|
|
|
73 |
|
|
|
74 |
public class MyViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
|
|
|
75 |
|
|
|
76 |
private TextView fecha,pendientes,titulo;
|
|
|
77 |
private CardView card;
|
|
|
78 |
private Button entrar;
|
|
|
79 |
private ImageView imagen;
|
|
|
80 |
|
|
|
81 |
|
|
|
82 |
public MyViewHolder(@NonNull View itemView) {
|
|
|
83 |
super(itemView);
|
|
|
84 |
titulo = itemView.findViewById(R.id.description);
|
|
|
85 |
fecha = itemView.findViewById(R.id.progressview);
|
|
|
86 |
imagen = itemView.findViewById(R.id.imagelist);
|
|
|
87 |
entrar = itemView.findViewById(R.id.button);
|
|
|
88 |
pendientes = itemView.findViewById(R.id.pendientes);
|
|
|
89 |
card = itemView.findViewById(R.id.card_notifi);
|
|
|
90 |
|
|
|
91 |
if (clickListener != null) {
|
|
|
92 |
card.setFocusable(true);
|
|
|
93 |
card.setOnClickListener(this);
|
|
|
94 |
entrar.setFocusable(true);
|
|
|
95 |
entrar.setOnClickListener(this);
|
|
|
96 |
}
|
|
|
97 |
}
|
|
|
98 |
|
|
|
99 |
public void bindData(final HashMap<String, String> data) {
|
|
|
100 |
|
|
|
101 |
data.entrySet();
|
|
|
102 |
|
|
|
103 |
String view, total, nombre, slides;
|
|
|
104 |
|
|
|
105 |
view= data.get("description");
|
|
|
106 |
total=data.get("total");
|
|
|
107 |
nombre = data.get("nombre");
|
|
|
108 |
slides= data.get("view");
|
|
|
109 |
|
|
|
110 |
if(nombre != null)
|
|
|
111 |
{
|
|
|
112 |
titulo.setText(nombre);
|
|
|
113 |
|
|
|
114 |
}
|
|
|
115 |
|
|
|
116 |
if(view != null )
|
|
|
117 |
{
|
|
|
118 |
fecha.setText((Html.fromHtml(view)));
|
|
|
119 |
}
|
|
|
120 |
|
|
|
121 |
if(total != null || slides != null)
|
|
|
122 |
{
|
|
|
123 |
pendientes.setText(slides+" / "+total+" items");
|
|
|
124 |
}
|
|
|
125 |
else
|
|
|
126 |
{
|
|
|
127 |
pendientes.setText("");
|
|
|
128 |
}
|
|
|
129 |
|
|
|
130 |
String imagens;
|
|
|
131 |
imagens=data.get("imagen");
|
|
|
132 |
|
|
|
133 |
|
|
|
134 |
//Verificamos que las imagenes no esten vacias
|
|
|
135 |
if (imagens != null && !imagens.equals("")) {
|
|
|
136 |
|
|
|
137 |
TimeZone timeZone = TimeZone.getTimeZone("UTC");
|
|
|
138 |
Calendar calendar = Calendar.getInstance(timeZone);
|
|
|
139 |
TimeZone tz = calendar.getTimeZone();
|
|
|
140 |
int created = (int) (calendar.getTimeInMillis() / 1000);
|
|
|
141 |
|
|
|
142 |
Random random = new Random(created);
|
|
|
143 |
int rand = 1000 + random.nextInt(8999);
|
|
|
144 |
|
|
|
145 |
|
|
|
146 |
String deviceUuid = iTwoGetSkills.getPreference().getDeviceUuid();
|
|
|
147 |
String password = iTwoGetSkills.getPreference().getPassword();
|
|
|
148 |
|
|
|
149 |
|
|
|
150 |
|
|
|
151 |
String secret = MD5.generar(password + ':' + created + ':' + rand);
|
|
|
152 |
GlideUrl url = new GlideUrl(imagens, new LazyHeaders.Builder()
|
|
|
153 |
.addHeader(Constants.HTTP_HEADER_ACCEPT, Constants.HTTP_HEADER_ACCEPT_VALUE)
|
|
|
154 |
.addHeader(Constants.HTTP_HEADER_SECURITY_TOKEN, deviceUuid)
|
|
|
155 |
.addHeader(Constants.HTTP_HEADER_SECURITY_SECRET, secret)
|
|
|
156 |
.addHeader(Constants.HTTP_HEADER_SECURITY_CREATED, String.valueOf(created))
|
|
|
157 |
.addHeader(Constants.HTTP_HEADER_SECURITY_RAND, String.valueOf(rand))
|
|
|
158 |
.build());
|
|
|
159 |
|
|
|
160 |
RequestOptions options = new RequestOptions()
|
|
|
161 |
.diskCacheStrategy(DiskCacheStrategy.ALL);
|
|
|
162 |
|
|
|
163 |
Glide.with(mContext).load(url)
|
|
|
164 |
.thumbnail()
|
|
|
165 |
.apply(options)
|
|
|
166 |
.into(imagen);
|
|
|
167 |
}
|
|
|
168 |
|
|
|
169 |
}
|
|
|
170 |
|
|
|
171 |
@Override
|
|
|
172 |
public void onClick(View v) {
|
|
|
173 |
if (clickListener != null) {
|
|
|
174 |
clickListener.onItemClick(getAbsoluteAdapterPosition(), v);
|
|
|
175 |
}
|
|
|
176 |
}
|
|
|
177 |
|
|
|
178 |
|
|
|
179 |
}
|
|
|
180 |
|
|
|
181 |
// allows clicks events to be caught
|
|
|
182 |
public void setClickListener(ClickListener itemClickListener) {
|
|
|
183 |
this.clickListener = itemClickListener;
|
|
|
184 |
}
|
|
|
185 |
|
|
|
186 |
public interface ClickListener {
|
|
|
187 |
void onItemClick(int position, View v);
|
|
|
188 |
}}
|