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