1 |
gabriel |
1 |
package com.cesams.twogetskills.inconcert.adapter;
|
|
|
2 |
|
|
|
3 |
import android.annotation.SuppressLint;
|
|
|
4 |
import android.content.Context;
|
|
|
5 |
import android.text.TextUtils;
|
|
|
6 |
import android.util.Log;
|
|
|
7 |
import android.view.LayoutInflater;
|
|
|
8 |
import android.view.View;
|
|
|
9 |
import android.view.ViewGroup;
|
|
|
10 |
import android.widget.Button;
|
|
|
11 |
import android.widget.ImageView;
|
|
|
12 |
|
|
|
13 |
import androidx.fragment.app.FragmentActivity;
|
|
|
14 |
import androidx.recyclerview.widget.RecyclerView;
|
|
|
15 |
|
18 |
efrain |
16 |
|
1 |
gabriel |
17 |
import com.cesams.twogetskills.inconcert.Constants;
|
|
|
18 |
import com.cesams.twogetskills.inconcert.R;
|
|
|
19 |
import com.cesams.twogetskills.inconcert.dao.ProgressDao;
|
|
|
20 |
import com.cesams.twogetskills.inconcert.dao.SyncDao;
|
|
|
21 |
import com.cesams.twogetskills.inconcert.dao.UserLogDao;
|
|
|
22 |
import com.cesams.twogetskills.inconcert.entity.Progress;
|
|
|
23 |
import com.cesams.twogetskills.inconcert.entity.Slide;
|
|
|
24 |
import com.cesams.twogetskills.inconcert.entity.Sync;
|
|
|
25 |
import com.cesams.twogetskills.inconcert.entity.UserLog;
|
18 |
efrain |
26 |
import com.cesams.twogetskills.inconcert.library.ImageService;
|
1 |
gabriel |
27 |
import com.cesams.twogetskills.inconcert.library.MD5;
|
|
|
28 |
import com.cesams.twogetskills.inconcert.skeleton.ITwoGetSkills;
|
|
|
29 |
|
|
|
30 |
import org.json.JSONException;
|
|
|
31 |
import org.json.JSONObject;
|
|
|
32 |
|
|
|
33 |
import java.text.SimpleDateFormat;
|
|
|
34 |
import java.util.Calendar;
|
|
|
35 |
import java.util.Date;
|
|
|
36 |
import java.util.List;
|
|
|
37 |
import java.util.Random;
|
|
|
38 |
import java.util.TimeZone;
|
|
|
39 |
|
|
|
40 |
public class GalleryViewPageAdapter extends RecyclerView.Adapter<GalleryViewPageAdapter.ViewHolder> {
|
|
|
41 |
private final static String TAG = "C2GS - GalleryAdapter";
|
|
|
42 |
private List<Slide> mData;
|
|
|
43 |
private LayoutInflater mInflater;
|
|
|
44 |
private ITwoGetSkills iTwoGetSkills;
|
|
|
45 |
private Context mContext;
|
|
|
46 |
private Slide mItemCurrent;
|
|
|
47 |
private Slide mItemCurrent2;
|
|
|
48 |
private int mItemCurrentLauncher=0;
|
|
|
49 |
|
|
|
50 |
|
|
|
51 |
|
|
|
52 |
// data is passed into the constructor
|
|
|
53 |
public GalleryViewPageAdapter(FragmentActivity context, List<Slide> data) {
|
|
|
54 |
this.mContext = context;
|
|
|
55 |
this.iTwoGetSkills = (ITwoGetSkills) context;
|
|
|
56 |
this.mInflater = LayoutInflater.from(context);
|
|
|
57 |
this.mData = data;
|
|
|
58 |
|
|
|
59 |
}
|
|
|
60 |
|
|
|
61 |
// inflates the row layout from xml when needed
|
|
|
62 |
@Override
|
|
|
63 |
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
|
|
64 |
View view = mInflater.inflate(R.layout.fragment_gallery_viewpager_item, parent, false);
|
|
|
65 |
return new ViewHolder(view);
|
|
|
66 |
}
|
|
|
67 |
|
|
|
68 |
// binds the data to the TextView in each row
|
|
|
69 |
@SuppressLint("NewApi")
|
|
|
70 |
@Override
|
|
|
71 |
public void onBindViewHolder(ViewHolder holder, @SuppressLint("RecyclerView") int position) {
|
|
|
72 |
|
|
|
73 |
holder.mCheckReady.setVisibility(View.GONE);
|
|
|
74 |
holder.mButtonFinish.setVisibility(View.GONE);
|
|
|
75 |
holder.mButtonViewer.setVisibility(View.GONE);
|
|
|
76 |
|
|
|
77 |
mItemCurrent = mData.get(position);
|
|
|
78 |
|
|
|
79 |
if(mItemCurrent.isShowFinish()) {
|
|
|
80 |
holder.mButtonFinish.setVisibility(View.VISIBLE);
|
|
|
81 |
}
|
|
|
82 |
if(mItemCurrent.getCompleted()== 1) {
|
|
|
83 |
holder.mCheckReady.setVisibility(View.VISIBLE);
|
|
|
84 |
}
|
18 |
efrain |
85 |
|
|
|
86 |
boolean setImageViewerControl = false;
|
1 |
gabriel |
87 |
switch(mItemCurrent.getType()) {
|
|
|
88 |
|
|
|
89 |
case Constants.SLIDE_TYPE_TEXT :
|
|
|
90 |
|
|
|
91 |
holder.mButtonViewer.setVisibility(View.VISIBLE);
|
|
|
92 |
holder.mButtonViewer.setText(this.mContext.getString(R.string.button_launch_text));
|
|
|
93 |
break;
|
|
|
94 |
|
|
|
95 |
|
|
|
96 |
case Constants.SLIDE_TYPE_AUDIO :
|
|
|
97 |
|
|
|
98 |
holder.mButtonViewer.setVisibility(View.VISIBLE);
|
|
|
99 |
holder.mButtonViewer.setText(this.mContext.getString(R.string.button_launch_audio));
|
|
|
100 |
break;
|
|
|
101 |
|
|
|
102 |
case Constants.SLIDE_TYPE_DOCUMENT :
|
|
|
103 |
|
|
|
104 |
holder.mButtonViewer.setVisibility(View.VISIBLE);
|
|
|
105 |
holder.mButtonViewer.setText(this.mContext.getString(R.string.button_launch_document));
|
|
|
106 |
break;
|
|
|
107 |
|
|
|
108 |
case Constants.SLIDE_TYPE_VIDEO :
|
|
|
109 |
|
|
|
110 |
holder.mButtonViewer.setVisibility(View.VISIBLE);
|
|
|
111 |
holder.mButtonViewer.setText(this.mContext.getString(R.string.button_launch_video));
|
18 |
efrain |
112 |
//DatabaseHelper.imagenviewerontrol="NO";
|
|
|
113 |
setImageViewerControl = false;
|
1 |
gabriel |
114 |
|
|
|
115 |
break;
|
|
|
116 |
|
|
|
117 |
|
|
|
118 |
case Constants.SLIDE_TYPE_QUIZ :
|
|
|
119 |
if(mItemCurrent.getCompleted() == 0) {
|
|
|
120 |
|
|
|
121 |
holder.mButtonViewer.setVisibility(View.VISIBLE);
|
|
|
122 |
holder.mButtonViewer.setText(this.mContext.getString(R.string.button_launch_quiz));
|
|
|
123 |
} else {
|
|
|
124 |
holder.mButtonViewer.setVisibility(View.INVISIBLE);
|
|
|
125 |
}
|
|
|
126 |
break;
|
|
|
127 |
|
|
|
128 |
default :
|
|
|
129 |
holder.mButtonViewer.setVisibility(View.INVISIBLE);
|
18 |
efrain |
130 |
//DatabaseHelper.imagenviewerontrol="SI";
|
|
|
131 |
setImageViewerControl = true;
|
1 |
gabriel |
132 |
break;
|
|
|
133 |
|
|
|
134 |
}
|
|
|
135 |
|
|
|
136 |
String image = TextUtils.isEmpty(mItemCurrent.getBackground()) ?mItemCurrent.getFile() : mItemCurrent.getBackground();
|
18 |
efrain |
137 |
ImageService.retrieve(mContext, image, holder.mImage);
|
1 |
gabriel |
138 |
|
|
|
139 |
holder.mButtonViewer.setOnClickListener(new View.OnClickListener() {
|
|
|
140 |
@Override
|
|
|
141 |
public void onClick(View view) {
|
|
|
142 |
// Toast.makeText(view.getContext(), String.valueOf(position), Toast.LENGTH_SHORT).show();
|
|
|
143 |
launchViewer();
|
|
|
144 |
}
|
|
|
145 |
});
|
|
|
146 |
|
|
|
147 |
}
|
|
|
148 |
|
|
|
149 |
|
|
|
150 |
|
|
|
151 |
|
|
|
152 |
// total number of rows
|
|
|
153 |
@Override
|
|
|
154 |
public int getItemCount() {
|
|
|
155 |
return mData.size();
|
|
|
156 |
}
|
|
|
157 |
|
|
|
158 |
|
|
|
159 |
// stores and recycles views as they are scrolled off screen
|
|
|
160 |
public class ViewHolder extends RecyclerView.ViewHolder {
|
|
|
161 |
ImageView mImage;
|
|
|
162 |
ImageView mCheckReady;
|
|
|
163 |
Button mButtonViewer;
|
|
|
164 |
Button mButtonFinish;
|
|
|
165 |
|
|
|
166 |
|
|
|
167 |
ViewHolder(View itemView) {
|
|
|
168 |
super(itemView);
|
|
|
169 |
mImage = itemView.findViewById(R.id.fragment_gallery_viewpage_item_image);
|
|
|
170 |
mCheckReady = itemView.findViewById(R.id.fragment_gallery_viewpage_item_check_ready);
|
|
|
171 |
mButtonViewer = itemView.findViewById(R.id.fragment_gallery_viewpage_item_button_viewer);
|
|
|
172 |
mButtonViewer.setOnClickListener(new View.OnClickListener() {
|
|
|
173 |
@Override
|
|
|
174 |
public void onClick(View view) {
|
|
|
175 |
|
|
|
176 |
launchViewer();
|
|
|
177 |
}
|
|
|
178 |
});
|
|
|
179 |
|
|
|
180 |
|
|
|
181 |
|
|
|
182 |
mButtonFinish = itemView.findViewById(R.id.fragment_gallery_viewpage_item_button_finish);
|
|
|
183 |
mButtonFinish.setOnClickListener(new View.OnClickListener() {
|
|
|
184 |
@Override
|
|
|
185 |
public void onClick(View view) {
|
|
|
186 |
finishCapsuleAndOrTopic();
|
|
|
187 |
}
|
|
|
188 |
});
|
|
|
189 |
}
|
|
|
190 |
|
|
|
191 |
}
|
|
|
192 |
|
|
|
193 |
public void launchViewer()
|
|
|
194 |
{
|
|
|
195 |
|
|
|
196 |
switch (mItemCurrent.getType()) {
|
|
|
197 |
case Constants.SLIDE_TYPE_TEXT:
|
|
|
198 |
|
|
|
199 |
iTwoGetSkills.launchTextViewer(mItemCurrent.getDescription());
|
|
|
200 |
break;
|
|
|
201 |
|
|
|
202 |
case Constants.SLIDE_TYPE_AUDIO:
|
|
|
203 |
|
|
|
204 |
iTwoGetSkills.launchAudioViewer(mItemCurrent.getFile());
|
|
|
205 |
break;
|
|
|
206 |
|
|
|
207 |
case Constants.SLIDE_TYPE_DOCUMENT:
|
|
|
208 |
iTwoGetSkills.launchDocumentViewer(mItemCurrent.getFile());
|
|
|
209 |
|
|
|
210 |
break;
|
|
|
211 |
|
|
|
212 |
case Constants.SLIDE_TYPE_VIDEO:
|
|
|
213 |
|
|
|
214 |
iTwoGetSkills.launchVideoViewer(mItemCurrent.getFile());
|
|
|
215 |
|
|
|
216 |
break;
|
|
|
217 |
|
|
|
218 |
|
|
|
219 |
case Constants.SLIDE_TYPE_QUIZ:
|
|
|
220 |
iTwoGetSkills.launchQuizViewer(mItemCurrent.getQuizUuid());
|
|
|
221 |
|
|
|
222 |
break;
|
|
|
223 |
}
|
|
|
224 |
}
|
|
|
225 |
|
|
|
226 |
public void finishCapsuleAndOrTopic()
|
|
|
227 |
{
|
|
|
228 |
String userUuid = iTwoGetSkills.getPreference().getUserUuid();
|
|
|
229 |
UserLogDao userLogDao = iTwoGetSkills.getDatabase().getUserLogDao();
|
|
|
230 |
SyncDao syncDao = iTwoGetSkills.getDatabase().getSyncDao();
|
|
|
231 |
ProgressDao progressDao = iTwoGetSkills.getDatabase().getProgressDao();
|
|
|
232 |
|
|
|
233 |
Progress progressCapsule = progressDao.selectByCapsuleUuidAndUserUuid(mItemCurrent.getCapsuleUuid(), userUuid);
|
|
|
234 |
Progress progressTopic = progressDao.selectByTopicUuidAndUserUuid(mItemCurrent.getTopicUuid(), userUuid);
|
|
|
235 |
|
|
|
236 |
Calendar calendar = Calendar.getInstance();
|
|
|
237 |
Date date = calendar.getTime();
|
|
|
238 |
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(Constants.FORMAT_DATETIME_SERVICE);
|
|
|
239 |
String dateOn = simpleDateFormat.format(date);
|
|
|
240 |
|
|
|
241 |
UserLog userLog;
|
|
|
242 |
Sync sync;
|
|
|
243 |
|
|
|
244 |
int toInvokeFragment = Constants.IDX_FRAGMENT_FINISH_TOPIC;
|
|
|
245 |
|
|
|
246 |
if(progressCapsule.getProgress() >= 100 && progressCapsule.getCompleted() == 0) {
|
|
|
247 |
toInvokeFragment = Constants.IDX_FRAGMENT_FINISH_CAPSULE;
|
|
|
248 |
|
|
|
249 |
userLog = new UserLog();
|
|
|
250 |
userLog.setUserUuid(iTwoGetSkills.getPreference().getUserUuid());
|
|
|
251 |
userLog.setActivity(Constants.USER_LOG_ACTIVITY_COMPLETED_CAPSULE);
|
|
|
252 |
userLog.setCompanyUuid(progressCapsule.getCompanyUuid());
|
|
|
253 |
userLog.setTopicUuid(progressCapsule.getTopicUuid());
|
|
|
254 |
userLog.setCapsuleUuid(progressCapsule.getCapsuleUuid());
|
|
|
255 |
userLog.setAddedOn(dateOn);
|
|
|
256 |
userLogDao.insert(userLog);
|
|
|
257 |
|
|
|
258 |
try {
|
|
|
259 |
JSONObject json = userLog.toJson();
|
|
|
260 |
json.put(Constants.SYNC_ADAPTER_DATA_TYPE_FIELD_NAME, Constants.SYNC_ADAPTER_DATA_TYPE_MICROLEARNING_USER_LOG);
|
|
|
261 |
|
|
|
262 |
sync = new Sync(Constants.SYNC_ADAPTER_TYPE_SYNC,json.toString());
|
|
|
263 |
syncDao.insert(sync);
|
|
|
264 |
|
|
|
265 |
} catch (JSONException e) {
|
|
|
266 |
Log.d(TAG, e.getMessage());
|
|
|
267 |
}
|
|
|
268 |
|
|
|
269 |
progressCapsule.setCompleted(1);
|
|
|
270 |
progressDao.update(progressCapsule);
|
|
|
271 |
|
|
|
272 |
try {
|
|
|
273 |
JSONObject json = progressCapsule.toJson();
|
|
|
274 |
json.put(Constants.SYNC_ADAPTER_DATA_TYPE_FIELD_NAME, Constants.SYNC_ADAPTER_DATA_TYPE_MICROLEARNING_PROGRESS);
|
|
|
275 |
|
|
|
276 |
sync = new Sync(Constants.SYNC_ADAPTER_TYPE_SYNC, json.toString());
|
|
|
277 |
syncDao.insert(sync);
|
|
|
278 |
|
|
|
279 |
} catch (JSONException e) {
|
|
|
280 |
Log.d(TAG, e.getMessage());
|
|
|
281 |
}
|
|
|
282 |
}
|
|
|
283 |
|
|
|
284 |
|
|
|
285 |
if (progressTopic.getProgress() >= 100 && progressTopic.getCompleted() == 0) {
|
|
|
286 |
toInvokeFragment = Constants.IDX_FRAGMENT_FINISH_TOPIC;
|
|
|
287 |
|
|
|
288 |
userLog = new UserLog();
|
|
|
289 |
userLog.setUserUuid(iTwoGetSkills.getPreference().getUserUuid());
|
|
|
290 |
userLog.setActivity(Constants.USER_LOG_ACTIVITY_COMPLETED_TOPIC);
|
|
|
291 |
userLog.setCompanyUuid(progressTopic.getCompanyUuid());
|
|
|
292 |
userLog.setTopicUuid(progressTopic.getTopicUuid());
|
|
|
293 |
userLog.setAddedOn(dateOn);
|
|
|
294 |
userLogDao.insert(userLog);
|
|
|
295 |
|
|
|
296 |
try {
|
|
|
297 |
JSONObject json = userLog.toJson();
|
|
|
298 |
json.put(Constants.SYNC_ADAPTER_DATA_TYPE_FIELD_NAME, Constants.SYNC_ADAPTER_DATA_TYPE_MICROLEARNING_USER_LOG);
|
|
|
299 |
|
|
|
300 |
sync = new Sync(Constants.SYNC_ADAPTER_TYPE_SYNC, json.toString());
|
|
|
301 |
syncDao.insert(sync);
|
|
|
302 |
|
|
|
303 |
} catch (JSONException e) {
|
|
|
304 |
Log.d(TAG, e.getMessage());
|
|
|
305 |
}
|
|
|
306 |
|
|
|
307 |
progressTopic.setCompleted(1);
|
|
|
308 |
progressDao.update(progressTopic);
|
|
|
309 |
|
|
|
310 |
try {
|
|
|
311 |
JSONObject json = progressTopic.toJson();
|
|
|
312 |
json.put(Constants.SYNC_ADAPTER_DATA_TYPE_FIELD_NAME, Constants.SYNC_ADAPTER_DATA_TYPE_MICROLEARNING_PROGRESS);
|
|
|
313 |
|
|
|
314 |
sync = new Sync(Constants.SYNC_ADAPTER_TYPE_SYNC,json.toString());
|
|
|
315 |
syncDao.insert(sync);
|
|
|
316 |
} catch (JSONException e) {
|
|
|
317 |
Log.d(TAG, e.getMessage());
|
|
|
318 |
}
|
|
|
319 |
}
|
|
|
320 |
|
|
|
321 |
iTwoGetSkills.requestExecuteSyncAdapter();
|
|
|
322 |
iTwoGetSkills.invokeFragment(toInvokeFragment);
|
|
|
323 |
}
|
|
|
324 |
}
|