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(() -> {
259
            loadContinuecard();
260
        });
261
    }
262
 
263
    @Override
264
    public void onHiddenChanged(boolean hidden) {
265
        super.onHiddenChanged(hidden);
266
 
267
       // Log.e("TAG", "onHiddenChanged : " + (hidden ? "true" : "false"));
268
 
269
        if(!hidden) {
270
          //  Log.e("Esta oculto", "el fragmento");
271
 
272
            getActivity().runOnUiThread(() -> {
273
 
274
                capsuleList.clear();
275
 
276
                loadContinuecard();
277
                loadData("pendientes","");
278
 
14 gabriel 279
                if (capsuleList.size() == 0) //Si no tenemos capsulas pendientes nos vamos a en curso
280
                {
281
                    capsuleList.clear();
282
                    loadData("cursando","");
283
 
284
                    tabs.selectTab(tabs.getTabAt(1),true);
285
 
286
                }
287
                else
288
                {
289
                    tabs.selectTab(tabs.getTabAt(0),true);
290
 
291
                }
1 gabriel 292
                adapter2.notifyDataSetChanged();
293
 
14 gabriel 294
 
1 gabriel 295
 
296
            });
297
 
298
 
299
        }
300
    }
301
 
302
    private void loadContinuecard(){
303
 
304
        //Log.e("Cargo datos"," en tarjeta principal");
305
 
306
        //Capsula de primera tarjeta
307
        CapsuleDao capsuleDao = iTwoGetSkills.getDatabase().getCapsuleDao();
308
        boolean continues=false;
309
        Progress progress;
310
        ProgressDao progressDao = iTwoGetSkills.getDatabase().getProgressDao();
311
 
312
 
313
        List<Capsule> dbCapsules= capsuleDao.selectAll();
314
        for(Capsule dbCapsule : dbCapsules)
315
        {
316
            progress = progressDao.selectByCapsuleUuid(dbCapsule.getUuid());
317
 
318
            if (progress != null) {
319
 
14 gabriel 320
            if (progress.getProgress() <=100 && progress.getCompleted()==0)
321
                {
322
                    titulotarjeta.setText(dbCapsule.getName());
323
                    if (dbCapsule.getImage() != null && !dbCapsule.getImage().equals("")) {
324
 
325
                        TimeZone timeZone = TimeZone.getTimeZone("UTC");
326
                        Calendar calendar = Calendar.getInstance(timeZone);
327
                        TimeZone tz = calendar.getTimeZone();
328
                        int created = (int) (calendar.getTimeInMillis() / 1000);
329
 
330
                        Random random = new Random(created);
331
                        int rand = 1000 + random.nextInt(8999);
332
 
333
 
334
                        String deviceUuid = iTwoGetSkills.getPreference().getDeviceUuid();
335
                        String password = iTwoGetSkills.getPreference().getPassword();
336
 
337
 
338
                        String secret = MD5.generar(password + ':' + created + ':' + rand);
339
                        GlideUrl url = new GlideUrl(dbCapsule.getImage(), new LazyHeaders.Builder()
340
                                .addHeader(Constants.HTTP_HEADER_ACCEPT, Constants.HTTP_HEADER_ACCEPT_VALUE)
341
                                .addHeader(Constants.HTTP_HEADER_SECURITY_TOKEN, deviceUuid)
342
                                .addHeader(Constants.HTTP_HEADER_SECURITY_SECRET, secret)
343
                                .addHeader(Constants.HTTP_HEADER_SECURITY_CREATED, String.valueOf(created))
344
                                .addHeader(Constants.HTTP_HEADER_SECURITY_RAND, String.valueOf(rand))
345
                                .build());
346
 
347
                        RequestOptions options = new RequestOptions()
348
                                .diskCacheStrategy(DiskCacheStrategy.ALL);
349
 
350
                        Glide.with(getContext()).load(url)
351
                                .thumbnail()
352
                                .apply(options)
353
                                .into(imagetarjeta);
354
                        iTwoGetSkills.setCapsulaActiva(dbCapsule.getUuid());
355
                    }
356
                }
357
                    if (progress.getProgress() < 100 && progress.getCompleted()==0) {
1 gabriel 358
                       // Log.e("Es menor"," a 100");
359
                        continues=true;
360
                        titulotarjeta.setText(dbCapsule.getName());
361
                        progresotarjeta.setVisibility(View.VISIBLE);
362
                        progresoporcentaje.setVisibility(View.VISIBLE);
363
                        progresotarjeta.setProgress((int) progress.getProgress());
364
                        progresoporcentaje.setText("" + progress.getProgress() + " %");
365
                        empezar.setText("En curso");
366
 
367
                        iTwoGetSkills.getPreference().setOrigennavigation("welcome");
368
 
369
                        int fragmentIdxActive = iTwoGetSkills.getPreference().getFragmentIdxActive();
370
 
371
                        if (fragmentIdxActive != Constants.IDX_FRAGMENT_WELCOME
372
                        ) {
373
                            return;
374
                        }
14 gabriel 375
                        iTwoGetSkills.setCapsulaActiva(dbCapsule.getUuid());
1 gabriel 376
                     //   Log.e("La capsula","activa en loadcurso"+dbCapsule.getUuid());
377
 
378
                        iTwoGetSkills.getPreference().setTopicUuidActive(dbCapsule.getTopicUuid());
379
 
380
                        if (dbCapsule.getImage() != null && !dbCapsule.getImage().equals("")) {
381
 
382
                            TimeZone timeZone = TimeZone.getTimeZone("UTC");
383
                            Calendar calendar = Calendar.getInstance(timeZone);
384
                            TimeZone tz = calendar.getTimeZone();
385
                            int created = (int) (calendar.getTimeInMillis() / 1000);
386
 
387
                            Random random = new Random(created);
388
                            int rand = 1000 + random.nextInt(8999);
389
 
390
 
391
                            String deviceUuid = iTwoGetSkills.getPreference().getDeviceUuid();
392
                            String password = iTwoGetSkills.getPreference().getPassword();
393
 
394
 
395
                            String secret = MD5.generar(password + ':' + created + ':' + rand);
396
                            GlideUrl url = new GlideUrl(dbCapsule.getImage(), new LazyHeaders.Builder()
397
                                    .addHeader(Constants.HTTP_HEADER_ACCEPT, Constants.HTTP_HEADER_ACCEPT_VALUE)
398
                                    .addHeader(Constants.HTTP_HEADER_SECURITY_TOKEN, deviceUuid)
399
                                    .addHeader(Constants.HTTP_HEADER_SECURITY_SECRET, secret)
400
                                    .addHeader(Constants.HTTP_HEADER_SECURITY_CREATED, String.valueOf(created))
401
                                    .addHeader(Constants.HTTP_HEADER_SECURITY_RAND, String.valueOf(rand))
402
                                    .build());
403
 
404
                            RequestOptions options = new RequestOptions()
405
                                    .diskCacheStrategy(DiskCacheStrategy.ALL);
406
 
407
                            Glide.with(getContext()).load(url)
408
                                    .thumbnail()
409
                                    .apply(options)
410
                                    .into(imagetarjeta);
411
                        }
412
                    }
413
 
414
            }
415
 
416
 
417
        }
418
        if(titulotarjeta.getText().equals(""))
419
        {
420
           // Log.e("Nombre","vacio");
421
            SlideDao slideDao = iTwoGetSkills.getDatabase().getSlideDao();
422
 
423
 
424
            //Despues del recorrido no se encontro progreso en ninguna capsula, por lo cual la tarjeta queda vacia
425
            // vamos a llenarla con la ultima capsula, que debe ser nueva al no tener progreso
426
 
427
 
428
            for(Capsule dbCapsule : dbCapsules)
429
            {
430
                List<Slide> slides = slideDao.selectAllByCapsuleUuid(dbCapsule.getUuid());
431
 
432
                if (slides.isEmpty()) {
433
 
434
                } else {
435
                progress = progressDao.selectByCapsuleUuid(dbCapsule.getUuid());
436
 
437
                    //  Log.e("Capsula","Es omitida, no tiene slides");
438
 
439
                    if (progress == null) {
440
 
441
                        //  Log.e("Es nueva","");
442
 
443
                        titulotarjeta.setText(dbCapsule.getName());
444
                        progresotarjeta.setVisibility(View.INVISIBLE);
445
                        progresoporcentaje.setVisibility(View.INVISIBLE);
446
                        empezar.setText("Nueva");
447
                        continuar.setText("Ver cápsula");
448
 
449
                        iTwoGetSkills.getPreference().setOrigennavigation("welcome");
450
 
451
                        int fragmentIdxActive = iTwoGetSkills.getPreference().getFragmentIdxActive();
452
 
453
                        if (fragmentIdxActive != Constants.IDX_FRAGMENT_WELCOME
454
                        ) {
455
                            return;
456
                        }
14 gabriel 457
                        iTwoGetSkills.setCapsulaActiva(dbCapsule.getUuid());
1 gabriel 458
                      //  Log.e("La capsula","activa en load"+dbCapsule.getUuid());
459
                        iTwoGetSkills.getPreference().setTopicUuidActive(dbCapsule.getTopicUuid());
460
 
461
                        if (dbCapsule.getImage() != null && !dbCapsule.getImage().equals("")) {
462
 
463
                            TimeZone timeZone = TimeZone.getTimeZone("UTC");
464
                            Calendar calendar = Calendar.getInstance(timeZone);
465
                            TimeZone tz = calendar.getTimeZone();
466
                            int created = (int) (calendar.getTimeInMillis() / 1000);
467
 
468
                            Random random = new Random(created);
469
                            int rand = 1000 + random.nextInt(8999);
470
 
471
 
472
                            String deviceUuid = iTwoGetSkills.getPreference().getDeviceUuid();
473
                            String password = iTwoGetSkills.getPreference().getPassword();
474
 
475
 
476
                            String secret = MD5.generar(password + ':' + created + ':' + rand);
477
                            GlideUrl url = new GlideUrl(dbCapsule.getImage(), new LazyHeaders.Builder()
478
                                    .addHeader(Constants.HTTP_HEADER_ACCEPT, Constants.HTTP_HEADER_ACCEPT_VALUE)
479
                                    .addHeader(Constants.HTTP_HEADER_SECURITY_TOKEN, deviceUuid)
480
                                    .addHeader(Constants.HTTP_HEADER_SECURITY_SECRET, secret)
481
                                    .addHeader(Constants.HTTP_HEADER_SECURITY_CREATED, String.valueOf(created))
482
                                    .addHeader(Constants.HTTP_HEADER_SECURITY_RAND, String.valueOf(rand))
483
                                    .build());
484
 
485
                            RequestOptions options = new RequestOptions()
486
                                    .diskCacheStrategy(DiskCacheStrategy.ALL);
487
 
488
                            Glide.with(getContext()).load(url)
489
                                    .thumbnail()
490
                                    .apply(options)
491
                                    .into(imagetarjeta);
492
                        }
493
 
494
                    }
495
                }
496
 
497
            }
498
 
499
 
500
 
501
        }
502
        else if (!titulotarjeta.getText().equals("") && !continues)
503
        {
504
            // Log.e("Nombre","vacio");
505
            SlideDao slideDao = iTwoGetSkills.getDatabase().getSlideDao();
506
 
507
 
508
            //Despues del recorrido no se encontro progreso en ninguna capsula, por lo cual la tarjeta queda vacia
509
            // vamos a llenarla con la ultima capsula, que debe ser nueva al no tener progreso
510
 
511
 
512
            for(Capsule dbCapsule : dbCapsules)
513
            {
514
                List<Slide> slides = slideDao.selectAllByCapsuleUuid(dbCapsule.getUuid());
515
 
516
                if (slides.isEmpty()) {
517
 
518
                } else {
519
                    progress = progressDao.selectByCapsuleUuid(dbCapsule.getUuid());
520
 
521
                    //  Log.e("Capsula","Es omitida, no tiene slides");
522
 
523
                    if (progress == null) {
524
 
525
                        //  Log.e("Es nueva","");
526
 
527
                        titulotarjeta.setText(dbCapsule.getName());
528
                        progresotarjeta.setVisibility(View.INVISIBLE);
529
                        progresoporcentaje.setVisibility(View.INVISIBLE);
530
                        empezar.setText("Nueva");
531
                        continuar.setText("Ver cápsula");
532
 
533
                        iTwoGetSkills.getPreference().setOrigennavigation("welcome");
534
 
535
 
536
                        int fragmentIdxActive = iTwoGetSkills.getPreference().getFragmentIdxActive();
537
 
538
                        if (fragmentIdxActive != Constants.IDX_FRAGMENT_WELCOME
539
                        ) {
540
                            return;
541
                        }
14 gabriel 542
                        iTwoGetSkills.setCapsulaActiva(dbCapsule.getUuid());
1 gabriel 543
                       // Log.e("La capsula","activa en load"+dbCapsule.getUuid());
544
                        iTwoGetSkills.getPreference().setTopicUuidActive(dbCapsule.getTopicUuid());
545
 
546
                        if (dbCapsule.getImage() != null && !dbCapsule.getImage().equals("")) {
547
 
548
                            TimeZone timeZone = TimeZone.getTimeZone("UTC");
549
                            Calendar calendar = Calendar.getInstance(timeZone);
550
                            TimeZone tz = calendar.getTimeZone();
551
                            int created = (int) (calendar.getTimeInMillis() / 1000);
552
 
553
                            Random random = new Random(created);
554
                            int rand = 1000 + random.nextInt(8999);
555
 
556
 
557
                            String deviceUuid = iTwoGetSkills.getPreference().getDeviceUuid();
558
                            String password = iTwoGetSkills.getPreference().getPassword();
559
 
560
 
561
                            String secret = MD5.generar(password + ':' + created + ':' + rand);
562
                            GlideUrl url = new GlideUrl(dbCapsule.getImage(), new LazyHeaders.Builder()
563
                                    .addHeader(Constants.HTTP_HEADER_ACCEPT, Constants.HTTP_HEADER_ACCEPT_VALUE)
564
                                    .addHeader(Constants.HTTP_HEADER_SECURITY_TOKEN, deviceUuid)
565
                                    .addHeader(Constants.HTTP_HEADER_SECURITY_SECRET, secret)
566
                                    .addHeader(Constants.HTTP_HEADER_SECURITY_CREATED, String.valueOf(created))
567
                                    .addHeader(Constants.HTTP_HEADER_SECURITY_RAND, String.valueOf(rand))
568
                                    .build());
569
 
570
                            RequestOptions options = new RequestOptions()
571
                                    .diskCacheStrategy(DiskCacheStrategy.ALL);
572
 
573
                            Glide.with(getContext()).load(url)
574
                                    .thumbnail()
575
                                    .apply(options)
576
                                    .into(imagetarjeta);
577
                        }
578
 
579
                    }
580
                }
581
 
582
            }
583
        }
584
 
585
        continuar.setOnClickListener(v -> {
586
 
587
 
588
           // Log.e("Guardo",""+iTwoGetSkills.getPreference().getOrigenNavigation());
14 gabriel 589
           // Log.e("Capsule","active"+iTwoGetSkills.getPreference().getCapsuleUuidActive());
590
 
591
            Progress progresscontinue; ProgressDao progressDaocontinue = iTwoGetSkills.getDatabase().getProgressDao();
592
            progresscontinue = progressDaocontinue.selectByCapsuleUuid(iTwoGetSkills.getCapsuleUuidActive());
593
            if (progresscontinue != null) {
594
                if (progresscontinue.getProgress() >= 100 && progresscontinue.getCompleted() == 1) {
595
                    iTwoGetSkills.invokeFragment(Constants.IDX_FRAGMENT_DETAIL_CAPSULE);
596
                } else {
597
                    iTwoGetSkills.invokeFragment(Constants.IDX_FRAGMENT_SLIDES);
598
                }
599
 
600
                iTwoGetSkills.getPreference().setOrigennavigation("welcome");
601
                iTwoGetSkills.hideKeyboard(v); //Ocultamos el teclado
602
            }
603
            else
604
            {
605
                iTwoGetSkills.invokeFragment(Constants.IDX_FRAGMENT_SLIDES);
606
 
607
            }
1 gabriel 608
        });
609
 
610
        //Fin de primer tarjeta
611
 
612
    }
613
 
614
    private void loadData(String tabposition, String buscar)
615
    {
616
 
617
 
618
        TopicDao topicDao = iTwoGetSkills.getDatabase().getTopicDao();
619
        ArrayList<Topic> dbTopics = (ArrayList<Topic>) topicDao.selectAll();
620
 
621
        List<Capsule> dbCapsules;
622
        CapsuleDao capsuleDao = iTwoGetSkills.getDatabase().getCapsuleDao();
623
 
624
        ProgressDao progressDao = iTwoGetSkills.getDatabase().getProgressDao();
625
        SlideDao slideDao = iTwoGetSkills.getDatabase().getSlideDao();
626
 
627
 
628
        if (tabposition.equals("pendientes"))
629
        {
630
            for (Topic dbTopic : dbTopics) {
631
 
632
                dbCapsules = capsuleDao.selectAllByTopicUuidandOrder(dbTopic.getUuid());
633
 
634
                Capsule capsule;
635
                Progress progress;
636
 
637
                HashMap<String, String> m_li;
638
 
639
 
640
 
641
                for(Capsule dbCapsule : dbCapsules) {
642
                    capsule = new Capsule();
643
                    capsule.setTopicUuid(dbCapsule.getTopicUuid());
644
                    capsule.setUuid(dbCapsule.getUuid());
645
                    capsule.setName(dbCapsule.getName());
646
                    capsule.setDescription(dbCapsule.getDescription());
647
                    capsule.setImage(dbCapsule.getImage());
648
                    capsule.setPosition(dbCapsule.getPosition());
649
                    capsule.setUpdatedOn(dbCapsule.getUpdatedOn());
650
 
651
                    m_li = new HashMap<>();
652
 
653
 
654
                    //m_li.put("copyright",copy);
655
 
656
                    progress = progressDao.selectByCapsuleUuid(capsule.getUuid());
657
 
658
                    if (progress != null) {
659
                        capsule.setCompleted(progress.getCompleted());
660
                        capsule.setViewSlides(progress.getViewSlides());
661
 
662
                        capsule.setTotalSlides(progress.getTotalSlides());
663
                        capsule.setProgress(progress.getProgress());
664
                        capsule.setAddedOn(progress.getAddedOn());
665
 
666
                        // Log.e("Agregado en"," "+progress.getAddedOn());
667
                        // m_li.put("addedon",progress.getAddedOn());
668
                        m_li.put("view", String.valueOf(progress.getViewSlides()));
669
                        m_li.put("total", String.valueOf(progress.getTotalSlides()));
670
                        m_li.put("progress", String.valueOf(progress.getProgress()));
671
                        m_li.put("completado",String.valueOf(progress.getCompleted()));
672
                        m_li.put("agregado",progress.getAddedOn());
673
 
674
                    }
675
 
676
                    m_li.put("imagen", capsule.getImage());
677
                    m_li.put("nombre", capsule.getName());
678
                    m_li.put("uuid", capsule.getUuid());
679
                    m_li.put("topicuuid", capsule.getTopicUuid());
680
                    m_li.put("description", capsule.getDescription());
681
 
682
 
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
 
693
                        if (progress == null) {
694
 
695
                            if (buscar.equals("")) {
696
 
697
                                capsuleList.add(m_li);
698
 
699
 
700
                            } else {
701
                                String nombre= capsule.getName();
702
                                String normalizada= Normalizer.normalize(nombre, Normalizer.Form.NFD);
703
                                normalizada= normalizada.replaceAll("[^\\p{ASCII}]", "");
704
                                if (normalizada.matches("(?i).*" + buscar + ".*")) {
705
                                    capsuleList.add(m_li);
706
                                }
707
 
708
                            }
709
 
710
                        }
711
 
712
                    }
713
 
714
                }
715
 
716
 
717
 
718
            }
719
 
720
        }
721
        else if (tabposition.equals("cursando"))
722
        {
723
 
724
                HashMap<String, String> m_li;
725
                List<Progress> progress;
726
                Capsule capsule;
727
 
728
 
729
 
730
            progress = progressDao.selectAllCapsulesProgress();
731
 
732
                for(Progress dbProgress : progress) {
733
                    m_li = new HashMap<>();
734
 
735
                    capsule = capsuleDao.selectByUuid(dbProgress.getCapsuleUuid());
736
 
737
                    m_li.put("view", String.valueOf(dbProgress.getViewSlides()));
738
                    m_li.put("total", String.valueOf(dbProgress.getTotalSlides()));
739
                    m_li.put("progress", String.valueOf(dbProgress.getProgress()));
740
                    m_li.put("completado",String.valueOf(dbProgress.getCompleted()));
741
                    m_li.put("agregado",dbProgress.getAddedOn());
742
 
743
 
6 gabriel 744
                    if(capsule == null)
745
                    {
746
                        Log.e("El objeto es"," nulo");
747
                    }
748
                    else {
749
                        m_li.put("imagen", capsule.getImage());
750
                        m_li.put("nombre", capsule.getName());
751
                        m_li.put("uuid", capsule.getUuid());
752
                        m_li.put("topicuuid", capsule.getTopicUuid());
753
                        m_li.put("description", capsule.getDescription());
1 gabriel 754
 
755
 
6 gabriel 756
 
1 gabriel 757
                    //Log.e("Lista",""+m_li);
758
                    //Lleno la lista segun el requerimiento de filtro accionado por el usuario
759
 
760
                    List<Slide> slides = slideDao.selectAllByCapsuleUuid(capsule.getUuid());
761
 
762
                    if (slides.isEmpty()) {
763
 
764
                        //  Log.e("Capsula","Es omitida, no tiene slides");
765
                    } else {
766
 
767
            if(dbProgress.getProgress() <= 100 && dbProgress.getCompleted()==0)
768
            {
769
            if (buscar.equals("")) {
770
                capsuleList.add(m_li);
771
 
772
            } else {
773
                String nombre= capsule.getName();
774
                String normalizada= Normalizer.normalize(nombre, Normalizer.Form.NFD);
775
                normalizada= normalizada.replaceAll("[^\\p{ASCII}]", "");
776
                if (normalizada.matches("(?i).*" + buscar + ".*")) {
777
                    capsuleList.add(m_li);
778
                }
779
 
780
            }
781
        }}
6 gabriel 782
                }}}
1 gabriel 783
 
784
       else if (tabposition.equals("finalizados")){
785
 
786
            HashMap<String, String> m_li;
787
            List<Progress> progress;
788
            Capsule capsule;
789
 
790
 
791
 
792
            progress = progressDao.selectAllCapsulesProgress();
793
 
794
            for(Progress dbProgress : progress) {
795
                m_li = new HashMap<>();
796
 
797
                capsule = capsuleDao.selectByUuid(dbProgress.getCapsuleUuid());
798
 
799
                m_li.put("view", String.valueOf(dbProgress.getViewSlides()));
800
                m_li.put("total", String.valueOf(dbProgress.getTotalSlides()));
801
                m_li.put("progress", String.valueOf(dbProgress.getProgress()));
802
                m_li.put("completado",String.valueOf(dbProgress.getCompleted()));
803
                m_li.put("agregado",dbProgress.getAddedOn());
804
 
6 gabriel 805
                if(capsule == null)
806
                {
807
                    Log.e("El objeto esta", "nulo");
808
                }
809
                else{
1 gabriel 810
 
811
                m_li.put("imagen", capsule.getImage());
812
                m_li.put("nombre", capsule.getName());
813
                m_li.put("uuid", capsule.getUuid());
814
                m_li.put("topicuuid", capsule.getTopicUuid());
815
                m_li.put("description", capsule.getDescription());
816
 
817
                //Lleno la lista segun el requerimiento de filtro accionado por el usuario
818
 
819
                    List<Slide> slides = slideDao.selectAllByCapsuleUuid(capsule.getUuid());
820
 
821
                    if (slides.isEmpty()) {
822
 
823
                        //  Log.e("Capsula","Es omitida, no tiene slides");
824
                    } else {
825
           if(dbProgress.getProgress() >= 100 && dbProgress.getCompleted()==1){
826
 
827
               if (buscar.equals("")) {
828
                   //capsule.getCompleted();
829
                   capsuleList.add(m_li);
830
 
831
               } else {
832
                   String nombre= capsule.getName();
833
                   String normalizada= Normalizer.normalize(nombre, Normalizer.Form.NFD);
834
                   normalizada= normalizada.replaceAll("[^\\p{ASCII}]", "");
835
                   if (normalizada.matches("(?i).*" + buscar + ".*")) {
836
                       capsuleList.add(m_li);
837
                   }
838
 
839
               }
840
           }
841
    }
6 gabriel 842
                }}}
1 gabriel 843
 
844
 
14 gabriel 845
       if(capsuleList.size() == 0)
846
       {
847
           ningunelemento.setVisibility(View.VISIBLE);
848
       }
849
       else
850
       {
851
           ningunelemento.setVisibility(View.GONE);
852
       }
853
 
1 gabriel 854
    }
855
 
856
 
857
    @Override
858
    public void onItemClick(int position, View v) {
859
 
14 gabriel 860
        iTwoGetSkills.setCapsulaActiva(capsuleList.get(position).get("uuid"));
861
        iTwoGetSkills.getPreference().setTopicUuidActive(capsuleList.get(position).get("topicuuid"));
1 gabriel 862
 
14 gabriel 863
        Progress progress; ProgressDao progressDao = iTwoGetSkills.getDatabase().getProgressDao();
864
        progress = progressDao.selectByCapsuleUuid(capsuleList.get(position).get("uuid"));
1 gabriel 865
 
14 gabriel 866
        if (progress != null) {
867
            if (progress.getProgress() >= 100 && progress.getCompleted() == 1) {
868
                iTwoGetSkills.invokeFragment(Constants.IDX_FRAGMENT_DETAIL_CAPSULE);
869
            } else {
870
                iTwoGetSkills.invokeFragment(Constants.IDX_FRAGMENT_SLIDES);
871
            }
1 gabriel 872
 
14 gabriel 873
            iTwoGetSkills.getPreference().setOrigennavigation("welcome");
874
            iTwoGetSkills.hideKeyboard(v); //Ocultamos el teclado
875
        }
876
        else
877
        {
878
            iTwoGetSkills.invokeFragment(Constants.IDX_FRAGMENT_SLIDES);
1 gabriel 879
 
14 gabriel 880
        }
1 gabriel 881
    }
14 gabriel 882
}