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;
14 gabriel 7
 
1 gabriel 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
 
14 gabriel 60
    TextView username, titulotarjeta, progresoporcentaje, empezar, ningunelemento; ProgressBar progresotarjeta;
1 gabriel 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
 
91
        View view= inflater.inflate(R.layout.fragment_welcome, container, false);
92
 
14 gabriel 93
        username=view.findViewById(R.id.textView14); ningunelemento=view.findViewById(R.id.textView25);
1 gabriel 94
        textowelcome= view.findViewById(R.id.textView15);
95
        busqueda=view.findViewById(R.id.busqueda);
96
        card= view.findViewById(R.id.include); empezar= view.findViewById(R.id.titlenotifi); tabs=view.findViewById(R.id.tabLayout);
97
        capsuleList = new ArrayList<>();
98
 
99
 
100
 
101
 
102
 
103
 
14 gabriel 104
 
1 gabriel 105
        //Tarjeta Principal
106
        titulotarjeta = view.findViewById(R.id.description); progresotarjeta= view.findViewById(R.id.progressBar2); imagetarjeta= view.findViewById(R.id.imagelist);
107
        continuar = view.findViewById(R.id.button); progresoporcentaje = view.findViewById(R.id.textView16);
108
 
109
 
110
        username.setText("¡Hola, "+(iTwoGetSkills.getPreference().getFirstName() +"!"));
111
 
112
        tabs.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
113
            @Override
114
            public void onTabSelected(TabLayout.Tab tab) {
115
                int position=tab.getPosition();
116
 
117
                capsuleList.clear();
118
                adapter2.notifyDataSetChanged();
119
 
120
                if(position==0)
121
                {
122
                    tabactual="pendientes";
123
                    loadData(tabactual,"");
124
                    adapter2.notifyDataSetChanged();
125
                }
126
                else if(position==1)
127
                {
128
                    tabactual="cursando";
129
                    loadData("cursando","");
130
                    adapter2.notifyDataSetChanged();
131
                }
132
                else if(position==2)
133
                {
134
                    tabactual="finalizados";
135
                    loadData("finalizados","");
136
                    adapter2.notifyDataSetChanged();
137
                }
138
            }
139
 
140
            @Override
141
            public void onTabUnselected(TabLayout.Tab tab) {
142
 
143
            }
144
 
145
            @Override
146
            public void onTabReselected(TabLayout.Tab tab) {
147
 
148
            }
149
        });
150
 
151
        loadData("pendientes","");
152
 
153
        busqueda.setOnFocusChangeListener(new View.OnFocusChangeListener() {
154
            @Override
155
            public void onFocusChange(View v, boolean hasFocus) {
156
                if(hasFocus)
157
                {
158
                        card.setVisibility(View.GONE);
159
                        username.setVisibility(View.GONE);
160
                        textowelcome.setVisibility(View.GONE);
161
                        Log.e("Tengo foco"," Oculto");
162
                }
163
 
164
            }
165
        });
166
 
167
        busqueda.addTextChangedListener(new TextWatcher() {
168
            @Override
169
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
170
 
171
            }
172
 
173
            @Override
174
            public void onTextChanged(CharSequence s, int start, int before, int count) {
175
            //    Log.e("El texto","buscado: "+s);
176
                capsuleList.clear();
177
                adapter2.notifyDataSetChanged();
178
                loadData(tabactual, s.toString());
179
            }
180
 
181
            @Override
182
            public void afterTextChanged(Editable s) {
183
 
184
 
185
 
186
            }
187
        });
188
 
189
 
190
        adapter2 = new TabsCapsulesAdapter(getContext(),capsuleList);
191
 
192
 
193
 
194
        categorizados = view.findViewById(R.id.categorizados);
195
        GridLayoutManager layoutcategoria = new GridLayoutManager(getContext(),1,GridLayoutManager.VERTICAL, false);
196
        categorizados.setLayoutManager(layoutcategoria);
197
        categorizados.setAdapter(adapter2);
198
 
199
 
200
        adapter2.setClickListener(this);
201
 
202
        categorizados.setOnFlingListener(new RecyclerView.OnFlingListener() {
203
            @Override
204
            public boolean onFling(int velocityX, int velocityY) {
205
 
206
                if (categorizados.canScrollVertically(-1) ) {
207
 
208
                   // Log.e("Se activa", "On fling");
209
                    card.setVisibility(View.GONE);
210
                    username.setVisibility(View.GONE);
211
                    textowelcome.setVisibility(View.GONE);
212
                }else
213
                {
214
                    card.setVisibility(View.VISIBLE);
215
                    username.setVisibility(View.VISIBLE);
216
                    textowelcome.setVisibility(View.VISIBLE);
217
                }
218
 
219
                return false;
220
            }
221
        });
222
 
223
 
224
     /*   categorizados.setOnScrollChangeListener(new View.OnScrollChangeListener() {
225
            @Override
226
            public void onScrollChange(View v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {
227
 
228
                if (!categorizados.canScrollVertically(-1)) {
229
                 //   Toast.makeText(getActivity(), "Last", Toast.LENGTH_LONG).show();
230
                    capsulas.setVisibility(View.VISIBLE);
231
                    username.setVisibility(View.VISIBLE);
232
                    textowelcome.setVisibility(View.VISIBLE);
233
                    Log.e("On scroll"," se activa");
234
                }
235
 
236
            }
237
        });
238
*/
239
        getActivity().runOnUiThread(() -> {
240
            String message = capsuleList.size() == 1
241
                    ? "Hay 1 cápsula nueva disponible"
242
                    : "Tiene " + capsuleList.size() + " cápsulas pendientes para ver";
243
 
244
            Toast.makeText(getContext(), ""+message, Toast.LENGTH_LONG).show();
245
 
246
            iTwoGetSkills.saveNotificationCenter("Contenidos disponibles","",message);
247
 
248
        });
8 gabriel 249
        iTwoGetSkills.showNavigationAndToolbar();
250
 
1 gabriel 251
        return view;
8 gabriel 252
 
1 gabriel 253
    }
254
 
255
    @Override
256
    public void onResume() {
257
        super.onResume();
258
        getActivity().runOnUiThread(() -> {
15 gabriel 259
            int fragmentIdxActive = iTwoGetSkills.getPreference().getFragmentIdxActive();
260
 
261
            if (fragmentIdxActive != Constants.IDX_FRAGMENT_WELCOME
262
            ) {
263
                return;
264
            }
1 gabriel 265
            loadContinuecard();
266
        });
267
    }
268
 
269
    @Override
270
    public void onHiddenChanged(boolean hidden) {
271
        super.onHiddenChanged(hidden);
272
 
273
       // Log.e("TAG", "onHiddenChanged : " + (hidden ? "true" : "false"));
274
 
275
        if(!hidden) {
276
          //  Log.e("Esta oculto", "el fragmento");
277
 
278
            getActivity().runOnUiThread(() -> {
279
 
280
                capsuleList.clear();
281
 
282
                loadContinuecard();
283
                loadData("pendientes","");
284
 
14 gabriel 285
                if (capsuleList.size() == 0) //Si no tenemos capsulas pendientes nos vamos a en curso
286
                {
287
                    capsuleList.clear();
288
                    loadData("cursando","");
289
 
290
                    tabs.selectTab(tabs.getTabAt(1),true);
291
 
292
                }
293
                else
294
                {
295
                    tabs.selectTab(tabs.getTabAt(0),true);
296
 
297
                }
1 gabriel 298
                adapter2.notifyDataSetChanged();
299
 
14 gabriel 300
 
1 gabriel 301
 
302
            });
303
 
304
 
305
        }
306
    }
307
 
308
    private void loadContinuecard(){
309
 
310
        //Log.e("Cargo datos"," en tarjeta principal");
311
 
312
        //Capsula de primera tarjeta
313
        CapsuleDao capsuleDao = iTwoGetSkills.getDatabase().getCapsuleDao();
314
        boolean continues=false;
315
        Progress progress;
316
        ProgressDao progressDao = iTwoGetSkills.getDatabase().getProgressDao();
317
 
318
 
319
        List<Capsule> dbCapsules= capsuleDao.selectAll();
320
        for(Capsule dbCapsule : dbCapsules)
321
        {
322
            progress = progressDao.selectByCapsuleUuid(dbCapsule.getUuid());
323
 
324
            if (progress != null) {
325
 
14 gabriel 326
            if (progress.getProgress() <=100 && progress.getCompleted()==0)
327
                {
328
                    titulotarjeta.setText(dbCapsule.getName());
329
                    if (dbCapsule.getImage() != null && !dbCapsule.getImage().equals("")) {
330
 
331
                        TimeZone timeZone = TimeZone.getTimeZone("UTC");
332
                        Calendar calendar = Calendar.getInstance(timeZone);
333
                        TimeZone tz = calendar.getTimeZone();
334
                        int created = (int) (calendar.getTimeInMillis() / 1000);
335
 
336
                        Random random = new Random(created);
337
                        int rand = 1000 + random.nextInt(8999);
338
 
339
 
340
                        String deviceUuid = iTwoGetSkills.getPreference().getDeviceUuid();
341
                        String password = iTwoGetSkills.getPreference().getPassword();
342
 
343
 
344
                        String secret = MD5.generar(password + ':' + created + ':' + rand);
345
                        GlideUrl url = new GlideUrl(dbCapsule.getImage(), new LazyHeaders.Builder()
346
                                .addHeader(Constants.HTTP_HEADER_ACCEPT, Constants.HTTP_HEADER_ACCEPT_VALUE)
347
                                .addHeader(Constants.HTTP_HEADER_SECURITY_TOKEN, deviceUuid)
348
                                .addHeader(Constants.HTTP_HEADER_SECURITY_SECRET, secret)
349
                                .addHeader(Constants.HTTP_HEADER_SECURITY_CREATED, String.valueOf(created))
350
                                .addHeader(Constants.HTTP_HEADER_SECURITY_RAND, String.valueOf(rand))
351
                                .build());
352
 
353
                        RequestOptions options = new RequestOptions()
354
                                .diskCacheStrategy(DiskCacheStrategy.ALL);
355
 
356
                        Glide.with(getContext()).load(url)
357
                                .thumbnail()
358
                                .apply(options)
359
                                .into(imagetarjeta);
360
                        iTwoGetSkills.setCapsulaActiva(dbCapsule.getUuid());
361
                    }
362
                }
363
                    if (progress.getProgress() < 100 && progress.getCompleted()==0) {
1 gabriel 364
                       // Log.e("Es menor"," a 100");
365
                        continues=true;
366
                        titulotarjeta.setText(dbCapsule.getName());
367
                        progresotarjeta.setVisibility(View.VISIBLE);
368
                        progresoporcentaje.setVisibility(View.VISIBLE);
369
                        progresotarjeta.setProgress((int) progress.getProgress());
370
                        progresoporcentaje.setText("" + progress.getProgress() + " %");
371
                        empezar.setText("En curso");
372
 
373
                        iTwoGetSkills.getPreference().setOrigennavigation("welcome");
374
 
375
                        int fragmentIdxActive = iTwoGetSkills.getPreference().getFragmentIdxActive();
376
 
377
                        if (fragmentIdxActive != Constants.IDX_FRAGMENT_WELCOME
378
                        ) {
379
                            return;
380
                        }
14 gabriel 381
                        iTwoGetSkills.setCapsulaActiva(dbCapsule.getUuid());
1 gabriel 382
                     //   Log.e("La capsula","activa en loadcurso"+dbCapsule.getUuid());
383
 
384
                        iTwoGetSkills.getPreference().setTopicUuidActive(dbCapsule.getTopicUuid());
385
 
386
                        if (dbCapsule.getImage() != null && !dbCapsule.getImage().equals("")) {
387
 
388
                            TimeZone timeZone = TimeZone.getTimeZone("UTC");
389
                            Calendar calendar = Calendar.getInstance(timeZone);
390
                            TimeZone tz = calendar.getTimeZone();
391
                            int created = (int) (calendar.getTimeInMillis() / 1000);
392
 
393
                            Random random = new Random(created);
394
                            int rand = 1000 + random.nextInt(8999);
395
 
396
 
397
                            String deviceUuid = iTwoGetSkills.getPreference().getDeviceUuid();
398
                            String password = iTwoGetSkills.getPreference().getPassword();
399
 
400
 
401
                            String secret = MD5.generar(password + ':' + created + ':' + rand);
402
                            GlideUrl url = new GlideUrl(dbCapsule.getImage(), new LazyHeaders.Builder()
403
                                    .addHeader(Constants.HTTP_HEADER_ACCEPT, Constants.HTTP_HEADER_ACCEPT_VALUE)
404
                                    .addHeader(Constants.HTTP_HEADER_SECURITY_TOKEN, deviceUuid)
405
                                    .addHeader(Constants.HTTP_HEADER_SECURITY_SECRET, secret)
406
                                    .addHeader(Constants.HTTP_HEADER_SECURITY_CREATED, String.valueOf(created))
407
                                    .addHeader(Constants.HTTP_HEADER_SECURITY_RAND, String.valueOf(rand))
408
                                    .build());
409
 
410
                            RequestOptions options = new RequestOptions()
411
                                    .diskCacheStrategy(DiskCacheStrategy.ALL);
412
 
413
                            Glide.with(getContext()).load(url)
414
                                    .thumbnail()
415
                                    .apply(options)
416
                                    .into(imagetarjeta);
417
                        }
418
                    }
419
 
420
            }
421
 
422
 
423
        }
424
        if(titulotarjeta.getText().equals(""))
425
        {
426
           // Log.e("Nombre","vacio");
427
            SlideDao slideDao = iTwoGetSkills.getDatabase().getSlideDao();
428
 
429
 
430
            //Despues del recorrido no se encontro progreso en ninguna capsula, por lo cual la tarjeta queda vacia
431
            // vamos a llenarla con la ultima capsula, que debe ser nueva al no tener progreso
432
 
433
 
434
            for(Capsule dbCapsule : dbCapsules)
435
            {
436
                List<Slide> slides = slideDao.selectAllByCapsuleUuid(dbCapsule.getUuid());
437
 
438
                if (slides.isEmpty()) {
439
 
440
                } else {
441
                progress = progressDao.selectByCapsuleUuid(dbCapsule.getUuid());
442
 
443
                    //  Log.e("Capsula","Es omitida, no tiene slides");
444
 
445
                    if (progress == null) {
446
 
447
                        //  Log.e("Es nueva","");
448
 
449
                        titulotarjeta.setText(dbCapsule.getName());
450
                        progresotarjeta.setVisibility(View.INVISIBLE);
451
                        progresoporcentaje.setVisibility(View.INVISIBLE);
452
                        empezar.setText("Nueva");
453
                        continuar.setText("Ver cápsula");
454
 
455
                        iTwoGetSkills.getPreference().setOrigennavigation("welcome");
456
 
457
                        int fragmentIdxActive = iTwoGetSkills.getPreference().getFragmentIdxActive();
458
 
459
                        if (fragmentIdxActive != Constants.IDX_FRAGMENT_WELCOME
460
                        ) {
461
                            return;
462
                        }
14 gabriel 463
                        iTwoGetSkills.setCapsulaActiva(dbCapsule.getUuid());
1 gabriel 464
                      //  Log.e("La capsula","activa en load"+dbCapsule.getUuid());
465
                        iTwoGetSkills.getPreference().setTopicUuidActive(dbCapsule.getTopicUuid());
466
 
467
                        if (dbCapsule.getImage() != null && !dbCapsule.getImage().equals("")) {
468
 
469
                            TimeZone timeZone = TimeZone.getTimeZone("UTC");
470
                            Calendar calendar = Calendar.getInstance(timeZone);
471
                            TimeZone tz = calendar.getTimeZone();
472
                            int created = (int) (calendar.getTimeInMillis() / 1000);
473
 
474
                            Random random = new Random(created);
475
                            int rand = 1000 + random.nextInt(8999);
476
 
477
 
478
                            String deviceUuid = iTwoGetSkills.getPreference().getDeviceUuid();
479
                            String password = iTwoGetSkills.getPreference().getPassword();
480
 
481
 
482
                            String secret = MD5.generar(password + ':' + created + ':' + rand);
483
                            GlideUrl url = new GlideUrl(dbCapsule.getImage(), new LazyHeaders.Builder()
484
                                    .addHeader(Constants.HTTP_HEADER_ACCEPT, Constants.HTTP_HEADER_ACCEPT_VALUE)
485
                                    .addHeader(Constants.HTTP_HEADER_SECURITY_TOKEN, deviceUuid)
486
                                    .addHeader(Constants.HTTP_HEADER_SECURITY_SECRET, secret)
487
                                    .addHeader(Constants.HTTP_HEADER_SECURITY_CREATED, String.valueOf(created))
488
                                    .addHeader(Constants.HTTP_HEADER_SECURITY_RAND, String.valueOf(rand))
489
                                    .build());
490
 
491
                            RequestOptions options = new RequestOptions()
492
                                    .diskCacheStrategy(DiskCacheStrategy.ALL);
493
 
494
                            Glide.with(getContext()).load(url)
495
                                    .thumbnail()
496
                                    .apply(options)
497
                                    .into(imagetarjeta);
498
                        }
499
 
500
                    }
501
                }
502
 
503
            }
504
 
505
 
506
 
507
        }
508
        else if (!titulotarjeta.getText().equals("") && !continues)
509
        {
510
            // Log.e("Nombre","vacio");
511
            SlideDao slideDao = iTwoGetSkills.getDatabase().getSlideDao();
512
 
513
 
514
            //Despues del recorrido no se encontro progreso en ninguna capsula, por lo cual la tarjeta queda vacia
515
            // vamos a llenarla con la ultima capsula, que debe ser nueva al no tener progreso
516
 
517
 
518
            for(Capsule dbCapsule : dbCapsules)
519
            {
520
                List<Slide> slides = slideDao.selectAllByCapsuleUuid(dbCapsule.getUuid());
521
 
522
                if (slides.isEmpty()) {
523
 
524
                } else {
525
                    progress = progressDao.selectByCapsuleUuid(dbCapsule.getUuid());
526
 
527
                    //  Log.e("Capsula","Es omitida, no tiene slides");
528
 
529
                    if (progress == null) {
530
 
531
                        //  Log.e("Es nueva","");
532
 
533
                        titulotarjeta.setText(dbCapsule.getName());
534
                        progresotarjeta.setVisibility(View.INVISIBLE);
535
                        progresoporcentaje.setVisibility(View.INVISIBLE);
536
                        empezar.setText("Nueva");
537
                        continuar.setText("Ver cápsula");
538
 
539
                        iTwoGetSkills.getPreference().setOrigennavigation("welcome");
540
 
541
 
542
                        int fragmentIdxActive = iTwoGetSkills.getPreference().getFragmentIdxActive();
543
 
544
                        if (fragmentIdxActive != Constants.IDX_FRAGMENT_WELCOME
545
                        ) {
546
                            return;
547
                        }
14 gabriel 548
                        iTwoGetSkills.setCapsulaActiva(dbCapsule.getUuid());
1 gabriel 549
                       // Log.e("La capsula","activa en load"+dbCapsule.getUuid());
550
                        iTwoGetSkills.getPreference().setTopicUuidActive(dbCapsule.getTopicUuid());
551
 
552
                        if (dbCapsule.getImage() != null && !dbCapsule.getImage().equals("")) {
553
 
554
                            TimeZone timeZone = TimeZone.getTimeZone("UTC");
555
                            Calendar calendar = Calendar.getInstance(timeZone);
556
                            TimeZone tz = calendar.getTimeZone();
557
                            int created = (int) (calendar.getTimeInMillis() / 1000);
558
 
559
                            Random random = new Random(created);
560
                            int rand = 1000 + random.nextInt(8999);
561
 
562
 
563
                            String deviceUuid = iTwoGetSkills.getPreference().getDeviceUuid();
564
                            String password = iTwoGetSkills.getPreference().getPassword();
565
 
566
 
567
                            String secret = MD5.generar(password + ':' + created + ':' + rand);
568
                            GlideUrl url = new GlideUrl(dbCapsule.getImage(), new LazyHeaders.Builder()
569
                                    .addHeader(Constants.HTTP_HEADER_ACCEPT, Constants.HTTP_HEADER_ACCEPT_VALUE)
570
                                    .addHeader(Constants.HTTP_HEADER_SECURITY_TOKEN, deviceUuid)
571
                                    .addHeader(Constants.HTTP_HEADER_SECURITY_SECRET, secret)
572
                                    .addHeader(Constants.HTTP_HEADER_SECURITY_CREATED, String.valueOf(created))
573
                                    .addHeader(Constants.HTTP_HEADER_SECURITY_RAND, String.valueOf(rand))
574
                                    .build());
575
 
576
                            RequestOptions options = new RequestOptions()
577
                                    .diskCacheStrategy(DiskCacheStrategy.ALL);
578
 
579
                            Glide.with(getContext()).load(url)
580
                                    .thumbnail()
581
                                    .apply(options)
582
                                    .into(imagetarjeta);
583
                        }
584
 
585
                    }
586
                }
587
 
588
            }
589
        }
590
 
591
        continuar.setOnClickListener(v -> {
592
 
593
 
594
           // Log.e("Guardo",""+iTwoGetSkills.getPreference().getOrigenNavigation());
14 gabriel 595
           // Log.e("Capsule","active"+iTwoGetSkills.getPreference().getCapsuleUuidActive());
596
 
597
            Progress progresscontinue; ProgressDao progressDaocontinue = iTwoGetSkills.getDatabase().getProgressDao();
598
            progresscontinue = progressDaocontinue.selectByCapsuleUuid(iTwoGetSkills.getCapsuleUuidActive());
599
            if (progresscontinue != null) {
600
                if (progresscontinue.getProgress() >= 100 && progresscontinue.getCompleted() == 1) {
601
                    iTwoGetSkills.invokeFragment(Constants.IDX_FRAGMENT_DETAIL_CAPSULE);
602
                } else {
603
                    iTwoGetSkills.invokeFragment(Constants.IDX_FRAGMENT_SLIDES);
604
                }
605
 
606
                iTwoGetSkills.getPreference().setOrigennavigation("welcome");
607
                iTwoGetSkills.hideKeyboard(v); //Ocultamos el teclado
608
            }
609
            else
610
            {
611
                iTwoGetSkills.invokeFragment(Constants.IDX_FRAGMENT_SLIDES);
612
 
613
            }
1 gabriel 614
        });
615
 
616
        //Fin de primer tarjeta
617
 
618
    }
619
 
620
    private void loadData(String tabposition, String buscar)
621
    {
622
 
623
 
624
        TopicDao topicDao = iTwoGetSkills.getDatabase().getTopicDao();
625
        ArrayList<Topic> dbTopics = (ArrayList<Topic>) topicDao.selectAll();
626
 
627
        List<Capsule> dbCapsules;
628
        CapsuleDao capsuleDao = iTwoGetSkills.getDatabase().getCapsuleDao();
629
 
630
        ProgressDao progressDao = iTwoGetSkills.getDatabase().getProgressDao();
631
        SlideDao slideDao = iTwoGetSkills.getDatabase().getSlideDao();
632
 
633
 
634
        if (tabposition.equals("pendientes"))
635
        {
636
            for (Topic dbTopic : dbTopics) {
637
 
638
                dbCapsules = capsuleDao.selectAllByTopicUuidandOrder(dbTopic.getUuid());
639
 
640
                Capsule capsule;
641
                Progress progress;
642
 
643
                HashMap<String, String> m_li;
644
 
645
 
646
 
647
                for(Capsule dbCapsule : dbCapsules) {
648
                    capsule = new Capsule();
649
                    capsule.setTopicUuid(dbCapsule.getTopicUuid());
650
                    capsule.setUuid(dbCapsule.getUuid());
651
                    capsule.setName(dbCapsule.getName());
652
                    capsule.setDescription(dbCapsule.getDescription());
653
                    capsule.setImage(dbCapsule.getImage());
654
                    capsule.setPosition(dbCapsule.getPosition());
655
                    capsule.setUpdatedOn(dbCapsule.getUpdatedOn());
656
 
657
                    m_li = new HashMap<>();
658
 
659
 
660
                    //m_li.put("copyright",copy);
661
 
662
                    progress = progressDao.selectByCapsuleUuid(capsule.getUuid());
663
 
664
                    if (progress != null) {
665
                        capsule.setCompleted(progress.getCompleted());
666
                        capsule.setViewSlides(progress.getViewSlides());
667
 
668
                        capsule.setTotalSlides(progress.getTotalSlides());
669
                        capsule.setProgress(progress.getProgress());
670
                        capsule.setAddedOn(progress.getAddedOn());
671
 
672
                        // Log.e("Agregado en"," "+progress.getAddedOn());
673
                        // m_li.put("addedon",progress.getAddedOn());
674
                        m_li.put("view", String.valueOf(progress.getViewSlides()));
675
                        m_li.put("total", String.valueOf(progress.getTotalSlides()));
676
                        m_li.put("progress", String.valueOf(progress.getProgress()));
677
                        m_li.put("completado",String.valueOf(progress.getCompleted()));
678
                        m_li.put("agregado",progress.getAddedOn());
679
 
680
                    }
681
 
682
                    m_li.put("imagen", capsule.getImage());
683
                    m_li.put("nombre", capsule.getName());
684
                    m_li.put("uuid", capsule.getUuid());
685
                    m_li.put("topicuuid", capsule.getTopicUuid());
686
                    m_li.put("description", capsule.getDescription());
687
 
688
 
689
                    //Lleno la lista segun el requerimiento de filtro accionado por el usuario
690
 
691
                    List<Slide> slides = slideDao.selectAllByCapsuleUuid(capsule.getUuid());
692
 
693
                    if (slides.isEmpty()) {
694
 
695
                        //  Log.e("Capsula","Es omitida, no tiene slides");
696
                    } else {
697
 
698
 
699
                        if (progress == null) {
700
 
701
                            if (buscar.equals("")) {
702
 
703
                                capsuleList.add(m_li);
704
 
705
 
706
                            } else {
707
                                String nombre= capsule.getName();
708
                                String normalizada= Normalizer.normalize(nombre, Normalizer.Form.NFD);
709
                                normalizada= normalizada.replaceAll("[^\\p{ASCII}]", "");
710
                                if (normalizada.matches("(?i).*" + buscar + ".*")) {
711
                                    capsuleList.add(m_li);
712
                                }
713
 
714
                            }
715
 
716
                        }
717
 
718
                    }
719
 
720
                }
721
 
722
 
723
 
724
            }
725
 
726
        }
727
        else if (tabposition.equals("cursando"))
728
        {
729
 
730
                HashMap<String, String> m_li;
731
                List<Progress> progress;
732
                Capsule capsule;
733
 
734
 
735
 
736
            progress = progressDao.selectAllCapsulesProgress();
737
 
738
                for(Progress dbProgress : progress) {
739
                    m_li = new HashMap<>();
740
 
741
                    capsule = capsuleDao.selectByUuid(dbProgress.getCapsuleUuid());
742
 
743
                    m_li.put("view", String.valueOf(dbProgress.getViewSlides()));
744
                    m_li.put("total", String.valueOf(dbProgress.getTotalSlides()));
745
                    m_li.put("progress", String.valueOf(dbProgress.getProgress()));
746
                    m_li.put("completado",String.valueOf(dbProgress.getCompleted()));
747
                    m_li.put("agregado",dbProgress.getAddedOn());
748
 
749
 
6 gabriel 750
                    if(capsule == null)
751
                    {
752
                        Log.e("El objeto es"," nulo");
753
                    }
754
                    else {
755
                        m_li.put("imagen", capsule.getImage());
756
                        m_li.put("nombre", capsule.getName());
757
                        m_li.put("uuid", capsule.getUuid());
758
                        m_li.put("topicuuid", capsule.getTopicUuid());
759
                        m_li.put("description", capsule.getDescription());
1 gabriel 760
 
761
 
6 gabriel 762
 
1 gabriel 763
                    //Log.e("Lista",""+m_li);
764
                    //Lleno la lista segun el requerimiento de filtro accionado por el usuario
765
 
766
                    List<Slide> slides = slideDao.selectAllByCapsuleUuid(capsule.getUuid());
767
 
768
                    if (slides.isEmpty()) {
769
 
770
                        //  Log.e("Capsula","Es omitida, no tiene slides");
771
                    } else {
772
 
773
            if(dbProgress.getProgress() <= 100 && dbProgress.getCompleted()==0)
774
            {
775
            if (buscar.equals("")) {
776
                capsuleList.add(m_li);
777
 
778
            } else {
779
                String nombre= capsule.getName();
780
                String normalizada= Normalizer.normalize(nombre, Normalizer.Form.NFD);
781
                normalizada= normalizada.replaceAll("[^\\p{ASCII}]", "");
782
                if (normalizada.matches("(?i).*" + buscar + ".*")) {
783
                    capsuleList.add(m_li);
784
                }
785
 
786
            }
787
        }}
6 gabriel 788
                }}}
1 gabriel 789
 
790
       else if (tabposition.equals("finalizados")){
791
 
792
            HashMap<String, String> m_li;
793
            List<Progress> progress;
794
            Capsule capsule;
795
 
796
 
797
 
798
            progress = progressDao.selectAllCapsulesProgress();
799
 
800
            for(Progress dbProgress : progress) {
801
                m_li = new HashMap<>();
802
 
803
                capsule = capsuleDao.selectByUuid(dbProgress.getCapsuleUuid());
804
 
805
                m_li.put("view", String.valueOf(dbProgress.getViewSlides()));
806
                m_li.put("total", String.valueOf(dbProgress.getTotalSlides()));
807
                m_li.put("progress", String.valueOf(dbProgress.getProgress()));
808
                m_li.put("completado",String.valueOf(dbProgress.getCompleted()));
809
                m_li.put("agregado",dbProgress.getAddedOn());
810
 
6 gabriel 811
                if(capsule == null)
812
                {
813
                    Log.e("El objeto esta", "nulo");
814
                }
815
                else{
1 gabriel 816
 
817
                m_li.put("imagen", capsule.getImage());
818
                m_li.put("nombre", capsule.getName());
819
                m_li.put("uuid", capsule.getUuid());
820
                m_li.put("topicuuid", capsule.getTopicUuid());
821
                m_li.put("description", capsule.getDescription());
822
 
823
                //Lleno la lista segun el requerimiento de filtro accionado por el usuario
824
 
825
                    List<Slide> slides = slideDao.selectAllByCapsuleUuid(capsule.getUuid());
826
 
827
                    if (slides.isEmpty()) {
828
 
829
                        //  Log.e("Capsula","Es omitida, no tiene slides");
830
                    } else {
831
           if(dbProgress.getProgress() >= 100 && dbProgress.getCompleted()==1){
832
 
833
               if (buscar.equals("")) {
834
                   //capsule.getCompleted();
835
                   capsuleList.add(m_li);
836
 
837
               } else {
838
                   String nombre= capsule.getName();
839
                   String normalizada= Normalizer.normalize(nombre, Normalizer.Form.NFD);
840
                   normalizada= normalizada.replaceAll("[^\\p{ASCII}]", "");
841
                   if (normalizada.matches("(?i).*" + buscar + ".*")) {
842
                       capsuleList.add(m_li);
843
                   }
844
 
845
               }
846
           }
847
    }
6 gabriel 848
                }}}
1 gabriel 849
 
850
 
14 gabriel 851
       if(capsuleList.size() == 0)
852
       {
853
           ningunelemento.setVisibility(View.VISIBLE);
854
       }
855
       else
856
       {
857
           ningunelemento.setVisibility(View.GONE);
858
       }
859
 
1 gabriel 860
    }
861
 
862
 
863
    @Override
864
    public void onItemClick(int position, View v) {
865
 
14 gabriel 866
        iTwoGetSkills.setCapsulaActiva(capsuleList.get(position).get("uuid"));
867
        iTwoGetSkills.getPreference().setTopicUuidActive(capsuleList.get(position).get("topicuuid"));
1 gabriel 868
 
14 gabriel 869
        Progress progress; ProgressDao progressDao = iTwoGetSkills.getDatabase().getProgressDao();
870
        progress = progressDao.selectByCapsuleUuid(capsuleList.get(position).get("uuid"));
1 gabriel 871
 
14 gabriel 872
        if (progress != null) {
873
            if (progress.getProgress() >= 100 && progress.getCompleted() == 1) {
874
                iTwoGetSkills.invokeFragment(Constants.IDX_FRAGMENT_DETAIL_CAPSULE);
875
            } else {
876
                iTwoGetSkills.invokeFragment(Constants.IDX_FRAGMENT_SLIDES);
877
            }
1 gabriel 878
 
14 gabriel 879
            iTwoGetSkills.getPreference().setOrigennavigation("welcome");
880
            iTwoGetSkills.hideKeyboard(v); //Ocultamos el teclado
881
        }
882
        else
883
        {
884
            iTwoGetSkills.invokeFragment(Constants.IDX_FRAGMENT_SLIDES);
1 gabriel 885
 
14 gabriel 886
        }
1 gabriel 887
    }
14 gabriel 888
}