Proyectos de Subversion Android Microlearning - Nuevo Interface

Rev

Ir a la última revisión | | Ultima modificación | Ver Log |

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