Proyectos de Subversion Android Microlearning - Nuevo Interface

Rev

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

Rev 26 Rev 27
Línea 19... Línea 19...
19
import android.app.PendingIntent;
19
import android.app.PendingIntent;
20
import android.content.ContentResolver;
20
import android.content.ContentResolver;
21
import android.content.DialogInterface;
21
import android.content.DialogInterface;
22
import android.net.ConnectivityManager;
22
import android.net.ConnectivityManager;
23
import android.os.Build;
23
import android.os.Build;
-
 
24
import android.os.Handler;
24
import android.text.TextUtils;
25
import android.text.TextUtils;
25
import android.util.Log;
26
import android.util.Log;
26
import android.content.Context;
27
import android.content.Context;
27
import android.content.Intent;
28
import android.content.Intent;
28
import android.content.IntentFilter;
29
import android.content.IntentFilter;
Línea 103... Línea 104...
103
import com.cesams.twogetskills.R;
104
import com.cesams.twogetskills.R;
Línea 104... Línea 105...
104
 
105
 
105
import com.cesams.twogetskills.fragment.IntroFragment;
106
import com.cesams.twogetskills.fragment.IntroFragment;
106
import com.cesams.twogetskills.fragment.SigninFragment;
107
import com.cesams.twogetskills.fragment.SigninFragment;
-
 
108
import com.cesams.twogetskills.skeleton.ITwoGetSkills;
Línea 107... Línea 109...
107
import com.cesams.twogetskills.skeleton.ITwoGetSkills;
109
import com.google.firebase.messaging.FirebaseMessagingService;
108
 
110
 
109
import org.json.JSONArray;
111
import org.json.JSONArray;
Línea 157... Línea 159...
157
    private InternalReceiver mInternalReceiver;
159
    private InternalReceiver mInternalReceiver;
158
    private ProgressBar mProgressBar;
160
    private ProgressBar mProgressBar;
159
    private Toolbar mToolbar;
161
    private Toolbar mToolbar;
160
    private Account mAccount;
162
    private Account mAccount;
161
    private AppDatabase mAppDatabase;
163
    private AppDatabase mAppDatabase;
162
 
-
 
163
    private SlideRefreshUIViewModel mSlideRefreshUIViewModel;
164
    private Handler handler;
Línea 164... Línea 165...
164
 
165
 
165
 
166
 
Línea 187... Línea 188...
187
        super.onCreate(savedInstanceState);
188
        super.onCreate(savedInstanceState);
188
        setContentView(R.layout.activity_main);
189
        setContentView(R.layout.activity_main);
Línea 189... Línea 190...
189
 
190
 
Línea -... Línea 191...
-
 
191
        Log.d(TAG, "MainActivity onCreate");
-
 
192
 
-
 
193
        mAppDatabase = DatabaseHelper.getInstance(getApplicationContext()).getAppDatabase();
-
 
194
 
-
 
195
        preference = Preference.getInstance(getApplicationContext());
-
 
196
        preference.load();
-
 
197
 
-
 
198
        handler = new Handler();
-
 
199
 
-
 
200
        final Runnable r = new Runnable() {
-
 
201
            public void run() {
-
 
202
 
-
 
203
                if(TextUtils.isEmpty(preference.getDeviceUuid())) {
-
 
204
                    //  Log.e("Encontre","vacio el preferencie"+preference.getDeviceUuid());
-
 
205
                    String uuid = UniqueID.id(getApplicationContext());
-
 
206
                    preference.setDeviceUuid(uuid);
-
 
207
                    Log.e("Device", "nuevo " + uuid);
-
 
208
                    preference.save();
-
 
209
 
-
 
210
                    Sync sync = new Sync(Constants.SYNC_ADAPTER_TYPE_DEVICE, uuid);
-
 
211
                    mAppDatabase.getSyncDao().insert(sync);
-
 
212
 
-
 
213
                }
-
 
214
                if(TextUtils.isEmpty(preference.getDeviceToken())) {
-
 
215
                    Log.e("Aun sin token "," vamos a esperar");
-
 
216
 
-
 
217
                    handler.postDelayed(this, 2000);
-
 
218
                }
-
 
219
                else
-
 
220
                {
-
 
221
                    Log.e("Ya tengo"," token");
-
 
222
                    if(TextUtils.isEmpty(preference.getDeviceUuid())) {
-
 
223
                        //  Log.e("Encontre","vacio el preferencie"+preference.getDeviceUuid());
-
 
224
                        String uuid = UniqueID.id(getApplicationContext());
-
 
225
                        preference.setDeviceUuid(uuid);
-
 
226
                        Log.e("Device","nuevo "+uuid);
-
 
227
                        preference.save();
-
 
228
 
-
 
229
                        Sync sync = new Sync(Constants.SYNC_ADAPTER_TYPE_DEVICE, uuid);
-
 
230
                        mAppDatabase.getSyncDao().insert(sync);
-
 
231
 
-
 
232
                        Log.e("Token a este", "punto: "+preference.getDeviceToken());
-
 
233
 
-
 
234
 
-
 
235
                    }
-
 
236
                    else
-
 
237
                    {
-
 
238
                        if(!TextUtils.isEmpty(preference.getDeviceToken()) && isSyncDevice) {
-
 
239
                           Sync sync = new Sync(Constants.SYNC_ADAPTER_TYPE_FCM, preference.getDeviceToken());
-
 
240
                            // Log.e("Intento","Sync token to server"+preference.getDeviceToken());
-
 
241
                            mAppDatabase.getSyncDao().insert(sync);
-
 
242
                            syncToServerOrCheckChanges();
-
 
243
                        }
-
 
244
                        {
-
 
245
                            Log.e("Tengo el FCM"," pero no he syn el device");
-
 
246
                        }
-
 
247
                    }
-
 
248
                }
-
 
249
            }
-
 
250
        };
-
 
251
 
190
        Log.d(TAG, "MainActivity onCreate");
252
        handler.postDelayed(r, 2000);
191
 
253
 
Línea 192... Línea 254...
192
        /**** CANAL DE NOTIFICACIONES **/
254
        /**** CANAL DE NOTIFICACIONES **/
193
        createNotificationChannel();
255
        createNotificationChannel();
Línea 194... Línea 256...
194
 
256
 
195
        /*** CUENTAS DE SINCRONIZACION **/
257
        /*** CUENTAS DE SINCRONIZACION **/
Línea 196... Línea -...
196
        mAccount =  CreateSyncAccount(getApplicationContext());
-
 
Línea 197... Línea -...
197
 
-
 
198
 
-
 
199
        // Get the content resolver for your app
-
 
200
        //mResolver = getContentResolver();
-
 
201
 
-
 
202
        mAppDatabase = DatabaseHelper.getInstance(getApplicationContext()).getAppDatabase();
-
 
203
 
-
 
204
        preference = Preference.getInstance(getApplicationContext());
-
 
205
        preference.load();
-
 
206
 
-
 
207
        if(TextUtils.isEmpty(preference.getDeviceUuid())) {
-
 
208
            Log.e("Encontre","vacio el preferencie"+preference.getDeviceUuid());
-
 
209
            String uuid = UniqueID.id(getApplicationContext());
-
 
210
            preference.setDeviceUuid(uuid);
-
 
211
            Log.e("Pero ya setie","uno nuevo"+uuid);
-
 
212
            preference.save();
-
 
213
 
-
 
214
            Sync sync = new Sync(Constants.SYNC_ADAPTER_TYPE_DEVICE, uuid);
-
 
Línea 215... Línea 258...
215
            mAppDatabase.getSyncDao().insert(sync);
258
        mAccount =  CreateSyncAccount(getApplicationContext());
Línea 216... Línea 259...
216
 
259
 
217
            if(!TextUtils.isEmpty(preference.getDeviceToken())) {
260
 
Línea 367... Línea 410...
367
      //  navHeaderUserName = header.findViewById(R.id.nav_header_user_name);
410
      //  navHeaderUserName = header.findViewById(R.id.nav_header_user_name);
368
      //  navHeaderUserEmail =  header.findViewById(R.id.nav_header_user_email);
411
      //  navHeaderUserEmail =  header.findViewById(R.id.nav_header_user_email);
Línea 369... Línea 412...
369
 
412
 
Línea 370... Línea -...
370
        textViewMessageNotConnection = findViewById(R.id.main_activity_text_view_message_not_connection);
-
 
Línea 371... Línea 413...
371
 
413
        textViewMessageNotConnection = findViewById(R.id.main_activity_text_view_message_not_connection);
372
        mSlideRefreshUIViewModel = new ViewModelProvider(this).get(SlideRefreshUIViewModel.class);
414
 
Línea 414... Línea 456...
414
        preference = Preference.getInstance(getApplicationContext());
456
        preference = Preference.getInstance(getApplicationContext());
415
        preference.load();
457
        preference.load();
Línea 416... Línea 458...
416
        
458
        
Línea 417... Línea 459...
417
       // reloadNavHeader();
459
       // reloadNavHeader();
Línea 418... Línea 460...
418
 
460
 
Línea 419... Línea 461...
419
        Log.e("Se ejecuta", "On resumen");
461
       // Log.e("Se ejecuta", "On resumen");
Línea 420... Línea 462...
420
 
462
 
421
        Log.e("El device uuid",""+preference.getDeviceUuid());
463
       // Log.e("El device uuid",""+preference.getDeviceUuid());
Línea 431... Línea 473...
431
 
473
 
432
 
474
 
433
        } else {
475
        } else {
434
            if(preference.getFragmentIdxActive() == 0) {
476
            if(preference.getFragmentIdxActive() == 0) {
435
                invokeFragment(Constants.IDX_FRAGMENT_TOPICS);
477
                invokeFragment(Constants.IDX_FRAGMENT_TOPICS);
436
                Log.e("El device uuid",""+preference.getDeviceUuid());
478
              //  Log.e("El device uuid",""+preference.getDeviceUuid());
437
            } else {
479
            } else {
438
                invokeFragment(preference.getFragmentIdxActive());
480
                invokeFragment(preference.getFragmentIdxActive());
Línea 622... Línea 664...
622
            notificacionueva = new com.cesams.twogetskills.entity.NotificationCenter();
664
            notificacionueva = new com.cesams.twogetskills.entity.NotificationCenter();
Línea 623... Línea 665...
623
 
665
 
624
            notificacionueva.setTitle("Nuevo contenido disponible");
666
            notificacionueva.setTitle("Nuevo contenido disponible");
625
            notificacionueva.setDate(dateOn);
667
            notificacionueva.setDate(dateOn);
626
            notificacionueva.setDescription(message);
668
            notificacionueva.setDescription(message);
627
            Log.e("Notificacion","a guardar"+notificacionueva);
669
           // Log.e("Notificacion","a guardar"+notificacionueva);
Línea 628... Línea 670...
628
            notificacionDao.insert(notificacionueva);
670
            notificacionDao.insert(notificacionueva);
629
 
671
 
630
            showMessageSnackBarWithClose(message);
672
            showMessageSnackBarWithClose(message);
Línea 631... Línea 673...
631
        } else {
673
        } else {
632
            notificacionueva = new com.cesams.twogetskills.entity.NotificationCenter();
674
            notificacionueva = new com.cesams.twogetskills.entity.NotificationCenter();
633
 
675
 
634
            notificacionueva.setTitle("Nuevo contenido disponible");
676
            notificacionueva.setTitle("Nuevo contenido disponible");
635
            notificacionueva.setDate(dateOn);
677
            notificacionueva.setDate(dateOn);
Línea 636... Línea 678...
636
            notificacionueva.setDescription(body);
678
            notificacionueva.setDescription(body);
637
            Log.e("Notificacion","a guardar"+notificacionueva);
679
          //  Log.e("Notificacion","a guardar"+notificacionueva);
Línea 676... Línea 718...
676
    }
718
    }
Línea 677... Línea 719...
677
 
719
 
678
    @Override
720
    @Override
Línea 679... Línea 721...
679
    public void onBackPressed() {
721
    public void onBackPressed() {
Línea 680... Línea 722...
680
 
722
 
681
        Log.e("Origen navegacion",""+preference.getOrigenNavigation());
723
       // Log.e("Origen navegacion",""+preference.getOrigenNavigation());
682
 
724
 
Línea 796... Línea 838...
796
    }
838
    }
Línea 797... Línea 839...
797
 
839
 
798
    @Override
840
    @Override
Línea 799... Línea 841...
799
    public void hideNavigationAndtoolbar() {
841
    public void hideNavigationAndtoolbar() {
800
 
842
 
801
        Log.e("Ocultar"," Navigation and Toolbar");
843
       // Log.e("Ocultar"," Navigation and Toolbar");
802
        //accessing it from ui-thread
844
        //accessing it from ui-thread
803
        runOnUiThread(() -> {
845
        runOnUiThread(() -> {
804
            mNavigationView.setVisibility(View.GONE);
846
            mNavigationView.setVisibility(View.GONE);
Línea 897... Línea 939...
897
 
939
 
898
    @Override
940
    @Override
899
    public void createSyncRecordNewToken(String token)
941
    public void createSyncRecordNewToken(String token)
Línea -... Línea 942...
-
 
942
    {
900
    {
943
 
901
 
944
        Log.e("Token", "Seteo en preferences el token FCM");
Línea 902... Línea 945...
902
        preference.setDeviceToken (token);
945
       // preference.setDeviceToken (token);
-
 
946
       // preference.save();
903
        preference.save();
947
 
904
 
948
        if(!TextUtils.isEmpty(preference.getDeviceUuid())) {
905
        if(!TextUtils.isEmpty(preference.getDeviceUuid())) {
949
            Log.e("Creacion"," del synctoken record");
906
            Sync sync = new Sync(Constants.SYNC_ADAPTER_TYPE_FCM, token);
950
            Sync sync = new Sync(Constants.SYNC_ADAPTER_TYPE_FCM, token);
Línea 965... Línea 1009...
965
    }
1009
    }
Línea 966... Línea 1010...
966
 
1010
 
967
    @Override
1011
    @Override
968
    public void invokeFragment(int fragmentIdxActiveNuevo)
1012
    public void invokeFragment(int fragmentIdxActiveNuevo)
969
    {
1013
    {
Línea 970... Línea 1014...
970
        Log.e("Invoco fragmento"," "+fragmentIdxActiveNuevo);
1014
       // Log.e("Invoco fragmento"," "+fragmentIdxActiveNuevo);
971
 
1015
 
972
        String fragmentKeyActual    = PREFIX_FRAG + preference.getFragmentIdxActive();
1016
        String fragmentKeyActual    = PREFIX_FRAG + preference.getFragmentIdxActive();
973
        String fragmentKeyNuevo 	= PREFIX_FRAG + fragmentIdxActiveNuevo;
1017
        String fragmentKeyNuevo 	= PREFIX_FRAG + fragmentIdxActiveNuevo;
Línea 1132... Línea 1176...
1132
                if(fragmentHashMap.containsKey(fragmentKeyNuevo)) {
1176
                if(fragmentHashMap.containsKey(fragmentKeyNuevo)) {
1133
                    fragment = fragmentHashMap.get(fragmentKeyNuevo);
1177
                    fragment = fragmentHashMap.get(fragmentKeyNuevo);
1134
                } else {
1178
                } else {
1135
                    add = true;
1179
                    add = true;
1136
                    fragment = new WelcomeFragment();
1180
                    fragment = new WelcomeFragment();
1137
                    Log.e("Vete"," a welcome");
1181
                  //  Log.e("Vete"," a welcome");
1138
                }
1182
                }
1139
                break;
1183
                break;
Línea 1140... Línea 1184...
1140
 
1184
 
1141
            default :
1185
            default :
Línea 2182... Línea 2226...
2182
 
2226
 
2183
 
2227
 
Línea 2184... Línea 2228...
2184
 
2228
 
2185
 
2229
 
2186
                    arrayCapsules = objTopic.getJSONArray("capsules");
2230
                    arrayCapsules = objTopic.getJSONArray("capsules");
2187
                    Log.e("Objeto:",""+objTopic.getJSONArray("capsules"));
2231
                  //  Log.e("Objeto:",""+objTopic.getJSONArray("capsules"));
Línea 2509... Línea 2553...
2509
                    notificacionueva = new com.cesams.twogetskills.entity.NotificationCenter();
2553
                    notificacionueva = new com.cesams.twogetskills.entity.NotificationCenter();
Línea 2510... Línea 2554...
2510
 
2554
 
2511
                    notificacionueva.setTitle("Nuevo contenido disponible");
2555
                    notificacionueva.setTitle("Nuevo contenido disponible");
2512
                    notificacionueva.setDate(dateOn);
2556
                    notificacionueva.setDate(dateOn);
2513
                    notificacionueva.setDescription(message);
2557
                    notificacionueva.setDescription(message);
2514
                    Log.e("Notificacion","a guardar"+notificacionueva);
2558
                   // Log.e("Notificacion","a guardar"+notificacionueva);
2515
                    notificacionDao.insert(notificacionueva);
2559
                    notificacionDao.insert(notificacionueva);
2516
                }
2560
                }
2517
            }
2561
            }
2518
        } catch (JSONException e) {
2562
        } catch (JSONException e) {
Línea 2563... Línea 2607...
2563
 
2607
 
2564
    public void syncToServer(List<Sync> records)
2608
    public void syncToServer(List<Sync> records)
Línea 2565... Línea -...
2565
    {
-
 
2566
 
2609
    {
2567
 
2610
 
2568
 
2611
 
Línea 2569... Línea 2612...
2569
        int maxRecordsSyncBatch = 0;
2612
        int maxRecordsSyncBatch = 0;
2570
        FormBody.Builder formBodyBatchBuilder = new FormBody.Builder();
2613
        FormBody.Builder formBodyBatchBuilder = new FormBody.Builder();
-
 
2614
        formBodyBatchBuilder.add(Constants.POST_SYNC_BATCH_FIELD_DEVICE_UUID, preference.getDeviceUuid());
-
 
2615
 
-
 
2616
        for(Sync record : records)
2571
        formBodyBatchBuilder.add(Constants.POST_SYNC_BATCH_FIELD_DEVICE_UUID, preference.getDeviceUuid());
2617
        {
Línea 2572... Línea 2618...
2572
 
2618
 
2573
        for(Sync record : records)
2619
           // Log.e("Ingreso a", "syncToServer"+record.getType()+" data"+record.getData());
2574
        {
2620
 
Línea 2619... Línea 2665...
2619
            }
2665
            }
Línea 2620... Línea 2666...
2620
 
2666
 
2621
            if(record.getType() == Constants.SYNC_ADAPTER_TYPE_FCM && !isSyncToken) {
2667
            if(record.getType() == Constants.SYNC_ADAPTER_TYPE_FCM && !isSyncToken) {
2622
                isSyncToken = true;
2668
                isSyncToken = true;
-
 
2669
                Log.d(TAG, "FCM");
Línea 2623... Línea 2670...
2623
                Log.d(TAG, "FCM");
2670
                Log.e("Token a Sync",""+record.getData());
2624
 
2671
 
2625
                try {
2672
                try {
Línea 2641... Línea 2688...
2641
                    Call call = client.newCall(request);
2688
                    Call call = client.newCall(request);
2642
                    call.enqueue(new okhttp3.Callback() {
2689
                    call.enqueue(new okhttp3.Callback() {
2643
                        public void onResponse(Call call, Response response)
2690
                        public void onResponse(Call call, Response response)
2644
                                throws IOException {
2691
                                throws IOException {
2645
                            isSyncToken = false;
2692
                            isSyncToken = false;
-
 
2693
                            Log.e("Se envio", "Procesando respuesta");
2646
                            processResponseSyncToServer(response.body().string());
2694
                            processResponseSyncToServer(response.body().string());
2647
                        }
2695
                        }
Línea 2648... Línea 2696...
2648
 
2696
 
2649
                        public void onFailure(Call call, IOException e) {
2697
                        public void onFailure(Call call, IOException e) {
Línea 2800... Línea 2848...
2800
        } catch (JSONException e) {
2848
        } catch (JSONException e) {
2801
            e.printStackTrace();
2849
            e.printStackTrace();
2802
        }
2850
        }
2803
    }
2851
    }
Línea -... Línea 2852...
-
 
2852
 
-
 
2853
    private void processResponseSyncTokenFCMtoServer(String dataString)
-
 
2854
    {
-
 
2855
        Log.e("Respuesta",""+dataString);
-
 
2856
        boolean success = false;
-
 
2857
 
-
 
2858
        try {
-
 
2859
            JSONObject objJSON = new JSONObject(dataString);
-
 
2860
            success = objJSON.has("success") && objJSON.getBoolean("success");
-
 
2861
 
-
 
2862
            if(success) {
-
 
2863
                Log.e("Token almacenado"," en server de manera exitosa");
-
 
2864
            }
-
 
2865
        } catch (JSONException e) {
-
 
2866
            e.printStackTrace();
-
 
2867
        }
-
 
2868
    }
-
 
2869
 
-
 
2870
 
2804
 
2871
 
2805
    /*
2872
    /*
Línea 2806... Línea 2873...
2806
    private void processResponseServerCheckChanges(String dataString) {
2873
    private void processResponseServerCheckChanges(String dataString) {