Proyectos de Subversion Android Microlearning - Nuevo Interface

Rev

Rev 11 | Rev 19 | 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();
11 gabriel 92
        mProgressBar =  getView().findViewById(R.id.signin_progress_bar);
93
        mEditTextEmail =  getView().findViewById(R.id.signin_edittext_email);
1 gabriel 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);
9 gabriel 350
 
351
                //Elimino antes de guardar.
352
                iTwoGetSkills.getDatabase().getAnswerDao().removeAll();
353
                iTwoGetSkills.getDatabase().getQuestionDao().removeAll();
354
                iTwoGetSkills.getDatabase().getQuizDao().removeAll();
355
                iTwoGetSkills.getDatabase().getSlideDao().removeAll();
356
                iTwoGetSkills.getDatabase().getCapsuleDao().removeAll();
357
                iTwoGetSkills.getDatabase().getTopicDao().removeAll();
358
                iTwoGetSkills.getDatabase().getUserExtendedDao().removeAll();
12 gabriel 359
                iTwoGetSkills.getDatabase().getNotificationCenterDao().removeAllnotifications();
1 gabriel 360
                iTwoGetSkills.syncFromServer(data);
361
 
362
 
363
                Preference preference = iTwoGetSkills.getPreference();
364
                JSONObject objUser = data.getJSONObject("user");
365
                preference.setUserUuid(objUser.getString("uuid"));
366
                preference.setFirstName(objUser.getString("first_name"));
367
                preference.setLastName(objUser.getString("last_name"));
368
                preference.setEmail(objUser.getString("email"));
369
                preference.setImage(objUser.getString("image"));
370
                preference.setLastDataRefresh(addedOn);
371
 
372
                JSONObject objDevice = data.getJSONObject("device");
373
                preference.setAes(objDevice.getString("aes"));
374
                preference.setPassword(objDevice.getString("password"));
3 gabriel 375
                preference.save();
1 gabriel 376
 
377
 
378
 
379
 
380
                UserLog userLog = new UserLog();
381
                userLog.setUserUuid(preference.getUserUuid());
382
                userLog.setActivity(Constants.USER_LOG_ACTIVITY_SIGNIN);
383
                userLog.setAddedOn(addedOn);
384
                JSONObject json = userLog.toJson();
385
                json.put(Constants.SYNC_ADAPTER_DATA_TYPE_FIELD_NAME, Constants.SYNC_ADAPTER_DATA_TYPE_USER_LOG);
386
 
387
                Sync sync = new Sync(Constants.SYNC_ADAPTER_TYPE_SYNC, json.toString());
388
 
389
                SyncDao syncDao = iTwoGetSkills.getDatabase().getSyncDao();
390
                syncDao.insert(sync);
391
 
392
 
393
                getActivity().runOnUiThread(new Runnable() {
394
 
395
                    @Override
396
                    public void run() {
397
 
398
                        ResultCount resultCount = iTwoGetSkills.getDatabase().getCapsuleDao().getCount();
399
                        String message = resultCount.getCount() == 1
400
                                ? "Hay 1 cápsula nueva disponible"
401
                                : "Hay " + resultCount.getCount() + " cápsulas disponible";
402
 
11 gabriel 403
                        iTwoGetSkills.showMessageSnackBarWithClose(message);
1 gabriel 404
 
405
 
8 gabriel 406
                      //  iTwoGetSkills.reloadNavHeader();
407
                        iTwoGetSkills.invokeFragment(Constants.IDX_FRAGMENT_WELCOME);
408
                        iTwoGetSkills.showNavigationAndToolbar();
1 gabriel 409
                    }
410
                });
411
 
412
 
413
 
414
 
415
            } else {
416
                if(!TextUtils.isEmpty(message)) {
417
                    iTwoGetSkills.showMessageSnackBar(message);
418
                }
419
                if(fatal) {
420
                    iTwoGetSkills.onErrorFatal();
421
                }
422
            }
423
 
424
 
425
        } catch (JSONException e) {
426
            e.printStackTrace();
427
            Log.e(TAG,  e.getMessage());
428
        }
429
 
430
 
431
    }
432
 
433
    /*
434
    @Override
435
    public void taskCallback(HttpCommResponse httpCommResponse) {
436
        inProgress = false;
437
        mEditTextEmail.setEnabled(true);
438
        mEditTextPassword.setEnabled(true);
439
 
440
        mButtonSignIn.setEnabled(true);
441
        mProgressBar.setVisibility(View.INVISIBLE);
442
 
443
        if(httpCommResponse.isSuccess()) {
444
 
445
            AnswerDao answerDao = new AnswerDao(getActivity());
446
            answerDao.removeAll();
447
 
448
            QuestionDao questionDao = new QuestionDao(getActivity());
449
            questionDao.removeAll();
450
 
451
            QuizDao quizDao = new QuizDao(getActivity());
452
            questionDao.removeAll();
453
 
454
            SlideDao slideDao = new SlideDao(getActivity());
455
            slideDao.removeAll();
456
 
457
            CapsuleDao capsuleDao = new CapsuleDao(getActivity());
458
            capsuleDao.removeAll();
459
 
460
            TopicDao topicDao = new TopicDao(getActivity());
461
            topicDao.removeAll();
462
 
463
            CompanyDao companyDao = new CompanyDao(getActivity());
464
            companyDao.removeAll();
465
 
466
            ProgressDao progressDao = new ProgressDao(getActivity());
467
            progressDao.removeAll();
468
 
469
            UserLogDao userLogDao = new UserLogDao(getActivity());
470
 
471
            UserNotificationDao userNotificationDao = new UserNotificationDao(getActivity());
472
            userNotificationDao.removeAll();
473
 
474
            try {
475
                JSONObject objData = httpCommResponse.getObjJSON().getJSONObject("data");
476
 
477
 
478
 
479
 
480
                JSONArray arrayCapsules;
481
                JSONArray arraySlides;
482
                JSONArray arrayAnswers;
483
                JSONArray arrayQuestions;
484
                JSONArray arrayProgress;
485
                JSONArray arrayQuizzes;
486
                JSONArray arrayUserLog;
487
 
488
 
489
                JSONObject objTopic;
490
                JSONObject objCapsule;
491
                JSONObject objSlide;
492
                JSONObject objAnswer;
493
                JSONObject objQuestion;
494
                JSONObject objQuiz;
495
                JSONObject objProgress;
496
                JSONObject objUserLog;
497
                int i,j,x;
498
 
499
                arrayProgress = objData.getJSONArray("progress");
500
                for(i = 0; i <  arrayProgress.length(); i++) {
501
                    objProgress = arrayProgress.getJSONObject(i);
502
 
503
                    Progress progress = new Progress();
504
                    progress.companyUuid = objProgress.getInt("company_uuid");
505
                    progress.topicUuid = objProgress.getInt("topic_uuid");
506
                    progress.capsuleUuid = objProgress.getInt("capsule_uuid");
507
                    progress.SlideUuid = objProgress.getInt("Slide_uuid");
508
                    progress.progress = objProgress.getDouble("progress");
509
                    progress.totalSlides = objProgress.getInt("total_slides");
510
                    progress.viewSlides = objProgress.getInt("view_slides");
511
                    progress.type = objProgress.getString("type");
512
                    progress.returning = objProgress.getInt("returning");
513
                    progress.returningAfterCompleted = objProgress.getInt("returning_after_completed");
514
                    progress.completed = objProgress.getInt("completed");
515
                    progress.addedOn = objProgress.getString("added_on");
516
                    progress.updatedOn = objProgress.getString("updated_on");
517
 
518
                    progressDao.insert(progress);
519
 
520
                }
521
 
522
                arrayUserLog = objData.getJSONArray("userlog");
523
                for(i = 0; i <   arrayUserLog.length(); i++) {
524
                    objUserLog =  arrayUserLog.getJSONObject(i);
525
 
526
                    UserLog userLog = new UserLog();
527
                    userLog.companyUuid  = objUserLog.getInt("company_uuid");
528
                    userLog.topicUuid    = objUserLog.getInt("topic_uuid");
529
                    userLog.capsuleUuid  = objUserLog.getInt("capsule_uuid");
530
                    userLog.SlideUuid    = objUserLog.getInt("Slide_uuid");
531
                    userLog.activity   = objUserLog.getString("activity");
532
                    userLog.addedOn    = objUserLog.getString("added_on");
533
                    userLogDao.insert(userLog);
534
                }
535
 
536
                arrayQuizzes = objData.getJSONArray("quizzes");
537
                for(i = 0; i <  arrayQuizzes.length(); i++)
538
                {
539
                    objQuiz = arrayQuizzes.getJSONObject(i);
540
                    Quiz quiz = new Quiz();
541
                    quiz.id = objQuiz.getInt("id");
542
                    quiz.companyUuid = objQuiz.getInt("company_uuid");
543
                    quiz.name = objQuiz.getString("name");
544
                    quiz.text = objQuiz.getString("text");
545
                    quiz.points = objQuiz.getInt("points");
546
                    quiz.minimumPointsRequired  = objQuiz.getInt("minimum_points_required");
547
 
548
                    Company company =  companyDao.selectById(quiz.companyUuid);
549
                    if(company == null) {
550
                        company = new Company();
551
                        company.id = objQuiz.getInt("company_uuid");
552
                        company.name  = objQuiz.getString("company_name");
553
                        company.image = objQuiz.getString("company_image");
554
 
555
                        companyDao.insert(company);
556
                    }
557
 
558
                    quizDao.insert(quiz);
559
 
560
                    arrayQuestions = objQuiz.getJSONArray("questions");
561
                    for(j = 0; j < arrayQuestions.length(); j++) {
562
                        objQuestion = arrayQuestions.getJSONObject(j);
563
                       Question question = new Question();
564
                       question.quizId = quiz.id;
565
                       question.id = objQuestion.getInt("id");
566
                       question.text = objQuestion.getString("text");
567
                       question.type = objQuestion.getString("type");
568
                       question.points = objQuestion.getInt("points");
569
                       question.maxlength = objQuestion.getInt("maxlength");
570
 
571
                        questionDao.insert(question);
572
 
573
                        arrayAnswers = objQuestion.getJSONArray("answers");
574
                        for(x = 0; x < arrayAnswers.length(); x++)
575
                        {
576
                            objAnswer = arrayAnswers.getJSONObject(x);
577
                            Answer answer = new Answer();
578
                            answer.questionId =question.id;
579
                            answer.id = objAnswer.getInt("id");
580
                            answer.text = objAnswer.getString("text");
581
                            answer.points = objAnswer.getInt("points");
582
                            answer.position = objAnswer.getInt("position");
583
                            answer.correct = objAnswer.getString("correct");
584
 
585
                            answerDao.insert(answer);
586
                        }
587
 
588
 
589
                    }
590
                }
591
 
592
 
593
 
594
 
595
 
596
                JSONArray arrayTopics = objData.getJSONArray("topics");
597
                for(i = 0; i < arrayTopics.length(); i++)
598
                {
599
                    objTopic = arrayTopics.getJSONObject(i);
600
                    Topic topic = new Topic();
601
                    topic.id = objTopic.getInt("id");
602
                    topic.companyUuid = objTopic.getInt("company_uuid");
603
                    topic.name = objTopic.getString("name");
604
                    topic.description = objTopic.getString("description");
605
                    topic.image = objTopic.getString("image");
606
                    topic.position = objTopic.getInt("position");
607
 
608
                    Company company = companyDao.selectById(topic.companyUuid);
609
                    if(company == null) {
610
                        company = new Company();
611
                        company.id = objTopic.getInt("company_uuid");
612
                        company.name  = objTopic.getString("company_name");
613
                        company.image  = objTopic.getString("company_image");
614
 
615
                        companyDao.insert(company);
616
                    }
617
 
618
                    topicDao.insert(topic);
619
 
620
                    arrayCapsules = objTopic.getJSONArray("capsules");
621
                    for(j = 0; j < arrayCapsules.length(); j++)
622
                    {
623
                        objCapsule = arrayCapsules.getJSONObject(j);
624
                        Capsule capsule = new Capsule();
625
                        capsule.topicUuid = topic.id;
626
                        capsule.id = objCapsule.getInt("id");
627
                        capsule.name = objCapsule.getString("name");
628
                        capsule.description = objCapsule.getString("description");
629
                        capsule.image = objCapsule.getString("image");
630
                        capsule.position = objCapsule.getInt("position");
631
                        capsuleDao.insert(capsule);
632
 
633
                        arraySlides = objCapsule.getJSONArray("slides");
634
                        for( x = 0; x < arraySlides.length(); x++) {
635
                            objSlide = arraySlides.getJSONObject(x);
636
                            Slide slide = new Slide();
637
                            slide.id = objSlide.getInt("id");
638
                            slide.topicUuid = capsule.topicUuid;
639
                            slide.capsuleUuid = capsule.id;
640
                            slide.quizId = objSlide.getInt("quiz_id");
641
                            slide.name = objSlide.getString("name");
642
                            slide.description = objSlide.getString("description");
643
                            slide.position = objSlide.getInt("position");
644
                            slide.type = objSlide.getString("type");
645
                            slide.file = objSlide.getString("file");
646
                            slide.background = objSlide.getString("background");
647
 
648
                            slideDao.insert(slide);
649
                        }
650
 
651
                    }
652
 
653
 
654
                }
655
 
656
                Calendar calendar = Calendar.getInstance();
657
                Date date = calendar.getTime();
658
                SimpleDateFormat simpleDateFormat = new SimpleDateFormat(Constants.FORMAT_DATETIME_SERVICE);
659
                String  addedOn = simpleDateFormat.format(date);
660
 
661
 
662
                UserLog userLog = new UserLog();
663
                userLog.activity = Constants.USER_LOG_ACTIVITY_SIGNIN;
664
                userLog.addedOn = addedOn;
665
 
666
              //  mSharedViewModel.insertUserLog(userLog);
667
 
668
                Preference preference = iTwoGetSkills.getPreference();
669
 
670
                JSONObject objUser = objData.getJSONObject("user");
671
                //mUser.id  =  objUser.getInt("id");
672
                preference.userId = objUser.getInt("id");
673
                preference.firstName =  objUser.getString("first_name");
674
                preference.lastName =  objUser.getString("last_name");
675
                preference.email =  objUser.getString("email");
676
                preference.image =  objUser.getString("image");
677
                preference.password =  objUser.getString("password");
678
                preference.rsaE = objUser.getInt("rsa_e");
679
                preference.rsaD = objUser.getInt("rsa_d");
680
                preference.rsaN = objUser.getInt("rsa_n");
681
                preference.save(getActivity());
682
 
683
 
684
                JSONObject json = userLog.toJson();
685
                json.put("user_id", preference.userId);
686
                json.put(Constants.SYNC_ADAPTER_DATA_TYPE_FIELD_NAME, Constants.SYNC_ADAPTER_DATA_TYPE_USER_LOG);
687
 
688
                Sync sync = new Sync();
689
                sync.type = Constants.SYNC_ADAPTER_TYPE_SYNC;
690
                sync.data = json.toString();
691
 
692
                SyncDao syncDao = new SyncDao(getActivity());
693
                syncDao.insert(sync);
694
                syncDao.close();
695
 
696
                iTwoGetSkills.reloadNavHeader();
697
                iTwoGetSkills.invokeFragment(Constants.IDX_FRAGMENT_TOPICS);
698
 
699
            } catch (JSONException e) {
700
                iTwoGetSkills.showMessageSnackBar(e.getMessage());
701
            }
702
 
703
            answerDao.close();
704
            questionDao.close();
705
            questionDao.close();
706
            slideDao.close();
707
            capsuleDao.close();
708
            topicDao.close();
709
            companyDao.close();
710
            progressDao.close();
711
            userLogDao.close();
712
            userNotificationDao.close();
713
 
714
 
715
        } else {
716
            iTwoGetSkills.showMessageSnackBar(httpCommResponse.getMessage());
717
            if(httpCommResponse.isFatal()) {
718
                iTwoGetSkills.onErrorFatal();
719
            }
720
        }
721
    }
722
 
723
     */
724
 
725
    @Override
726
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
727
                             Bundle savedInstanceState) {
728
        // Inflate the layout for this fragment
729
        return inflater.inflate(R.layout.fragment_signin, container, false);
730
    }
731
}