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