Proyectos de Subversion Android Microlearning - Nuevo Interface

Rev

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