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