Proyectos de Subversion Android Microlearning - Nuevo Interface

Rev

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