1 |
gabriel |
1 |
package com.cesams.twogetskills.inconcert.adapter;
|
|
|
2 |
|
|
|
3 |
import android.content.Context;
|
|
|
4 |
import android.text.TextUtils;
|
|
|
5 |
import android.util.Log;
|
|
|
6 |
import android.view.LayoutInflater;
|
|
|
7 |
import android.view.View;
|
|
|
8 |
import android.view.ViewGroup;
|
|
|
9 |
import android.widget.ImageView;
|
|
|
10 |
import android.widget.TextView;
|
|
|
11 |
|
|
|
12 |
import androidx.recyclerview.widget.RecyclerView;
|
|
|
13 |
|
18 |
efrain |
14 |
|
1 |
gabriel |
15 |
import com.cesams.twogetskills.inconcert.Constants;
|
|
|
16 |
import com.cesams.twogetskills.inconcert.R;
|
|
|
17 |
import com.cesams.twogetskills.inconcert.entity.Slide;
|
18 |
efrain |
18 |
import com.cesams.twogetskills.inconcert.library.ImageService;
|
1 |
gabriel |
19 |
import com.cesams.twogetskills.inconcert.library.MD5;
|
|
|
20 |
import com.cesams.twogetskills.inconcert.skeleton.ITwoGetSkills;
|
|
|
21 |
|
|
|
22 |
|
|
|
23 |
import java.util.Calendar;
|
|
|
24 |
import java.util.List;
|
|
|
25 |
import java.util.Random;
|
|
|
26 |
import java.util.TimeZone;
|
|
|
27 |
|
|
|
28 |
public class SlideListViewAdapter extends RecyclerView.Adapter<SlideListViewAdapter.ViewHolder> {
|
|
|
29 |
private final static String TAG = "C2GS - SlideViewAdapter";
|
|
|
30 |
private List<Slide> mData;
|
|
|
31 |
private LayoutInflater mInflater;
|
|
|
32 |
private ItemClickListener mClickListener;
|
|
|
33 |
private Context mContext;
|
|
|
34 |
private ITwoGetSkills iTwoGetSkills;
|
|
|
35 |
|
|
|
36 |
|
|
|
37 |
// data is passed into the constructor
|
|
|
38 |
public SlideListViewAdapter(Context context, List<Slide> data) {
|
|
|
39 |
this.mContext = context;
|
|
|
40 |
this.iTwoGetSkills = (ITwoGetSkills) context;
|
|
|
41 |
this.mInflater = LayoutInflater.from(context);
|
|
|
42 |
this.mData = data;
|
|
|
43 |
}
|
|
|
44 |
|
|
|
45 |
// inflates the row layout from xml when needed
|
|
|
46 |
@Override
|
|
|
47 |
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
|
|
48 |
View view = mInflater.inflate(R.layout.fragment_slide_listitem, parent, false);
|
|
|
49 |
return new ViewHolder(view);
|
|
|
50 |
}
|
|
|
51 |
|
|
|
52 |
// binds the data to the TextView in each row
|
|
|
53 |
@Override
|
|
|
54 |
public void onBindViewHolder(ViewHolder holder, int position) {
|
|
|
55 |
Slide mItem = mData.get(position);
|
|
|
56 |
holder.mName.setText(mItem.getName());
|
|
|
57 |
|
|
|
58 |
if(mItem.getCompleted() == 1) {
|
|
|
59 |
holder.mCheckReady.setVisibility(View.VISIBLE);
|
|
|
60 |
|
|
|
61 |
} else {
|
|
|
62 |
holder.mCheckReady.setVisibility(View.INVISIBLE);
|
|
|
63 |
}
|
|
|
64 |
|
18 |
efrain |
65 |
|
1 |
gabriel |
66 |
|
|
|
67 |
String image = TextUtils.isEmpty(mItem.getBackground()) ? mItem.getFile() : mItem.getBackground();
|
18 |
efrain |
68 |
ImageService.retrieve(mContext,image, holder.mImage);
|
1 |
gabriel |
69 |
|
|
|
70 |
}
|
|
|
71 |
|
|
|
72 |
// total number of rows
|
|
|
73 |
@Override
|
|
|
74 |
public int getItemCount() {
|
|
|
75 |
return mData.size();
|
|
|
76 |
}
|
|
|
77 |
|
|
|
78 |
|
|
|
79 |
// stores and recycles views as they are scrolled off screen
|
|
|
80 |
public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
|
|
|
81 |
TextView mName;
|
|
|
82 |
//TextView mDescription;
|
|
|
83 |
//JustifyTextView mDescription;
|
|
|
84 |
ImageView mImage;
|
|
|
85 |
ImageView mCheckReady;
|
|
|
86 |
// ProgressBar mProgressbar;
|
|
|
87 |
//TextView mProgreess;
|
|
|
88 |
|
|
|
89 |
|
|
|
90 |
ViewHolder(View itemView) {
|
|
|
91 |
super(itemView);
|
|
|
92 |
mName = (TextView) itemView.findViewById(R.id.fragment_slide_listitem_name);
|
|
|
93 |
//mDescription = (TextView) itemView.findViewById(R.id.fragment_home_list_item_topic_description);
|
|
|
94 |
mImage = (ImageView) itemView.findViewById(R.id.fragment_slide_listitem_image);
|
|
|
95 |
mCheckReady = (ImageView) itemView.findViewById(R.id.fragment_slide_listitem_check_ready);
|
|
|
96 |
// mProgreess = (TextView) itemView.findViewById(R.id.fragment_slide_listitem_progress);
|
|
|
97 |
// mProgressbar = (ProgressBar) itemView.findViewById(R.id.fragment_slide_listitem_progressbar);
|
|
|
98 |
itemView.setOnClickListener(this);
|
|
|
99 |
}
|
|
|
100 |
|
|
|
101 |
@Override
|
|
|
102 |
public void onClick(View view) {
|
|
|
103 |
if (mClickListener != null) {
|
|
|
104 |
mClickListener.onItemClick(view, getAdapterPosition());
|
|
|
105 |
}
|
|
|
106 |
}
|
|
|
107 |
}
|
|
|
108 |
|
|
|
109 |
// convenience method for getting data at click position
|
|
|
110 |
public Slide getItem(int id) {
|
|
|
111 |
return mData.get(id);
|
|
|
112 |
}
|
|
|
113 |
|
|
|
114 |
// allows clicks events to be caught
|
|
|
115 |
public void setClickListener(ItemClickListener itemClickListener) {
|
|
|
116 |
this.mClickListener = itemClickListener;
|
|
|
117 |
}
|
|
|
118 |
|
|
|
119 |
// parent activity will implement this method to respond to click events
|
|
|
120 |
public interface ItemClickListener {
|
|
|
121 |
public void onItemClick(View view, int position);
|
|
|
122 |
}
|
18 |
efrain |
123 |
}
|