Proyectos de Subversion Android Microlearning - Inconcert

Rev

| Ultima modificación | Ver Log |

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