Proyectos de Subversion Android Microlearning - Nuevo Interface

Rev

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