Proyectos de Subversion Android Microlearning - Nuevo Interface

Rev

Rev 21 | Rev 54 | Ir a la última revisión | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 gabriel 1
package com.cesams.twogetskills.fragment;
2
 
3
import android.app.Activity;
4
import android.content.Context;
5
import android.content.Intent;
6
import android.location.GnssAntennaInfo;
7
import android.net.Uri;
8
import android.os.Bundle;
9
 
10
import androidx.annotation.NonNull;
11
import androidx.annotation.Nullable;
12
import androidx.fragment.app.Fragment;
13
import androidx.lifecycle.LifecycleOwner;
14
 
15
import android.text.TextUtils;
16
import android.util.Log;
17
import android.view.KeyEvent;
18
import android.view.LayoutInflater;
19
import android.view.Menu;
20
import android.view.MenuInflater;
21
import android.view.View;
22
import android.view.ViewGroup;
23
import android.view.inputmethod.EditorInfo;
24
import android.view.inputmethod.InputMethodManager;
25
import android.widget.Button;
26
import android.widget.EditText;
27
import android.widget.ProgressBar;
28
import android.widget.TextView;
29
 
30
import com.cesams.twogetskills.Configuration;
31
import com.cesams.twogetskills.Constants;
32
import com.cesams.twogetskills.R;
33
import com.cesams.twogetskills.activity.MainActivity;
25 gabriel 34
import com.cesams.twogetskills.dao.NotificationCenterDao;
1 gabriel 35
import com.cesams.twogetskills.dao.SyncDao;
36
import com.cesams.twogetskills.library.AesCipher;
37
import com.cesams.twogetskills.library.Functions;
38
import com.cesams.twogetskills.library.Http;
39
import com.cesams.twogetskills.entity.Sync;
40
import com.cesams.twogetskills.entity.UserLog;
41
import com.cesams.twogetskills.preference.Preference;
42
import com.cesams.twogetskills.room.ResultCount;
43
import com.cesams.twogetskills.skeleton.ITwoGetSkills;
44
 
45
import org.json.JSONException;
46
import org.json.JSONObject;
47
 
48
import java.io.IOException;
49
import java.text.SimpleDateFormat;
50
import java.util.Calendar;
51
import java.util.Date;
52
 
53
import okhttp3.Call;
54
import okhttp3.Callback;
55
import okhttp3.FormBody;
56
import okhttp3.OkHttpClient;
57
import okhttp3.Request;
58
import okhttp3.RequestBody;
59
import okhttp3.Response;
60
 
61
 
62
public class SigninFragment extends Fragment implements LifecycleOwner  {
63
    //implements ITaskCallback {
64
    private final static String TAG = "C2GS - SigninFragment";
65
    private ITwoGetSkills iTwoGetSkills;
66
    private EditText mEditTextEmail;
67
    private EditText mEditTextPassword;
68
    private boolean inProgress = false;
69
    private Button mButtonSignIn;
70
    private Button mButtonSignUp;
71
    private ProgressBar mProgressBar;
25 gabriel 72
    String dateOn;
1 gabriel 73
 
74
    @Override
75
    public void onCreate(@Nullable Bundle savedInstanceState) {
76
        super.onCreate(savedInstanceState);
77
        setHasOptionsMenu(true);
8 gabriel 78
 
79
 
1 gabriel 80
    }
81
 
82
    @Override
83
    public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
84
        super.onCreateOptionsMenu(menu, inflater);
85
        menu.clear();
86
    }
87
 
88
 
89
    @Override
90
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
91
        super.onViewCreated(view, savedInstanceState);
92
        iTwoGetSkills = (ITwoGetSkills) getActivity();
19 gabriel 93
        mProgressBar = (ProgressBar) getView().findViewById(R.id.signin_progress_bar);
94
        mEditTextEmail = (EditText) getView().findViewById(R.id.signin_edittext_email);
1 gabriel 95
        //mEditTextEmail.setText("santiago.olivera@leaderslinked.com");
96
        //mEditTextEmail.setText("efrain.yanez@leaderslinked.com");
97
        //mEditTextEmail.setText("snof@adinet.com.uy");
98
        //mEditTextEmail.setText("mmarrugo@coosalud.com");
19 gabriel 99
        //mEditTextEmail.setText("daniela.lara@mdsmexico.com");
1 gabriel 100
 
101
 
102
        mEditTextEmail.setOnEditorActionListener(new TextView.OnEditorActionListener() {
103
            @Override
104
            public boolean onEditorAction(TextView textView, int id, KeyEvent keyEvent) {
105
                mEditTextPassword.requestFocus();
106
                return true;
107
            }
108
        });
109
 
110
        mEditTextPassword = (EditText) getView().findViewById(R.id.signin_edittext_password);
111
        //mEditTextPassword.setText("Cesa2020");
112
        //mEditTextPassword.setText("Aalmiron2021");
113
        //mEditTextPassword.setText("Mmarrugo2021");
114
        //mEditTextPassword.setText("Cesa2020*");
115
        mEditTextPassword.setOnEditorActionListener(new TextView.OnEditorActionListener() {
116
            @Override
117
            public boolean onEditorAction(TextView textView, int id, KeyEvent keyEvent) {
118
                if (id == EditorInfo.IME_ACTION_DONE || id == EditorInfo.IME_NULL) {
119
                    attemptLogin();
120
                    return true;
121
                }
122
                return false;
123
            }
124
        });
125
 
126
        mButtonSignIn = (Button) getView().findViewById(R.id.signin_button_sign_in);
127
        mButtonSignIn.setOnClickListener(new View.OnClickListener() {
128
            @Override
129
            public void onClick(View view) {
130
 
131
                //Ocultar el teclado al intentar inicia sesion
132
                hideKeyboard(view);
133
 
134
                attemptLogin();
135
            }
136
        });
137
 
138
 
139
        //
140
 
141
        mButtonSignUp = (Button) getView().findViewById(R.id.signin_button_sign_up);
142
        mButtonSignUp.setOnClickListener(new View.OnClickListener() {
143
            @Override
144
            public void onClick(View view) {
145
                Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://leaderslinked.com/signup"));
146
                startActivity(browserIntent);
147
            }
148
        });
149
 
150
        mEditTextEmail.setOnFocusChangeListener(new View.OnFocusChangeListener() {
151
            @Override
152
            public void onFocusChange(View v, boolean hasFocus) {
153
                if(!hasFocus) {
154
                    hideKeyboard(v);
155
                }
156
            }
157
        });
158
 
159
 
160
    }
161
 
162
    public void hideKeyboard(View view) {
163
        // Check if no view has focus:
164
        //View view = getActivity().getCurrentFocus();
165
 
166
        try {
167
            InputMethodManager inputManager = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
168
            inputManager.hideSoftInputFromWindow(view.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
169
        } catch (Exception e) {
170
            e.printStackTrace();
171
        }
172
    }
173
 
174
    private void attemptLogin() {
175
 
176
 
177
 
178
        if (inProgress) {
179
            return;
180
        }
181
 
3 gabriel 182
        /*
1 gabriel 183
        if(TextUtils.isEmpty(iTwoGetSkills.getPreference().getAes())) {
184
            iTwoGetSkills.reloadPreference();
185
        }
3 gabriel 186
        */
1 gabriel 187
 
188
 
189
        mEditTextEmail.setError(null);
190
        mEditTextPassword.setError(null);
191
 
192
        String email = Functions.trimNull(mEditTextEmail.getText().toString());
193
        String password = Functions.trimNull(mEditTextPassword.getText().toString());
194
 
195
        if (TextUtils.isEmpty(email)) {
196
            mEditTextEmail.setError(getString(R.string.error_field_required));
197
            mEditTextEmail.requestFocus();
198
            return;
199
        }
200
 
3 gabriel 201
        if (!Functions.emailcheckengine(email)) {
202
            mEditTextEmail.setError("Formato de email invalido");
203
            mEditTextEmail.requestFocus();
204
            return;
205
        }
206
 
1 gabriel 207
        if (TextUtils.isEmpty(password)) {
208
            mEditTextPassword.setError(getString(R.string.error_field_required));
209
            mEditTextPassword.requestFocus();
210
            return;
211
        }
212
 
213
 
214
        if (!Functions.passwordStrengthCheck(password)) {
215
            mEditTextPassword.setError(getString(R.string.error_invalid_password_format));
216
            mEditTextPassword.requestFocus();
217
            return;
218
        }
219
 
220
        if(iTwoGetSkills.isConnectedInternet()) {
221
            inProgress = true;
222
 
223
 
224
            String aes = iTwoGetSkills.getPreference().getAes();
225
 
226
            mEditTextEmail.setEnabled(false);
227
            mEditTextPassword.setEnabled(false);
19 gabriel 228
            mButtonSignUp.setEnabled(false);
1 gabriel 229
            mButtonSignIn.setEnabled(false);
19 gabriel 230
            iTwoGetSkills.showProgressBar();
1 gabriel 231
 
232
            try {
233
 
234
                Log.d("AES", aes);
235
 
236
                Http http = new Http(getActivity().getCacheDir());
237
                OkHttpClient client = http.getHttpClient(false);
238
 
239
                Log.d(TAG, "URL = " + Configuration.URL_SIGNIN);
240
 
241
                RequestBody formBody = null;
242
                if(aes.isEmpty()) {
243
                    formBody = new FormBody.Builder()
244
                            .add(Constants.POST_SIGNIN_FIELD_APPLICATION_ID, String.valueOf(Configuration.APPLICATION_ID))
245
                            .add(Constants.POST_SIGNIN_FIELD_DEVICE_UUID, iTwoGetSkills.getPreference().getDeviceUuid())
246
                            .add(Constants.POST_SIGNIN_FIELD_EMAIL, email)
247
                            .add(Constants.POST_SIGNIN_FIELD_PASSWORD, password)
248
                            .add(Constants.POST_SIGNIN_FIELD_DEVICE_ENCRYPTER, "") //Constants.SIGNIN_ENCRYPTER)
249
                            .build();
250
                } else {
251
                    AesCipher encryptedEmail    = AesCipher.encrypt(aes, email);
252
                    AesCipher encryptedPassword = AesCipher.encrypt(aes, password);
253
 
254
                    formBody = new FormBody.Builder()
255
                            .add(Constants.POST_SIGNIN_FIELD_APPLICATION_ID, String.valueOf(Configuration.APPLICATION_ID))
256
                            .add(Constants.POST_SIGNIN_FIELD_DEVICE_UUID, iTwoGetSkills.getPreference().getDeviceUuid())
257
                            .add(Constants.POST_SIGNIN_FIELD_EMAIL, encryptedEmail.getData())
258
                            .add(Constants.POST_SIGNIN_FIELD_PASSWORD, encryptedPassword.getData())
259
                            .add(Constants.POST_SIGNIN_FIELD_DEVICE_ENCRYPTER, Constants.SIGNIN_ENCRYPTER)
260
                            .build();
261
                }
262
 
263
 
264
 
265
 
266
 
267
 
268
                Request request = new Request.Builder()
269
                        .url(Configuration.URL_SIGNIN)
270
                        .post(formBody)
271
                        .build();
272
 
273
                Call call = client.newCall(request);
274
 
275
                call.enqueue(new Callback() {
276
                    public void onResponse(Call call, Response response)
277
                            throws IOException {
278
 
19 gabriel 279
                        processResponseServer(response.body().string());
1 gabriel 280
                        iTwoGetSkills.hideProgressBar();
19 gabriel 281
                        getActivity().runOnUiThread(new Runnable() {
1 gabriel 282
 
19 gabriel 283
                            @Override
284
                            public void run() {
285
                                mButtonSignIn.setEnabled(true);
286
                                mButtonSignUp.setEnabled(true);
287
                                mEditTextEmail.setEnabled(true);
288
                                mEditTextPassword.setEnabled(true);
289
                                inProgress = false;
290
                            }
1 gabriel 291
 
19 gabriel 292
                        });
293
 
1 gabriel 294
                    }
295
 
296
                    public void onFailure(Call call, IOException e) {
297
                        Log.d(TAG, "Error :  " +  e.getMessage());
298
                        iTwoGetSkills.hideProgressBar();
19 gabriel 299
                        getActivity().runOnUiThread(new Runnable() {
300
 
301
                            @Override
302
                            public void run() {
303
                                mButtonSignIn.setEnabled(true);
304
                                mButtonSignUp.setEnabled(true);
305
                                mEditTextEmail.setEnabled(true);
306
                                mEditTextPassword.setEnabled(true);
307
                                inProgress = false;
308
                            }
309
                        });
310
 
311
 
312
 
313
 
1 gabriel 314
                    }
315
                });
316
 
317
            } catch (Exception e) {
318
                iTwoGetSkills.showMessageSnackBar(e.getMessage());
319
            } finally {
320
 
321
            }
322
 
323
 
324
        }
325
    }
326
 
327
    private boolean isPasswordValid(String password) {
328
        //TODO: Replace this with your own logic
329
        return password.length() > 5;
330
    }
331
 
332
    private void processResponseServer(String dataString) {
333
        boolean success = false;
334
        boolean fatal = false;
335
        String message = "";
336
 
337
        mProgressBar.setVisibility(View.INVISIBLE);
338
 
339
        try {
340
            JSONObject objData = new JSONObject(dataString);
341
            success = objData.has("success") ? objData.getBoolean("success")  : false;
342
            if(objData.has("data")) {
343
                Object item = objData.get("data");
344
                if (item instanceof String) {
345
                    message = (String) item;
346
                }
347
                fatal = objData.has("fatal");
348
            }
349
 
350
            if(success) {
351
                JSONObject data = objData.getJSONObject("data");
352
 
353
 
354
                Calendar calendar = Calendar.getInstance();
355
                Date date = calendar.getTime();
356
                SimpleDateFormat simpleDateFormat = new SimpleDateFormat(Constants.FORMAT_DATETIME_SERVICE);
357
                String  addedOn = simpleDateFormat.format(date);
9 gabriel 358
 
359
                //Elimino antes de guardar.
19 gabriel 360
                JSONObject objUser = data.getJSONObject("user");
361
                String userUuid = objUser.getString("uuid");
362
 
9 gabriel 363
                iTwoGetSkills.getDatabase().getAnswerDao().removeAll();
364
                iTwoGetSkills.getDatabase().getQuestionDao().removeAll();
365
                iTwoGetSkills.getDatabase().getQuizDao().removeAll();
366
                iTwoGetSkills.getDatabase().getSlideDao().removeAll();
367
                iTwoGetSkills.getDatabase().getCapsuleDao().removeAll();
368
                iTwoGetSkills.getDatabase().getTopicDao().removeAll();
369
                iTwoGetSkills.getDatabase().getUserExtendedDao().removeAll();
21 gabriel 370
                iTwoGetSkills.getDatabase().getNotificationCenterDao().removeAllnotifications();
19 gabriel 371
                iTwoGetSkills.getDatabase().getProgressDao().removeAllUserUuidNotEqual(userUuid);
372
                iTwoGetSkills.getDatabase().getUserLogDao().removeAllUserUuidNotEqual(userUuid);
1 gabriel 373
                iTwoGetSkills.syncFromServer(data);
374
 
375
 
376
                Preference preference = iTwoGetSkills.getPreference();
19 gabriel 377
                preference.setUserUuid(userUuid);
1 gabriel 378
                preference.setFirstName(objUser.getString("first_name"));
379
                preference.setLastName(objUser.getString("last_name"));
380
                preference.setEmail(objUser.getString("email"));
381
                preference.setImage(objUser.getString("image"));
382
                preference.setLastDataRefresh(addedOn);
383
 
384
                JSONObject objDevice = data.getJSONObject("device");
385
                preference.setAes(objDevice.getString("aes"));
386
                preference.setPassword(objDevice.getString("password"));
3 gabriel 387
                preference.save();
1 gabriel 388
 
21 gabriel 389
                getActivity().runOnUiThread(() -> {
1 gabriel 390
 
21 gabriel 391
                    iTwoGetSkills.invokeFragment(Constants.IDX_FRAGMENT_WELCOME);
392
                    iTwoGetSkills.showNavigationAndToolbar();
393
                });
1 gabriel 394
 
395
 
396
                UserLog userLog = new UserLog();
397
                userLog.setUserUuid(preference.getUserUuid());
398
                userLog.setActivity(Constants.USER_LOG_ACTIVITY_SIGNIN);
399
                userLog.setAddedOn(addedOn);
400
                JSONObject json = userLog.toJson();
401
                json.put(Constants.SYNC_ADAPTER_DATA_TYPE_FIELD_NAME, Constants.SYNC_ADAPTER_DATA_TYPE_USER_LOG);
402
 
403
                Sync sync = new Sync(Constants.SYNC_ADAPTER_TYPE_SYNC, json.toString());
404
 
405
                SyncDao syncDao = iTwoGetSkills.getDatabase().getSyncDao();
406
                syncDao.insert(sync);
407
 
408
 
25 gabriel 409
                dateOn = simpleDateFormat.format(date);
410
 
411
 
412
 
1 gabriel 413
            } else {
414
                if(!TextUtils.isEmpty(message)) {
25 gabriel 415
 
416
                    NotificationCenterDao notificacionDao =  iTwoGetSkills.getDatabase().getNotificationCenterDao();
417
                    com.cesams.twogetskills.entity.NotificationCenter notificacionueva;
418
                    notificacionueva = new com.cesams.twogetskills.entity.NotificationCenter();
419
 
420
                    notificacionueva.setTitle("Nuevo contenido disponible");
421
                    notificacionueva.setDate(dateOn);
422
                    notificacionueva.setDescription(message);
423
                    Log.e("Notificacion","a guardar"+notificacionueva);
424
                    notificacionDao.insert(notificacionueva);
425
 
1 gabriel 426
                    iTwoGetSkills.showMessageSnackBar(message);
427
                }
428
                if(fatal) {
429
                    iTwoGetSkills.onErrorFatal();
430
                }
431
            }
432
 
433
 
434
        } catch (JSONException e) {
435
            e.printStackTrace();
436
            Log.e(TAG,  e.getMessage());
437
        }
438
 
439
 
440
    }
441
 
442
    /*
443
    @Override
444
    public void taskCallback(HttpCommResponse httpCommResponse) {
445
        inProgress = false;
446
        mEditTextEmail.setEnabled(true);
447
        mEditTextPassword.setEnabled(true);
448
 
449
        mButtonSignIn.setEnabled(true);
450
        mProgressBar.setVisibility(View.INVISIBLE);
451
 
452
        if(httpCommResponse.isSuccess()) {
453
 
454
            AnswerDao answerDao = new AnswerDao(getActivity());
455
            answerDao.removeAll();
456
 
457
            QuestionDao questionDao = new QuestionDao(getActivity());
458
            questionDao.removeAll();
459
 
460
            QuizDao quizDao = new QuizDao(getActivity());
461
            questionDao.removeAll();
462
 
463
            SlideDao slideDao = new SlideDao(getActivity());
464
            slideDao.removeAll();
465
 
466
            CapsuleDao capsuleDao = new CapsuleDao(getActivity());
467
            capsuleDao.removeAll();
468
 
469
            TopicDao topicDao = new TopicDao(getActivity());
470
            topicDao.removeAll();
471
 
472
            CompanyDao companyDao = new CompanyDao(getActivity());
473
            companyDao.removeAll();
474
 
475
            ProgressDao progressDao = new ProgressDao(getActivity());
476
            progressDao.removeAll();
477
 
478
            UserLogDao userLogDao = new UserLogDao(getActivity());
479
 
480
            UserNotificationDao userNotificationDao = new UserNotificationDao(getActivity());
481
            userNotificationDao.removeAll();
482
 
483
            try {
484
                JSONObject objData = httpCommResponse.getObjJSON().getJSONObject("data");
485
 
486
 
487
 
488
 
489
                JSONArray arrayCapsules;
490
                JSONArray arraySlides;
491
                JSONArray arrayAnswers;
492
                JSONArray arrayQuestions;
493
                JSONArray arrayProgress;
494
                JSONArray arrayQuizzes;
495
                JSONArray arrayUserLog;
496
 
497
 
498
                JSONObject objTopic;
499
                JSONObject objCapsule;
500
                JSONObject objSlide;
501
                JSONObject objAnswer;
502
                JSONObject objQuestion;
503
                JSONObject objQuiz;
504
                JSONObject objProgress;
505
                JSONObject objUserLog;
506
                int i,j,x;
507
 
508
                arrayProgress = objData.getJSONArray("progress");
509
                for(i = 0; i <  arrayProgress.length(); i++) {
510
                    objProgress = arrayProgress.getJSONObject(i);
511
 
512
                    Progress progress = new Progress();
513
                    progress.companyUuid = objProgress.getInt("company_uuid");
514
                    progress.topicUuid = objProgress.getInt("topic_uuid");
515
                    progress.capsuleUuid = objProgress.getInt("capsule_uuid");
516
                    progress.SlideUuid = objProgress.getInt("Slide_uuid");
517
                    progress.progress = objProgress.getDouble("progress");
518
                    progress.totalSlides = objProgress.getInt("total_slides");
519
                    progress.viewSlides = objProgress.getInt("view_slides");
520
                    progress.type = objProgress.getString("type");
521
                    progress.returning = objProgress.getInt("returning");
522
                    progress.returningAfterCompleted = objProgress.getInt("returning_after_completed");
523
                    progress.completed = objProgress.getInt("completed");
524
                    progress.addedOn = objProgress.getString("added_on");
525
                    progress.updatedOn = objProgress.getString("updated_on");
526
 
527
                    progressDao.insert(progress);
528
 
529
                }
530
 
531
                arrayUserLog = objData.getJSONArray("userlog");
532
                for(i = 0; i <   arrayUserLog.length(); i++) {
533
                    objUserLog =  arrayUserLog.getJSONObject(i);
534
 
535
                    UserLog userLog = new UserLog();
536
                    userLog.companyUuid  = objUserLog.getInt("company_uuid");
537
                    userLog.topicUuid    = objUserLog.getInt("topic_uuid");
538
                    userLog.capsuleUuid  = objUserLog.getInt("capsule_uuid");
539
                    userLog.SlideUuid    = objUserLog.getInt("Slide_uuid");
540
                    userLog.activity   = objUserLog.getString("activity");
541
                    userLog.addedOn    = objUserLog.getString("added_on");
542
                    userLogDao.insert(userLog);
543
                }
544
 
545
                arrayQuizzes = objData.getJSONArray("quizzes");
546
                for(i = 0; i <  arrayQuizzes.length(); i++)
547
                {
548
                    objQuiz = arrayQuizzes.getJSONObject(i);
549
                    Quiz quiz = new Quiz();
550
                    quiz.id = objQuiz.getInt("id");
551
                    quiz.companyUuid = objQuiz.getInt("company_uuid");
552
                    quiz.name = objQuiz.getString("name");
553
                    quiz.text = objQuiz.getString("text");
554
                    quiz.points = objQuiz.getInt("points");
555
                    quiz.minimumPointsRequired  = objQuiz.getInt("minimum_points_required");
556
 
557
                    Company company =  companyDao.selectById(quiz.companyUuid);
558
                    if(company == null) {
559
                        company = new Company();
560
                        company.id = objQuiz.getInt("company_uuid");
561
                        company.name  = objQuiz.getString("company_name");
562
                        company.image = objQuiz.getString("company_image");
563
 
564
                        companyDao.insert(company);
565
                    }
566
 
567
                    quizDao.insert(quiz);
568
 
569
                    arrayQuestions = objQuiz.getJSONArray("questions");
570
                    for(j = 0; j < arrayQuestions.length(); j++) {
571
                        objQuestion = arrayQuestions.getJSONObject(j);
572
                       Question question = new Question();
573
                       question.quizId = quiz.id;
574
                       question.id = objQuestion.getInt("id");
575
                       question.text = objQuestion.getString("text");
576
                       question.type = objQuestion.getString("type");
577
                       question.points = objQuestion.getInt("points");
578
                       question.maxlength = objQuestion.getInt("maxlength");
579
 
580
                        questionDao.insert(question);
581
 
582
                        arrayAnswers = objQuestion.getJSONArray("answers");
583
                        for(x = 0; x < arrayAnswers.length(); x++)
584
                        {
585
                            objAnswer = arrayAnswers.getJSONObject(x);
586
                            Answer answer = new Answer();
587
                            answer.questionId =question.id;
588
                            answer.id = objAnswer.getInt("id");
589
                            answer.text = objAnswer.getString("text");
590
                            answer.points = objAnswer.getInt("points");
591
                            answer.position = objAnswer.getInt("position");
592
                            answer.correct = objAnswer.getString("correct");
593
 
594
                            answerDao.insert(answer);
595
                        }
596
 
597
 
598
                    }
599
                }
600
 
601
 
602
 
603
 
604
 
605
                JSONArray arrayTopics = objData.getJSONArray("topics");
606
                for(i = 0; i < arrayTopics.length(); i++)
607
                {
608
                    objTopic = arrayTopics.getJSONObject(i);
609
                    Topic topic = new Topic();
610
                    topic.id = objTopic.getInt("id");
611
                    topic.companyUuid = objTopic.getInt("company_uuid");
612
                    topic.name = objTopic.getString("name");
613
                    topic.description = objTopic.getString("description");
614
                    topic.image = objTopic.getString("image");
615
                    topic.position = objTopic.getInt("position");
616
 
617
                    Company company = companyDao.selectById(topic.companyUuid);
618
                    if(company == null) {
619
                        company = new Company();
620
                        company.id = objTopic.getInt("company_uuid");
621
                        company.name  = objTopic.getString("company_name");
622
                        company.image  = objTopic.getString("company_image");
623
 
624
                        companyDao.insert(company);
625
                    }
626
 
627
                    topicDao.insert(topic);
628
 
629
                    arrayCapsules = objTopic.getJSONArray("capsules");
630
                    for(j = 0; j < arrayCapsules.length(); j++)
631
                    {
632
                        objCapsule = arrayCapsules.getJSONObject(j);
633
                        Capsule capsule = new Capsule();
634
                        capsule.topicUuid = topic.id;
635
                        capsule.id = objCapsule.getInt("id");
636
                        capsule.name = objCapsule.getString("name");
637
                        capsule.description = objCapsule.getString("description");
638
                        capsule.image = objCapsule.getString("image");
639
                        capsule.position = objCapsule.getInt("position");
640
                        capsuleDao.insert(capsule);
641
 
642
                        arraySlides = objCapsule.getJSONArray("slides");
643
                        for( x = 0; x < arraySlides.length(); x++) {
644
                            objSlide = arraySlides.getJSONObject(x);
645
                            Slide slide = new Slide();
646
                            slide.id = objSlide.getInt("id");
647
                            slide.topicUuid = capsule.topicUuid;
648
                            slide.capsuleUuid = capsule.id;
649
                            slide.quizId = objSlide.getInt("quiz_id");
650
                            slide.name = objSlide.getString("name");
651
                            slide.description = objSlide.getString("description");
652
                            slide.position = objSlide.getInt("position");
653
                            slide.type = objSlide.getString("type");
654
                            slide.file = objSlide.getString("file");
655
                            slide.background = objSlide.getString("background");
656
 
657
                            slideDao.insert(slide);
658
                        }
659
 
660
                    }
661
 
662
 
663
                }
664
 
665
                Calendar calendar = Calendar.getInstance();
666
                Date date = calendar.getTime();
667
                SimpleDateFormat simpleDateFormat = new SimpleDateFormat(Constants.FORMAT_DATETIME_SERVICE);
668
                String  addedOn = simpleDateFormat.format(date);
669
 
670
 
671
                UserLog userLog = new UserLog();
672
                userLog.activity = Constants.USER_LOG_ACTIVITY_SIGNIN;
673
                userLog.addedOn = addedOn;
674
 
675
              //  mSharedViewModel.insertUserLog(userLog);
676
 
677
                Preference preference = iTwoGetSkills.getPreference();
678
 
679
                JSONObject objUser = objData.getJSONObject("user");
680
                //mUser.id  =  objUser.getInt("id");
681
                preference.userId = objUser.getInt("id");
682
                preference.firstName =  objUser.getString("first_name");
683
                preference.lastName =  objUser.getString("last_name");
684
                preference.email =  objUser.getString("email");
685
                preference.image =  objUser.getString("image");
686
                preference.password =  objUser.getString("password");
687
                preference.rsaE = objUser.getInt("rsa_e");
688
                preference.rsaD = objUser.getInt("rsa_d");
689
                preference.rsaN = objUser.getInt("rsa_n");
690
                preference.save(getActivity());
691
 
692
 
693
                JSONObject json = userLog.toJson();
694
                json.put("user_id", preference.userId);
695
                json.put(Constants.SYNC_ADAPTER_DATA_TYPE_FIELD_NAME, Constants.SYNC_ADAPTER_DATA_TYPE_USER_LOG);
696
 
697
                Sync sync = new Sync();
698
                sync.type = Constants.SYNC_ADAPTER_TYPE_SYNC;
699
                sync.data = json.toString();
700
 
701
                SyncDao syncDao = new SyncDao(getActivity());
702
                syncDao.insert(sync);
703
                syncDao.close();
704
 
705
                iTwoGetSkills.reloadNavHeader();
706
                iTwoGetSkills.invokeFragment(Constants.IDX_FRAGMENT_TOPICS);
707
 
708
            } catch (JSONException e) {
709
                iTwoGetSkills.showMessageSnackBar(e.getMessage());
710
            }
711
 
712
            answerDao.close();
713
            questionDao.close();
714
            questionDao.close();
715
            slideDao.close();
716
            capsuleDao.close();
717
            topicDao.close();
718
            companyDao.close();
719
            progressDao.close();
720
            userLogDao.close();
721
            userNotificationDao.close();
722
 
723
 
724
        } else {
725
            iTwoGetSkills.showMessageSnackBar(httpCommResponse.getMessage());
726
            if(httpCommResponse.isFatal()) {
727
                iTwoGetSkills.onErrorFatal();
728
            }
729
        }
730
    }
731
 
732
     */
733
 
734
    @Override
735
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
736
                             Bundle savedInstanceState) {
737
        // Inflate the layout for this fragment
738
        return inflater.inflate(R.layout.fragment_signin, container, false);
739
    }
19 gabriel 740
}