Proyectos de Subversion Android Microlearning - Nuevo Interface

Rev

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