Proyectos de Subversion Android Microlearning

Rev

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

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