Proyectos de Subversion Android Microlearning - Nuevo Interface

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
2 gabriel 1
package com.cesams.twogetskills.fragment;
2
 
3
import android.os.Bundle;
4
 
11 gabriel 5
import androidx.annotation.NonNull;
2 gabriel 6
import androidx.fragment.app.Fragment;
7
import androidx.lifecycle.LifecycleOwner;
17 gabriel 8
import androidx.lifecycle.ViewModelProvider;
2 gabriel 9
import androidx.recyclerview.widget.GridLayoutManager;
10
import androidx.recyclerview.widget.RecyclerView;
11
 
13 gabriel 12
import android.text.Editable;
13
import android.text.TextWatcher;
2 gabriel 14
import android.util.Log;
15
import android.view.LayoutInflater;
11 gabriel 16
import android.view.MotionEvent;
2 gabriel 17
import android.view.View;
18
import android.view.ViewGroup;
11 gabriel 19
import android.widget.AdapterView;
9 gabriel 20
import android.widget.Button;
8 gabriel 21
import android.widget.EditText;
9 gabriel 22
import android.widget.ImageView;
23
import android.widget.ProgressBar;
2 gabriel 24
import android.widget.TextView;
25
 
9 gabriel 26
import com.bumptech.glide.Glide;
27
import com.bumptech.glide.load.engine.DiskCacheStrategy;
28
import com.bumptech.glide.load.model.GlideUrl;
29
import com.bumptech.glide.load.model.LazyHeaders;
30
import com.bumptech.glide.request.RequestOptions;
31
import com.cesams.twogetskills.Constants;
2 gabriel 32
import com.cesams.twogetskills.R;
33
import com.cesams.twogetskills.adapter.CapsuleListViewAdapter;
4 gabriel 34
import com.cesams.twogetskills.adapter.TabsCapsulesAdapter;
2 gabriel 35
import com.cesams.twogetskills.dao.CapsuleDao;
25 gabriel 36
import com.cesams.twogetskills.dao.NotificationCenterDao;
2 gabriel 37
import com.cesams.twogetskills.dao.ProgressDao;
16 gabriel 38
import com.cesams.twogetskills.dao.SlideDao;
2 gabriel 39
import com.cesams.twogetskills.dao.TopicDao;
40
import com.cesams.twogetskills.entity.Capsule;
41
import com.cesams.twogetskills.entity.Progress;
16 gabriel 42
import com.cesams.twogetskills.entity.Slide;
2 gabriel 43
import com.cesams.twogetskills.entity.Topic;
9 gabriel 44
import com.cesams.twogetskills.library.MD5;
2 gabriel 45
import com.cesams.twogetskills.skeleton.ITwoGetSkills;
17 gabriel 46
import com.cesams.twogetskills.viewmodel.SlideRefreshUIViewModel;
12 gabriel 47
import com.google.android.material.tabs.TabLayout;
2 gabriel 48
 
24 gabriel 49
import java.text.DateFormat;
21 gabriel 50
import java.text.Normalizer;
24 gabriel 51
import java.text.SimpleDateFormat;
2 gabriel 52
import java.util.ArrayList;
9 gabriel 53
import java.util.Calendar;
25 gabriel 54
import java.util.Date;
2 gabriel 55
import java.util.HashMap;
56
import java.util.List;
9 gabriel 57
import java.util.Random;
58
import java.util.TimeZone;
2 gabriel 59
 
60
/**
61
 * A simple {@link Fragment} subclass.
62
 * Use the {@link WelcomeFragment#newInstance} factory method to
63
 * create an instance of this fragment.
64
 */
17 gabriel 65
public class WelcomeFragment extends Fragment implements TabsCapsulesAdapter.ClickListener, LifecycleOwner {
2 gabriel 66
 
10 gabriel 67
    TextView username, titulotarjeta, progresoporcentaje, empezar; ProgressBar progresotarjeta;
9 gabriel 68
    private ITwoGetSkills iTwoGetSkills; View card;
2 gabriel 69
    ArrayList<HashMap<String, String>> capsuleList;
11 gabriel 70
    ImageView imagetarjeta;
71
    TabsCapsulesAdapter adapter2;
72
    RecyclerView categorizados;
9 gabriel 73
    EditText busqueda; TextView textowelcome; Button continuar;
17 gabriel 74
    TabLayout tabs; String tabactual="pendientes";     private SlideRefreshUIViewModel mSlideRefreshUi;
2 gabriel 75
 
17 gabriel 76
 
2 gabriel 77
    public WelcomeFragment() {
78
        // Required empty public constructor
79
    }
80
 
81
    public static WelcomeFragment newInstance() {
82
        WelcomeFragment fragment = new WelcomeFragment();
83
        return fragment;
84
    }
85
 
86
    @Override
87
    public void onCreate(Bundle savedInstanceState) {
88
        super.onCreate(savedInstanceState);
89
          }
90
 
91
    @Override
92
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
93
                             Bundle savedInstanceState) {
94
 
8 gabriel 95
 
2 gabriel 96
        iTwoGetSkills = (ITwoGetSkills) getActivity();
8 gabriel 97
        iTwoGetSkills.showNavigationAndToolbar();
2 gabriel 98
 
99
        View view= inflater.inflate(R.layout.fragment_welcome, container, false);
100
 
101
        username=view.findViewById(R.id.textView14);
8 gabriel 102
        textowelcome= view.findViewById(R.id.textView15);
103
        busqueda=view.findViewById(R.id.busqueda);
12 gabriel 104
        card= view.findViewById(R.id.include); empezar= view.findViewById(R.id.titlenotifi); tabs=view.findViewById(R.id.tabLayout);
8 gabriel 105
        capsuleList = new ArrayList<>();
2 gabriel 106
 
17 gabriel 107
 
108
        mSlideRefreshUi = new ViewModelProvider(requireActivity()).get(SlideRefreshUIViewModel.class);
109
 
110
 
111
 
112
 
9 gabriel 113
        //Tarjeta Principal
11 gabriel 114
        titulotarjeta = view.findViewById(R.id.description); progresotarjeta= view.findViewById(R.id.progressBar2); imagetarjeta= view.findViewById(R.id.imagelist);
9 gabriel 115
        continuar = view.findViewById(R.id.button); progresoporcentaje = view.findViewById(R.id.textView16);
116
 
117
 
2 gabriel 118
        username.setText("¡Hola, "+(iTwoGetSkills.getPreference().getFirstName() +"!"));
119
 
12 gabriel 120
        tabs.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
121
            @Override
122
            public void onTabSelected(TabLayout.Tab tab) {
123
                int position=tab.getPosition();
2 gabriel 124
 
12 gabriel 125
                capsuleList.clear();
126
                adapter2.notifyDataSetChanged();
2 gabriel 127
 
12 gabriel 128
                if(position==0)
129
                {
13 gabriel 130
                    tabactual="pendientes";
131
                    loadData(tabactual,"");
12 gabriel 132
                    adapter2.notifyDataSetChanged();
133
                }
134
                else if(position==1)
135
                {
13 gabriel 136
                    tabactual="cursando";
137
                    loadData("cursando","");
12 gabriel 138
                    adapter2.notifyDataSetChanged();
139
                }
140
                else if(position==2)
141
                {
13 gabriel 142
                    tabactual="finalizados";
143
                    loadData("finalizados","");
12 gabriel 144
                    adapter2.notifyDataSetChanged();
145
                }
146
            }
147
 
148
            @Override
149
            public void onTabUnselected(TabLayout.Tab tab) {
150
 
151
            }
152
 
153
            @Override
154
            public void onTabReselected(TabLayout.Tab tab) {
155
 
156
            }
157
        });
158
 
13 gabriel 159
        loadData("pendientes","");
12 gabriel 160
 
8 gabriel 161
        busqueda.setOnFocusChangeListener(new View.OnFocusChangeListener() {
162
            @Override
163
            public void onFocusChange(View v, boolean hasFocus) {
164
                if(hasFocus)
165
                {
9 gabriel 166
                        card.setVisibility(View.GONE);
8 gabriel 167
                        username.setVisibility(View.GONE);
168
                        textowelcome.setVisibility(View.GONE);
34 gabriel 169
                        Log.e("Tengo foco"," Oculto");
8 gabriel 170
                }
171
 
172
            }
173
        });
174
 
13 gabriel 175
        busqueda.addTextChangedListener(new TextWatcher() {
176
            @Override
177
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
8 gabriel 178
 
13 gabriel 179
            }
180
 
181
            @Override
182
            public void onTextChanged(CharSequence s, int start, int before, int count) {
17 gabriel 183
            //    Log.e("El texto","buscado: "+s);
13 gabriel 184
                capsuleList.clear();
185
                adapter2.notifyDataSetChanged();
186
                loadData(tabactual, s.toString());
187
            }
188
 
189
            @Override
190
            public void afterTextChanged(Editable s) {
191
 
192
 
193
 
194
            }
195
        });
196
 
197
 
4 gabriel 198
        adapter2 = new TabsCapsulesAdapter(getContext(),capsuleList);
2 gabriel 199
 
200
 
201
 
4 gabriel 202
        categorizados = view.findViewById(R.id.categorizados);
203
        GridLayoutManager layoutcategoria = new GridLayoutManager(getContext(),1,GridLayoutManager.VERTICAL, false);
204
        categorizados.setLayoutManager(layoutcategoria);
205
        categorizados.setAdapter(adapter2);
206
 
11 gabriel 207
 
17 gabriel 208
        adapter2.setClickListener(this);
11 gabriel 209
 
8 gabriel 210
        categorizados.setOnFlingListener(new RecyclerView.OnFlingListener() {
211
            @Override
212
            public boolean onFling(int velocityX, int velocityY) {
213
 
214
                if (categorizados.canScrollVertically(-1) ) {
215
 
17 gabriel 216
                   // Log.e("Se activa", "On fling");
9 gabriel 217
                    card.setVisibility(View.GONE);
8 gabriel 218
                    username.setVisibility(View.GONE);
219
                    textowelcome.setVisibility(View.GONE);
220
                }else
221
                {
9 gabriel 222
                    card.setVisibility(View.VISIBLE);
8 gabriel 223
                    username.setVisibility(View.VISIBLE);
224
                    textowelcome.setVisibility(View.VISIBLE);
225
                }
226
 
227
                return false;
228
            }
229
        });
230
 
11 gabriel 231
 
8 gabriel 232
     /*   categorizados.setOnScrollChangeListener(new View.OnScrollChangeListener() {
233
            @Override
234
            public void onScrollChange(View v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {
235
 
236
                if (!categorizados.canScrollVertically(-1)) {
237
                 //   Toast.makeText(getActivity(), "Last", Toast.LENGTH_LONG).show();
238
                    capsulas.setVisibility(View.VISIBLE);
239
                    username.setVisibility(View.VISIBLE);
240
                    textowelcome.setVisibility(View.VISIBLE);
241
                    Log.e("On scroll"," se activa");
242
                }
243
 
244
            }
245
        });
246
*/
21 gabriel 247
 
248
        getActivity().runOnUiThread(() -> {
249
            String message = capsuleList.size() == 1
250
                    ? "Hay 1 cápsula nueva disponible"
251
                    : "Tiene " + capsuleList.size() + " cápsulas pendientes para ver";
252
 
25 gabriel 253
 
254
            Calendar calendar = Calendar.getInstance();
255
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat(Constants.FORMAT_DATETIME_SERVICE);
256
            Date date = calendar.getTime();
257
 
258
            String  dateOn = simpleDateFormat.format(date);
259
 
260
 
261
            NotificationCenterDao notificacionDao =  iTwoGetSkills.getDatabase().getNotificationCenterDao();
262
            com.cesams.twogetskills.entity.NotificationCenter notificacionueva;
263
 
264
            notificacionueva = new com.cesams.twogetskills.entity.NotificationCenter();
265
 
266
            notificacionueva.setTitle("Nuevo contenido disponible");
267
            notificacionueva.setDate(dateOn);
268
            notificacionueva.setDescription(message);
27 gabriel 269
           // Log.e("Notificacion","a guardar"+notificacionueva);
25 gabriel 270
 
271
            List<com.cesams.twogetskills.entity.NotificationCenter> lista;
272
            lista=notificacionDao.selectAllNotification();
273
 
274
 
275
            if(lista.size()==0)
276
            {
277
                notificacionDao.insert(notificacionueva);
278
 
279
            }
280
            else {
281
                for (com.cesams.twogetskills.entity.NotificationCenter notificacion : lista) {
282
                    if (notificacion.getDescription().equals(message)) {
27 gabriel 283
                       // Log.e("Notification Center", " omitir, he registrado esta notificacion");
25 gabriel 284
                    } else {
285
                        notificacionDao.insert(notificacionueva);
27 gabriel 286
                       // Log.e("Notification Center", "guardar");
25 gabriel 287
 
288
                    }
289
                }
290
            }
21 gabriel 291
            iTwoGetSkills.showMessageSnackBarWithClose(message);
292
 
293
        });
2 gabriel 294
        return view;
295
    }
296
 
9 gabriel 297
    @Override
298
    public void onResume() {
299
        super.onResume();
38 gabriel 300
        getActivity().runOnUiThread(() -> {
301
            loadContinuecard();
302
        });
9 gabriel 303
    }
2 gabriel 304
 
9 gabriel 305
    @Override
306
    public void onHiddenChanged(boolean hidden) {
307
        super.onHiddenChanged(hidden);
308
 
17 gabriel 309
       // Log.e("TAG", "onHiddenChanged : " + (hidden ? "true" : "false"));
9 gabriel 310
 
311
        if(!hidden) {
27 gabriel 312
          //  Log.e("Esta oculto", "el fragmento");
16 gabriel 313
 
314
            getActivity().runOnUiThread(() -> {
315
 
316
                capsuleList.clear();
317
 
318
                loadContinuecard();
319
                loadData("pendientes","");
320
 
321
                adapter2.notifyDataSetChanged();
322
 
323
                tabs.getTabAt(0).select();
324
 
325
            });
326
 
327
 
9 gabriel 328
        }
329
    }
330
 
331
    private void loadContinuecard(){
332
 
38 gabriel 333
        Log.e("Cargo datos"," en tarjeta principal");
9 gabriel 334
 
335
        //Capsula de primera tarjeta
336
        CapsuleDao capsuleDao = iTwoGetSkills.getDatabase().getCapsuleDao();
337
 
338
        Progress progress;
339
        ProgressDao progressDao = iTwoGetSkills.getDatabase().getProgressDao();
340
 
17 gabriel 341
 
9 gabriel 342
        List<Capsule> dbCapsules= capsuleDao.selectAll();
343
        for(Capsule dbCapsule : dbCapsules)
344
        {
345
            progress = progressDao.selectByCapsuleUuid(dbCapsule.getUuid());
346
 
347
            if (progress != null) {
348
 
10 gabriel 349
                    if (progress.getProgress() < 100) {
17 gabriel 350
                    //    Log.e("Es menor"," a 100");
9 gabriel 351
 
352
                        titulotarjeta.setText(dbCapsule.getName());
10 gabriel 353
                        progresotarjeta.setVisibility(View.VISIBLE);
354
                        progresoporcentaje.setVisibility(View.VISIBLE);
9 gabriel 355
                        progresotarjeta.setProgress((int) progress.getProgress());
356
                        progresoporcentaje.setText("" + progress.getProgress() + " %");
10 gabriel 357
                        empezar.setText("En curso");
9 gabriel 358
 
38 gabriel 359
                        int fragmentIdxActive = iTwoGetSkills.getPreference().getFragmentIdxActive();
360
 
361
                        if (fragmentIdxActive != Constants.IDX_FRAGMENT_WELCOME
362
                        ) {
363
                            return;
364
                        }
26 gabriel 365
                        iTwoGetSkills.getPreference().setCapsuleUuidActive(dbCapsule.getUuid());
38 gabriel 366
                     //   Log.e("La capsula","activa en loadcurso"+dbCapsule.getUuid());
367
 
26 gabriel 368
                        iTwoGetSkills.getPreference().setTopicUuidActive(dbCapsule.getTopicUuid());
369
                        iTwoGetSkills.getPreference().setOrigennavigation("welcome");
9 gabriel 370
 
371
                        if (dbCapsule.getImage() != null && !dbCapsule.getImage().equals("")) {
372
 
373
                            TimeZone timeZone = TimeZone.getTimeZone("UTC");
374
                            Calendar calendar = Calendar.getInstance(timeZone);
375
                            TimeZone tz = calendar.getTimeZone();
376
                            int created = (int) (calendar.getTimeInMillis() / 1000);
377
 
378
                            Random random = new Random(created);
379
                            int rand = 1000 + random.nextInt(8999);
380
 
381
 
382
                            String deviceUuid = iTwoGetSkills.getPreference().getDeviceUuid();
383
                            String password = iTwoGetSkills.getPreference().getPassword();
384
 
385
 
386
                            String secret = MD5.generar(password + ':' + created + ':' + rand);
387
                            GlideUrl url = new GlideUrl(dbCapsule.getImage(), new LazyHeaders.Builder()
388
                                    .addHeader(Constants.HTTP_HEADER_ACCEPT, Constants.HTTP_HEADER_ACCEPT_VALUE)
389
                                    .addHeader(Constants.HTTP_HEADER_SECURITY_TOKEN, deviceUuid)
390
                                    .addHeader(Constants.HTTP_HEADER_SECURITY_SECRET, secret)
391
                                    .addHeader(Constants.HTTP_HEADER_SECURITY_CREATED, String.valueOf(created))
392
                                    .addHeader(Constants.HTTP_HEADER_SECURITY_RAND, String.valueOf(rand))
393
                                    .build());
394
 
395
                            RequestOptions options = new RequestOptions()
396
                                    .diskCacheStrategy(DiskCacheStrategy.ALL);
397
 
398
                            Glide.with(getContext()).load(url)
399
                                    .thumbnail()
400
                                    .apply(options)
401
                                    .into(imagetarjeta);
402
                        }
403
                    }
404
 
10 gabriel 405
            }
406
 
407
 
408
        }
409
        if(titulotarjeta.getText().equals(""))
410
        {
17 gabriel 411
           // Log.e("Nombre","vacio");
37 gabriel 412
            SlideDao slideDao = iTwoGetSkills.getDatabase().getSlideDao();
10 gabriel 413
 
37 gabriel 414
 
10 gabriel 415
            //Despues del recorrido no se encontro progreso en ninguna capsula, por lo cual la tarjeta queda vacia
416
            // vamos a llenarla con la ultima capsula, que debe ser nueva al no tener progreso
417
 
38 gabriel 418
 
10 gabriel 419
            for(Capsule dbCapsule : dbCapsules)
420
            {
37 gabriel 421
                List<Slide> slides = slideDao.selectAllByCapsuleUuid(dbCapsule.getUuid());
10 gabriel 422
 
37 gabriel 423
                if (slides.isEmpty()) {
424
 
425
                } else {
10 gabriel 426
                progress = progressDao.selectByCapsuleUuid(dbCapsule.getUuid());
38 gabriel 427
 
37 gabriel 428
                    //  Log.e("Capsula","Es omitida, no tiene slides");
10 gabriel 429
 
37 gabriel 430
                    if (progress == null) {
10 gabriel 431
 
37 gabriel 432
                        //  Log.e("Es nueva","");
10 gabriel 433
 
434
                        titulotarjeta.setText(dbCapsule.getName());
435
                        progresotarjeta.setVisibility(View.INVISIBLE);
436
                        progresoporcentaje.setVisibility(View.INVISIBLE);
437
                        empezar.setText("Nueva");
438
                        continuar.setText("Ver cápsula");
439
 
38 gabriel 440
                        int fragmentIdxActive = iTwoGetSkills.getPreference().getFragmentIdxActive();
10 gabriel 441
 
38 gabriel 442
                        if (fragmentIdxActive != Constants.IDX_FRAGMENT_WELCOME
443
                        ) {
444
                            return;
445
                        }
37 gabriel 446
                        iTwoGetSkills.getPreference().setCapsuleUuidActive(dbCapsule.getUuid());
38 gabriel 447
                      //  Log.e("La capsula","activa en load"+dbCapsule.getUuid());
37 gabriel 448
                        iTwoGetSkills.getPreference().setTopicUuidActive(dbCapsule.getTopicUuid());
449
                        iTwoGetSkills.getPreference().setOrigennavigation("welcome");
26 gabriel 450
 
37 gabriel 451
                        if (dbCapsule.getImage() != null && !dbCapsule.getImage().equals("")) {
10 gabriel 452
 
453
                            TimeZone timeZone = TimeZone.getTimeZone("UTC");
454
                            Calendar calendar = Calendar.getInstance(timeZone);
455
                            TimeZone tz = calendar.getTimeZone();
456
                            int created = (int) (calendar.getTimeInMillis() / 1000);
457
 
458
                            Random random = new Random(created);
459
                            int rand = 1000 + random.nextInt(8999);
460
 
461
 
462
                            String deviceUuid = iTwoGetSkills.getPreference().getDeviceUuid();
463
                            String password = iTwoGetSkills.getPreference().getPassword();
464
 
465
 
466
                            String secret = MD5.generar(password + ':' + created + ':' + rand);
467
                            GlideUrl url = new GlideUrl(dbCapsule.getImage(), new LazyHeaders.Builder()
468
                                    .addHeader(Constants.HTTP_HEADER_ACCEPT, Constants.HTTP_HEADER_ACCEPT_VALUE)
469
                                    .addHeader(Constants.HTTP_HEADER_SECURITY_TOKEN, deviceUuid)
470
                                    .addHeader(Constants.HTTP_HEADER_SECURITY_SECRET, secret)
471
                                    .addHeader(Constants.HTTP_HEADER_SECURITY_CREATED, String.valueOf(created))
472
                                    .addHeader(Constants.HTTP_HEADER_SECURITY_RAND, String.valueOf(rand))
473
                                    .build());
474
 
475
                            RequestOptions options = new RequestOptions()
476
                                    .diskCacheStrategy(DiskCacheStrategy.ALL);
477
 
478
                            Glide.with(getContext()).load(url)
479
                                    .thumbnail()
480
                                    .apply(options)
481
                                    .into(imagetarjeta);
482
                        }
483
 
484
                    }
37 gabriel 485
                }
10 gabriel 486
 
38 gabriel 487
            }
10 gabriel 488
 
489
 
490
 
38 gabriel 491
        }
492
        else if (!titulotarjeta.getText().equals(""))
493
        {
494
            // Log.e("Nombre","vacio");
495
            SlideDao slideDao = iTwoGetSkills.getDatabase().getSlideDao();
10 gabriel 496
 
38 gabriel 497
 
498
            //Despues del recorrido no se encontro progreso en ninguna capsula, por lo cual la tarjeta queda vacia
499
            // vamos a llenarla con la ultima capsula, que debe ser nueva al no tener progreso
500
 
501
 
502
            for(Capsule dbCapsule : dbCapsules)
503
            {
504
                List<Slide> slides = slideDao.selectAllByCapsuleUuid(dbCapsule.getUuid());
505
 
506
                if (slides.isEmpty()) {
507
 
508
                } else {
509
                    progress = progressDao.selectByCapsuleUuid(dbCapsule.getUuid());
510
 
511
                    //  Log.e("Capsula","Es omitida, no tiene slides");
512
 
513
                    if (progress == null) {
514
 
515
                        //  Log.e("Es nueva","");
516
 
10 gabriel 517
                        titulotarjeta.setText(dbCapsule.getName());
518
                        progresotarjeta.setVisibility(View.INVISIBLE);
519
                        progresoporcentaje.setVisibility(View.INVISIBLE);
520
                        empezar.setText("Nueva");
521
                        continuar.setText("Ver cápsula");
522
 
38 gabriel 523
                        int fragmentIdxActive = iTwoGetSkills.getPreference().getFragmentIdxActive();
524
 
525
                        if (fragmentIdxActive != Constants.IDX_FRAGMENT_WELCOME
526
                        ) {
527
                            return;
528
                        }
10 gabriel 529
                        iTwoGetSkills.getPreference().setCapsuleUuidActive(dbCapsule.getUuid());
38 gabriel 530
                       // Log.e("La capsula","activa en load"+dbCapsule.getUuid());
10 gabriel 531
                        iTwoGetSkills.getPreference().setTopicUuidActive(dbCapsule.getTopicUuid());
38 gabriel 532
                        iTwoGetSkills.getPreference().setOrigennavigation("welcome");
10 gabriel 533
 
534
                        if (dbCapsule.getImage() != null && !dbCapsule.getImage().equals("")) {
535
 
536
                            TimeZone timeZone = TimeZone.getTimeZone("UTC");
537
                            Calendar calendar = Calendar.getInstance(timeZone);
538
                            TimeZone tz = calendar.getTimeZone();
539
                            int created = (int) (calendar.getTimeInMillis() / 1000);
540
 
541
                            Random random = new Random(created);
542
                            int rand = 1000 + random.nextInt(8999);
543
 
544
 
545
                            String deviceUuid = iTwoGetSkills.getPreference().getDeviceUuid();
546
                            String password = iTwoGetSkills.getPreference().getPassword();
547
 
548
 
549
                            String secret = MD5.generar(password + ':' + created + ':' + rand);
550
                            GlideUrl url = new GlideUrl(dbCapsule.getImage(), new LazyHeaders.Builder()
551
                                    .addHeader(Constants.HTTP_HEADER_ACCEPT, Constants.HTTP_HEADER_ACCEPT_VALUE)
552
                                    .addHeader(Constants.HTTP_HEADER_SECURITY_TOKEN, deviceUuid)
553
                                    .addHeader(Constants.HTTP_HEADER_SECURITY_SECRET, secret)
554
                                    .addHeader(Constants.HTTP_HEADER_SECURITY_CREATED, String.valueOf(created))
555
                                    .addHeader(Constants.HTTP_HEADER_SECURITY_RAND, String.valueOf(rand))
556
                                    .build());
557
 
558
                            RequestOptions options = new RequestOptions()
559
                                    .diskCacheStrategy(DiskCacheStrategy.ALL);
560
 
561
                            Glide.with(getContext()).load(url)
562
                                    .thumbnail()
563
                                    .apply(options)
564
                                    .into(imagetarjeta);
565
                        }
566
 
567
                    }
9 gabriel 568
                }
38 gabriel 569
 
10 gabriel 570
            }
9 gabriel 571
        }
572
 
26 gabriel 573
        continuar.setOnClickListener(v -> {
10 gabriel 574
 
575
 
23 gabriel 576
           // Log.e("Guardo",""+iTwoGetSkills.getPreference().getOrigenNavigation());
38 gabriel 577
            Log.e("Capsule","active"+iTwoGetSkills.getPreference().getCapsuleUuidActive());
9 gabriel 578
            iTwoGetSkills.invokeFragment(Constants.IDX_FRAGMENT_SLIDES);
579
        });
580
 
581
        //Fin de primer tarjeta
582
 
583
    }
584
 
13 gabriel 585
    private void loadData(String tabposition, String buscar)
2 gabriel 586
    {
587
 
12 gabriel 588
 
2 gabriel 589
        TopicDao topicDao = iTwoGetSkills.getDatabase().getTopicDao();
590
        ArrayList<Topic> dbTopics = (ArrayList<Topic>) topicDao.selectAll();
591
 
592
        List<Capsule> dbCapsules;
593
        CapsuleDao capsuleDao = iTwoGetSkills.getDatabase().getCapsuleDao();
594
 
24 gabriel 595
        ProgressDao progressDao = iTwoGetSkills.getDatabase().getProgressDao();
596
        SlideDao slideDao = iTwoGetSkills.getDatabase().getSlideDao();
9 gabriel 597
 
598
 
24 gabriel 599
        if (tabposition.equals("pendientes"))
600
        {
601
            for (Topic dbTopic : dbTopics) {
9 gabriel 602
 
24 gabriel 603
                dbCapsules = capsuleDao.selectAllByTopicUuidandOrder(dbTopic.getUuid());
2 gabriel 604
 
24 gabriel 605
                Capsule capsule;
606
                Progress progress;
2 gabriel 607
 
24 gabriel 608
                HashMap<String, String> m_li;
9 gabriel 609
 
2 gabriel 610
 
611
 
24 gabriel 612
                for(Capsule dbCapsule : dbCapsules) {
613
                    capsule = new Capsule();
614
                    capsule.setTopicUuid(dbCapsule.getTopicUuid());
615
                    capsule.setUuid(dbCapsule.getUuid());
616
                    capsule.setName(dbCapsule.getName());
617
                    capsule.setDescription(dbCapsule.getDescription());
618
                    capsule.setImage(dbCapsule.getImage());
619
                    capsule.setPosition(dbCapsule.getPosition());
620
                    capsule.setUpdatedOn(dbCapsule.getUpdatedOn());
9 gabriel 621
 
24 gabriel 622
                    m_li = new HashMap<>();
9 gabriel 623
 
2 gabriel 624
 
24 gabriel 625
                    //m_li.put("copyright",copy);
2 gabriel 626
 
24 gabriel 627
                    progress = progressDao.selectByCapsuleUuid(capsule.getUuid());
2 gabriel 628
 
24 gabriel 629
                    if (progress != null) {
630
                        capsule.setCompleted(progress.getCompleted());
631
                        capsule.setViewSlides(progress.getViewSlides());
2 gabriel 632
 
24 gabriel 633
                        capsule.setTotalSlides(progress.getTotalSlides());
634
                        capsule.setProgress(progress.getProgress());
635
                        capsule.setAddedOn(progress.getAddedOn());
2 gabriel 636
 
24 gabriel 637
                        // Log.e("Agregado en"," "+progress.getAddedOn());
638
                        // m_li.put("addedon",progress.getAddedOn());
639
                        m_li.put("view", String.valueOf(progress.getViewSlides()));
640
                        m_li.put("total", String.valueOf(progress.getTotalSlides()));
641
                        m_li.put("progress", String.valueOf(progress.getProgress()));
642
                        m_li.put("completado",String.valueOf(progress.getCompleted()));
643
                        m_li.put("agregado",progress.getAddedOn());
2 gabriel 644
 
24 gabriel 645
                    }
2 gabriel 646
 
24 gabriel 647
                    m_li.put("imagen", capsule.getImage());
648
                    m_li.put("nombre", capsule.getName());
649
                    m_li.put("uuid", capsule.getUuid());
650
                    m_li.put("topicuuid", capsule.getTopicUuid());
651
                    m_li.put("description", capsule.getDescription());
16 gabriel 652
 
18 gabriel 653
 
24 gabriel 654
                    //Lleno la lista segun el requerimiento de filtro accionado por el usuario
2 gabriel 655
 
24 gabriel 656
                    List<Slide> slides = slideDao.selectAllByCapsuleUuid(capsule.getUuid());
2 gabriel 657
 
24 gabriel 658
                    if (slides.isEmpty()) {
13 gabriel 659
 
24 gabriel 660
                        //  Log.e("Capsula","Es omitida, no tiene slides");
661
                    } else {
2 gabriel 662
 
12 gabriel 663
 
24 gabriel 664
                        if (progress == null) {
18 gabriel 665
 
24 gabriel 666
                            if (buscar.equals("")) {
18 gabriel 667
 
24 gabriel 668
                                capsuleList.add(m_li);
16 gabriel 669
 
13 gabriel 670
 
24 gabriel 671
                            } else {
672
                                String nombre= capsule.getName();
673
                                String normalizada= Normalizer.normalize(nombre, Normalizer.Form.NFD);
674
                                normalizada= normalizada.replaceAll("[^\\p{ASCII}]", "");
675
                                if (normalizada.matches("(?i).*" + buscar + ".*")) {
676
                                    capsuleList.add(m_li);
677
                                }
21 gabriel 678
 
16 gabriel 679
                            }
13 gabriel 680
 
16 gabriel 681
                        }
12 gabriel 682
 
24 gabriel 683
                    }
12 gabriel 684
 
24 gabriel 685
                }
16 gabriel 686
 
687
 
13 gabriel 688
 
24 gabriel 689
            }
13 gabriel 690
 
24 gabriel 691
        }
692
        else if (tabposition.equals("cursando"))
693
        {
2 gabriel 694
 
24 gabriel 695
                HashMap<String, String> m_li;
696
                List<Progress> progress;
697
                Capsule capsule;
2 gabriel 698
 
13 gabriel 699
 
700
 
24 gabriel 701
            progress = progressDao.selectAllCapsulesProgress();
702
 
703
                for(Progress dbProgress : progress) {
704
                    m_li = new HashMap<>();
705
 
706
                    capsule = capsuleDao.selectByUuid(dbProgress.getCapsuleUuid());
707
 
708
                    m_li.put("view", String.valueOf(dbProgress.getViewSlides()));
709
                    m_li.put("total", String.valueOf(dbProgress.getTotalSlides()));
710
                    m_li.put("progress", String.valueOf(dbProgress.getProgress()));
711
                    m_li.put("completado",String.valueOf(dbProgress.getCompleted()));
712
                    m_li.put("agregado",dbProgress.getAddedOn());
713
 
714
 
715
                    m_li.put("imagen", capsule.getImage());
716
                    m_li.put("nombre", capsule.getName());
717
                    m_li.put("uuid", capsule.getUuid());
718
                    m_li.put("topicuuid", capsule.getTopicUuid());
719
                    m_li.put("description", capsule.getDescription());
720
 
721
 
722
                    //Log.e("Lista",""+m_li);
723
                    //Lleno la lista segun el requerimiento de filtro accionado por el usuario
724
 
725
                    List<Slide> slides = slideDao.selectAllByCapsuleUuid(capsule.getUuid());
726
 
727
                    if (slides.isEmpty()) {
728
 
729
                        //  Log.e("Capsula","Es omitida, no tiene slides");
730
                    } else {
731
 
732
            if(dbProgress.getProgress() <= 100 && dbProgress.getCompleted()==0)
733
            {
734
            if (buscar.equals("")) {
735
                capsuleList.add(m_li);
736
 
737
            } else {
738
                String nombre= capsule.getName();
739
                String normalizada= Normalizer.normalize(nombre, Normalizer.Form.NFD);
740
                normalizada= normalizada.replaceAll("[^\\p{ASCII}]", "");
741
                if (normalizada.matches("(?i).*" + buscar + ".*")) {
742
                    capsuleList.add(m_li);
12 gabriel 743
                }
2 gabriel 744
 
12 gabriel 745
            }
24 gabriel 746
        }}
747
                }}
2 gabriel 748
 
24 gabriel 749
       else if (tabposition.equals("finalizados")){
12 gabriel 750
 
24 gabriel 751
            HashMap<String, String> m_li;
752
            List<Progress> progress;
753
            Capsule capsule;
2 gabriel 754
 
21 gabriel 755
 
24 gabriel 756
 
757
            progress = progressDao.selectAllCapsulesProgress();
758
 
759
            for(Progress dbProgress : progress) {
760
                m_li = new HashMap<>();
761
 
762
                capsule = capsuleDao.selectByUuid(dbProgress.getCapsuleUuid());
763
 
764
                m_li.put("view", String.valueOf(dbProgress.getViewSlides()));
765
                m_li.put("total", String.valueOf(dbProgress.getTotalSlides()));
766
                m_li.put("progress", String.valueOf(dbProgress.getProgress()));
767
                m_li.put("completado",String.valueOf(dbProgress.getCompleted()));
768
                m_li.put("agregado",dbProgress.getAddedOn());
769
 
770
 
771
                m_li.put("imagen", capsule.getImage());
772
                m_li.put("nombre", capsule.getName());
773
                m_li.put("uuid", capsule.getUuid());
774
                m_li.put("topicuuid", capsule.getTopicUuid());
775
                m_li.put("description", capsule.getDescription());
776
 
777
                //Lleno la lista segun el requerimiento de filtro accionado por el usuario
778
 
779
                    List<Slide> slides = slideDao.selectAllByCapsuleUuid(capsule.getUuid());
780
 
781
                    if (slides.isEmpty()) {
782
 
783
                        //  Log.e("Capsula","Es omitida, no tiene slides");
784
                    } else {
785
           if(dbProgress.getProgress() >= 100 && dbProgress.getCompleted()==1){
786
 
787
               if (buscar.equals("")) {
788
                   //capsule.getCompleted();
789
                   capsuleList.add(m_li);
790
 
791
               } else {
792
                   String nombre= capsule.getName();
793
                   String normalizada= Normalizer.normalize(nombre, Normalizer.Form.NFD);
794
                   normalizada= normalizada.replaceAll("[^\\p{ASCII}]", "");
795
                   if (normalizada.matches("(?i).*" + buscar + ".*")) {
796
                       capsuleList.add(m_li);
797
                   }
798
 
799
               }
800
           }
2 gabriel 801
    }
24 gabriel 802
                }}
2 gabriel 803
 
804
 
24 gabriel 805
    }
806
 
807
 
17 gabriel 808
    @Override
809
    public void onItemClick(int position, View v) {
810
 
24 gabriel 811
       // Log.e("Evento","del click"+position);
17 gabriel 812
 
813
 
814
        iTwoGetSkills.getPreference().setCapsuleUuidActive(capsuleList.get(position).get("uuid"));
815
        iTwoGetSkills.getPreference().setTopicUuidActive(capsuleList.get(position).get("topicuuid"));
816
        iTwoGetSkills.invokeFragment(Constants.IDX_FRAGMENT_SLIDES);
817
 
18 gabriel 818
        iTwoGetSkills.getPreference().setOrigennavigation("welcome");
24 gabriel 819
       // Log.e("Completada",""+capsuleList.get(position).get("completado"));
18 gabriel 820
 
17 gabriel 821
       // Log.e("Capsula","topic active"+mDataSet.get(viewHolder.getAbsoluteAdapterPosition()).get("topicuuid"));
822
 
823
    }
2 gabriel 824
}