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
 
17 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
        Capsule capsulafinal = null;
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
 
17 gabriel 357
                        capsulafinal=dbCapsule;
9 gabriel 358
 
359
                        if (dbCapsule.getImage() != null && !dbCapsule.getImage().equals("")) {
360
 
361
                            TimeZone timeZone = TimeZone.getTimeZone("UTC");
362
                            Calendar calendar = Calendar.getInstance(timeZone);
363
                            TimeZone tz = calendar.getTimeZone();
364
                            int created = (int) (calendar.getTimeInMillis() / 1000);
365
 
366
                            Random random = new Random(created);
367
                            int rand = 1000 + random.nextInt(8999);
368
 
369
 
370
                            String deviceUuid = iTwoGetSkills.getPreference().getDeviceUuid();
371
                            String password = iTwoGetSkills.getPreference().getPassword();
372
 
373
 
374
                            String secret = MD5.generar(password + ':' + created + ':' + rand);
375
                            GlideUrl url = new GlideUrl(dbCapsule.getImage(), new LazyHeaders.Builder()
376
                                    .addHeader(Constants.HTTP_HEADER_ACCEPT, Constants.HTTP_HEADER_ACCEPT_VALUE)
377
                                    .addHeader(Constants.HTTP_HEADER_SECURITY_TOKEN, deviceUuid)
378
                                    .addHeader(Constants.HTTP_HEADER_SECURITY_SECRET, secret)
379
                                    .addHeader(Constants.HTTP_HEADER_SECURITY_CREATED, String.valueOf(created))
380
                                    .addHeader(Constants.HTTP_HEADER_SECURITY_RAND, String.valueOf(rand))
381
                                    .build());
382
 
383
                            RequestOptions options = new RequestOptions()
384
                                    .diskCacheStrategy(DiskCacheStrategy.ALL);
385
 
386
                            Glide.with(getContext()).load(url)
387
                                    .thumbnail()
388
                                    .apply(options)
389
                                    .into(imagetarjeta);
390
                        }
391
                    }
392
 
10 gabriel 393
            }
394
 
395
 
396
        }
397
 
398
        if(titulotarjeta.getText().equals(""))
399
        {
17 gabriel 400
           // Log.e("Nombre","vacio");
10 gabriel 401
 
402
            //Despues del recorrido no se encontro progreso en ninguna capsula, por lo cual la tarjeta queda vacia
403
            // vamos a llenarla con la ultima capsula, que debe ser nueva al no tener progreso
404
 
405
            for(Capsule dbCapsule : dbCapsules)
406
            {
407
 
408
                progress = progressDao.selectByCapsuleUuid(dbCapsule.getUuid());
409
 
410
                if (progress == null) {
411
 
17 gabriel 412
                      //  Log.e("Es nueva","");
10 gabriel 413
 
414
                        titulotarjeta.setText(dbCapsule.getName());
415
                        progresotarjeta.setVisibility(View.INVISIBLE);
416
                        progresoporcentaje.setVisibility(View.INVISIBLE);
417
                        empezar.setText("Nueva");
418
                        continuar.setText("Ver cápsula");
419
 
17 gabriel 420
                        capsulafinal=dbCapsule;
10 gabriel 421
 
17 gabriel 422
                    if (dbCapsule.getImage() != null && !dbCapsule.getImage().equals("")) {
10 gabriel 423
 
424
                            TimeZone timeZone = TimeZone.getTimeZone("UTC");
425
                            Calendar calendar = Calendar.getInstance(timeZone);
426
                            TimeZone tz = calendar.getTimeZone();
427
                            int created = (int) (calendar.getTimeInMillis() / 1000);
428
 
429
                            Random random = new Random(created);
430
                            int rand = 1000 + random.nextInt(8999);
431
 
432
 
433
                            String deviceUuid = iTwoGetSkills.getPreference().getDeviceUuid();
434
                            String password = iTwoGetSkills.getPreference().getPassword();
435
 
436
 
437
                            String secret = MD5.generar(password + ':' + created + ':' + rand);
438
                            GlideUrl url = new GlideUrl(dbCapsule.getImage(), new LazyHeaders.Builder()
439
                                    .addHeader(Constants.HTTP_HEADER_ACCEPT, Constants.HTTP_HEADER_ACCEPT_VALUE)
440
                                    .addHeader(Constants.HTTP_HEADER_SECURITY_TOKEN, deviceUuid)
441
                                    .addHeader(Constants.HTTP_HEADER_SECURITY_SECRET, secret)
442
                                    .addHeader(Constants.HTTP_HEADER_SECURITY_CREATED, String.valueOf(created))
443
                                    .addHeader(Constants.HTTP_HEADER_SECURITY_RAND, String.valueOf(rand))
444
                                    .build());
445
 
446
                            RequestOptions options = new RequestOptions()
447
                                    .diskCacheStrategy(DiskCacheStrategy.ALL);
448
 
449
                            Glide.with(getContext()).load(url)
450
                                    .thumbnail()
451
                                    .apply(options)
452
                                    .into(imagetarjeta);
453
                        }
454
 
455
                    }
456
 
457
                /*
458
                if (progress != null) {
459
 
460
                    double progre = progress.getProgress();
461
 
462
                    if (progre >= 100) {
463
                        Log.e("Es mayor"," a 100");
464
 
465
                    } else {
466
 
467
                        Log.e("Es nueva","");
468
 
469
                        titulotarjeta.setText(dbCapsule.getName());
470
                        progresotarjeta.setVisibility(View.INVISIBLE);
471
                        progresoporcentaje.setVisibility(View.INVISIBLE);
472
                        empezar.setText("Nueva");
473
                        continuar.setText("Ver cápsula");
474
 
475
                        iTwoGetSkills.getPreference().setCapsuleUuidActive(dbCapsule.getUuid());
476
                        iTwoGetSkills.getPreference().setTopicUuidActive(dbCapsule.getTopicUuid());
477
 
478
                        if (dbCapsule.getImage() != null && !dbCapsule.getImage().equals("")) {
479
 
480
                            TimeZone timeZone = TimeZone.getTimeZone("UTC");
481
                            Calendar calendar = Calendar.getInstance(timeZone);
482
                            TimeZone tz = calendar.getTimeZone();
483
                            int created = (int) (calendar.getTimeInMillis() / 1000);
484
 
485
                            Random random = new Random(created);
486
                            int rand = 1000 + random.nextInt(8999);
487
 
488
 
489
                            String deviceUuid = iTwoGetSkills.getPreference().getDeviceUuid();
490
                            String password = iTwoGetSkills.getPreference().getPassword();
491
 
492
 
493
                            String secret = MD5.generar(password + ':' + created + ':' + rand);
494
                            GlideUrl url = new GlideUrl(dbCapsule.getImage(), new LazyHeaders.Builder()
495
                                    .addHeader(Constants.HTTP_HEADER_ACCEPT, Constants.HTTP_HEADER_ACCEPT_VALUE)
496
                                    .addHeader(Constants.HTTP_HEADER_SECURITY_TOKEN, deviceUuid)
497
                                    .addHeader(Constants.HTTP_HEADER_SECURITY_SECRET, secret)
498
                                    .addHeader(Constants.HTTP_HEADER_SECURITY_CREATED, String.valueOf(created))
499
                                    .addHeader(Constants.HTTP_HEADER_SECURITY_RAND, String.valueOf(rand))
500
                                    .build());
501
 
502
                            RequestOptions options = new RequestOptions()
503
                                    .diskCacheStrategy(DiskCacheStrategy.ALL);
504
 
505
                            Glide.with(getContext()).load(url)
506
                                    .thumbnail()
507
                                    .apply(options)
508
                                    .into(imagetarjeta);
509
                        }
510
 
511
                    }
9 gabriel 512
                }
10 gabriel 513
*/
514
            }
9 gabriel 515
 
10 gabriel 516
 
517
 
9 gabriel 518
        }
519
 
10 gabriel 520
 
17 gabriel 521
        Capsule finalCapsulafinal = capsulafinal;
10 gabriel 522
 
9 gabriel 523
        continuar.setOnClickListener(v -> {
524
 
17 gabriel 525
            iTwoGetSkills.getPreference().setCapsuleUuidActive(finalCapsulafinal.getUuid());
526
            iTwoGetSkills.getPreference().setTopicUuidActive(finalCapsulafinal.getTopicUuid());
18 gabriel 527
            iTwoGetSkills.getPreference().setOrigennavigation("welcome");
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
}