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);
169
                }
170
 
171
            }
172
        });
173
 
13 gabriel 174
        busqueda.addTextChangedListener(new TextWatcher() {
175
            @Override
176
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
8 gabriel 177
 
13 gabriel 178
            }
179
 
180
            @Override
181
            public void onTextChanged(CharSequence s, int start, int before, int count) {
17 gabriel 182
            //    Log.e("El texto","buscado: "+s);
13 gabriel 183
                capsuleList.clear();
184
                adapter2.notifyDataSetChanged();
185
                loadData(tabactual, s.toString());
186
            }
187
 
188
            @Override
189
            public void afterTextChanged(Editable s) {
190
 
191
 
192
 
193
            }
194
        });
195
 
196
 
4 gabriel 197
        adapter2 = new TabsCapsulesAdapter(getContext(),capsuleList);
2 gabriel 198
 
199
 
200
 
4 gabriel 201
        categorizados = view.findViewById(R.id.categorizados);
202
        GridLayoutManager layoutcategoria = new GridLayoutManager(getContext(),1,GridLayoutManager.VERTICAL, false);
203
        categorizados.setLayoutManager(layoutcategoria);
204
        categorizados.setAdapter(adapter2);
205
 
11 gabriel 206
 
17 gabriel 207
        adapter2.setClickListener(this);
11 gabriel 208
 
8 gabriel 209
        categorizados.setOnFlingListener(new RecyclerView.OnFlingListener() {
210
            @Override
211
            public boolean onFling(int velocityX, int velocityY) {
212
 
213
                if (categorizados.canScrollVertically(-1) ) {
214
 
17 gabriel 215
                   // Log.e("Se activa", "On fling");
9 gabriel 216
                    card.setVisibility(View.GONE);
8 gabriel 217
                    username.setVisibility(View.GONE);
218
                    textowelcome.setVisibility(View.GONE);
219
                }else
220
                {
9 gabriel 221
                    card.setVisibility(View.VISIBLE);
8 gabriel 222
                    username.setVisibility(View.VISIBLE);
223
                    textowelcome.setVisibility(View.VISIBLE);
224
                }
225
 
226
                return false;
227
            }
228
        });
229
 
11 gabriel 230
 
8 gabriel 231
     /*   categorizados.setOnScrollChangeListener(new View.OnScrollChangeListener() {
232
            @Override
233
            public void onScrollChange(View v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {
234
 
235
                if (!categorizados.canScrollVertically(-1)) {
236
                 //   Toast.makeText(getActivity(), "Last", Toast.LENGTH_LONG).show();
237
                    capsulas.setVisibility(View.VISIBLE);
238
                    username.setVisibility(View.VISIBLE);
239
                    textowelcome.setVisibility(View.VISIBLE);
240
                    Log.e("On scroll"," se activa");
241
                }
242
 
243
            }
244
        });
245
*/
21 gabriel 246
 
247
        getActivity().runOnUiThread(() -> {
248
            String message = capsuleList.size() == 1
249
                    ? "Hay 1 cápsula nueva disponible"
250
                    : "Tiene " + capsuleList.size() + " cápsulas pendientes para ver";
251
 
25 gabriel 252
 
253
            Calendar calendar = Calendar.getInstance();
254
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat(Constants.FORMAT_DATETIME_SERVICE);
255
            Date date = calendar.getTime();
256
 
257
            String  dateOn = simpleDateFormat.format(date);
258
 
259
 
260
            NotificationCenterDao notificacionDao =  iTwoGetSkills.getDatabase().getNotificationCenterDao();
261
            com.cesams.twogetskills.entity.NotificationCenter notificacionueva;
262
 
263
            notificacionueva = new com.cesams.twogetskills.entity.NotificationCenter();
264
 
265
            notificacionueva.setTitle("Nuevo contenido disponible");
266
            notificacionueva.setDate(dateOn);
267
            notificacionueva.setDescription(message);
268
            Log.e("Notificacion","a guardar"+notificacionueva);
269
 
270
            List<com.cesams.twogetskills.entity.NotificationCenter> lista;
271
            lista=notificacionDao.selectAllNotification();
272
 
273
 
274
            if(lista.size()==0)
275
            {
276
                notificacionDao.insert(notificacionueva);
277
 
278
            }
279
            else {
280
                for (com.cesams.twogetskills.entity.NotificationCenter notificacion : lista) {
281
                    if (notificacion.getDescription().equals(message)) {
282
                        Log.e("Notification Center", " omitir, he registrado esta notificacion");
283
                    } else {
284
                        notificacionDao.insert(notificacionueva);
285
                        Log.e("Notification Center", "guardar");
286
 
287
                    }
288
                }
289
            }
21 gabriel 290
            iTwoGetSkills.showMessageSnackBarWithClose(message);
291
 
292
        });
2 gabriel 293
        return view;
294
    }
295
 
9 gabriel 296
    @Override
297
    public void onResume() {
298
        super.onResume();
299
        loadContinuecard();
300
    }
2 gabriel 301
 
9 gabriel 302
    @Override
303
    public void onHiddenChanged(boolean hidden) {
304
        super.onHiddenChanged(hidden);
305
 
17 gabriel 306
       // Log.e("TAG", "onHiddenChanged : " + (hidden ? "true" : "false"));
9 gabriel 307
 
308
        if(!hidden) {
16 gabriel 309
            Log.e("Esta oculto", "el fragmento");
310
 
311
            getActivity().runOnUiThread(() -> {
312
 
313
                capsuleList.clear();
314
 
315
                loadContinuecard();
316
                loadData("pendientes","");
317
 
318
                adapter2.notifyDataSetChanged();
319
 
320
                tabs.getTabAt(0).select();
321
 
322
            });
323
 
324
 
9 gabriel 325
        }
326
    }
327
 
328
    private void loadContinuecard(){
329
 
26 gabriel 330
        Log.e("Cargo datos"," en tarjeta principal");
9 gabriel 331
 
332
        //Capsula de primera tarjeta
333
        CapsuleDao capsuleDao = iTwoGetSkills.getDatabase().getCapsuleDao();
334
 
335
        Progress progress;
336
        ProgressDao progressDao = iTwoGetSkills.getDatabase().getProgressDao();
337
 
17 gabriel 338
 
9 gabriel 339
        List<Capsule> dbCapsules= capsuleDao.selectAll();
340
        for(Capsule dbCapsule : dbCapsules)
341
        {
342
            progress = progressDao.selectByCapsuleUuid(dbCapsule.getUuid());
343
 
344
            if (progress != null) {
345
 
10 gabriel 346
                    if (progress.getProgress() < 100) {
17 gabriel 347
                    //    Log.e("Es menor"," a 100");
9 gabriel 348
 
349
                        titulotarjeta.setText(dbCapsule.getName());
10 gabriel 350
                        progresotarjeta.setVisibility(View.VISIBLE);
351
                        progresoporcentaje.setVisibility(View.VISIBLE);
9 gabriel 352
                        progresotarjeta.setProgress((int) progress.getProgress());
353
                        progresoporcentaje.setText("" + progress.getProgress() + " %");
10 gabriel 354
                        empezar.setText("En curso");
9 gabriel 355
 
26 gabriel 356
                        iTwoGetSkills.getPreference().setCapsuleUuidActive(dbCapsule.getUuid());
357
                        iTwoGetSkills.getPreference().setTopicUuidActive(dbCapsule.getTopicUuid());
358
                        iTwoGetSkills.getPreference().setOrigennavigation("welcome");
9 gabriel 359
 
360
                        if (dbCapsule.getImage() != null && !dbCapsule.getImage().equals("")) {
361
 
362
                            TimeZone timeZone = TimeZone.getTimeZone("UTC");
363
                            Calendar calendar = Calendar.getInstance(timeZone);
364
                            TimeZone tz = calendar.getTimeZone();
365
                            int created = (int) (calendar.getTimeInMillis() / 1000);
366
 
367
                            Random random = new Random(created);
368
                            int rand = 1000 + random.nextInt(8999);
369
 
370
 
371
                            String deviceUuid = iTwoGetSkills.getPreference().getDeviceUuid();
372
                            String password = iTwoGetSkills.getPreference().getPassword();
373
 
374
 
375
                            String secret = MD5.generar(password + ':' + created + ':' + rand);
376
                            GlideUrl url = new GlideUrl(dbCapsule.getImage(), new LazyHeaders.Builder()
377
                                    .addHeader(Constants.HTTP_HEADER_ACCEPT, Constants.HTTP_HEADER_ACCEPT_VALUE)
378
                                    .addHeader(Constants.HTTP_HEADER_SECURITY_TOKEN, deviceUuid)
379
                                    .addHeader(Constants.HTTP_HEADER_SECURITY_SECRET, secret)
380
                                    .addHeader(Constants.HTTP_HEADER_SECURITY_CREATED, String.valueOf(created))
381
                                    .addHeader(Constants.HTTP_HEADER_SECURITY_RAND, String.valueOf(rand))
382
                                    .build());
383
 
384
                            RequestOptions options = new RequestOptions()
385
                                    .diskCacheStrategy(DiskCacheStrategy.ALL);
386
 
387
                            Glide.with(getContext()).load(url)
388
                                    .thumbnail()
389
                                    .apply(options)
390
                                    .into(imagetarjeta);
391
                        }
392
                    }
393
 
10 gabriel 394
            }
395
 
396
 
397
        }
398
 
399
        if(titulotarjeta.getText().equals(""))
400
        {
17 gabriel 401
           // Log.e("Nombre","vacio");
10 gabriel 402
 
403
            //Despues del recorrido no se encontro progreso en ninguna capsula, por lo cual la tarjeta queda vacia
404
            // vamos a llenarla con la ultima capsula, que debe ser nueva al no tener progreso
405
 
406
            for(Capsule dbCapsule : dbCapsules)
407
            {
408
 
409
                progress = progressDao.selectByCapsuleUuid(dbCapsule.getUuid());
410
 
411
                if (progress == null) {
412
 
17 gabriel 413
                      //  Log.e("Es nueva","");
10 gabriel 414
 
415
                        titulotarjeta.setText(dbCapsule.getName());
416
                        progresotarjeta.setVisibility(View.INVISIBLE);
417
                        progresoporcentaje.setVisibility(View.INVISIBLE);
418
                        empezar.setText("Nueva");
419
                        continuar.setText("Ver cápsula");
420
 
421
 
26 gabriel 422
                    iTwoGetSkills.getPreference().setCapsuleUuidActive(dbCapsule.getUuid());
423
                    iTwoGetSkills.getPreference().setTopicUuidActive(dbCapsule.getTopicUuid());
424
                    iTwoGetSkills.getPreference().setOrigennavigation("welcome");
425
 
17 gabriel 426
                    if (dbCapsule.getImage() != null && !dbCapsule.getImage().equals("")) {
10 gabriel 427
 
428
                            TimeZone timeZone = TimeZone.getTimeZone("UTC");
429
                            Calendar calendar = Calendar.getInstance(timeZone);
430
                            TimeZone tz = calendar.getTimeZone();
431
                            int created = (int) (calendar.getTimeInMillis() / 1000);
432
 
433
                            Random random = new Random(created);
434
                            int rand = 1000 + random.nextInt(8999);
435
 
436
 
437
                            String deviceUuid = iTwoGetSkills.getPreference().getDeviceUuid();
438
                            String password = iTwoGetSkills.getPreference().getPassword();
439
 
440
 
441
                            String secret = MD5.generar(password + ':' + created + ':' + rand);
442
                            GlideUrl url = new GlideUrl(dbCapsule.getImage(), new LazyHeaders.Builder()
443
                                    .addHeader(Constants.HTTP_HEADER_ACCEPT, Constants.HTTP_HEADER_ACCEPT_VALUE)
444
                                    .addHeader(Constants.HTTP_HEADER_SECURITY_TOKEN, deviceUuid)
445
                                    .addHeader(Constants.HTTP_HEADER_SECURITY_SECRET, secret)
446
                                    .addHeader(Constants.HTTP_HEADER_SECURITY_CREATED, String.valueOf(created))
447
                                    .addHeader(Constants.HTTP_HEADER_SECURITY_RAND, String.valueOf(rand))
448
                                    .build());
449
 
450
                            RequestOptions options = new RequestOptions()
451
                                    .diskCacheStrategy(DiskCacheStrategy.ALL);
452
 
453
                            Glide.with(getContext()).load(url)
454
                                    .thumbnail()
455
                                    .apply(options)
456
                                    .into(imagetarjeta);
457
                        }
458
 
459
                    }
460
 
461
                /*
462
                if (progress != null) {
463
 
464
                    double progre = progress.getProgress();
465
 
466
                    if (progre >= 100) {
467
                        Log.e("Es mayor"," a 100");
468
 
469
                    } else {
470
 
471
                        Log.e("Es nueva","");
472
 
473
                        titulotarjeta.setText(dbCapsule.getName());
474
                        progresotarjeta.setVisibility(View.INVISIBLE);
475
                        progresoporcentaje.setVisibility(View.INVISIBLE);
476
                        empezar.setText("Nueva");
477
                        continuar.setText("Ver cápsula");
478
 
479
                        iTwoGetSkills.getPreference().setCapsuleUuidActive(dbCapsule.getUuid());
480
                        iTwoGetSkills.getPreference().setTopicUuidActive(dbCapsule.getTopicUuid());
481
 
482
                        if (dbCapsule.getImage() != null && !dbCapsule.getImage().equals("")) {
483
 
484
                            TimeZone timeZone = TimeZone.getTimeZone("UTC");
485
                            Calendar calendar = Calendar.getInstance(timeZone);
486
                            TimeZone tz = calendar.getTimeZone();
487
                            int created = (int) (calendar.getTimeInMillis() / 1000);
488
 
489
                            Random random = new Random(created);
490
                            int rand = 1000 + random.nextInt(8999);
491
 
492
 
493
                            String deviceUuid = iTwoGetSkills.getPreference().getDeviceUuid();
494
                            String password = iTwoGetSkills.getPreference().getPassword();
495
 
496
 
497
                            String secret = MD5.generar(password + ':' + created + ':' + rand);
498
                            GlideUrl url = new GlideUrl(dbCapsule.getImage(), new LazyHeaders.Builder()
499
                                    .addHeader(Constants.HTTP_HEADER_ACCEPT, Constants.HTTP_HEADER_ACCEPT_VALUE)
500
                                    .addHeader(Constants.HTTP_HEADER_SECURITY_TOKEN, deviceUuid)
501
                                    .addHeader(Constants.HTTP_HEADER_SECURITY_SECRET, secret)
502
                                    .addHeader(Constants.HTTP_HEADER_SECURITY_CREATED, String.valueOf(created))
503
                                    .addHeader(Constants.HTTP_HEADER_SECURITY_RAND, String.valueOf(rand))
504
                                    .build());
505
 
506
                            RequestOptions options = new RequestOptions()
507
                                    .diskCacheStrategy(DiskCacheStrategy.ALL);
508
 
509
                            Glide.with(getContext()).load(url)
510
                                    .thumbnail()
511
                                    .apply(options)
512
                                    .into(imagetarjeta);
513
                        }
514
 
515
                    }
9 gabriel 516
                }
10 gabriel 517
*/
518
            }
9 gabriel 519
 
10 gabriel 520
 
521
 
9 gabriel 522
        }
523
 
26 gabriel 524
        continuar.setOnClickListener(v -> {
10 gabriel 525
 
526
 
23 gabriel 527
           // Log.e("Guardo",""+iTwoGetSkills.getPreference().getOrigenNavigation());
17 gabriel 528
 
9 gabriel 529
            iTwoGetSkills.invokeFragment(Constants.IDX_FRAGMENT_SLIDES);
530
        });
531
 
532
        //Fin de primer tarjeta
533
 
534
    }
535
 
13 gabriel 536
    private void loadData(String tabposition, String buscar)
2 gabriel 537
    {
538
 
12 gabriel 539
 
2 gabriel 540
        TopicDao topicDao = iTwoGetSkills.getDatabase().getTopicDao();
541
        ArrayList<Topic> dbTopics = (ArrayList<Topic>) topicDao.selectAll();
542
 
543
        List<Capsule> dbCapsules;
544
        CapsuleDao capsuleDao = iTwoGetSkills.getDatabase().getCapsuleDao();
545
 
24 gabriel 546
        ProgressDao progressDao = iTwoGetSkills.getDatabase().getProgressDao();
547
        SlideDao slideDao = iTwoGetSkills.getDatabase().getSlideDao();
9 gabriel 548
 
549
 
24 gabriel 550
        if (tabposition.equals("pendientes"))
551
        {
552
            for (Topic dbTopic : dbTopics) {
9 gabriel 553
 
24 gabriel 554
                dbCapsules = capsuleDao.selectAllByTopicUuidandOrder(dbTopic.getUuid());
2 gabriel 555
 
24 gabriel 556
                Capsule capsule;
557
                Progress progress;
2 gabriel 558
 
24 gabriel 559
                HashMap<String, String> m_li;
9 gabriel 560
 
2 gabriel 561
 
562
 
24 gabriel 563
                for(Capsule dbCapsule : dbCapsules) {
564
                    capsule = new Capsule();
565
                    capsule.setTopicUuid(dbCapsule.getTopicUuid());
566
                    capsule.setUuid(dbCapsule.getUuid());
567
                    capsule.setName(dbCapsule.getName());
568
                    capsule.setDescription(dbCapsule.getDescription());
569
                    capsule.setImage(dbCapsule.getImage());
570
                    capsule.setPosition(dbCapsule.getPosition());
571
                    capsule.setUpdatedOn(dbCapsule.getUpdatedOn());
9 gabriel 572
 
24 gabriel 573
                    m_li = new HashMap<>();
9 gabriel 574
 
2 gabriel 575
 
24 gabriel 576
                    //m_li.put("copyright",copy);
2 gabriel 577
 
24 gabriel 578
                    progress = progressDao.selectByCapsuleUuid(capsule.getUuid());
2 gabriel 579
 
24 gabriel 580
                    if (progress != null) {
581
                        capsule.setCompleted(progress.getCompleted());
582
                        capsule.setViewSlides(progress.getViewSlides());
2 gabriel 583
 
24 gabriel 584
                        capsule.setTotalSlides(progress.getTotalSlides());
585
                        capsule.setProgress(progress.getProgress());
586
                        capsule.setAddedOn(progress.getAddedOn());
2 gabriel 587
 
24 gabriel 588
                        // Log.e("Agregado en"," "+progress.getAddedOn());
589
                        // m_li.put("addedon",progress.getAddedOn());
590
                        m_li.put("view", String.valueOf(progress.getViewSlides()));
591
                        m_li.put("total", String.valueOf(progress.getTotalSlides()));
592
                        m_li.put("progress", String.valueOf(progress.getProgress()));
593
                        m_li.put("completado",String.valueOf(progress.getCompleted()));
594
                        m_li.put("agregado",progress.getAddedOn());
2 gabriel 595
 
24 gabriel 596
                    }
2 gabriel 597
 
24 gabriel 598
                    m_li.put("imagen", capsule.getImage());
599
                    m_li.put("nombre", capsule.getName());
600
                    m_li.put("uuid", capsule.getUuid());
601
                    m_li.put("topicuuid", capsule.getTopicUuid());
602
                    m_li.put("description", capsule.getDescription());
16 gabriel 603
 
18 gabriel 604
 
24 gabriel 605
                    //Lleno la lista segun el requerimiento de filtro accionado por el usuario
2 gabriel 606
 
24 gabriel 607
                    List<Slide> slides = slideDao.selectAllByCapsuleUuid(capsule.getUuid());
2 gabriel 608
 
24 gabriel 609
                    if (slides.isEmpty()) {
13 gabriel 610
 
24 gabriel 611
                        //  Log.e("Capsula","Es omitida, no tiene slides");
612
                    } else {
2 gabriel 613
 
12 gabriel 614
 
24 gabriel 615
                        if (progress == null) {
18 gabriel 616
 
24 gabriel 617
                            if (buscar.equals("")) {
18 gabriel 618
 
24 gabriel 619
                                capsuleList.add(m_li);
16 gabriel 620
 
13 gabriel 621
 
24 gabriel 622
                            } else {
623
                                String nombre= capsule.getName();
624
                                String normalizada= Normalizer.normalize(nombre, Normalizer.Form.NFD);
625
                                normalizada= normalizada.replaceAll("[^\\p{ASCII}]", "");
626
                                if (normalizada.matches("(?i).*" + buscar + ".*")) {
627
                                    capsuleList.add(m_li);
628
                                }
21 gabriel 629
 
16 gabriel 630
                            }
13 gabriel 631
 
16 gabriel 632
                        }
12 gabriel 633
 
24 gabriel 634
                    }
12 gabriel 635
 
24 gabriel 636
                }
16 gabriel 637
 
638
 
13 gabriel 639
 
24 gabriel 640
            }
13 gabriel 641
 
24 gabriel 642
        }
643
        else if (tabposition.equals("cursando"))
644
        {
2 gabriel 645
 
24 gabriel 646
                HashMap<String, String> m_li;
647
                List<Progress> progress;
648
                Capsule capsule;
2 gabriel 649
 
13 gabriel 650
 
651
 
24 gabriel 652
            progress = progressDao.selectAllCapsulesProgress();
653
 
654
                for(Progress dbProgress : progress) {
655
                    m_li = new HashMap<>();
656
 
657
                    capsule = capsuleDao.selectByUuid(dbProgress.getCapsuleUuid());
658
 
659
                    m_li.put("view", String.valueOf(dbProgress.getViewSlides()));
660
                    m_li.put("total", String.valueOf(dbProgress.getTotalSlides()));
661
                    m_li.put("progress", String.valueOf(dbProgress.getProgress()));
662
                    m_li.put("completado",String.valueOf(dbProgress.getCompleted()));
663
                    m_li.put("agregado",dbProgress.getAddedOn());
664
 
665
 
666
                    m_li.put("imagen", capsule.getImage());
667
                    m_li.put("nombre", capsule.getName());
668
                    m_li.put("uuid", capsule.getUuid());
669
                    m_li.put("topicuuid", capsule.getTopicUuid());
670
                    m_li.put("description", capsule.getDescription());
671
 
672
 
673
                    //Log.e("Lista",""+m_li);
674
                    //Lleno la lista segun el requerimiento de filtro accionado por el usuario
675
 
676
                    List<Slide> slides = slideDao.selectAllByCapsuleUuid(capsule.getUuid());
677
 
678
                    if (slides.isEmpty()) {
679
 
680
                        //  Log.e("Capsula","Es omitida, no tiene slides");
681
                    } else {
682
 
683
            if(dbProgress.getProgress() <= 100 && dbProgress.getCompleted()==0)
684
            {
685
            if (buscar.equals("")) {
686
                capsuleList.add(m_li);
687
 
688
            } else {
689
                String nombre= capsule.getName();
690
                String normalizada= Normalizer.normalize(nombre, Normalizer.Form.NFD);
691
                normalizada= normalizada.replaceAll("[^\\p{ASCII}]", "");
692
                if (normalizada.matches("(?i).*" + buscar + ".*")) {
693
                    capsuleList.add(m_li);
12 gabriel 694
                }
2 gabriel 695
 
12 gabriel 696
            }
24 gabriel 697
        }}
698
                }}
2 gabriel 699
 
24 gabriel 700
       else if (tabposition.equals("finalizados")){
12 gabriel 701
 
24 gabriel 702
            HashMap<String, String> m_li;
703
            List<Progress> progress;
704
            Capsule capsule;
2 gabriel 705
 
21 gabriel 706
 
24 gabriel 707
 
708
            progress = progressDao.selectAllCapsulesProgress();
709
 
710
            for(Progress dbProgress : progress) {
711
                m_li = new HashMap<>();
712
 
713
                capsule = capsuleDao.selectByUuid(dbProgress.getCapsuleUuid());
714
 
715
                m_li.put("view", String.valueOf(dbProgress.getViewSlides()));
716
                m_li.put("total", String.valueOf(dbProgress.getTotalSlides()));
717
                m_li.put("progress", String.valueOf(dbProgress.getProgress()));
718
                m_li.put("completado",String.valueOf(dbProgress.getCompleted()));
719
                m_li.put("agregado",dbProgress.getAddedOn());
720
 
721
 
722
                m_li.put("imagen", capsule.getImage());
723
                m_li.put("nombre", capsule.getName());
724
                m_li.put("uuid", capsule.getUuid());
725
                m_li.put("topicuuid", capsule.getTopicUuid());
726
                m_li.put("description", capsule.getDescription());
727
 
728
                //Lleno la lista segun el requerimiento de filtro accionado por el usuario
729
 
730
                    List<Slide> slides = slideDao.selectAllByCapsuleUuid(capsule.getUuid());
731
 
732
                    if (slides.isEmpty()) {
733
 
734
                        //  Log.e("Capsula","Es omitida, no tiene slides");
735
                    } else {
736
           if(dbProgress.getProgress() >= 100 && dbProgress.getCompleted()==1){
737
 
738
               if (buscar.equals("")) {
739
                   //capsule.getCompleted();
740
                   capsuleList.add(m_li);
741
 
742
               } else {
743
                   String nombre= capsule.getName();
744
                   String normalizada= Normalizer.normalize(nombre, Normalizer.Form.NFD);
745
                   normalizada= normalizada.replaceAll("[^\\p{ASCII}]", "");
746
                   if (normalizada.matches("(?i).*" + buscar + ".*")) {
747
                       capsuleList.add(m_li);
748
                   }
749
 
750
               }
751
           }
2 gabriel 752
    }
24 gabriel 753
                }}
2 gabriel 754
 
755
 
24 gabriel 756
    }
757
 
758
 
17 gabriel 759
    @Override
760
    public void onItemClick(int position, View v) {
761
 
24 gabriel 762
       // Log.e("Evento","del click"+position);
17 gabriel 763
 
764
 
765
        iTwoGetSkills.getPreference().setCapsuleUuidActive(capsuleList.get(position).get("uuid"));
766
        iTwoGetSkills.getPreference().setTopicUuidActive(capsuleList.get(position).get("topicuuid"));
767
        iTwoGetSkills.invokeFragment(Constants.IDX_FRAGMENT_SLIDES);
768
 
18 gabriel 769
        iTwoGetSkills.getPreference().setOrigennavigation("welcome");
24 gabriel 770
       // Log.e("Completada",""+capsuleList.get(position).get("completado"));
18 gabriel 771
 
17 gabriel 772
       // Log.e("Capsula","topic active"+mDataSet.get(viewHolder.getAbsoluteAdapterPosition()).get("topicuuid"));
773
 
774
    }
2 gabriel 775
}