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
 
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();
300
        loadContinuecard();
301
    }
2 gabriel 302
 
9 gabriel 303
    @Override
304
    public void onHiddenChanged(boolean hidden) {
305
        super.onHiddenChanged(hidden);
306
 
17 gabriel 307
       // Log.e("TAG", "onHiddenChanged : " + (hidden ? "true" : "false"));
9 gabriel 308
 
309
        if(!hidden) {
27 gabriel 310
          //  Log.e("Esta oculto", "el fragmento");
16 gabriel 311
 
312
            getActivity().runOnUiThread(() -> {
313
 
314
                capsuleList.clear();
315
 
316
                loadContinuecard();
317
                loadData("pendientes","");
318
 
319
                adapter2.notifyDataSetChanged();
320
 
321
                tabs.getTabAt(0).select();
322
 
323
            });
324
 
325
 
9 gabriel 326
        }
327
    }
328
 
329
    private void loadContinuecard(){
330
 
27 gabriel 331
       // Log.e("Cargo datos"," en tarjeta principal");
9 gabriel 332
 
333
        //Capsula de primera tarjeta
334
        CapsuleDao capsuleDao = iTwoGetSkills.getDatabase().getCapsuleDao();
335
 
336
        Progress progress;
337
        ProgressDao progressDao = iTwoGetSkills.getDatabase().getProgressDao();
338
 
17 gabriel 339
 
9 gabriel 340
        List<Capsule> dbCapsules= capsuleDao.selectAll();
341
        for(Capsule dbCapsule : dbCapsules)
342
        {
343
            progress = progressDao.selectByCapsuleUuid(dbCapsule.getUuid());
344
 
345
            if (progress != null) {
346
 
10 gabriel 347
                    if (progress.getProgress() < 100) {
17 gabriel 348
                    //    Log.e("Es menor"," a 100");
9 gabriel 349
 
350
                        titulotarjeta.setText(dbCapsule.getName());
10 gabriel 351
                        progresotarjeta.setVisibility(View.VISIBLE);
352
                        progresoporcentaje.setVisibility(View.VISIBLE);
9 gabriel 353
                        progresotarjeta.setProgress((int) progress.getProgress());
354
                        progresoporcentaje.setText("" + progress.getProgress() + " %");
10 gabriel 355
                        empezar.setText("En curso");
9 gabriel 356
 
26 gabriel 357
                        iTwoGetSkills.getPreference().setCapsuleUuidActive(dbCapsule.getUuid());
358
                        iTwoGetSkills.getPreference().setTopicUuidActive(dbCapsule.getTopicUuid());
359
                        iTwoGetSkills.getPreference().setOrigennavigation("welcome");
9 gabriel 360
 
361
                        if (dbCapsule.getImage() != null && !dbCapsule.getImage().equals("")) {
362
 
363
                            TimeZone timeZone = TimeZone.getTimeZone("UTC");
364
                            Calendar calendar = Calendar.getInstance(timeZone);
365
                            TimeZone tz = calendar.getTimeZone();
366
                            int created = (int) (calendar.getTimeInMillis() / 1000);
367
 
368
                            Random random = new Random(created);
369
                            int rand = 1000 + random.nextInt(8999);
370
 
371
 
372
                            String deviceUuid = iTwoGetSkills.getPreference().getDeviceUuid();
373
                            String password = iTwoGetSkills.getPreference().getPassword();
374
 
375
 
376
                            String secret = MD5.generar(password + ':' + created + ':' + rand);
377
                            GlideUrl url = new GlideUrl(dbCapsule.getImage(), new LazyHeaders.Builder()
378
                                    .addHeader(Constants.HTTP_HEADER_ACCEPT, Constants.HTTP_HEADER_ACCEPT_VALUE)
379
                                    .addHeader(Constants.HTTP_HEADER_SECURITY_TOKEN, deviceUuid)
380
                                    .addHeader(Constants.HTTP_HEADER_SECURITY_SECRET, secret)
381
                                    .addHeader(Constants.HTTP_HEADER_SECURITY_CREATED, String.valueOf(created))
382
                                    .addHeader(Constants.HTTP_HEADER_SECURITY_RAND, String.valueOf(rand))
383
                                    .build());
384
 
385
                            RequestOptions options = new RequestOptions()
386
                                    .diskCacheStrategy(DiskCacheStrategy.ALL);
387
 
388
                            Glide.with(getContext()).load(url)
389
                                    .thumbnail()
390
                                    .apply(options)
391
                                    .into(imagetarjeta);
392
                        }
393
                    }
394
 
10 gabriel 395
            }
396
 
397
 
398
        }
399
 
400
        if(titulotarjeta.getText().equals(""))
401
        {
17 gabriel 402
           // Log.e("Nombre","vacio");
10 gabriel 403
 
404
            //Despues del recorrido no se encontro progreso en ninguna capsula, por lo cual la tarjeta queda vacia
405
            // vamos a llenarla con la ultima capsula, que debe ser nueva al no tener progreso
406
 
407
            for(Capsule dbCapsule : dbCapsules)
408
            {
409
 
410
                progress = progressDao.selectByCapsuleUuid(dbCapsule.getUuid());
411
 
412
                if (progress == null) {
413
 
17 gabriel 414
                      //  Log.e("Es nueva","");
10 gabriel 415
 
416
                        titulotarjeta.setText(dbCapsule.getName());
417
                        progresotarjeta.setVisibility(View.INVISIBLE);
418
                        progresoporcentaje.setVisibility(View.INVISIBLE);
419
                        empezar.setText("Nueva");
420
                        continuar.setText("Ver cápsula");
421
 
422
 
26 gabriel 423
                    iTwoGetSkills.getPreference().setCapsuleUuidActive(dbCapsule.getUuid());
424
                    iTwoGetSkills.getPreference().setTopicUuidActive(dbCapsule.getTopicUuid());
425
                    iTwoGetSkills.getPreference().setOrigennavigation("welcome");
426
 
17 gabriel 427
                    if (dbCapsule.getImage() != null && !dbCapsule.getImage().equals("")) {
10 gabriel 428
 
429
                            TimeZone timeZone = TimeZone.getTimeZone("UTC");
430
                            Calendar calendar = Calendar.getInstance(timeZone);
431
                            TimeZone tz = calendar.getTimeZone();
432
                            int created = (int) (calendar.getTimeInMillis() / 1000);
433
 
434
                            Random random = new Random(created);
435
                            int rand = 1000 + random.nextInt(8999);
436
 
437
 
438
                            String deviceUuid = iTwoGetSkills.getPreference().getDeviceUuid();
439
                            String password = iTwoGetSkills.getPreference().getPassword();
440
 
441
 
442
                            String secret = MD5.generar(password + ':' + created + ':' + rand);
443
                            GlideUrl url = new GlideUrl(dbCapsule.getImage(), new LazyHeaders.Builder()
444
                                    .addHeader(Constants.HTTP_HEADER_ACCEPT, Constants.HTTP_HEADER_ACCEPT_VALUE)
445
                                    .addHeader(Constants.HTTP_HEADER_SECURITY_TOKEN, deviceUuid)
446
                                    .addHeader(Constants.HTTP_HEADER_SECURITY_SECRET, secret)
447
                                    .addHeader(Constants.HTTP_HEADER_SECURITY_CREATED, String.valueOf(created))
448
                                    .addHeader(Constants.HTTP_HEADER_SECURITY_RAND, String.valueOf(rand))
449
                                    .build());
450
 
451
                            RequestOptions options = new RequestOptions()
452
                                    .diskCacheStrategy(DiskCacheStrategy.ALL);
453
 
454
                            Glide.with(getContext()).load(url)
455
                                    .thumbnail()
456
                                    .apply(options)
457
                                    .into(imagetarjeta);
458
                        }
459
 
460
                    }
461
 
462
                /*
463
                if (progress != null) {
464
 
465
                    double progre = progress.getProgress();
466
 
467
                    if (progre >= 100) {
468
                        Log.e("Es mayor"," a 100");
469
 
470
                    } else {
471
 
472
                        Log.e("Es nueva","");
473
 
474
                        titulotarjeta.setText(dbCapsule.getName());
475
                        progresotarjeta.setVisibility(View.INVISIBLE);
476
                        progresoporcentaje.setVisibility(View.INVISIBLE);
477
                        empezar.setText("Nueva");
478
                        continuar.setText("Ver cápsula");
479
 
480
                        iTwoGetSkills.getPreference().setCapsuleUuidActive(dbCapsule.getUuid());
481
                        iTwoGetSkills.getPreference().setTopicUuidActive(dbCapsule.getTopicUuid());
482
 
483
                        if (dbCapsule.getImage() != null && !dbCapsule.getImage().equals("")) {
484
 
485
                            TimeZone timeZone = TimeZone.getTimeZone("UTC");
486
                            Calendar calendar = Calendar.getInstance(timeZone);
487
                            TimeZone tz = calendar.getTimeZone();
488
                            int created = (int) (calendar.getTimeInMillis() / 1000);
489
 
490
                            Random random = new Random(created);
491
                            int rand = 1000 + random.nextInt(8999);
492
 
493
 
494
                            String deviceUuid = iTwoGetSkills.getPreference().getDeviceUuid();
495
                            String password = iTwoGetSkills.getPreference().getPassword();
496
 
497
 
498
                            String secret = MD5.generar(password + ':' + created + ':' + rand);
499
                            GlideUrl url = new GlideUrl(dbCapsule.getImage(), new LazyHeaders.Builder()
500
                                    .addHeader(Constants.HTTP_HEADER_ACCEPT, Constants.HTTP_HEADER_ACCEPT_VALUE)
501
                                    .addHeader(Constants.HTTP_HEADER_SECURITY_TOKEN, deviceUuid)
502
                                    .addHeader(Constants.HTTP_HEADER_SECURITY_SECRET, secret)
503
                                    .addHeader(Constants.HTTP_HEADER_SECURITY_CREATED, String.valueOf(created))
504
                                    .addHeader(Constants.HTTP_HEADER_SECURITY_RAND, String.valueOf(rand))
505
                                    .build());
506
 
507
                            RequestOptions options = new RequestOptions()
508
                                    .diskCacheStrategy(DiskCacheStrategy.ALL);
509
 
510
                            Glide.with(getContext()).load(url)
511
                                    .thumbnail()
512
                                    .apply(options)
513
                                    .into(imagetarjeta);
514
                        }
515
 
516
                    }
9 gabriel 517
                }
10 gabriel 518
*/
519
            }
9 gabriel 520
 
10 gabriel 521
 
522
 
9 gabriel 523
        }
524
 
26 gabriel 525
        continuar.setOnClickListener(v -> {
10 gabriel 526
 
527
 
23 gabriel 528
           // Log.e("Guardo",""+iTwoGetSkills.getPreference().getOrigenNavigation());
17 gabriel 529
 
9 gabriel 530
            iTwoGetSkills.invokeFragment(Constants.IDX_FRAGMENT_SLIDES);
531
        });
532
 
533
        //Fin de primer tarjeta
534
 
535
    }
536
 
13 gabriel 537
    private void loadData(String tabposition, String buscar)
2 gabriel 538
    {
539
 
12 gabriel 540
 
2 gabriel 541
        TopicDao topicDao = iTwoGetSkills.getDatabase().getTopicDao();
542
        ArrayList<Topic> dbTopics = (ArrayList<Topic>) topicDao.selectAll();
543
 
544
        List<Capsule> dbCapsules;
545
        CapsuleDao capsuleDao = iTwoGetSkills.getDatabase().getCapsuleDao();
546
 
24 gabriel 547
        ProgressDao progressDao = iTwoGetSkills.getDatabase().getProgressDao();
548
        SlideDao slideDao = iTwoGetSkills.getDatabase().getSlideDao();
9 gabriel 549
 
550
 
24 gabriel 551
        if (tabposition.equals("pendientes"))
552
        {
553
            for (Topic dbTopic : dbTopics) {
9 gabriel 554
 
24 gabriel 555
                dbCapsules = capsuleDao.selectAllByTopicUuidandOrder(dbTopic.getUuid());
2 gabriel 556
 
24 gabriel 557
                Capsule capsule;
558
                Progress progress;
2 gabriel 559
 
24 gabriel 560
                HashMap<String, String> m_li;
9 gabriel 561
 
2 gabriel 562
 
563
 
24 gabriel 564
                for(Capsule dbCapsule : dbCapsules) {
565
                    capsule = new Capsule();
566
                    capsule.setTopicUuid(dbCapsule.getTopicUuid());
567
                    capsule.setUuid(dbCapsule.getUuid());
568
                    capsule.setName(dbCapsule.getName());
569
                    capsule.setDescription(dbCapsule.getDescription());
570
                    capsule.setImage(dbCapsule.getImage());
571
                    capsule.setPosition(dbCapsule.getPosition());
572
                    capsule.setUpdatedOn(dbCapsule.getUpdatedOn());
9 gabriel 573
 
24 gabriel 574
                    m_li = new HashMap<>();
9 gabriel 575
 
2 gabriel 576
 
24 gabriel 577
                    //m_li.put("copyright",copy);
2 gabriel 578
 
24 gabriel 579
                    progress = progressDao.selectByCapsuleUuid(capsule.getUuid());
2 gabriel 580
 
24 gabriel 581
                    if (progress != null) {
582
                        capsule.setCompleted(progress.getCompleted());
583
                        capsule.setViewSlides(progress.getViewSlides());
2 gabriel 584
 
24 gabriel 585
                        capsule.setTotalSlides(progress.getTotalSlides());
586
                        capsule.setProgress(progress.getProgress());
587
                        capsule.setAddedOn(progress.getAddedOn());
2 gabriel 588
 
24 gabriel 589
                        // Log.e("Agregado en"," "+progress.getAddedOn());
590
                        // m_li.put("addedon",progress.getAddedOn());
591
                        m_li.put("view", String.valueOf(progress.getViewSlides()));
592
                        m_li.put("total", String.valueOf(progress.getTotalSlides()));
593
                        m_li.put("progress", String.valueOf(progress.getProgress()));
594
                        m_li.put("completado",String.valueOf(progress.getCompleted()));
595
                        m_li.put("agregado",progress.getAddedOn());
2 gabriel 596
 
24 gabriel 597
                    }
2 gabriel 598
 
24 gabriel 599
                    m_li.put("imagen", capsule.getImage());
600
                    m_li.put("nombre", capsule.getName());
601
                    m_li.put("uuid", capsule.getUuid());
602
                    m_li.put("topicuuid", capsule.getTopicUuid());
603
                    m_li.put("description", capsule.getDescription());
16 gabriel 604
 
18 gabriel 605
 
24 gabriel 606
                    //Lleno la lista segun el requerimiento de filtro accionado por el usuario
2 gabriel 607
 
24 gabriel 608
                    List<Slide> slides = slideDao.selectAllByCapsuleUuid(capsule.getUuid());
2 gabriel 609
 
24 gabriel 610
                    if (slides.isEmpty()) {
13 gabriel 611
 
24 gabriel 612
                        //  Log.e("Capsula","Es omitida, no tiene slides");
613
                    } else {
2 gabriel 614
 
12 gabriel 615
 
24 gabriel 616
                        if (progress == null) {
18 gabriel 617
 
24 gabriel 618
                            if (buscar.equals("")) {
18 gabriel 619
 
24 gabriel 620
                                capsuleList.add(m_li);
16 gabriel 621
 
13 gabriel 622
 
24 gabriel 623
                            } else {
624
                                String nombre= capsule.getName();
625
                                String normalizada= Normalizer.normalize(nombre, Normalizer.Form.NFD);
626
                                normalizada= normalizada.replaceAll("[^\\p{ASCII}]", "");
627
                                if (normalizada.matches("(?i).*" + buscar + ".*")) {
628
                                    capsuleList.add(m_li);
629
                                }
21 gabriel 630
 
16 gabriel 631
                            }
13 gabriel 632
 
16 gabriel 633
                        }
12 gabriel 634
 
24 gabriel 635
                    }
12 gabriel 636
 
24 gabriel 637
                }
16 gabriel 638
 
639
 
13 gabriel 640
 
24 gabriel 641
            }
13 gabriel 642
 
24 gabriel 643
        }
644
        else if (tabposition.equals("cursando"))
645
        {
2 gabriel 646
 
24 gabriel 647
                HashMap<String, String> m_li;
648
                List<Progress> progress;
649
                Capsule capsule;
2 gabriel 650
 
13 gabriel 651
 
652
 
24 gabriel 653
            progress = progressDao.selectAllCapsulesProgress();
654
 
655
                for(Progress dbProgress : progress) {
656
                    m_li = new HashMap<>();
657
 
658
                    capsule = capsuleDao.selectByUuid(dbProgress.getCapsuleUuid());
659
 
660
                    m_li.put("view", String.valueOf(dbProgress.getViewSlides()));
661
                    m_li.put("total", String.valueOf(dbProgress.getTotalSlides()));
662
                    m_li.put("progress", String.valueOf(dbProgress.getProgress()));
663
                    m_li.put("completado",String.valueOf(dbProgress.getCompleted()));
664
                    m_li.put("agregado",dbProgress.getAddedOn());
665
 
666
 
667
                    m_li.put("imagen", capsule.getImage());
668
                    m_li.put("nombre", capsule.getName());
669
                    m_li.put("uuid", capsule.getUuid());
670
                    m_li.put("topicuuid", capsule.getTopicUuid());
671
                    m_li.put("description", capsule.getDescription());
672
 
673
 
674
                    //Log.e("Lista",""+m_li);
675
                    //Lleno la lista segun el requerimiento de filtro accionado por el usuario
676
 
677
                    List<Slide> slides = slideDao.selectAllByCapsuleUuid(capsule.getUuid());
678
 
679
                    if (slides.isEmpty()) {
680
 
681
                        //  Log.e("Capsula","Es omitida, no tiene slides");
682
                    } else {
683
 
684
            if(dbProgress.getProgress() <= 100 && dbProgress.getCompleted()==0)
685
            {
686
            if (buscar.equals("")) {
687
                capsuleList.add(m_li);
688
 
689
            } else {
690
                String nombre= capsule.getName();
691
                String normalizada= Normalizer.normalize(nombre, Normalizer.Form.NFD);
692
                normalizada= normalizada.replaceAll("[^\\p{ASCII}]", "");
693
                if (normalizada.matches("(?i).*" + buscar + ".*")) {
694
                    capsuleList.add(m_li);
12 gabriel 695
                }
2 gabriel 696
 
12 gabriel 697
            }
24 gabriel 698
        }}
699
                }}
2 gabriel 700
 
24 gabriel 701
       else if (tabposition.equals("finalizados")){
12 gabriel 702
 
24 gabriel 703
            HashMap<String, String> m_li;
704
            List<Progress> progress;
705
            Capsule capsule;
2 gabriel 706
 
21 gabriel 707
 
24 gabriel 708
 
709
            progress = progressDao.selectAllCapsulesProgress();
710
 
711
            for(Progress dbProgress : progress) {
712
                m_li = new HashMap<>();
713
 
714
                capsule = capsuleDao.selectByUuid(dbProgress.getCapsuleUuid());
715
 
716
                m_li.put("view", String.valueOf(dbProgress.getViewSlides()));
717
                m_li.put("total", String.valueOf(dbProgress.getTotalSlides()));
718
                m_li.put("progress", String.valueOf(dbProgress.getProgress()));
719
                m_li.put("completado",String.valueOf(dbProgress.getCompleted()));
720
                m_li.put("agregado",dbProgress.getAddedOn());
721
 
722
 
723
                m_li.put("imagen", capsule.getImage());
724
                m_li.put("nombre", capsule.getName());
725
                m_li.put("uuid", capsule.getUuid());
726
                m_li.put("topicuuid", capsule.getTopicUuid());
727
                m_li.put("description", capsule.getDescription());
728
 
729
                //Lleno la lista segun el requerimiento de filtro accionado por el usuario
730
 
731
                    List<Slide> slides = slideDao.selectAllByCapsuleUuid(capsule.getUuid());
732
 
733
                    if (slides.isEmpty()) {
734
 
735
                        //  Log.e("Capsula","Es omitida, no tiene slides");
736
                    } else {
737
           if(dbProgress.getProgress() >= 100 && dbProgress.getCompleted()==1){
738
 
739
               if (buscar.equals("")) {
740
                   //capsule.getCompleted();
741
                   capsuleList.add(m_li);
742
 
743
               } else {
744
                   String nombre= capsule.getName();
745
                   String normalizada= Normalizer.normalize(nombre, Normalizer.Form.NFD);
746
                   normalizada= normalizada.replaceAll("[^\\p{ASCII}]", "");
747
                   if (normalizada.matches("(?i).*" + buscar + ".*")) {
748
                       capsuleList.add(m_li);
749
                   }
750
 
751
               }
752
           }
2 gabriel 753
    }
24 gabriel 754
                }}
2 gabriel 755
 
756
 
24 gabriel 757
    }
758
 
759
 
17 gabriel 760
    @Override
761
    public void onItemClick(int position, View v) {
762
 
24 gabriel 763
       // Log.e("Evento","del click"+position);
17 gabriel 764
 
765
 
766
        iTwoGetSkills.getPreference().setCapsuleUuidActive(capsuleList.get(position).get("uuid"));
767
        iTwoGetSkills.getPreference().setTopicUuidActive(capsuleList.get(position).get("topicuuid"));
768
        iTwoGetSkills.invokeFragment(Constants.IDX_FRAGMENT_SLIDES);
769
 
18 gabriel 770
        iTwoGetSkills.getPreference().setOrigennavigation("welcome");
24 gabriel 771
       // Log.e("Completada",""+capsuleList.get(position).get("completado"));
18 gabriel 772
 
17 gabriel 773
       // Log.e("Capsula","topic active"+mDataSet.get(viewHolder.getAbsoluteAdapterPosition()).get("topicuuid"));
774
 
775
    }
2 gabriel 776
}