Proyectos de Subversion Android Microlearning - Nuevo Interface

Rev

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