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