18 |
efrain |
1 |
package com.cesams.twogetskills.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.cesams.twogetskills.inconcert.Constants;
|
|
|
18 |
import com.cesams.twogetskills.inconcert.R;
|
|
|
19 |
import com.cesams.twogetskills.inconcert.entity.Capsule;
|
|
|
20 |
import com.cesams.twogetskills.inconcert.library.ImageService;
|
|
|
21 |
import com.cesams.twogetskills.inconcert.skeleton.ITwoGetSkills;
|
|
|
22 |
|
|
|
23 |
import org.apache.commons.lang3.StringUtils;
|
|
|
24 |
|
|
|
25 |
import java.util.ArrayList;
|
|
|
26 |
import java.util.HashMap;
|
|
|
27 |
import java.util.List;
|
|
|
28 |
|
|
|
29 |
public class MyCapsulesAdapter extends RecyclerView.Adapter<MyCapsulesAdapter.MyViewHolder> {
|
|
|
30 |
|
|
|
31 |
private List<Capsule> mDataSet;
|
|
|
32 |
|
|
|
33 |
private Context mContext;
|
|
|
34 |
private ITwoGetSkills iTwoGetSkills;
|
|
|
35 |
private ClickListener clickListener;
|
|
|
36 |
|
|
|
37 |
|
|
|
38 |
public MyCapsulesAdapter(Context context, List<Capsule> mDataSet) {
|
|
|
39 |
this.mDataSet = mDataSet;
|
|
|
40 |
this.mContext = context;
|
|
|
41 |
this.iTwoGetSkills = (ITwoGetSkills) context;
|
|
|
42 |
}
|
|
|
43 |
|
|
|
44 |
@NonNull
|
|
|
45 |
@Override
|
|
|
46 |
public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
|
|
47 |
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.fragment_my_capsules_item, parent, false);
|
|
|
48 |
|
|
|
49 |
MyViewHolder viewHolder = new MyViewHolder(v);
|
|
|
50 |
|
|
|
51 |
return viewHolder;
|
|
|
52 |
}
|
|
|
53 |
|
|
|
54 |
@Override
|
|
|
55 |
public void onBindViewHolder(@NonNull MyViewHolder holder, int position) {
|
|
|
56 |
Capsule data = mDataSet.get(position);
|
|
|
57 |
holder.bindData(data);
|
|
|
58 |
}
|
|
|
59 |
|
|
|
60 |
@Override
|
|
|
61 |
public int getItemCount() {
|
|
|
62 |
return (mDataSet != null) ? mDataSet.size() : 0;
|
|
|
63 |
}
|
|
|
64 |
|
|
|
65 |
/* void setOnItemClickListener(ClickListener clickListener) {
|
|
|
66 |
this.clickListener = clickListener;
|
|
|
67 |
}
|
|
|
68 |
*/
|
|
|
69 |
|
|
|
70 |
public class MyViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
|
|
|
71 |
|
|
|
72 |
private TextView textViewTitle;
|
|
|
73 |
private TextView textViewSlides;
|
|
|
74 |
private TextView textViewProgress;
|
|
|
75 |
private CardView cardView;
|
|
|
76 |
private ImageView imageView;
|
|
|
77 |
|
|
|
78 |
|
|
|
79 |
public MyViewHolder(@NonNull View itemView) {
|
|
|
80 |
super(itemView);
|
|
|
81 |
textViewTitle = itemView.findViewById(R.id.fragment_my_capsules_item_textview_title);
|
|
|
82 |
textViewSlides = itemView.findViewById(R.id.fragment_my_capsules_item_textview_slides);
|
|
|
83 |
textViewProgress = itemView.findViewById(R.id.fragment_my_capsules_item_textview_progress);
|
|
|
84 |
imageView = itemView.findViewById(R.id.fragment_my_capsules_item_imageview);
|
|
|
85 |
|
|
|
86 |
|
|
|
87 |
cardView = itemView.findViewById(R.id.fragment_my_capsules_item);
|
|
|
88 |
|
|
|
89 |
if (clickListener != null) {
|
|
|
90 |
cardView.setFocusable(true);
|
|
|
91 |
cardView.setOnClickListener(this);
|
|
|
92 |
|
|
|
93 |
/*
|
|
|
94 |
entrar.setFocusable(true);
|
|
|
95 |
entrar.setOnClickListener(this);
|
|
|
96 |
|
|
|
97 |
*/
|
|
|
98 |
}
|
|
|
99 |
}
|
|
|
100 |
|
|
|
101 |
public void bindData(final Capsule capsule) {
|
|
|
102 |
|
|
|
103 |
String title = StringUtils.trim(capsule.getName());
|
|
|
104 |
if (title.length() > Constants.MY_CAPSULES_ITEM_TITLE_MAX_LENGTH) {
|
|
|
105 |
textViewTitle.setText(StringUtils.substring(title, 0, Constants.MY_CAPSULES_ITEM_TITLE_MAX_LENGTH) + "...");
|
|
|
106 |
} else {
|
|
|
107 |
textViewTitle.setText(title);
|
|
|
108 |
}
|
|
|
109 |
|
|
|
110 |
String textSlides = mContext.getString(R.string.my_capsules_listing_item_slides);
|
|
|
111 |
textSlides = StringUtils.replace(textSlides, "%totalViews%", String.valueOf(capsule.getViewSlides()));
|
|
|
112 |
textSlides = StringUtils.replace(textSlides, "%totalSlides%", String.valueOf(capsule.getTotalSlides()));
|
|
|
113 |
|
|
|
114 |
textViewSlides.setText(textSlides);
|
|
|
115 |
textViewProgress.setText("");
|
|
|
116 |
|
|
|
117 |
if (!StringUtils.isEmpty(capsule.getImage())) {
|
|
|
118 |
ImageService.retrieve(mContext, capsule.getImage(), imageView);
|
|
|
119 |
}
|
|
|
120 |
|
|
|
121 |
}
|
|
|
122 |
|
|
|
123 |
@Override
|
|
|
124 |
public void onClick(View v) {
|
|
|
125 |
if (clickListener != null) {
|
|
|
126 |
clickListener.onItemClick(getAbsoluteAdapterPosition(), v);
|
|
|
127 |
}
|
|
|
128 |
}
|
|
|
129 |
|
|
|
130 |
|
|
|
131 |
}
|
|
|
132 |
|
|
|
133 |
// allows clicks events to be caught
|
|
|
134 |
public void setClickListener(ClickListener itemClickListener) {
|
|
|
135 |
this.clickListener = itemClickListener;
|
|
|
136 |
}
|
|
|
137 |
|
|
|
138 |
public interface ClickListener {
|
|
|
139 |
void onItemClick(int position, View v);
|
|
|
140 |
}}
|