Proyectos de Subversion Android Microlearning - Nuevo Interface

Rev

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