Proyectos de Subversion Android Microlearning - Nuevo Interface

Rev

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