Proyectos de Subversion Android Microlearning - Nuevo Interface

Rev

Rev 39 | Rev 44 | Ir a la última revisión | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 39 Rev 43
Línea 327... Línea 327...
327
            }
327
            }
328
        }, 10000);
328
        }, 10000);
Línea -... Línea 329...
-
 
329
 
-
 
330
 
-
 
331
 
-
 
332
        if(preference.isRefreshContentRequired()){
-
 
333
 
Línea 329... Línea 334...
329
 
334
            Cartelrefreshcontent();
Línea 330... Línea 335...
330
 
335
 
Línea 359... Línea 364...
359
        isForeground = true;
364
        isForeground = true;
Línea 360... Línea 365...
360
 
365
 
361
        preference = Preference.getInstance(getApplicationContext());
366
        preference = Preference.getInstance(getApplicationContext());
Línea -... Línea 367...
-
 
367
        preference.load();
-
 
368
 
-
 
369
        if(preference.isRefreshContentRequired())
-
 
370
        {
Línea 362... Línea 371...
362
        preference.load();
371
            Cartelrefreshcontent();
Línea 363... Línea 372...
363
 
372
        }
364
 
373
 
Línea 439... Línea 448...
439
        // Add as notification
448
        // Add as notification
440
        NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
449
        NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
441
        manager.notify(0, builder.build());
450
        manager.notify(0, builder.build());
Línea -... Línea 451...
-
 
451
 
-
 
452
 
-
 
453
 
-
 
454
 
-
 
455
        if(new_capsules > 0) {
-
 
456
 
-
 
457
            String message = new_capsules == 1
-
 
458
                    ? "Hay 1 cápsula nueva disponible"
-
 
459
                    : "Hay " + new_capsules + " cápsulas disponible";
-
 
460
 
-
 
461
 
-
 
462
            showMessageSnackBarWithClose(message);
-
 
463
 
-
 
464
            saveNotificationCenterNew("Nuevo cápsula","",message);
-
 
465
        } else {
-
 
466
 
-
 
467
            showMessageSnackBarWithClose(body);
-
 
468
            saveNotificationCenterNew("Nuevo contenido","",body);
-
 
469
 
-
 
470
        }
-
 
471
 
-
 
472
 
-
 
473
    }
442
 
474
 
443
 
475
    public void saveNotificationCenterNew(String title,String url,String message){
444
        Calendar calendar = Calendar.getInstance();
476
        Calendar calendar = Calendar.getInstance();
445
        Date date = calendar.getTime();
477
        Date date = calendar.getTime();
Línea 446... Línea 478...
446
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat(Constants.FORMAT_DATETIME_SERVICE);
478
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat(Constants.FORMAT_DATETIME_SERVICE);
447
        String  dateOn = simpleDateFormat.format(date);
479
        String  dateOn = simpleDateFormat.format(date);
Línea 448... Línea 480...
448
 
480
 
Línea -... Línea 481...
-
 
481
        NotificationCenterDao notificacionDao =  mAppDatabase.getNotificationCenterDao();
449
        NotificationCenterDao notificacionDao =  mAppDatabase.getNotificationCenterDao();
482
        com.cesams.twogetskills.entity.NotificationCenter notificacionueva;
450
        com.cesams.twogetskills.entity.NotificationCenter notificacionueva;
483
 
451
 
484
        notificacionueva = new com.cesams.twogetskills.entity.NotificationCenter();
Línea 452... Línea -...
452
        notificacionueva = new com.cesams.twogetskills.entity.NotificationCenter();
-
 
453
 
-
 
454
        notificacionueva.setTitle("Nuevo contenido disponible");
-
 
455
        notificacionueva.setDate(dateOn);
-
 
456
        notificacionueva.setUrl(url);
-
 
457
 
-
 
458
        if(new_capsules > 0) {
485
 
459
 
-
 
460
            String message = new_capsules == 1
-
 
461
                    ? "Hay 1 cápsula nueva disponible"
-
 
462
                    : "Hay " + new_capsules + " cápsulas disponible";
-
 
463
 
-
 
464
            List<com.cesams.twogetskills.entity.NotificationCenter> lista;
-
 
465
            lista=notificacionDao.selectAllNotification();
-
 
466
 
-
 
467
            boolean registrada=false;
-
 
468
            notificacionueva.setDescription(message);
-
 
469
 
-
 
470
            for(com.cesams.twogetskills.entity.NotificationCenter notificacion: lista)
-
 
471
            {
-
 
472
                if(notificacion.getDescription().equals(notificacionueva.getDescription()))
-
 
473
                {
-
 
474
                    registrada=true;
-
 
475
                    Log.e("Ya registrada"," ignoro esta notificacion");
-
 
476
                }
-
 
477
            }
-
 
478
            if(!registrada)
-
 
479
            {
-
 
480
                notificacionDao.insert(notificacionueva);
-
 
481
            }
486
 
Línea 482... Línea 487...
482
 
487
        notificacionueva.setTitle(title);
483
            showMessageSnackBarWithClose(message);
488
        notificacionueva.setDate(dateOn);
Línea 484... Línea 489...
484
        } else {
489
        notificacionueva.setUrl(url);
485
 
490
 
486
            List<com.cesams.twogetskills.entity.NotificationCenter> lista;
491
        List<com.cesams.twogetskills.entity.NotificationCenter> lista;
487
            lista=notificacionDao.selectAllNotification();
-
 
488
 
-
 
489
            boolean registrada=false;
-
 
490
            notificacionueva.setDescription(body);
-
 
491
 
-
 
492
            for(com.cesams.twogetskills.entity.NotificationCenter notificacion: lista)
-
 
493
            {
492
        lista=notificacionDao.selectAllNotification();
-
 
493
 
-
 
494
        boolean registrada=false;
-
 
495
        notificacionueva.setDescription(message);
-
 
496
 
494
                if(notificacion.getDescription().equals(notificacionueva.getDescription()))
497
        for(com.cesams.twogetskills.entity.NotificationCenter notificacion: lista)
-
 
498
        {
495
                {
499
            if(notificacion.getDescription().equals(notificacionueva.getDescription()))
496
                    registrada=true;
-
 
497
                    Log.e("Ya registrada"," ignoro esta notificacion");
-
 
498
                }
500
            {
-
 
501
                registrada=true;
-
 
502
                //Ya existia, como llego de nuevo la pongo en no vista nuevamente.
-
 
503
                notificacionueva.setId(notificacion.getId());
-
 
504
                notificacionueva.setViewed("No");
499
            }
505
                notificacionDao.update(notificacionueva);
Línea 500... Línea 506...
500
            if(!registrada)
506
                Log.e("Ya existia","la notificacion: "+notificacion.getDescription());
Línea 501... Línea 507...
501
            {
507
            }
502
                notificacionDao.insert(notificacionueva);
508
        }
Línea 789... Línea 795...
789
            signout();
795
            signout();
790
        }
796
        }
Línea 791... Línea 797...
791
 
797
 
Línea -... Línea 798...
-
 
798
        if (command.equals("content-refresh")){
Línea 792... Línea -...
792
        if (command.equals("content-refresh")){
-
 
793
 
-
 
794
 
-
 
795
            AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(MainActivity.this);
799
 
796
            alertDialogBuilder.setMessage("Tienes nuevas capsulas para descargar");
-
 
797
                    alertDialogBuilder.setPositiveButton("Si, actualizar ahora",
-
 
Línea 798... Línea 800...
798
                            new DialogInterface.OnClickListener() {
800
            saveNotificationCenterNew("Nuevo contenido para descargar","","Tienes nuevas capsulas de aprendizaje para descargar");
799
                                @Override
-
 
800
                                public void onClick(DialogInterface arg0, int arg1) {
-
 
Línea 801... Línea -...
801
 
-
 
802
                                    preference.setRefreshContentRequired(true);
-
 
Línea 803... Línea -...
803
                                    Toast.makeText(MainActivity.this,"Actualizando tus capsulas...",Toast.LENGTH_LONG).show();
-
 
804
                                    invokeFragment(Constants.IDX_FRAGMENT_TOPICS);
-
 
805
 
-
 
806
                                }
-
 
807
                            });
-
 
808
 
-
 
809
            alertDialogBuilder.setNegativeButton("No, ahora no",new DialogInterface.OnClickListener() {
-
 
810
                @Override
-
 
811
                public void onClick(DialogInterface dialog, int which) {
-
 
812
                    Toast.makeText(MainActivity.this,"Ok, al finalizar recuerda actualizar tus capsulas en Tópicos deslizando hacia abajo",Toast.LENGTH_LONG).show();
-
 
813
                }
-
 
814
            });
801
 
815
 
802
            preference.setRefreshContentRequired(true);
Línea -... Línea 803...
-
 
803
 
-
 
804
            Cartelrefreshcontent();
-
 
805
 
-
 
806
 
-
 
807
        }
-
 
808
    }
-
 
809
 
Línea -... Línea 810...
-
 
810
    public void Cartelrefreshcontent (){
-
 
811
        AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(MainActivity.this);
-
 
812
        alertDialogBuilder.setMessage("Tienes nuevas capsulas para descargar");
-
 
813
        alertDialogBuilder.setPositiveButton("Si, actualizar ahora",
-
 
814
                new DialogInterface.OnClickListener() {
-
 
815
                    @Override
-
 
816
                    public void onClick(DialogInterface arg0, int arg1) {
-
 
817
 
-
 
818
                        Toast.makeText(MainActivity.this,"Actualizando tus capsulas...",Toast.LENGTH_LONG).show();
-
 
819
                        invokeFragment(Constants.IDX_FRAGMENT_TOPICS);
-
 
820
 
-
 
821
                    }
Línea 816... Línea 822...
816
            AlertDialog alertDialog = alertDialogBuilder.create();
822
                });
817
            alertDialog.show();
823
 
818
            alertDialog.getButton(alertDialog.BUTTON_NEGATIVE).setTextColor(getResources().getColor(R.color.backgroundErrorConnection, null));
824
 
819
            alertDialog.getButton(alertDialog.BUTTON_POSITIVE).setTextColor(getResources().getColor(R.color.teal_700, null));
825
        AlertDialog alertDialog = alertDialogBuilder.create();
Línea 2350... Línea 2356...
2350
                            }
2356
                            }
Línea 2351... Línea 2357...
2351
 
2357
 
2352
                        }
2358
                        }
Línea 2353... Línea -...
2353
                    }*/
-
 
2354
 
-
 
2355
                    Date date = calendar.getTime();
-
 
2356
 
-
 
2357
                    String  dateOn = simpleDateFormat.format(date);
-
 
2358
 
-
 
2359
 
-
 
Línea 2360... Línea -...
2360
                    NotificationCenterDao notificacionDao =  mAppDatabase.getNotificationCenterDao();
-
 
2361
                    com.cesams.twogetskills.entity.NotificationCenter notificacionueva;
-
 
2362
 
-
 
2363
                    notificacionueva = new com.cesams.twogetskills.entity.NotificationCenter();
-
 
2364
 
-
 
2365
                    notificacionueva.setTitle("Nuevo contenido disponible");
-
 
2366
                    notificacionueva.setDate(dateOn);
-
 
2367
                    notificacionueva.setDescription(message);
-
 
2368
 
-
 
2369
                    List<com.cesams.twogetskills.entity.NotificationCenter> lista;
-
 
2370
                    lista=notificacionDao.selectAllNotification();
-
 
2371
 
-
 
2372
                    for(com.cesams.twogetskills.entity.NotificationCenter notificacion: lista)
-
 
2373
                    {
-
 
2374
                        if(!notificacion.getDescription().equals(notificacionueva.getDescription()))
-
 
2375
                        {
-
 
2376
                            notificacionDao.insert(notificacionueva);
-
 
2377
                            Log.e("Ya registrada"," ignoro esta notificacion");
2359
                    }*/
2378
                        }
2360
 
2379
                    }
2361
 
2380
                }
2362
                }
2381
            }
2363
            }
Línea 2518... Línea 2500...
2518
                        public void onResponse(Call call, Response response)
2500
                        public void onResponse(Call call, Response response)
2519
                                throws IOException {
2501
                                throws IOException {
2520
                            Log.d(TAG, "Response Device :  " +  response.body().toString());
2502
                            Log.d(TAG, "Response Device :  " +  response.body().toString());
2521
                            isSyncDevice = false;
2503
                            isSyncDevice = false;
Línea 2522... Línea 2504...
2522
 
2504
 
2523
                            processResponseSyncToServer(response.body().string());
2505
                            processResponseSyncToServer(response.body().string(),"device");
Línea 2524... Línea 2506...
2524
                        }
2506
                        }
2525
 
2507
 
2526
                        public void onFailure(Call call, IOException e) {
2508
                        public void onFailure(Call call, IOException e) {
Línea 2557... Línea 2539...
2557
                    call.enqueue(new okhttp3.Callback() {
2539
                    call.enqueue(new okhttp3.Callback() {
2558
                        public void onResponse(Call call, Response response)
2540
                        public void onResponse(Call call, Response response)
2559
                                throws IOException {
2541
                                throws IOException {
2560
                            isSyncToken = false;
2542
                            isSyncToken = false;
2561
                            Log.e("Se envio", "Procesando respuesta");
2543
                            Log.e("Se envio", "Procesando respuesta");
2562
                            processResponseSyncToServer(response.body().string());
2544
                            processResponseSyncToServer(response.body().string(),"");
2563
                        }
2545
                        }
Línea 2564... Línea 2546...
2564
 
2546
 
2565
                        public void onFailure(Call call, IOException e) {
2547
                        public void onFailure(Call call, IOException e) {
2566
                            Log.d(TAG, "Error :  " +  e.getMessage());
2548
                            Log.d(TAG, "Error :  " +  e.getMessage());
Línea 2672... Línea 2654...
2672
        } catch (JSONException e) {
2654
        } catch (JSONException e) {
2673
            e.printStackTrace();
2655
            e.printStackTrace();
2674
        }
2656
        }
2675
    }
2657
    }
Línea 2676... Línea 2658...
2676
 
2658
 
2677
    private void processResponseSyncToServer(String dataString)
2659
    private void processResponseSyncToServer(String dataString, String origen)
2678
    {
2660
    {
2679
        boolean success = false;
2661
        boolean success = false;
Línea 2680... Línea 2662...
2680
        long sync_id = 0;
2662
        long sync_id = 0;
Línea 2709... Línea 2691...
2709
            }
2691
            }
2710
            Log.d(TAG, "SyncID = " + sync_id);
2692
            Log.d(TAG, "SyncID = " + sync_id);
2711
            if(success && sync_id > 0) {
2693
            if(success && sync_id > 0) {
2712
                Log.d(TAG, "DELETE SYNC RECORD : " + sync_id);
2694
                Log.d(TAG, "DELETE SYNC RECORD : " + sync_id);
2713
                mAppDatabase.getSyncDao().remove(sync_id);
2695
                mAppDatabase.getSyncDao().remove(sync_id);
-
 
2696
 
-
 
2697
                if(origen.equals("device"))
-
 
2698
                {
-
 
2699
                    syncToServerOrCheckChanges();
-
 
2700
 
-
 
2701
                }
2714
            }
2702
            }
2715
        } catch (JSONException e) {
2703
        } catch (JSONException e) {
2716
            e.printStackTrace();
2704
            e.printStackTrace();
2717
        }
2705
        }
2718
    }
2706
    }