Proyectos de Subversion Android Microlearning - Nuevo Interface

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
2 gabriel 1
package com.cesams.twogetskills.fragment;
2
 
3
import android.os.Bundle;
4
 
5
import androidx.fragment.app.Fragment;
6
import androidx.lifecycle.LifecycleOwner;
7
import androidx.recyclerview.widget.GridLayoutManager;
8
import androidx.recyclerview.widget.RecyclerView;
9
 
13 gabriel 10
import android.text.Editable;
11
import android.text.TextWatcher;
2 gabriel 12
import android.util.Log;
13
import android.view.LayoutInflater;
14
import android.view.View;
15
import android.view.ViewGroup;
9 gabriel 16
import android.widget.Button;
8 gabriel 17
import android.widget.EditText;
9 gabriel 18
import android.widget.ImageView;
19
import android.widget.ProgressBar;
2 gabriel 20
import android.widget.TextView;
46 gabriel 21
import android.widget.Toast;
2 gabriel 22
 
9 gabriel 23
import com.bumptech.glide.Glide;
24
import com.bumptech.glide.load.engine.DiskCacheStrategy;
25
import com.bumptech.glide.load.model.GlideUrl;
26
import com.bumptech.glide.load.model.LazyHeaders;
27
import com.bumptech.glide.request.RequestOptions;
28
import com.cesams.twogetskills.Constants;
2 gabriel 29
import com.cesams.twogetskills.R;
4 gabriel 30
import com.cesams.twogetskills.adapter.TabsCapsulesAdapter;
2 gabriel 31
import com.cesams.twogetskills.dao.CapsuleDao;
32
import com.cesams.twogetskills.dao.ProgressDao;
16 gabriel 33
import com.cesams.twogetskills.dao.SlideDao;
2 gabriel 34
import com.cesams.twogetskills.dao.TopicDao;
35
import com.cesams.twogetskills.entity.Capsule;
36
import com.cesams.twogetskills.entity.Progress;
16 gabriel 37
import com.cesams.twogetskills.entity.Slide;
2 gabriel 38
import com.cesams.twogetskills.entity.Topic;
9 gabriel 39
import com.cesams.twogetskills.library.MD5;
2 gabriel 40
import com.cesams.twogetskills.skeleton.ITwoGetSkills;
12 gabriel 41
import com.google.android.material.tabs.TabLayout;
2 gabriel 42
 
21 gabriel 43
import java.text.Normalizer;
2 gabriel 44
import java.util.ArrayList;
9 gabriel 45
import java.util.Calendar;
2 gabriel 46
import java.util.HashMap;
47
import java.util.List;
9 gabriel 48
import java.util.Random;
49
import java.util.TimeZone;
2 gabriel 50
 
51
/**
52
 * A simple {@link Fragment} subclass.
53
 * Use the {@link WelcomeFragment#newInstance} factory method to
54
 * create an instance of this fragment.
55
 */
17 gabriel 56
public class WelcomeFragment extends Fragment implements TabsCapsulesAdapter.ClickListener, LifecycleOwner {
2 gabriel 57
 
66 gabriel 58
    TextView username, titulotarjeta, progresoporcentaje, empezar, ningunelemento; ProgressBar progresotarjeta;
9 gabriel 59
    private ITwoGetSkills iTwoGetSkills; View card;
2 gabriel 60
    ArrayList<HashMap<String, String>> capsuleList;
11 gabriel 61
    ImageView imagetarjeta;
62
    TabsCapsulesAdapter adapter2;
63
    RecyclerView categorizados;
9 gabriel 64
    EditText busqueda; TextView textowelcome; Button continuar;
65 gabriel 65
    TabLayout tabs; String tabactual="pendientes";
2 gabriel 66
 
17 gabriel 67
 
2 gabriel 68
    public WelcomeFragment() {
69
        // Required empty public constructor
70
    }
71
 
72
    public static WelcomeFragment newInstance() {
73
        WelcomeFragment fragment = new WelcomeFragment();
74
        return fragment;
75
    }
76
 
77
    @Override
78
    public void onCreate(Bundle savedInstanceState) {
79
        super.onCreate(savedInstanceState);
80
          }
81
 
82
    @Override
83
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
84
                             Bundle savedInstanceState) {
85
 
8 gabriel 86
 
2 gabriel 87
        iTwoGetSkills = (ITwoGetSkills) getActivity();
88
 
56 gabriel 89
 
2 gabriel 90
        View view= inflater.inflate(R.layout.fragment_welcome, container, false);
91
 
66 gabriel 92
        username=view.findViewById(R.id.textView14); ningunelemento=view.findViewById(R.id.textView25);
8 gabriel 93
        textowelcome= view.findViewById(R.id.textView15);
94
        busqueda=view.findViewById(R.id.busqueda);
12 gabriel 95
        card= view.findViewById(R.id.include); empezar= view.findViewById(R.id.titlenotifi); tabs=view.findViewById(R.id.tabLayout);
8 gabriel 96
        capsuleList = new ArrayList<>();
2 gabriel 97
 
17 gabriel 98
 
9 gabriel 99
        //Tarjeta Principal
11 gabriel 100
        titulotarjeta = view.findViewById(R.id.description); progresotarjeta= view.findViewById(R.id.progressBar2); imagetarjeta= view.findViewById(R.id.imagelist);
9 gabriel 101
        continuar = view.findViewById(R.id.button); progresoporcentaje = view.findViewById(R.id.textView16);
102
 
103
 
2 gabriel 104
        username.setText("¡Hola, "+(iTwoGetSkills.getPreference().getFirstName() +"!"));
105
 
12 gabriel 106
        tabs.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
107
            @Override
108
            public void onTabSelected(TabLayout.Tab tab) {
109
                int position=tab.getPosition();
2 gabriel 110
 
12 gabriel 111
                capsuleList.clear();
112
                adapter2.notifyDataSetChanged();
2 gabriel 113
 
12 gabriel 114
                if(position==0)
115
                {
13 gabriel 116
                    tabactual="pendientes";
117
                    loadData(tabactual,"");
12 gabriel 118
                    adapter2.notifyDataSetChanged();
119
                }
120
                else if(position==1)
121
                {
13 gabriel 122
                    tabactual="cursando";
123
                    loadData("cursando","");
12 gabriel 124
                    adapter2.notifyDataSetChanged();
125
                }
126
                else if(position==2)
127
                {
13 gabriel 128
                    tabactual="finalizados";
129
                    loadData("finalizados","");
12 gabriel 130
                    adapter2.notifyDataSetChanged();
131
                }
132
            }
133
 
134
            @Override
135
            public void onTabUnselected(TabLayout.Tab tab) {
136
 
137
            }
138
 
139
            @Override
140
            public void onTabReselected(TabLayout.Tab tab) {
141
 
142
            }
143
        });
144
 
13 gabriel 145
        loadData("pendientes","");
12 gabriel 146
 
8 gabriel 147
        busqueda.setOnFocusChangeListener(new View.OnFocusChangeListener() {
148
            @Override
149
            public void onFocusChange(View v, boolean hasFocus) {
150
                if(hasFocus)
151
                {
9 gabriel 152
                        card.setVisibility(View.GONE);
8 gabriel 153
                        username.setVisibility(View.GONE);
154
                        textowelcome.setVisibility(View.GONE);
34 gabriel 155
                        Log.e("Tengo foco"," Oculto");
8 gabriel 156
                }
157
 
158
            }
159
        });
160
 
13 gabriel 161
        busqueda.addTextChangedListener(new TextWatcher() {
162
            @Override
163
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
8 gabriel 164
 
13 gabriel 165
            }
166
 
167
            @Override
168
            public void onTextChanged(CharSequence s, int start, int before, int count) {
17 gabriel 169
            //    Log.e("El texto","buscado: "+s);
13 gabriel 170
                capsuleList.clear();
171
                adapter2.notifyDataSetChanged();
172
                loadData(tabactual, s.toString());
173
            }
174
 
175
            @Override
176
            public void afterTextChanged(Editable s) {
177
 
178
 
179
 
180
            }
181
        });
182
 
183
 
4 gabriel 184
        adapter2 = new TabsCapsulesAdapter(getContext(),capsuleList);
2 gabriel 185
 
186
 
187
 
4 gabriel 188
        categorizados = view.findViewById(R.id.categorizados);
189
        GridLayoutManager layoutcategoria = new GridLayoutManager(getContext(),1,GridLayoutManager.VERTICAL, false);
190
        categorizados.setLayoutManager(layoutcategoria);
191
        categorizados.setAdapter(adapter2);
192
 
11 gabriel 193
 
17 gabriel 194
        adapter2.setClickListener(this);
11 gabriel 195
 
8 gabriel 196
        categorizados.setOnFlingListener(new RecyclerView.OnFlingListener() {
197
            @Override
198
            public boolean onFling(int velocityX, int velocityY) {
199
 
200
                if (categorizados.canScrollVertically(-1) ) {
201
 
17 gabriel 202
                   // Log.e("Se activa", "On fling");
9 gabriel 203
                    card.setVisibility(View.GONE);
8 gabriel 204
                    username.setVisibility(View.GONE);
205
                    textowelcome.setVisibility(View.GONE);
206
                }else
207
                {
9 gabriel 208
                    card.setVisibility(View.VISIBLE);
8 gabriel 209
                    username.setVisibility(View.VISIBLE);
210
                    textowelcome.setVisibility(View.VISIBLE);
211
                }
212
 
213
                return false;
214
            }
215
        });
216
 
11 gabriel 217
 
8 gabriel 218
     /*   categorizados.setOnScrollChangeListener(new View.OnScrollChangeListener() {
219
            @Override
220
            public void onScrollChange(View v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {
221
 
222
                if (!categorizados.canScrollVertically(-1)) {
223
                 //   Toast.makeText(getActivity(), "Last", Toast.LENGTH_LONG).show();
224
                    capsulas.setVisibility(View.VISIBLE);
225
                    username.setVisibility(View.VISIBLE);
226
                    textowelcome.setVisibility(View.VISIBLE);
227
                    Log.e("On scroll"," se activa");
228
                }
229
 
230
            }
231
        });
232
*/
21 gabriel 233
        getActivity().runOnUiThread(() -> {
234
            String message = capsuleList.size() == 1
235
                    ? "Hay 1 cápsula nueva disponible"
236
                    : "Tiene " + capsuleList.size() + " cápsulas pendientes para ver";
237
 
46 gabriel 238
            Toast.makeText(getContext(), ""+message, Toast.LENGTH_LONG).show();
25 gabriel 239
 
53 gabriel 240
            iTwoGetSkills.saveNotificationCenter("Contenidos disponibles","",message);
241
 
21 gabriel 242
        });
56 gabriel 243
        iTwoGetSkills.showNavigationAndToolbar();
244
 
2 gabriel 245
        return view;
246
    }
247
 
9 gabriel 248
    @Override
249
    public void onResume() {
250
        super.onResume();
38 gabriel 251
        getActivity().runOnUiThread(() -> {
67 gabriel 252
 
253
            int fragmentIdxActive = iTwoGetSkills.getPreference().getFragmentIdxActive();
254
 
255
            if (fragmentIdxActive != Constants.IDX_FRAGMENT_WELCOME
256
            ) {
257
                return;
258
            }
38 gabriel 259
            loadContinuecard();
260
        });
9 gabriel 261
    }
2 gabriel 262
 
9 gabriel 263
    @Override
264
    public void onHiddenChanged(boolean hidden) {
265
        super.onHiddenChanged(hidden);
266
 
17 gabriel 267
       // Log.e("TAG", "onHiddenChanged : " + (hidden ? "true" : "false"));
9 gabriel 268
 
269
        if(!hidden) {
27 gabriel 270
          //  Log.e("Esta oculto", "el fragmento");
16 gabriel 271
 
272
            getActivity().runOnUiThread(() -> {
273
 
274
                capsuleList.clear();
275
 
276
                loadContinuecard();
277
                loadData("pendientes","");
278
 
66 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
                }
16 gabriel 292
                adapter2.notifyDataSetChanged();
293
 
294
 
295
            });
296
 
297
 
9 gabriel 298
        }
299
    }
300
 
301
    private void loadContinuecard(){
302
 
66 gabriel 303
        Log.e("Cargo datos"," en tarjeta principal");
9 gabriel 304
 
305
        //Capsula de primera tarjeta
306
        CapsuleDao capsuleDao = iTwoGetSkills.getDatabase().getCapsuleDao();
39 gabriel 307
        boolean continues=false;
9 gabriel 308
        Progress progress;
309
        ProgressDao progressDao = iTwoGetSkills.getDatabase().getProgressDao();
310
 
17 gabriel 311
 
9 gabriel 312
        List<Capsule> dbCapsules= capsuleDao.selectAll();
313
        for(Capsule dbCapsule : dbCapsules)
314
        {
315
            progress = progressDao.selectByCapsuleUuid(dbCapsule.getUuid());
316
 
317
            if (progress != null) {
66 gabriel 318
              //  Log.e("Capsula para"," continuar "+dbCapsule.getUuid());
9 gabriel 319
 
66 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) {
43 gabriel 358
                       // Log.e("Es menor"," a 100");
39 gabriel 359
                        continues=true;
9 gabriel 360
                        titulotarjeta.setText(dbCapsule.getName());
10 gabriel 361
                        progresotarjeta.setVisibility(View.VISIBLE);
362
                        progresoporcentaje.setVisibility(View.VISIBLE);
9 gabriel 363
                        progresotarjeta.setProgress((int) progress.getProgress());
364
                        progresoporcentaje.setText("" + progress.getProgress() + " %");
10 gabriel 365
                        empezar.setText("En curso");
9 gabriel 366
 
39 gabriel 367
                        iTwoGetSkills.getPreference().setOrigennavigation("welcome");
368
 
38 gabriel 369
                        int fragmentIdxActive = iTwoGetSkills.getPreference().getFragmentIdxActive();
370
 
371
                        if (fragmentIdxActive != Constants.IDX_FRAGMENT_WELCOME
372
                        ) {
373
                            return;
374
                        }
65 gabriel 375
                        iTwoGetSkills.setCapsulaActiva(dbCapsule.getUuid());
38 gabriel 376
                     //   Log.e("La capsula","activa en loadcurso"+dbCapsule.getUuid());
377
 
26 gabriel 378
                        iTwoGetSkills.getPreference().setTopicUuidActive(dbCapsule.getTopicUuid());
9 gabriel 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
 
10 gabriel 414
            }
415
 
416
 
417
        }
418
        if(titulotarjeta.getText().equals(""))
419
        {
17 gabriel 420
           // Log.e("Nombre","vacio");
37 gabriel 421
            SlideDao slideDao = iTwoGetSkills.getDatabase().getSlideDao();
10 gabriel 422
 
37 gabriel 423
 
10 gabriel 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
 
38 gabriel 427
 
10 gabriel 428
            for(Capsule dbCapsule : dbCapsules)
429
            {
37 gabriel 430
                List<Slide> slides = slideDao.selectAllByCapsuleUuid(dbCapsule.getUuid());
10 gabriel 431
 
37 gabriel 432
                if (slides.isEmpty()) {
433
 
434
                } else {
10 gabriel 435
                progress = progressDao.selectByCapsuleUuid(dbCapsule.getUuid());
38 gabriel 436
 
37 gabriel 437
                    //  Log.e("Capsula","Es omitida, no tiene slides");
10 gabriel 438
 
37 gabriel 439
                    if (progress == null) {
10 gabriel 440
 
37 gabriel 441
                        //  Log.e("Es nueva","");
10 gabriel 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
 
39 gabriel 449
                        iTwoGetSkills.getPreference().setOrigennavigation("welcome");
450
 
38 gabriel 451
                        int fragmentIdxActive = iTwoGetSkills.getPreference().getFragmentIdxActive();
10 gabriel 452
 
38 gabriel 453
                        if (fragmentIdxActive != Constants.IDX_FRAGMENT_WELCOME
454
                        ) {
455
                            return;
456
                        }
65 gabriel 457
                        iTwoGetSkills.setCapsulaActiva(dbCapsule.getUuid());
38 gabriel 458
                      //  Log.e("La capsula","activa en load"+dbCapsule.getUuid());
37 gabriel 459
                        iTwoGetSkills.getPreference().setTopicUuidActive(dbCapsule.getTopicUuid());
26 gabriel 460
 
37 gabriel 461
                        if (dbCapsule.getImage() != null && !dbCapsule.getImage().equals("")) {
10 gabriel 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
                    }
37 gabriel 495
                }
10 gabriel 496
 
38 gabriel 497
            }
10 gabriel 498
 
499
 
500
 
38 gabriel 501
        }
39 gabriel 502
        else if (!titulotarjeta.getText().equals("") && !continues)
38 gabriel 503
        {
504
            // Log.e("Nombre","vacio");
505
            SlideDao slideDao = iTwoGetSkills.getDatabase().getSlideDao();
10 gabriel 506
 
38 gabriel 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
 
10 gabriel 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
 
39 gabriel 533
                        iTwoGetSkills.getPreference().setOrigennavigation("welcome");
534
 
535
 
38 gabriel 536
                        int fragmentIdxActive = iTwoGetSkills.getPreference().getFragmentIdxActive();
537
 
538
                        if (fragmentIdxActive != Constants.IDX_FRAGMENT_WELCOME
539
                        ) {
540
                            return;
541
                        }
65 gabriel 542
                        iTwoGetSkills.setCapsulaActiva(dbCapsule.getUuid());
38 gabriel 543
                       // Log.e("La capsula","activa en load"+dbCapsule.getUuid());
10 gabriel 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
                    }
9 gabriel 580
                }
38 gabriel 581
 
10 gabriel 582
            }
9 gabriel 583
        }
584
 
26 gabriel 585
        continuar.setOnClickListener(v -> {
10 gabriel 586
 
587
 
23 gabriel 588
           // Log.e("Guardo",""+iTwoGetSkills.getPreference().getOrigenNavigation());
65 gabriel 589
           // Log.e("Capsule","active"+iTwoGetSkills.getPreference().getCapsuleUuidActive());
63 gabriel 590
 
591
            Progress progresscontinue; ProgressDao progressDaocontinue = iTwoGetSkills.getDatabase().getProgressDao();
65 gabriel 592
            progresscontinue = progressDaocontinue.selectByCapsuleUuid(iTwoGetSkills.getCapsuleUuidActive());
63 gabriel 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
            }
9 gabriel 608
        });
609
 
610
        //Fin de primer tarjeta
611
 
612
    }
613
 
13 gabriel 614
    private void loadData(String tabposition, String buscar)
2 gabriel 615
    {
616
 
12 gabriel 617
 
2 gabriel 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
 
24 gabriel 624
        ProgressDao progressDao = iTwoGetSkills.getDatabase().getProgressDao();
625
        SlideDao slideDao = iTwoGetSkills.getDatabase().getSlideDao();
9 gabriel 626
 
627
 
24 gabriel 628
        if (tabposition.equals("pendientes"))
629
        {
630
            for (Topic dbTopic : dbTopics) {
9 gabriel 631
 
24 gabriel 632
                dbCapsules = capsuleDao.selectAllByTopicUuidandOrder(dbTopic.getUuid());
2 gabriel 633
 
24 gabriel 634
                Capsule capsule;
635
                Progress progress;
2 gabriel 636
 
24 gabriel 637
                HashMap<String, String> m_li;
9 gabriel 638
 
2 gabriel 639
 
640
 
24 gabriel 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());
9 gabriel 650
 
24 gabriel 651
                    m_li = new HashMap<>();
9 gabriel 652
 
2 gabriel 653
 
24 gabriel 654
                    //m_li.put("copyright",copy);
2 gabriel 655
 
24 gabriel 656
                    progress = progressDao.selectByCapsuleUuid(capsule.getUuid());
2 gabriel 657
 
24 gabriel 658
                    if (progress != null) {
659
                        capsule.setCompleted(progress.getCompleted());
660
                        capsule.setViewSlides(progress.getViewSlides());
2 gabriel 661
 
24 gabriel 662
                        capsule.setTotalSlides(progress.getTotalSlides());
663
                        capsule.setProgress(progress.getProgress());
664
                        capsule.setAddedOn(progress.getAddedOn());
2 gabriel 665
 
24 gabriel 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());
2 gabriel 673
 
24 gabriel 674
                    }
2 gabriel 675
 
24 gabriel 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());
16 gabriel 681
 
18 gabriel 682
 
24 gabriel 683
                    //Lleno la lista segun el requerimiento de filtro accionado por el usuario
2 gabriel 684
 
24 gabriel 685
                    List<Slide> slides = slideDao.selectAllByCapsuleUuid(capsule.getUuid());
2 gabriel 686
 
24 gabriel 687
                    if (slides.isEmpty()) {
13 gabriel 688
 
24 gabriel 689
                        //  Log.e("Capsula","Es omitida, no tiene slides");
690
                    } else {
2 gabriel 691
 
12 gabriel 692
 
24 gabriel 693
                        if (progress == null) {
18 gabriel 694
 
24 gabriel 695
                            if (buscar.equals("")) {
18 gabriel 696
 
24 gabriel 697
                                capsuleList.add(m_li);
16 gabriel 698
 
13 gabriel 699
 
24 gabriel 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
                                }
21 gabriel 707
 
16 gabriel 708
                            }
13 gabriel 709
 
16 gabriel 710
                        }
12 gabriel 711
 
24 gabriel 712
                    }
12 gabriel 713
 
24 gabriel 714
                }
16 gabriel 715
 
716
 
13 gabriel 717
 
24 gabriel 718
            }
13 gabriel 719
 
24 gabriel 720
        }
721
        else if (tabposition.equals("cursando"))
722
        {
2 gabriel 723
 
24 gabriel 724
                HashMap<String, String> m_li;
725
                List<Progress> progress;
726
                Capsule capsule;
2 gabriel 727
 
13 gabriel 728
 
729
 
24 gabriel 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
 
56 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());
24 gabriel 754
 
755
 
56 gabriel 756
 
24 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);
12 gabriel 778
                }
2 gabriel 779
 
12 gabriel 780
            }
24 gabriel 781
        }}
56 gabriel 782
                }}}
2 gabriel 783
 
24 gabriel 784
       else if (tabposition.equals("finalizados")){
12 gabriel 785
 
24 gabriel 786
            HashMap<String, String> m_li;
787
            List<Progress> progress;
788
            Capsule capsule;
2 gabriel 789
 
21 gabriel 790
 
24 gabriel 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
 
56 gabriel 805
                if(capsule == null)
806
                {
807
                    Log.e("El objeto esta", "nulo");
808
                }
809
                else{
24 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
           }
2 gabriel 841
    }
56 gabriel 842
                }}}
2 gabriel 843
 
844
 
66 gabriel 845
       if(capsuleList.size() == 0)
846
       {
847
           ningunelemento.setVisibility(View.VISIBLE);
848
       }
849
       else
850
       {
851
           ningunelemento.setVisibility(View.GONE);
852
       }
853
 
24 gabriel 854
    }
855
 
856
 
17 gabriel 857
    @Override
858
    public void onItemClick(int position, View v) {
859
 
65 gabriel 860
        iTwoGetSkills.setCapsulaActiva(capsuleList.get(position).get("uuid"));
17 gabriel 861
        iTwoGetSkills.getPreference().setTopicUuidActive(capsuleList.get(position).get("topicuuid"));
862
 
63 gabriel 863
        Progress progress; ProgressDao progressDao = iTwoGetSkills.getDatabase().getProgressDao();
864
        progress = progressDao.selectByCapsuleUuid(capsuleList.get(position).get("uuid"));
18 gabriel 865
 
63 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
            }
17 gabriel 872
 
63 gabriel 873
            iTwoGetSkills.getPreference().setOrigennavigation("welcome");
874
            iTwoGetSkills.hideKeyboard(v); //Ocultamos el teclado
875
        }
876
        else
877
        {
878
            iTwoGetSkills.invokeFragment(Constants.IDX_FRAGMENT_SLIDES);
879
 
880
        }
17 gabriel 881
    }
56 gabriel 882
}