1 |
efrain |
1 |
package com.cesams.twogetskills.activity;
|
|
|
2 |
|
|
|
3 |
import androidx.activity.result.ActivityResultLauncher;
|
|
|
4 |
import androidx.activity.result.contract.ActivityResultContracts;
|
|
|
5 |
import androidx.annotation.NonNull;
|
|
|
6 |
import androidx.appcompat.app.ActionBarDrawerToggle;
|
|
|
7 |
import androidx.appcompat.app.AlertDialog;
|
|
|
8 |
import androidx.appcompat.app.AppCompatActivity;
|
|
|
9 |
import androidx.core.app.NotificationCompat;
|
|
|
10 |
import androidx.core.view.GravityCompat;
|
|
|
11 |
import androidx.fragment.app.Fragment;
|
|
|
12 |
import androidx.fragment.app.FragmentTransaction;
|
|
|
13 |
|
|
|
14 |
import android.accounts.Account;
|
|
|
15 |
import android.accounts.AccountManager;
|
|
|
16 |
import android.app.NotificationChannel;
|
|
|
17 |
import android.app.NotificationManager;
|
|
|
18 |
import android.app.PendingIntent;
|
|
|
19 |
import android.content.ContentResolver;
|
|
|
20 |
import android.content.DialogInterface;
|
|
|
21 |
import android.net.ConnectivityManager;
|
|
|
22 |
import android.os.Build;
|
|
|
23 |
import android.text.TextUtils;
|
|
|
24 |
import android.util.Log;
|
|
|
25 |
import android.content.Context;
|
|
|
26 |
import android.content.Intent;
|
|
|
27 |
import android.content.IntentFilter;
|
|
|
28 |
import android.os.Bundle;
|
|
|
29 |
import android.view.Menu;
|
|
|
30 |
import android.view.MenuItem;
|
|
|
31 |
import android.view.View;
|
|
|
32 |
import android.widget.ImageView;
|
|
|
33 |
import android.widget.ProgressBar;
|
|
|
34 |
import android.widget.TextView;
|
|
|
35 |
|
|
|
36 |
|
|
|
37 |
import com.bumptech.glide.Glide;
|
|
|
38 |
import com.bumptech.glide.load.engine.DiskCacheStrategy;
|
|
|
39 |
import com.bumptech.glide.load.model.GlideUrl;
|
|
|
40 |
import com.bumptech.glide.load.model.LazyHeaders;
|
|
|
41 |
import com.bumptech.glide.request.RequestOptions;
|
|
|
42 |
import com.cesams.twogetskills.Configuration;
|
|
|
43 |
import com.cesams.twogetskills.dao.AnswerDao;
|
|
|
44 |
import com.cesams.twogetskills.dao.AppDatabase;
|
|
|
45 |
import com.cesams.twogetskills.dao.CapsuleDao;
|
|
|
46 |
import com.cesams.twogetskills.dao.CompanyDao;
|
|
|
47 |
import com.cesams.twogetskills.dao.DatabaseHelper;
|
|
|
48 |
import com.cesams.twogetskills.dao.ProgressDao;
|
|
|
49 |
import com.cesams.twogetskills.dao.QuestionDao;
|
|
|
50 |
import com.cesams.twogetskills.dao.QuizDao;
|
|
|
51 |
import com.cesams.twogetskills.dao.SlideDao;
|
|
|
52 |
import com.cesams.twogetskills.dao.SyncDao;
|
|
|
53 |
import com.cesams.twogetskills.dao.TopicDao;
|
|
|
54 |
import com.cesams.twogetskills.dao.UserExtendedDao;
|
|
|
55 |
import com.cesams.twogetskills.dao.UserLogDao;
|
|
|
56 |
import com.cesams.twogetskills.entity.UserExtended;
|
|
|
57 |
import com.cesams.twogetskills.fragment.CapsuleFragment;
|
|
|
58 |
import com.cesams.twogetskills.fragment.CompanyFragment;
|
|
|
59 |
import com.cesams.twogetskills.fragment.FinishCapsuleFragment;
|
|
|
60 |
import com.cesams.twogetskills.fragment.FinishTopicFragment;
|
|
|
61 |
import com.cesams.twogetskills.fragment.GalleryFragment;
|
|
|
62 |
import com.cesams.twogetskills.fragment.ProgressFragment;
|
|
|
63 |
import com.cesams.twogetskills.fragment.SlideFragment;
|
|
|
64 |
import com.cesams.twogetskills.fragment.TimelineFragment;
|
|
|
65 |
import com.cesams.twogetskills.fragment.TopicFragment;
|
|
|
66 |
import com.cesams.twogetskills.fragment.UserProfileFragment;
|
|
|
67 |
import com.cesams.twogetskills.library.Http;
|
|
|
68 |
import com.cesams.twogetskills.library.MD5;
|
|
|
69 |
import com.cesams.twogetskills.library.UniqueID;
|
|
|
70 |
import com.cesams.twogetskills.entity.Answer;
|
|
|
71 |
import com.cesams.twogetskills.entity.Capsule;
|
|
|
72 |
import com.cesams.twogetskills.entity.Company;
|
|
|
73 |
import com.cesams.twogetskills.entity.Progress;
|
|
|
74 |
import com.cesams.twogetskills.entity.Question;
|
|
|
75 |
import com.cesams.twogetskills.entity.Quiz;
|
|
|
76 |
import com.cesams.twogetskills.entity.Slide;
|
|
|
77 |
import com.cesams.twogetskills.entity.Sync;
|
|
|
78 |
import com.cesams.twogetskills.entity.Topic;
|
|
|
79 |
import com.cesams.twogetskills.entity.UserLog;
|
|
|
80 |
import com.cesams.twogetskills.preference.Preference;
|
|
|
81 |
import com.cesams.twogetskills.receiver.ConnectivityReceiver;
|
|
|
82 |
import com.cesams.twogetskills.receiver.InternalReceiver;
|
|
|
83 |
import com.cesams.twogetskills.room.ResultCount;
|
|
|
84 |
import com.google.android.material.snackbar.Snackbar;
|
|
|
85 |
import com.google.android.material.navigation.NavigationView;
|
|
|
86 |
|
|
|
87 |
import androidx.drawerlayout.widget.DrawerLayout;
|
|
|
88 |
import androidx.appcompat.widget.Toolbar;
|
27 |
efrain |
89 |
import androidx.lifecycle.ViewModelProvider;
|
8 |
gabriel |
90 |
import androidx.room.Database;
|
|
|
91 |
|
1 |
efrain |
92 |
import com.cesams.twogetskills.Constants;
|
|
|
93 |
import com.cesams.twogetskills.R;
|
|
|
94 |
|
|
|
95 |
import com.cesams.twogetskills.fragment.IntroFragment;
|
|
|
96 |
import com.cesams.twogetskills.fragment.SigninFragment;
|
|
|
97 |
import com.cesams.twogetskills.skeleton.ITwoGetSkills;
|
|
|
98 |
|
|
|
99 |
import org.json.JSONArray;
|
|
|
100 |
import org.json.JSONException;
|
|
|
101 |
import org.json.JSONObject;
|
|
|
102 |
|
|
|
103 |
import java.io.IOException;
|
|
|
104 |
import java.text.SimpleDateFormat;
|
|
|
105 |
import java.util.Calendar;
|
|
|
106 |
import java.util.Date;
|
|
|
107 |
import java.util.HashMap;
|
27 |
efrain |
108 |
import java.util.Iterator;
|
1 |
efrain |
109 |
import java.util.List;
|
27 |
efrain |
110 |
import java.util.Map;
|
1 |
efrain |
111 |
import java.util.Random;
|
|
|
112 |
import java.util.TimeZone;
|
|
|
113 |
|
|
|
114 |
//import de.hdodenhof.circleimageview.CircleImageView;
|
|
|
115 |
import okhttp3.Call;
|
|
|
116 |
import okhttp3.FormBody;
|
|
|
117 |
import okhttp3.OkHttpClient;
|
|
|
118 |
import okhttp3.Request;
|
|
|
119 |
import okhttp3.RequestBody;
|
|
|
120 |
import okhttp3.Response;
|
|
|
121 |
|
|
|
122 |
public class MainActivity extends AppCompatActivity implements ITwoGetSkills,NavigationView.OnNavigationItemSelectedListener {
|
|
|
123 |
private boolean isSyncDevice = false;
|
|
|
124 |
private boolean isSyncToken = false;
|
|
|
125 |
private boolean isSyncBatch = false;
|
|
|
126 |
private boolean isForeground = false;
|
30 |
efrain |
127 |
private boolean isSmartLockLoginRun = false;
|
1 |
efrain |
128 |
|
|
|
129 |
private final static String PREFIX_FRAG = "FRAG";
|
|
|
130 |
private final static String TAG = "C2GS - MainActivity";
|
|
|
131 |
|
|
|
132 |
private DrawerLayout mDrawer;
|
|
|
133 |
private ActionBarDrawerToggle mDrawerToggle;
|
|
|
134 |
|
|
|
135 |
private HashMap<String, Fragment> fragmentHashMap;
|
|
|
136 |
|
|
|
137 |
private ImageView navHeaderUserImage;
|
|
|
138 |
|
|
|
139 |
private TextView navHeaderUserName;
|
|
|
140 |
private TextView navHeaderUserEmail;
|
|
|
141 |
private TextView textViewMessageNotConnection;
|
|
|
142 |
|
|
|
143 |
|
|
|
144 |
|
|
|
145 |
private Preference preference;
|
|
|
146 |
private boolean connected = false;
|
|
|
147 |
private ConnectivityReceiver mConnectivityReceiver;
|
|
|
148 |
private InternalReceiver mInternalReceiver;
|
|
|
149 |
private ProgressBar mProgressBar;
|
|
|
150 |
|
|
|
151 |
private Account mAccount;
|
|
|
152 |
private AppDatabase mAppDatabase;
|
|
|
153 |
|
|
|
154 |
ActivityResultLauncher<Intent> mLauncher = registerForActivityResult(
|
|
|
155 |
new ActivityResultContracts.StartActivityForResult(),
|
|
|
156 |
result -> {
|
|
|
157 |
if(result.getResultCode() == RESULT_OK) {
|
6 |
gabriel |
158 |
boolean completed = result.getData().hasExtra("completed") && result.getData().getBooleanExtra("completed", false);
|
1 |
efrain |
159 |
int requestCode = result.getData().hasExtra("requestCode") ? result.getData().getIntExtra("requestCode", 0) : 0;
|
|
|
160 |
if(requestCode == Constants.REQUEST_CODE_QUIZ) {
|
|
|
161 |
createProgressAndSyncRecord(preference.getSlideUuidActive(), completed, true, false);
|
|
|
162 |
} else if(requestCode == Constants.REQUEST_CODE_AUDIO_VIDEO) {
|
|
|
163 |
createProgressAndSyncRecord(preference.getSlideUuidActive(), completed, false, true);
|
|
|
164 |
} else {
|
|
|
165 |
createProgressAndSyncRecord(preference.getSlideUuidActive(), completed, false, false);
|
|
|
166 |
}
|
|
|
167 |
}
|
|
|
168 |
}
|
|
|
169 |
);
|
|
|
170 |
|
|
|
171 |
|
|
|
172 |
@Override
|
|
|
173 |
protected void onCreate(Bundle savedInstanceState) {
|
|
|
174 |
super.onCreate(savedInstanceState);
|
|
|
175 |
setContentView(R.layout.activity_main);
|
|
|
176 |
|
|
|
177 |
Log.d(TAG, "MainActivity onCreate");
|
|
|
178 |
|
|
|
179 |
/**** CANAL DE NOTIFICACIONES **/
|
|
|
180 |
createNotificationChannel();
|
|
|
181 |
|
|
|
182 |
/*** CUENTAS DE SINCRONIZACION **/
|
26 |
gabriel |
183 |
mAccount = CreateSyncAccount(getApplicationContext());
|
1 |
efrain |
184 |
|
|
|
185 |
|
|
|
186 |
// Get the content resolver for your app
|
|
|
187 |
//mResolver = getContentResolver();
|
|
|
188 |
|
33 |
gabriel |
189 |
mAppDatabase = DatabaseHelper.getInstance(getApplicationContext()).getAppDatabase();
|
1 |
efrain |
190 |
|
29 |
efrain |
191 |
preference = Preference.getInstance(getApplicationContext());
|
44 |
efrain |
192 |
|
|
|
193 |
Log.d("BUG 2PLANO", "MainActivity - onCreate");
|
30 |
efrain |
194 |
preference.load();
|
1 |
efrain |
195 |
|
|
|
196 |
if(TextUtils.isEmpty(preference.getDeviceUuid())) {
|
26 |
gabriel |
197 |
String uuid = UniqueID.id(getApplicationContext());
|
1 |
efrain |
198 |
preference.setDeviceUuid(uuid);
|
29 |
efrain |
199 |
preference.save();
|
1 |
efrain |
200 |
|
|
|
201 |
Sync sync = new Sync(Constants.SYNC_ADAPTER_TYPE_DEVICE, uuid);
|
|
|
202 |
mAppDatabase.getSyncDao().insert(sync);
|
|
|
203 |
|
|
|
204 |
if(!TextUtils.isEmpty(preference.getDeviceToken())) {
|
|
|
205 |
sync = new Sync(Constants.SYNC_ADAPTER_TYPE_FCM, preference.getDeviceToken());
|
|
|
206 |
mAppDatabase.getSyncDao().insert(sync);
|
|
|
207 |
}
|
|
|
208 |
}
|
|
|
209 |
|
|
|
210 |
fragmentHashMap = new HashMap<>();
|
|
|
211 |
|
|
|
212 |
mProgressBar = findViewById(R.id.progressBar);
|
6 |
gabriel |
213 |
Toolbar mToolbar = findViewById(R.id.toolbar);
|
1 |
efrain |
214 |
setSupportActionBar((Toolbar) findViewById(R.id.toolbar));
|
|
|
215 |
|
|
|
216 |
mDrawer = findViewById(R.id.drawer_layout);
|
|
|
217 |
mDrawerToggle = new ActionBarDrawerToggle(
|
|
|
218 |
this, mDrawer, mToolbar, R.string.navigation_drawer_open,
|
|
|
219 |
R.string.navigation_drawer_close);
|
|
|
220 |
|
|
|
221 |
mDrawerToggle.setToolbarNavigationClickListener(v -> onBackPressed());
|
|
|
222 |
|
|
|
223 |
mDrawer.addDrawerListener(mDrawerToggle);
|
|
|
224 |
mDrawerToggle.syncState();
|
|
|
225 |
|
|
|
226 |
NavigationView navigationView = findViewById(R.id.navigation_view);
|
|
|
227 |
navigationView.setNavigationItemSelectedListener(this);
|
|
|
228 |
|
|
|
229 |
View header = navigationView.getHeaderView(0);
|
|
|
230 |
//navHeaderUserImage = (CircleImageView) header.findViewById(R.id.nav_header_user_image);
|
4 |
gabriel |
231 |
navHeaderUserImage = header.findViewById(R.id.nav_header_user_image);
|
|
|
232 |
navHeaderUserName = header.findViewById(R.id.nav_header_user_name);
|
|
|
233 |
navHeaderUserEmail = header.findViewById(R.id.nav_header_user_email);
|
1 |
efrain |
234 |
|
4 |
gabriel |
235 |
textViewMessageNotConnection = findViewById(R.id.main_activity_text_view_message_not_connection);
|
1 |
efrain |
236 |
|
|
|
237 |
mConnectivityReceiver = new ConnectivityReceiver();
|
|
|
238 |
registerReceiver(mConnectivityReceiver, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));
|
|
|
239 |
|
|
|
240 |
IntentFilter intentFilterInternal = new IntentFilter();
|
|
|
241 |
intentFilterInternal.addAction(Constants.BROADCAST_TYPE_NOTIFICATION);
|
|
|
242 |
intentFilterInternal.addAction(Constants.BROADCAST_TYPE_TOKEN);
|
|
|
243 |
intentFilterInternal.addAction(Constants.BROADCAST_TYPE_COMMAND);
|
|
|
244 |
intentFilterInternal.addAction(Constants.BROADCAST_TYPE_SYNC_TO_SERVER_OR_CHECK_CHANGES);
|
|
|
245 |
|
|
|
246 |
mInternalReceiver = new InternalReceiver();
|
|
|
247 |
registerReceiver(mInternalReceiver, intentFilterInternal);
|
|
|
248 |
|
|
|
249 |
}
|
|
|
250 |
|
|
|
251 |
@Override
|
|
|
252 |
protected void onDestroy() {
|
|
|
253 |
super.onDestroy();
|
|
|
254 |
|
|
|
255 |
try {
|
|
|
256 |
unregisterReceiver(mConnectivityReceiver);
|
|
|
257 |
unregisterReceiver(mInternalReceiver);
|
|
|
258 |
} catch (IllegalArgumentException e) {
|
|
|
259 |
e.printStackTrace();
|
|
|
260 |
}
|
|
|
261 |
}
|
|
|
262 |
|
|
|
263 |
|
|
|
264 |
@Override
|
|
|
265 |
protected void onResume() {
|
|
|
266 |
super.onResume();
|
|
|
267 |
isForeground = true;
|
|
|
268 |
|
44 |
efrain |
269 |
Log.d("BUG 2PLANO", "MainActivity - onCreate");
|
29 |
efrain |
270 |
preference = Preference.getInstance(getApplicationContext());
|
30 |
efrain |
271 |
preference.load();
|
|
|
272 |
|
1 |
efrain |
273 |
reloadNavHeader();
|
|
|
274 |
|
6 |
gabriel |
275 |
Log.e("Se ejecuta", "On resumen");
|
|
|
276 |
|
1 |
efrain |
277 |
if(TextUtils.isEmpty(preference.getUserUuid())) {
|
6 |
gabriel |
278 |
|
|
|
279 |
//Verifico que el teclado no vaya a relanzar el fragment de intro al usar Google Smartlock para traer
|
|
|
280 |
//Informacion de inicio de sesion almacenada en su cuenta personal de Google
|
30 |
efrain |
281 |
if (!isSmartLockLoginRun) {
|
6 |
gabriel |
282 |
invokeFragment(Constants.IDX_FRAGMENT_INTRO);
|
30 |
efrain |
283 |
isSmartLockLoginRun= true;
|
6 |
gabriel |
284 |
}
|
|
|
285 |
|
|
|
286 |
|
1 |
efrain |
287 |
} else {
|
|
|
288 |
if(preference.getFragmentIdxActive() == 0) {
|
|
|
289 |
invokeFragment(Constants.IDX_FRAGMENT_TOPICS);
|
|
|
290 |
} else {
|
|
|
291 |
invokeFragment(preference.getFragmentIdxActive());
|
|
|
292 |
}
|
|
|
293 |
}
|
|
|
294 |
|
|
|
295 |
}
|
|
|
296 |
|
|
|
297 |
@Override
|
|
|
298 |
protected void onPause() {
|
|
|
299 |
super.onPause();
|
|
|
300 |
|
|
|
301 |
isForeground = false;
|
29 |
efrain |
302 |
preference.save();
|
1 |
efrain |
303 |
}
|
|
|
304 |
|
29 |
efrain |
305 |
/*
|
1 |
efrain |
306 |
@Override
|
24 |
gabriel |
307 |
protected void onRestart() {
|
|
|
308 |
super.onRestart();
|
29 |
efrain |
309 |
preference = Preference.getInstance(getApplicationContext());
|
30 |
efrain |
310 |
preference.load();
|
24 |
gabriel |
311 |
|
25 |
gabriel |
312 |
if(TextUtils.isEmpty(preference.getUserUuid())) {
|
24 |
gabriel |
313 |
|
25 |
gabriel |
314 |
//Verifico que el teclado no vaya a relanzar el fragment de intro al usar Google Smartlock para traer
|
|
|
315 |
//Informacion de inicio de sesion almacenada en su cuenta personal de Google
|
30 |
efrain |
316 |
if (!isSmartLockLoginRun) {
|
25 |
gabriel |
317 |
invokeFragment(Constants.IDX_FRAGMENT_INTRO);
|
30 |
efrain |
318 |
isSmartLockLoginRun= true;
|
25 |
gabriel |
319 |
}
|
|
|
320 |
|
|
|
321 |
|
|
|
322 |
} else {
|
|
|
323 |
if(preference.getFragmentIdxActive() == 0) {
|
|
|
324 |
invokeFragment(Constants.IDX_FRAGMENT_TOPICS);
|
|
|
325 |
} else {
|
|
|
326 |
invokeFragment(preference.getFragmentIdxActive());
|
|
|
327 |
}
|
|
|
328 |
}
|
|
|
329 |
|
|
|
330 |
|
24 |
gabriel |
331 |
}
|
29 |
efrain |
332 |
*/
|
24 |
gabriel |
333 |
|
29 |
efrain |
334 |
/*
|
24 |
gabriel |
335 |
@Override
|
|
|
336 |
protected void onStop() {
|
|
|
337 |
super.onStop();
|
29 |
efrain |
338 |
preference.save();
|
24 |
gabriel |
339 |
|
|
|
340 |
}
|
29 |
efrain |
341 |
*/
|
24 |
gabriel |
342 |
|
|
|
343 |
@Override
|
1 |
efrain |
344 |
public boolean onNavigationItemSelected(@NonNull MenuItem menuItem) {
|
|
|
345 |
int title;
|
|
|
346 |
mDrawer.closeDrawers();
|
|
|
347 |
|
|
|
348 |
switch (menuItem.getItemId()) {
|
|
|
349 |
case R.id.nav_topics :
|
|
|
350 |
setTitleActionBar(getString(R.string.menu_topics));
|
|
|
351 |
invokeFragment(Constants.IDX_FRAGMENT_TOPICS);
|
|
|
352 |
break;
|
|
|
353 |
case R.id.nav_timeline:
|
|
|
354 |
setTitleActionBar(getString(R.string.menu_timeline));
|
|
|
355 |
invokeFragment(Constants.IDX_FRAGMENT_TIMELINE);
|
|
|
356 |
|
|
|
357 |
break;
|
|
|
358 |
case R.id.nav_progress:
|
|
|
359 |
|
|
|
360 |
if(preference.getCompanyCount() > 1) {
|
|
|
361 |
invokeFragment(Constants.IDX_FRAGMENT_COMPANIES);
|
|
|
362 |
} else {
|
|
|
363 |
setTitleActionBar(getString(R.string.menu_progress));
|
|
|
364 |
invokeFragment(Constants.IDX_FRAGMENT_PROGRESS);
|
|
|
365 |
}
|
|
|
366 |
break;
|
|
|
367 |
|
|
|
368 |
case R.id.nav_userprofile:
|
|
|
369 |
setTitleActionBar(getString(R.string.menu_user_profile));
|
|
|
370 |
invokeFragment(Constants.IDX_FRAGMENT_USER_PROFILE);
|
|
|
371 |
break;
|
|
|
372 |
|
|
|
373 |
case R.id.nav_exit_app:
|
|
|
374 |
setTitleActionBar(getString(R.string.menu_exit));
|
|
|
375 |
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
|
|
|
376 |
builder.setTitle(R.string.alter_dialog_close_app_title);
|
|
|
377 |
builder.setMessage(R.string.alter_dialog_close_app_message);
|
|
|
378 |
builder.setNegativeButton(R.string.alter_dialog_button_no, new DialogInterface.OnClickListener() {
|
|
|
379 |
@Override
|
|
|
380 |
public void onClick(DialogInterface dialog, int which) {
|
|
|
381 |
|
|
|
382 |
}
|
|
|
383 |
});
|
|
|
384 |
builder.setPositiveButton(R.string.alter_dialog_button_yes, new DialogInterface.OnClickListener() {
|
|
|
385 |
@Override
|
|
|
386 |
public void onClick(DialogInterface dialog, int which) {
|
|
|
387 |
signout();
|
|
|
388 |
}
|
|
|
389 |
});
|
|
|
390 |
|
|
|
391 |
AlertDialog dialog = builder.create();
|
|
|
392 |
dialog.show();
|
|
|
393 |
|
|
|
394 |
break;
|
|
|
395 |
|
|
|
396 |
default:
|
|
|
397 |
throw new IllegalArgumentException("menu option not implemented!!");
|
|
|
398 |
}
|
|
|
399 |
|
|
|
400 |
mDrawer.closeDrawer(GravityCompat.START);
|
|
|
401 |
|
|
|
402 |
return true;
|
|
|
403 |
}
|
|
|
404 |
|
|
|
405 |
private void createNotificationChannel() {
|
|
|
406 |
// Create the NotificationChannel, but only on API 26+ because
|
|
|
407 |
// the NotificationChannel class is new and not in the support library
|
4 |
gabriel |
408 |
CharSequence name = getString(R.string.channel_name);
|
|
|
409 |
String description = getString(R.string.channel_description);
|
|
|
410 |
int importance = NotificationManager.IMPORTANCE_DEFAULT;
|
|
|
411 |
NotificationChannel channel = new NotificationChannel(Constants.NOTIFICATION_CHANNEL_ID, name, importance);
|
|
|
412 |
channel.setDescription(description);
|
|
|
413 |
channel.setShowBadge(true);
|
1 |
efrain |
414 |
|
|
|
415 |
|
4 |
gabriel |
416 |
// Register the channel with the system; you can't change the importance
|
|
|
417 |
// or other notification behaviors after this
|
|
|
418 |
NotificationManager notificationManager = getSystemService(NotificationManager.class);
|
|
|
419 |
notificationManager.createNotificationChannel(channel);
|
1 |
efrain |
420 |
}
|
|
|
421 |
|
|
|
422 |
|
|
|
423 |
@Override
|
|
|
424 |
public void showFcmNotification(String title, String body, int new_capsules)
|
|
|
425 |
{
|
|
|
426 |
|
|
|
427 |
NotificationCompat.Builder builder =
|
|
|
428 |
new NotificationCompat.Builder(MainActivity.this, Constants.NOTIFICATION_CHANNEL_ID)
|
|
|
429 |
.setSmallIcon(R.drawable.ic_notificacion) //set icon for notification
|
|
|
430 |
.setContentTitle(title) //set title of notification
|
|
|
431 |
.setContentText(body)//this is notification message
|
|
|
432 |
.setAutoCancel(true) // makes auto cancel of notification
|
|
|
433 |
.setPriority(NotificationCompat.PRIORITY_DEFAULT); //set priority of notification
|
|
|
434 |
|
|
|
435 |
if(new_capsules > 0) {
|
|
|
436 |
builder.setBadgeIconType(NotificationCompat.BADGE_ICON_LARGE);
|
|
|
437 |
builder.setNumber(new_capsules);
|
|
|
438 |
}
|
|
|
439 |
|
26 |
gabriel |
440 |
Intent notificationIntent = new Intent(getApplicationContext(), MainActivity.class);
|
1 |
efrain |
441 |
notificationIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
|
|
442 |
//notification message will get at NotificationView
|
|
|
443 |
notificationIntent.putExtra(title, body);
|
|
|
444 |
|
26 |
gabriel |
445 |
PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(), 0, notificationIntent,
|
15 |
gabriel |
446 |
PendingIntent.FLAG_IMMUTABLE);
|
1 |
efrain |
447 |
builder.setContentIntent(pendingIntent);
|
|
|
448 |
|
|
|
449 |
// Add as notification
|
|
|
450 |
NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
|
|
|
451 |
manager.notify(0, builder.build());
|
|
|
452 |
|
|
|
453 |
|
|
|
454 |
if(new_capsules > 0) {
|
|
|
455 |
|
|
|
456 |
String message = new_capsules == 1
|
|
|
457 |
? "Hay 1 cápsula nueva disponible"
|
|
|
458 |
: "Hay " + new_capsules + " cápsulas disponible";
|
|
|
459 |
|
|
|
460 |
showMessageSnackBarWithClose(message);
|
|
|
461 |
} else {
|
|
|
462 |
showMessageSnackBarWithClose(body);
|
|
|
463 |
}
|
|
|
464 |
|
|
|
465 |
|
|
|
466 |
}
|
|
|
467 |
|
|
|
468 |
@Override
|
|
|
469 |
public void signout()
|
|
|
470 |
{
|
|
|
471 |
mAppDatabase.getAnswerDao().removeAll();
|
|
|
472 |
mAppDatabase.getQuestionDao().removeAll();
|
|
|
473 |
mAppDatabase.getQuizDao().removeAll();
|
|
|
474 |
mAppDatabase.getSlideDao().removeAll();
|
|
|
475 |
mAppDatabase.getCapsuleDao().removeAll();
|
|
|
476 |
mAppDatabase.getTopicDao().removeAll();
|
|
|
477 |
mAppDatabase.getUserExtendedDao().removeAll();
|
|
|
478 |
|
|
|
479 |
|
44 |
efrain |
480 |
mAppDatabase.getUserLogDao().removeAll();
|
|
|
481 |
mAppDatabase.getProgressDao().removeAll();
|
|
|
482 |
|
1 |
efrain |
483 |
preference.setUserUuid("");
|
|
|
484 |
preference.setFirstName("");
|
|
|
485 |
preference.setLastName("");
|
|
|
486 |
preference.setEmail("");
|
|
|
487 |
preference.setImage("");
|
|
|
488 |
preference.setMaxDateChanges("");
|
|
|
489 |
preference.setCompanyCount(0);
|
|
|
490 |
preference.setCompanyUuidActive("");
|
|
|
491 |
preference.setTopicUuidActive("");
|
|
|
492 |
preference.setCapsuleUuidActive("");
|
|
|
493 |
preference.setSlideUuidActive("");
|
29 |
efrain |
494 |
preference.save();
|
1 |
efrain |
495 |
|
|
|
496 |
invokeFragment(Constants.IDX_FRAGMENT_INTRO);
|
|
|
497 |
}
|
|
|
498 |
|
|
|
499 |
@Override
|
|
|
500 |
public void onBackPressed() {
|
|
|
501 |
|
|
|
502 |
//super.onBackPressed();
|
|
|
503 |
switch (preference.getFragmentIdxActive())
|
|
|
504 |
{
|
|
|
505 |
|
|
|
506 |
/*
|
|
|
507 |
case Constants.IDX_FRAGMENT_INTRO :
|
|
|
508 |
case Constants.IDX_FRAGMENT_SIGNIN :
|
|
|
509 |
case Constants.IDX_FRAGMENT_TOPICS :
|
|
|
510 |
finish();
|
|
|
511 |
return;*/
|
|
|
512 |
|
|
|
513 |
case Constants.IDX_FRAGMENT_PROGRESS :
|
|
|
514 |
if(preference.getCompanyCount() > 1) {
|
|
|
515 |
invokeFragment(Constants.IDX_FRAGMENT_COMPANIES);
|
|
|
516 |
} else {
|
|
|
517 |
invokeFragment(Constants.IDX_FRAGMENT_TOPICS);
|
|
|
518 |
}
|
|
|
519 |
break;
|
|
|
520 |
|
|
|
521 |
case Constants.IDX_FRAGMENT_COMPANIES:
|
|
|
522 |
case Constants.IDX_FRAGMENT_TIMELINE :
|
|
|
523 |
case Constants.IDX_FRAGMENT_CAPSULES :
|
|
|
524 |
case Constants.IDX_FRAGMENT_FINISH_TOPIC :
|
|
|
525 |
|
|
|
526 |
preference.setTopicUuidActive("");
|
|
|
527 |
preference.setCapsuleUuidActive("");
|
|
|
528 |
preference.setSlideUuidActive("");
|
29 |
efrain |
529 |
preference.save();
|
1 |
efrain |
530 |
|
|
|
531 |
invokeFragment(Constants.IDX_FRAGMENT_TOPICS);
|
|
|
532 |
return;
|
|
|
533 |
|
|
|
534 |
case Constants.IDX_FRAGMENT_SLIDES :
|
|
|
535 |
invokeFragment(Constants.IDX_FRAGMENT_CAPSULES);
|
|
|
536 |
return;
|
|
|
537 |
|
|
|
538 |
case Constants.IDX_FRAGMENT_GALLERY :
|
|
|
539 |
invokeFragment(Constants.IDX_FRAGMENT_SLIDES);
|
|
|
540 |
return;
|
|
|
541 |
|
|
|
542 |
case Constants.IDX_FRAGMENT_FINISH_CAPSULE :
|
|
|
543 |
preference.setCapsuleUuidActive("");
|
|
|
544 |
preference.setSlideUuidActive("");
|
29 |
efrain |
545 |
preference.save();
|
1 |
efrain |
546 |
|
|
|
547 |
invokeFragment(Constants.IDX_FRAGMENT_CAPSULES);
|
|
|
548 |
return;
|
|
|
549 |
|
|
|
550 |
}
|
|
|
551 |
}
|
|
|
552 |
|
|
|
553 |
|
|
|
554 |
|
|
|
555 |
@Override
|
|
|
556 |
public void hideProgressBar() {
|
|
|
557 |
|
|
|
558 |
//accessing it from ui-thread
|
|
|
559 |
runOnUiThread(new Runnable() {
|
|
|
560 |
@Override
|
|
|
561 |
public void run() {
|
|
|
562 |
mProgressBar.setVisibility(View.INVISIBLE);
|
|
|
563 |
}
|
|
|
564 |
});
|
|
|
565 |
|
|
|
566 |
}
|
|
|
567 |
|
|
|
568 |
@Override
|
|
|
569 |
public void showProgressBar() {
|
|
|
570 |
runOnUiThread(new Runnable() {
|
|
|
571 |
@Override
|
|
|
572 |
public void run() {
|
|
|
573 |
mProgressBar.setVisibility(View.VISIBLE);
|
|
|
574 |
}
|
|
|
575 |
});
|
|
|
576 |
|
|
|
577 |
|
|
|
578 |
}
|
|
|
579 |
|
|
|
580 |
|
|
|
581 |
|
|
|
582 |
|
|
|
583 |
|
|
|
584 |
@Override
|
|
|
585 |
public boolean onCreateOptionsMenu(Menu menu) {
|
|
|
586 |
// Inflate the menu; this adds items to the action bar if it is present.
|
|
|
587 |
getMenuInflater().inflate(R.menu.drawer, menu);
|
|
|
588 |
return true;
|
|
|
589 |
}
|
|
|
590 |
|
|
|
591 |
|
|
|
592 |
|
|
|
593 |
|
|
|
594 |
/**
|
|
|
595 |
* Create a new dummy account for the sync adapter
|
|
|
596 |
*
|
|
|
597 |
* @param context The application context
|
|
|
598 |
*/
|
|
|
599 |
public static Account CreateSyncAccount(Context context) {
|
|
|
600 |
// Create the account type and default account
|
|
|
601 |
Account newAccount = new Account(
|
|
|
602 |
Constants.ACCOUNT, Constants.ACCOUNT_TYPE);
|
|
|
603 |
// Get an instance of the Android account manager
|
|
|
604 |
AccountManager accountManager =
|
|
|
605 |
(AccountManager) context.getSystemService(
|
|
|
606 |
ACCOUNT_SERVICE);
|
|
|
607 |
/*
|
|
|
608 |
* Add the account and account type, no password or user data
|
|
|
609 |
* If successful, return the Account object, otherwise report an error.
|
|
|
610 |
*/
|
|
|
611 |
if (accountManager.addAccountExplicitly(newAccount, null, null)) {
|
|
|
612 |
/*
|
|
|
613 |
* If you don't set android:syncable="true" in
|
|
|
614 |
* in your <provider> element in the manifest,
|
|
|
615 |
* then call context.setIsSyncable(account, AUTHORITY, 1)
|
|
|
616 |
* here.
|
|
|
617 |
*/
|
|
|
618 |
|
|
|
619 |
ContentResolver.setIsSyncable(newAccount, Constants.AUTHORITY, 1);
|
|
|
620 |
ContentResolver.setSyncAutomatically(newAccount, Constants.AUTHORITY, true);
|
|
|
621 |
ContentResolver.addPeriodicSync(newAccount,
|
|
|
622 |
Constants.AUTHORITY, Bundle.EMPTY, Constants.SYNC_INTERVAL);
|
|
|
623 |
|
|
|
624 |
|
|
|
625 |
} else {
|
|
|
626 |
/*
|
|
|
627 |
* The account exists or some other error occurred. Log this, report it,
|
|
|
628 |
* or handle it internally.
|
|
|
629 |
*/
|
|
|
630 |
|
|
|
631 |
Account[] accounts = accountManager.getAccounts();
|
|
|
632 |
if(accounts != null && accounts.length > 0) {
|
|
|
633 |
|
|
|
634 |
for(Account account : accounts)
|
|
|
635 |
{
|
|
|
636 |
if(account.type.equals(Constants.ACCOUNT_TYPE)) {
|
|
|
637 |
return account;
|
|
|
638 |
}
|
|
|
639 |
}
|
|
|
640 |
return accounts[0];
|
|
|
641 |
} else {
|
|
|
642 |
return null;
|
|
|
643 |
}
|
|
|
644 |
|
|
|
645 |
|
|
|
646 |
|
|
|
647 |
}
|
|
|
648 |
|
|
|
649 |
return newAccount;
|
|
|
650 |
|
|
|
651 |
|
|
|
652 |
}
|
|
|
653 |
|
|
|
654 |
|
|
|
655 |
|
|
|
656 |
|
|
|
657 |
|
|
|
658 |
@Override
|
|
|
659 |
public void createSyncRecordNewToken(String token)
|
|
|
660 |
{
|
|
|
661 |
|
|
|
662 |
preference.setDeviceToken (token);
|
29 |
efrain |
663 |
preference.save();
|
1 |
efrain |
664 |
|
|
|
665 |
if(!TextUtils.isEmpty(preference.getDeviceUuid())) {
|
|
|
666 |
Sync sync = new Sync(Constants.SYNC_ADAPTER_TYPE_FCM, token);
|
|
|
667 |
mAppDatabase.getSyncDao().insert(sync);
|
|
|
668 |
}
|
|
|
669 |
}
|
|
|
670 |
|
|
|
671 |
|
|
|
672 |
|
|
|
673 |
|
|
|
674 |
@Override
|
|
|
675 |
public void executeFcmCommand(String command)
|
|
|
676 |
{
|
|
|
677 |
|
|
|
678 |
if (command.equals("signout")) {
|
|
|
679 |
signout();
|
|
|
680 |
}
|
|
|
681 |
}
|
|
|
682 |
|
|
|
683 |
|
|
|
684 |
|
|
|
685 |
@Override
|
|
|
686 |
public void setConnectedInternet(Boolean isConnected)
|
|
|
687 |
{
|
|
|
688 |
connected = isConnected;
|
|
|
689 |
textViewMessageNotConnection.setVisibility(isConnected ? View.INVISIBLE : View.VISIBLE);
|
|
|
690 |
}
|
|
|
691 |
|
|
|
692 |
@Override
|
|
|
693 |
public boolean isConnectedInternet() {
|
|
|
694 |
return connected;
|
|
|
695 |
}
|
|
|
696 |
|
|
|
697 |
@Override
|
|
|
698 |
public void showMessageSnackBar(String message) {
|
|
|
699 |
Snackbar.make(this.findViewById(R.id.fragment_container), message, Snackbar.LENGTH_LONG).show();
|
|
|
700 |
}
|
|
|
701 |
|
|
|
702 |
|
|
|
703 |
@Override
|
|
|
704 |
public void showMessageSnackBarWithClose(String message) {
|
|
|
705 |
final Snackbar snackBar = Snackbar.make(this.findViewById(R.id.fragment_container), message, Snackbar.LENGTH_INDEFINITE);
|
|
|
706 |
|
|
|
707 |
snackBar.setAction(R.string.snackbar_close, new View.OnClickListener() {
|
|
|
708 |
@Override
|
|
|
709 |
public void onClick(View v) {
|
|
|
710 |
// Call your action method here
|
|
|
711 |
snackBar.dismiss();
|
|
|
712 |
}
|
|
|
713 |
});
|
|
|
714 |
snackBar.show();
|
|
|
715 |
|
|
|
716 |
|
|
|
717 |
}
|
|
|
718 |
|
|
|
719 |
@Override
|
|
|
720 |
public void onErrorFatal() {
|
|
|
721 |
|
|
|
722 |
|
|
|
723 |
invokeFragment(Constants.IDX_FRAGMENT_SIGNIN);
|
|
|
724 |
}
|
|
|
725 |
|
|
|
726 |
@Override
|
|
|
727 |
public void invokeFragment(int fragmentIdxActiveNuevo)
|
|
|
728 |
{
|
|
|
729 |
String fragmentKeyActual = PREFIX_FRAG + preference.getFragmentIdxActive();
|
|
|
730 |
String fragmentKeyNuevo = PREFIX_FRAG + fragmentIdxActiveNuevo;
|
|
|
731 |
preference.setFragmentIdxActive(fragmentIdxActiveNuevo);
|
29 |
efrain |
732 |
preference.save();
|
1 |
efrain |
733 |
|
|
|
734 |
Fragment fragment;
|
|
|
735 |
if(!fragmentKeyActual.equalsIgnoreCase(fragmentKeyNuevo)) {
|
|
|
736 |
if(fragmentHashMap.containsKey(fragmentKeyActual)) {
|
|
|
737 |
fragment = fragmentHashMap.get(fragmentKeyActual);
|
|
|
738 |
if(fragment != null) {
|
|
|
739 |
FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
|
|
|
740 |
fragmentTransaction.hide(fragment);
|
25 |
gabriel |
741 |
fragmentTransaction.commitAllowingStateLoss();
|
1 |
efrain |
742 |
}
|
|
|
743 |
}
|
|
|
744 |
}
|
|
|
745 |
|
|
|
746 |
boolean add = false;
|
|
|
747 |
fragment = null;
|
|
|
748 |
getSupportActionBar().setDisplayHomeAsUpEnabled(false);
|
|
|
749 |
mDrawerToggle.setDrawerIndicatorEnabled(false);
|
|
|
750 |
|
|
|
751 |
|
|
|
752 |
switch(fragmentIdxActiveNuevo) {
|
|
|
753 |
case Constants.IDX_FRAGMENT_SIGNIN :
|
|
|
754 |
getSupportActionBar().hide();
|
|
|
755 |
if(fragmentHashMap.containsKey(fragmentKeyNuevo)) {
|
|
|
756 |
fragment = fragmentHashMap.get(fragmentKeyNuevo);
|
|
|
757 |
} else {
|
|
|
758 |
add = true;
|
|
|
759 |
fragment = new SigninFragment();
|
|
|
760 |
}
|
|
|
761 |
break;
|
|
|
762 |
|
|
|
763 |
case Constants.IDX_FRAGMENT_TOPICS :
|
|
|
764 |
|
|
|
765 |
|
|
|
766 |
getSupportActionBar().show();
|
|
|
767 |
mDrawerToggle.setDrawerIndicatorEnabled(true);
|
|
|
768 |
if(fragmentHashMap.containsKey(fragmentKeyNuevo)) {
|
|
|
769 |
fragment = fragmentHashMap.get(fragmentKeyNuevo);
|
|
|
770 |
} else {
|
|
|
771 |
add = true;
|
|
|
772 |
fragment = new TopicFragment();
|
|
|
773 |
}
|
|
|
774 |
break;
|
|
|
775 |
|
4 |
gabriel |
776 |
|
1 |
efrain |
777 |
case Constants.IDX_FRAGMENT_CAPSULES :
|
|
|
778 |
getSupportActionBar().show();
|
|
|
779 |
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
|
|
780 |
if(fragmentHashMap.containsKey(fragmentKeyNuevo)) {
|
|
|
781 |
fragment = fragmentHashMap.get(fragmentKeyNuevo);
|
|
|
782 |
} else {
|
|
|
783 |
add = true;
|
|
|
784 |
fragment = new CapsuleFragment();
|
|
|
785 |
}
|
|
|
786 |
break;
|
|
|
787 |
|
|
|
788 |
case Constants.IDX_FRAGMENT_SLIDES :
|
|
|
789 |
getSupportActionBar().show();
|
|
|
790 |
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
|
|
791 |
if(fragmentHashMap.containsKey(fragmentKeyNuevo)) {
|
|
|
792 |
fragment = fragmentHashMap.get(fragmentKeyNuevo);
|
|
|
793 |
} else {
|
|
|
794 |
add = true;
|
|
|
795 |
fragment = new SlideFragment();
|
|
|
796 |
}
|
|
|
797 |
break;
|
|
|
798 |
|
|
|
799 |
case Constants.IDX_FRAGMENT_GALLERY :
|
|
|
800 |
getSupportActionBar().show();
|
|
|
801 |
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
|
|
802 |
if(fragmentHashMap.containsKey(fragmentKeyNuevo)) {
|
|
|
803 |
fragment = fragmentHashMap.get(fragmentKeyNuevo);
|
|
|
804 |
} else {
|
|
|
805 |
add = true;
|
|
|
806 |
fragment = new GalleryFragment();
|
|
|
807 |
}
|
|
|
808 |
|
|
|
809 |
break;
|
|
|
810 |
|
|
|
811 |
case Constants.IDX_FRAGMENT_FINISH_CAPSULE :
|
|
|
812 |
getSupportActionBar().hide();
|
|
|
813 |
if(fragmentHashMap.containsKey(fragmentKeyNuevo)) {
|
|
|
814 |
fragment = fragmentHashMap.get(fragmentKeyNuevo);
|
|
|
815 |
} else {
|
|
|
816 |
add = true;
|
|
|
817 |
fragment = new FinishCapsuleFragment();
|
|
|
818 |
}
|
|
|
819 |
break;
|
4 |
gabriel |
820 |
|
1 |
efrain |
821 |
case Constants.IDX_FRAGMENT_FINISH_TOPIC :
|
|
|
822 |
getSupportActionBar().hide();
|
|
|
823 |
if(fragmentHashMap.containsKey(fragmentKeyNuevo)) {
|
|
|
824 |
fragment = fragmentHashMap.get(fragmentKeyNuevo);
|
|
|
825 |
} else {
|
|
|
826 |
add = true;
|
|
|
827 |
fragment = new FinishTopicFragment();
|
|
|
828 |
}
|
|
|
829 |
break;
|
|
|
830 |
|
|
|
831 |
case Constants.IDX_FRAGMENT_TIMELINE :
|
|
|
832 |
getSupportActionBar().show();
|
|
|
833 |
mDrawerToggle.setDrawerIndicatorEnabled(true);
|
|
|
834 |
if(fragmentHashMap.containsKey(fragmentKeyNuevo)) {
|
|
|
835 |
fragment = fragmentHashMap.get(fragmentKeyNuevo);
|
|
|
836 |
} else {
|
|
|
837 |
add = true;
|
|
|
838 |
fragment = new TimelineFragment();
|
|
|
839 |
}
|
|
|
840 |
break;
|
|
|
841 |
|
|
|
842 |
case Constants.IDX_FRAGMENT_COMPANIES:
|
|
|
843 |
getSupportActionBar().show();
|
|
|
844 |
mDrawerToggle.setDrawerIndicatorEnabled(true);
|
|
|
845 |
if(fragmentHashMap.containsKey(fragmentKeyNuevo)) {
|
|
|
846 |
fragment = fragmentHashMap.get(fragmentKeyNuevo);
|
|
|
847 |
} else {
|
|
|
848 |
add = true;
|
|
|
849 |
fragment = new CompanyFragment();
|
|
|
850 |
}
|
|
|
851 |
break;
|
|
|
852 |
|
|
|
853 |
case Constants.IDX_FRAGMENT_PROGRESS :
|
|
|
854 |
getSupportActionBar().show();
|
|
|
855 |
mDrawerToggle.setDrawerIndicatorEnabled(true);
|
|
|
856 |
if(fragmentHashMap.containsKey(fragmentKeyNuevo)) {
|
|
|
857 |
fragment = fragmentHashMap.get(fragmentKeyNuevo);
|
|
|
858 |
} else {
|
|
|
859 |
add = true;
|
|
|
860 |
fragment = new ProgressFragment();
|
|
|
861 |
}
|
|
|
862 |
break;
|
|
|
863 |
|
|
|
864 |
case Constants.IDX_FRAGMENT_USER_PROFILE:
|
|
|
865 |
getSupportActionBar().show();
|
|
|
866 |
mDrawerToggle.setDrawerIndicatorEnabled(true);
|
|
|
867 |
if(fragmentHashMap.containsKey(fragmentKeyNuevo)) {
|
|
|
868 |
fragment = fragmentHashMap.get(fragmentKeyNuevo);
|
|
|
869 |
} else {
|
|
|
870 |
add = true;
|
|
|
871 |
fragment = new UserProfileFragment();
|
|
|
872 |
}
|
|
|
873 |
break;
|
|
|
874 |
|
|
|
875 |
default :
|
|
|
876 |
getSupportActionBar().hide();
|
|
|
877 |
if(fragmentHashMap.containsKey(fragmentKeyNuevo)) {
|
|
|
878 |
fragment = fragmentHashMap.get(fragmentKeyNuevo);
|
|
|
879 |
} else {
|
|
|
880 |
add = true;
|
|
|
881 |
fragment = new IntroFragment();
|
|
|
882 |
}
|
|
|
883 |
break;
|
|
|
884 |
|
|
|
885 |
|
|
|
886 |
}
|
|
|
887 |
|
|
|
888 |
if(add) {
|
|
|
889 |
fragmentHashMap.put(fragmentKeyNuevo, fragment);
|
|
|
890 |
|
|
|
891 |
FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
|
|
|
892 |
fragmentTransaction.add(R.id.fragment_container, fragment, fragmentKeyNuevo);
|
25 |
gabriel |
893 |
fragmentTransaction.commitAllowingStateLoss();
|
1 |
efrain |
894 |
}
|
|
|
895 |
|
|
|
896 |
|
|
|
897 |
if(fragment != null) {
|
|
|
898 |
FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
|
|
|
899 |
fragmentTransaction.show(fragment);
|
25 |
gabriel |
900 |
fragmentTransaction.commitAllowingStateLoss();
|
1 |
efrain |
901 |
}
|
|
|
902 |
|
|
|
903 |
}
|
|
|
904 |
|
|
|
905 |
@Override
|
|
|
906 |
public void changeTopicActive(String topicUuid)
|
|
|
907 |
{
|
|
|
908 |
Log.d(TAG, "changeTopicActive : " + topicUuid);
|
16 |
gabriel |
909 |
// Log.e("Guardo", "Topico en Main");
|
1 |
efrain |
910 |
|
|
|
911 |
preference.setTopicUuidActive(topicUuid);
|
|
|
912 |
preference.setCapsuleUuidActive("");
|
|
|
913 |
preference.setSlideUuidActive("");
|
29 |
efrain |
914 |
preference.save();
|
1 |
efrain |
915 |
|
|
|
916 |
invokeFragment(Constants.IDX_FRAGMENT_CAPSULES);
|
|
|
917 |
}
|
|
|
918 |
|
|
|
919 |
@Override
|
|
|
920 |
public void changeCapsuleActive(String capsuleUuid)
|
|
|
921 |
{
|
|
|
922 |
Log.d(TAG, "changeCapsuleActive : " + capsuleUuid);
|
|
|
923 |
|
|
|
924 |
|
8 |
gabriel |
925 |
|
1 |
efrain |
926 |
preference.setCapsuleUuidActive(capsuleUuid);
|
|
|
927 |
preference.setSlideUuidActive("");
|
29 |
efrain |
928 |
preference.save();
|
1 |
efrain |
929 |
|
|
|
930 |
invokeFragment(Constants.IDX_FRAGMENT_SLIDES);
|
|
|
931 |
}
|
|
|
932 |
|
|
|
933 |
@Override
|
|
|
934 |
public void changeCompanyActive(String companyUuid)
|
|
|
935 |
{
|
|
|
936 |
Log.d(TAG, "changeCompanyActive : " + companyUuid);
|
|
|
937 |
|
|
|
938 |
preference.setCompanyUuidActive(companyUuid);
|
29 |
efrain |
939 |
preference.save();
|
1 |
efrain |
940 |
}
|
|
|
941 |
|
|
|
942 |
@Override
|
44 |
efrain |
943 |
public synchronized void changeSlideActive(String slideUuid, String type, boolean showGallery)
|
1 |
efrain |
944 |
{
|
|
|
945 |
|
|
|
946 |
Log.d(TAG, "changeSlideActive : " + slideUuid);
|
|
|
947 |
|
|
|
948 |
if(!preference.getSlideUuidActive().equals(slideUuid) && type.equals(Constants.SLIDE_TYPE_IMAGE)) {
|
|
|
949 |
Log.d(TAG, "registerOnPageChangeCallback - createProgressAndSyncRecord");
|
|
|
950 |
|
|
|
951 |
createProgressAndSyncRecord(slideUuid, true, false, false);
|
|
|
952 |
}
|
|
|
953 |
preference.setSlideUuidActive(slideUuid);
|
29 |
efrain |
954 |
preference.save();
|
1 |
efrain |
955 |
|
|
|
956 |
|
|
|
957 |
if(showGallery) {
|
|
|
958 |
invokeFragment(Constants.IDX_FRAGMENT_GALLERY);
|
|
|
959 |
}
|
|
|
960 |
}
|
|
|
961 |
|
|
|
962 |
@Override
|
|
|
963 |
public String getTopicUuidActive()
|
|
|
964 |
{
|
|
|
965 |
return preference.getTopicUuidActive();
|
|
|
966 |
}
|
|
|
967 |
|
|
|
968 |
@Override
|
|
|
969 |
public String getCapsuleUuidActive()
|
|
|
970 |
{
|
|
|
971 |
return preference.getCapsuleUuidActive();
|
|
|
972 |
}
|
|
|
973 |
|
|
|
974 |
@Override
|
|
|
975 |
public String getSlideUuidActive()
|
|
|
976 |
{
|
|
|
977 |
return preference.getSlideUuidActive();
|
|
|
978 |
}
|
|
|
979 |
|
|
|
980 |
@Override
|
|
|
981 |
public String getCompanyUuidActive()
|
|
|
982 |
{
|
|
|
983 |
return preference.getCompanyUuidActive();
|
|
|
984 |
}
|
|
|
985 |
|
|
|
986 |
@Override
|
|
|
987 |
public void setTitleActionBar(String title)
|
|
|
988 |
{
|
|
|
989 |
getSupportActionBar().setTitle(title);
|
|
|
990 |
}
|
|
|
991 |
|
|
|
992 |
@Override
|
|
|
993 |
public synchronized void createProgressAndSyncRecord(String slideUuid, boolean completed, boolean isQuiz, boolean isAudioOrVideo)
|
|
|
994 |
{
|
|
|
995 |
Calendar calendar = Calendar.getInstance();
|
|
|
996 |
Date date = calendar.getTime();
|
|
|
997 |
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(Constants.FORMAT_DATETIME_SERVICE);
|
|
|
998 |
String dateOn = simpleDateFormat.format(date);
|
|
|
999 |
|
|
|
1000 |
SlideDao slideDao = mAppDatabase.getSlideDao();
|
|
|
1001 |
Slide slide = slideDao.selectByUuid(slideUuid);
|
|
|
1002 |
|
|
|
1003 |
CapsuleDao capsuleDao = mAppDatabase.getCapsuleDao();
|
|
|
1004 |
Capsule capsule = capsuleDao.selectByUuid(slide.getCapsuleUuid());
|
|
|
1005 |
|
|
|
1006 |
TopicDao topicDao = mAppDatabase.getTopicDao();
|
|
|
1007 |
Topic topic = topicDao.selectByUuid(capsule.getTopicUuid());
|
|
|
1008 |
|
|
|
1009 |
UserLog userLog;
|
|
|
1010 |
UserLogDao userLogDao = mAppDatabase.getUserLogDao();
|
|
|
1011 |
|
|
|
1012 |
SyncDao syncDao = mAppDatabase.getSyncDao();
|
|
|
1013 |
Sync sync;
|
|
|
1014 |
|
44 |
efrain |
1015 |
String userUuid = preference.getUserUuid();
|
|
|
1016 |
|
1 |
efrain |
1017 |
// Progreso y UserLog del Slide
|
|
|
1018 |
ProgressDao progressDao = mAppDatabase.getProgressDao();
|
44 |
efrain |
1019 |
Progress progressSlide = progressDao.selectBySlideUuidAndUserUuid(slide.getUuid(), userUuid);
|
|
|
1020 |
Progress progressCapsule = progressDao.selectByCapsuleUuidAndUserUuid(slide.getCapsuleUuid(),userUuid);
|
|
|
1021 |
Progress progressTopic = progressDao.selectByTopicUuidAndUserUuid(slide.getTopicUuid(),userUuid);
|
1 |
efrain |
1022 |
|
|
|
1023 |
int totalSlides = 0;
|
|
|
1024 |
int viewSlides = 0;
|
|
|
1025 |
double percentaje = 0;
|
|
|
1026 |
boolean newRecord = false;
|
|
|
1027 |
boolean retakeQuiz = false;
|
|
|
1028 |
|
|
|
1029 |
/*** INICIO PROCESO DIAPOSITIVA ***/
|
|
|
1030 |
if(progressSlide == null) {
|
|
|
1031 |
|
|
|
1032 |
retakeQuiz = false;
|
|
|
1033 |
|
|
|
1034 |
|
|
|
1035 |
progressSlide = new Progress();
|
|
|
1036 |
progressSlide.setUserUuid(preference.getUserUuid());
|
|
|
1037 |
progressSlide.setCompanyUuid(topic.getCompanyUuid());
|
|
|
1038 |
progressSlide.setTopicUuid(topic.getUuid());
|
|
|
1039 |
progressSlide.setCapsuleUuid(capsule.getUuid());
|
|
|
1040 |
progressSlide.setSlideUuid(slide.getUuid());
|
|
|
1041 |
progressSlide.setType(Constants.PROGERSS_TYPE_SLIDE);
|
|
|
1042 |
progressSlide.setCompleted(completed ? 1 : 0);
|
|
|
1043 |
progressSlide.setAddedOn(dateOn);
|
|
|
1044 |
progressSlide.setUpdatedOn(dateOn);
|
|
|
1045 |
progressDao.insert(progressSlide);
|
|
|
1046 |
} else {
|
|
|
1047 |
retakeQuiz = true;
|
|
|
1048 |
|
|
|
1049 |
if (progressSlide.getCompleted() == 1) {
|
|
|
1050 |
progressSlide.setReturningAfterCompleted(progressSlide.getReturningAfterCompleted() + 1);
|
|
|
1051 |
} else {
|
|
|
1052 |
if (completed) {
|
4 |
gabriel |
1053 |
//0 y 1 para Boolean
|
1 |
efrain |
1054 |
progressSlide.setCompleted(completed ? 1 : 0);
|
|
|
1055 |
} else {
|
|
|
1056 |
progressSlide.setReturning(progressSlide.getReturning() + 1);
|
|
|
1057 |
}
|
|
|
1058 |
}
|
|
|
1059 |
|
|
|
1060 |
progressSlide.setUpdatedOn(dateOn);
|
|
|
1061 |
progressDao.update(progressSlide);
|
|
|
1062 |
}
|
|
|
1063 |
|
|
|
1064 |
|
27 |
efrain |
1065 |
|
1 |
efrain |
1066 |
/*** FIN PROCESO DIAPOSITIVA ***/
|
|
|
1067 |
|
|
|
1068 |
|
|
|
1069 |
|
|
|
1070 |
/*** INICIO PROCESO TOPICO ***/
|
|
|
1071 |
ResultCount resultCount;
|
|
|
1072 |
|
|
|
1073 |
|
|
|
1074 |
resultCount = slideDao.getCountByTopicUuid(slide.getTopicUuid());
|
|
|
1075 |
totalSlides = resultCount.getCount();
|
|
|
1076 |
|
44 |
efrain |
1077 |
resultCount = progressDao.getCountSlidesCompletedByTopicUuidAndUserUuid(slide.getTopicUuid(), userUuid);
|
1 |
efrain |
1078 |
viewSlides = resultCount.getCount();
|
|
|
1079 |
if(totalSlides == 0) {
|
|
|
1080 |
percentaje = 0;
|
|
|
1081 |
} else {
|
|
|
1082 |
percentaje = (viewSlides * 100) / totalSlides;
|
|
|
1083 |
}
|
|
|
1084 |
|
|
|
1085 |
if(progressTopic == null) {
|
|
|
1086 |
newRecord = true;
|
|
|
1087 |
progressTopic = new Progress();
|
|
|
1088 |
progressTopic.setUserUuid(preference.getUserUuid());
|
|
|
1089 |
progressTopic.setCompanyUuid( topic.getCompanyUuid());
|
|
|
1090 |
progressTopic.setTopicUuid (topic.getUuid());
|
|
|
1091 |
|
|
|
1092 |
progressTopic.setViewSlides(viewSlides);
|
|
|
1093 |
progressTopic.setTotalSlides(totalSlides);
|
|
|
1094 |
progressTopic.setProgress (percentaje);
|
|
|
1095 |
progressTopic.setType(Constants.PROGERSS_TYPE_TOPIC);
|
|
|
1096 |
|
|
|
1097 |
progressTopic.setAddedOn(dateOn);
|
|
|
1098 |
progressTopic.setUpdatedOn(dateOn);
|
|
|
1099 |
progressDao.insert(progressTopic);
|
|
|
1100 |
} else {
|
|
|
1101 |
newRecord = false;
|
|
|
1102 |
progressTopic.setViewSlides(viewSlides);
|
|
|
1103 |
progressTopic.setTotalSlides(totalSlides);
|
|
|
1104 |
progressTopic.setProgress (percentaje);
|
|
|
1105 |
progressDao.update(progressTopic);
|
|
|
1106 |
}
|
|
|
1107 |
|
|
|
1108 |
try {
|
|
|
1109 |
JSONObject json = progressTopic.toJson();
|
|
|
1110 |
json.put(Constants.SYNC_ADAPTER_DATA_TYPE_FIELD_NAME, Constants.SYNC_ADAPTER_DATA_TYPE_MICROLEARNING_PROGRESS);
|
|
|
1111 |
|
|
|
1112 |
sync = new Sync(Constants.SYNC_ADAPTER_TYPE_SYNC, json.toString());
|
|
|
1113 |
syncDao.insert(sync);
|
|
|
1114 |
} catch (JSONException e) {
|
|
|
1115 |
}
|
|
|
1116 |
|
|
|
1117 |
if(newRecord) {
|
|
|
1118 |
userLog = new UserLog();
|
|
|
1119 |
userLog.setUserUuid(preference.getUserUuid());
|
|
|
1120 |
userLog.setActivity(Constants.USER_LOG_ACTIVITY_START_TOPIC);
|
|
|
1121 |
userLog.setCompanyUuid (topic.getCompanyUuid());
|
|
|
1122 |
userLog.setTopicUuid (topic.getUuid());
|
|
|
1123 |
userLog.setAddedOn(dateOn);
|
|
|
1124 |
|
|
|
1125 |
|
|
|
1126 |
userLogDao.insert(userLog);
|
|
|
1127 |
try {
|
|
|
1128 |
JSONObject json = userLog.toJson();
|
|
|
1129 |
json.put(Constants.SYNC_ADAPTER_DATA_TYPE_FIELD_NAME, Constants.SYNC_ADAPTER_DATA_TYPE_MICROLEARNING_USER_LOG);
|
|
|
1130 |
|
|
|
1131 |
sync = new Sync(Constants.SYNC_ADAPTER_TYPE_SYNC, json.toString());
|
|
|
1132 |
syncDao.insert(sync);
|
|
|
1133 |
} catch (JSONException e) {
|
|
|
1134 |
}
|
|
|
1135 |
}
|
|
|
1136 |
/*** FIN PROCESO TOPICO ***/
|
|
|
1137 |
|
|
|
1138 |
|
|
|
1139 |
|
|
|
1140 |
/*** INICIO PROCESO CAPSULA ***/
|
|
|
1141 |
resultCount = slideDao.getCountByCapsuleUuid(slide.getCapsuleUuid());
|
|
|
1142 |
totalSlides = resultCount.getCount();
|
44 |
efrain |
1143 |
resultCount = progressDao.getCountSlidesCompletedByCapsuleUuidAndUserUuid(slide.getCapsuleUuid(), userUuid);
|
1 |
efrain |
1144 |
viewSlides = resultCount.getCount();
|
|
|
1145 |
if(totalSlides == 0) {
|
|
|
1146 |
percentaje = 0;
|
|
|
1147 |
} else {
|
|
|
1148 |
percentaje = (viewSlides * 100) / totalSlides;
|
|
|
1149 |
}
|
|
|
1150 |
|
|
|
1151 |
if(progressCapsule == null) {
|
|
|
1152 |
newRecord = true;
|
|
|
1153 |
progressCapsule = new Progress();
|
|
|
1154 |
progressCapsule.setUserUuid(preference.getUserUuid());
|
|
|
1155 |
progressCapsule.setCompanyUuid(topic.getCompanyUuid());
|
|
|
1156 |
progressCapsule.setTopicUuid(topic.getUuid());
|
|
|
1157 |
progressCapsule.setCapsuleUuid (capsule.getUuid());
|
|
|
1158 |
progressCapsule.setViewSlides(viewSlides);
|
|
|
1159 |
progressCapsule.setTotalSlides(totalSlides);
|
|
|
1160 |
progressCapsule.setProgress(percentaje);
|
|
|
1161 |
progressCapsule.setType(Constants.PROGERSS_TYPE_CAPSULE);
|
|
|
1162 |
progressCapsule.setAddedOn(dateOn);
|
|
|
1163 |
progressCapsule.setUpdatedOn(dateOn);
|
|
|
1164 |
progressDao.insert(progressCapsule);
|
|
|
1165 |
|
|
|
1166 |
Log.d(TAG, "Progress Capsule Nueva : setLastCapsuleActive : " + preference.getLastCapsuleUuidActive());
|
|
|
1167 |
preference.setLastCapsuleUuidActive(capsule.getUuid());
|
|
|
1168 |
} else {
|
|
|
1169 |
newRecord = false;
|
|
|
1170 |
progressCapsule.setViewSlides(viewSlides);
|
|
|
1171 |
progressCapsule.setTotalSlides(totalSlides);
|
|
|
1172 |
progressCapsule.setProgress(percentaje);
|
|
|
1173 |
|
|
|
1174 |
Log.d(TAG, "Progress Capsule : getLastCapsuleActive : " + preference.getLastCapsuleUuidActive());
|
|
|
1175 |
Log.d(TAG, "Progress Capsule : CapsuleActive : " + preference.getCapsuleUuidActive());
|
|
|
1176 |
|
|
|
1177 |
if (!preference.getLastCapsuleUuidActive().equals(preference.getCapsuleUuidActive())) {
|
|
|
1178 |
|
|
|
1179 |
Log.d(TAG, "Capsule Progress : " + progressCapsule.getProgress());
|
|
|
1180 |
Log.d(TAG, "Capsule Completed : " + progressCapsule.getCompleted());
|
|
|
1181 |
Log.d(TAG, "Capsule Total slides : " + progressCapsule.getTotalSlides());
|
|
|
1182 |
Log.d(TAG, "Capsule View slides : " + progressCapsule.getViewSlides());
|
|
|
1183 |
|
|
|
1184 |
if(progressCapsule.getCompleted() == 1) {
|
|
|
1185 |
Log.d(TAG, "Capsule OLD returningAfterCompleted = " + progressCapsule.getReturningAfterCompleted());
|
|
|
1186 |
|
|
|
1187 |
int returningAfterCompleted = progressCapsule.getReturningAfterCompleted() + 1;
|
|
|
1188 |
|
|
|
1189 |
Log.d(TAG, "Capsule NEW returningAfterCompleted = " + returningAfterCompleted);
|
|
|
1190 |
progressCapsule.setReturningAfterCompleted(returningAfterCompleted);
|
|
|
1191 |
}
|
|
|
1192 |
|
|
|
1193 |
preference.setLastCapsuleUuidActive(capsule.getUuid());
|
29 |
efrain |
1194 |
preference.save();
|
1 |
efrain |
1195 |
|
|
|
1196 |
Log.d(TAG, "Progress Capsule : setLastCapsuleActive : " + preference.getLastCapsuleUuidActive());
|
|
|
1197 |
}
|
|
|
1198 |
|
|
|
1199 |
progressDao.update(progressCapsule);
|
|
|
1200 |
}
|
|
|
1201 |
try {
|
|
|
1202 |
JSONObject json = progressCapsule.toJson();
|
|
|
1203 |
json.put(Constants.SYNC_ADAPTER_DATA_TYPE_FIELD_NAME, Constants.SYNC_ADAPTER_DATA_TYPE_MICROLEARNING_PROGRESS);
|
|
|
1204 |
|
|
|
1205 |
sync = new Sync(Constants.SYNC_ADAPTER_TYPE_SYNC, json.toString());
|
|
|
1206 |
syncDao.insert(sync);
|
|
|
1207 |
} catch (JSONException e) {
|
|
|
1208 |
|
|
|
1209 |
}
|
|
|
1210 |
|
|
|
1211 |
if(newRecord) {
|
|
|
1212 |
userLog = new UserLog();
|
|
|
1213 |
userLog.setUserUuid(preference.getUserUuid());
|
|
|
1214 |
userLog.setActivity(Constants.USER_LOG_ACTIVITY_START_CAPSULE);
|
|
|
1215 |
userLog.setCompanyUuid(topic.getCompanyUuid());
|
|
|
1216 |
userLog.setTopicUuid(topic.getUuid());
|
|
|
1217 |
userLog.setCapsuleUuid(capsule.getUuid());
|
|
|
1218 |
userLog.setAddedOn(dateOn);
|
|
|
1219 |
|
|
|
1220 |
|
|
|
1221 |
userLogDao.insert(userLog);
|
|
|
1222 |
try {
|
|
|
1223 |
JSONObject json = userLog.toJson();
|
|
|
1224 |
json.put(Constants.SYNC_ADAPTER_DATA_TYPE_FIELD_NAME, Constants.SYNC_ADAPTER_DATA_TYPE_MICROLEARNING_USER_LOG);
|
|
|
1225 |
|
|
|
1226 |
sync = new Sync(Constants.SYNC_ADAPTER_TYPE_SYNC, json.toString());
|
|
|
1227 |
syncDao.insert(sync);
|
|
|
1228 |
} catch (JSONException e) {
|
|
|
1229 |
}
|
|
|
1230 |
}
|
|
|
1231 |
|
|
|
1232 |
|
|
|
1233 |
/*** FIN PROCESO CAPSULA ***/
|
|
|
1234 |
|
|
|
1235 |
/*** INICIO USERLOG SLIDE ***/
|
|
|
1236 |
userLog = new UserLog();
|
|
|
1237 |
userLog.setUserUuid(preference.getUserUuid());
|
|
|
1238 |
userLog.setActivity(Constants.USER_LOG_ACTIVITY_VIEW_SLIDE);
|
|
|
1239 |
userLog.setCompanyUuid(topic.getCompanyUuid());
|
|
|
1240 |
userLog.setTopicUuid(topic.getUuid());
|
|
|
1241 |
userLog.setCapsuleUuid(capsule.getUuid());
|
|
|
1242 |
userLog.setSlideUuid(slide.getUuid());
|
|
|
1243 |
userLog.setAddedOn(dateOn);
|
|
|
1244 |
|
|
|
1245 |
|
|
|
1246 |
userLogDao.insert(userLog);
|
|
|
1247 |
try {
|
|
|
1248 |
JSONObject json = userLog.toJson();
|
|
|
1249 |
json.put(Constants.SYNC_ADAPTER_DATA_TYPE_FIELD_NAME, Constants.SYNC_ADAPTER_DATA_TYPE_MICROLEARNING_USER_LOG);
|
|
|
1250 |
|
|
|
1251 |
sync = new Sync(Constants.SYNC_ADAPTER_TYPE_SYNC, json.toString());
|
|
|
1252 |
syncDao.insert(sync);
|
|
|
1253 |
} catch (JSONException e) {
|
|
|
1254 |
}
|
|
|
1255 |
|
|
|
1256 |
/*** FIN ***/
|
|
|
1257 |
|
|
|
1258 |
|
|
|
1259 |
/*** PROGRESS SLIDE***/
|
|
|
1260 |
try {
|
|
|
1261 |
JSONObject json = progressSlide.toJson();
|
|
|
1262 |
json.put(Constants.SYNC_ADAPTER_DATA_TYPE_FIELD_NAME, Constants.SYNC_ADAPTER_DATA_TYPE_MICROLEARNING_PROGRESS);
|
|
|
1263 |
|
|
|
1264 |
sync = new Sync(Constants.SYNC_ADAPTER_TYPE_SYNC, json.toString());
|
|
|
1265 |
syncDao.insert(sync);
|
|
|
1266 |
} catch (JSONException e) {
|
|
|
1267 |
}
|
|
|
1268 |
|
|
|
1269 |
/** IS SLIDE = QUIZ **/
|
|
|
1270 |
if (isQuiz) {
|
|
|
1271 |
userLog = new UserLog();
|
|
|
1272 |
userLog.setUserUuid(preference.getUserUuid());
|
|
|
1273 |
userLog.setActivity(retakeQuiz ? Constants.USER_LOG_ACTIVITY_RETAKE_A_TEST : Constants.USER_LOG_ACTIVITY_TAKE_A_TEST);
|
|
|
1274 |
userLog.setCompanyUuid (topic.getCompanyUuid());
|
|
|
1275 |
userLog.setTopicUuid(slide.getTopicUuid());
|
|
|
1276 |
userLog.setCapsuleUuid(slide.getCapsuleUuid());
|
|
|
1277 |
userLog.setSlideUuid(slide.getUuid());
|
|
|
1278 |
userLog.setAddedOn(dateOn);
|
|
|
1279 |
|
|
|
1280 |
userLogDao.insert(userLog);
|
|
|
1281 |
try {
|
|
|
1282 |
JSONObject json = userLog.toJson();
|
|
|
1283 |
json.put(Constants.SYNC_ADAPTER_DATA_TYPE_FIELD_NAME, Constants.SYNC_ADAPTER_DATA_TYPE_MICROLEARNING_USER_LOG);
|
|
|
1284 |
|
|
|
1285 |
sync = new Sync(Constants.SYNC_ADAPTER_TYPE_SYNC, json.toString());
|
|
|
1286 |
syncDao.insert(sync);
|
|
|
1287 |
} catch (JSONException e) {
|
|
|
1288 |
}
|
|
|
1289 |
|
|
|
1290 |
|
|
|
1291 |
if(progressSlide.getCompleted() == 1) {
|
|
|
1292 |
userLog = new UserLog();
|
|
|
1293 |
userLog.setUserUuid(preference.getUserUuid());
|
|
|
1294 |
userLog.setActivity(Constants.USER_LOG_ACTIVITY_APPROVED_TEST);
|
|
|
1295 |
userLog.setCompanyUuid(topic.getCompanyUuid());
|
|
|
1296 |
userLog.setTopicUuid(slide.getTopicUuid());
|
|
|
1297 |
userLog.setCapsuleUuid(slide.getCapsuleUuid());
|
|
|
1298 |
userLog.setSlideUuid(slide.getUuid());
|
|
|
1299 |
userLog.setAddedOn(dateOn);
|
|
|
1300 |
|
|
|
1301 |
userLogDao.insert(userLog);
|
|
|
1302 |
try {
|
|
|
1303 |
JSONObject json = userLog.toJson();
|
|
|
1304 |
json.put(Constants.SYNC_ADAPTER_DATA_TYPE_FIELD_NAME, Constants.SYNC_ADAPTER_DATA_TYPE_MICROLEARNING_USER_LOG);
|
|
|
1305 |
|
|
|
1306 |
sync = new Sync(Constants.SYNC_ADAPTER_TYPE_SYNC, json.toString());
|
|
|
1307 |
syncDao.insert(sync);
|
|
|
1308 |
} catch (JSONException e) {
|
|
|
1309 |
}
|
|
|
1310 |
|
|
|
1311 |
} else {
|
|
|
1312 |
if(progressSlide.getCompleted() == 1) {
|
|
|
1313 |
userLog = new UserLog();
|
|
|
1314 |
userLog.setUserUuid(preference.getUserUuid());
|
|
|
1315 |
userLog.setActivity( Constants.USER_LOG_ACTIVITY_VIEW_SLIDE);
|
|
|
1316 |
userLog.setCompanyUuid(topic.getCompanyUuid());
|
|
|
1317 |
userLog.setTopicUuid(slide.getTopicUuid());
|
|
|
1318 |
userLog.setCapsuleUuid(slide.getCapsuleUuid());
|
|
|
1319 |
userLog.setSlideUuid(slide.getUuid());
|
|
|
1320 |
userLog.setAddedOn(dateOn);
|
|
|
1321 |
|
|
|
1322 |
userLogDao.insert(userLog);
|
|
|
1323 |
try {
|
|
|
1324 |
JSONObject json = userLog.toJson();
|
|
|
1325 |
json.put(Constants.SYNC_ADAPTER_DATA_TYPE_FIELD_NAME, Constants.SYNC_ADAPTER_DATA_TYPE_MICROLEARNING_USER_LOG);
|
|
|
1326 |
|
|
|
1327 |
sync = new Sync(Constants.SYNC_ADAPTER_TYPE_SYNC, json.toString());
|
|
|
1328 |
syncDao.insert(sync);
|
|
|
1329 |
} catch (JSONException e) {
|
|
|
1330 |
}
|
|
|
1331 |
}
|
|
|
1332 |
}
|
|
|
1333 |
}
|
|
|
1334 |
|
|
|
1335 |
requestExecuteSyncAdapter();
|
|
|
1336 |
}
|
|
|
1337 |
|
|
|
1338 |
@Override
|
|
|
1339 |
public void launchVideoViewer(String videoAudioUrl)
|
|
|
1340 |
{
|
|
|
1341 |
|
26 |
gabriel |
1342 |
Intent intent = new Intent(getApplicationContext(), VideoAudioActivity.class);
|
1 |
efrain |
1343 |
intent.putExtra("videoAudioUrl",videoAudioUrl);
|
|
|
1344 |
intent.putExtra("deviceId", preference.getDeviceUuid());
|
|
|
1345 |
intent.putExtra("password", preference.getPassword());
|
|
|
1346 |
//startActivityForResult(intent, Constants.REQUEST_CODE_VIDEO);
|
|
|
1347 |
|
|
|
1348 |
mLauncher.launch(intent);
|
|
|
1349 |
|
|
|
1350 |
}
|
|
|
1351 |
|
|
|
1352 |
@Override
|
|
|
1353 |
public void launchAudioViewer(String videoAudioUrl)
|
|
|
1354 |
{
|
|
|
1355 |
|
26 |
gabriel |
1356 |
Intent intent = new Intent(getApplicationContext(), VideoAudioActivity.class);
|
1 |
efrain |
1357 |
intent.putExtra("videoAudioUrl",videoAudioUrl);
|
|
|
1358 |
intent.putExtra("deviceId", preference.getDeviceUuid());
|
|
|
1359 |
intent.putExtra("password", preference.getPassword());
|
|
|
1360 |
//startActivityForResult(intent, Constants.REQUEST_CODE_AUDIO);
|
|
|
1361 |
|
|
|
1362 |
|
|
|
1363 |
mLauncher.launch(intent);
|
|
|
1364 |
}
|
|
|
1365 |
|
|
|
1366 |
@Override
|
|
|
1367 |
public void launchTextViewer(String description)
|
|
|
1368 |
{
|
26 |
gabriel |
1369 |
Intent intent = new Intent(getApplicationContext(),TextActivity.class);
|
1 |
efrain |
1370 |
intent.putExtra("description",description);
|
|
|
1371 |
|
|
|
1372 |
//startActivityForResult(intent, Constants.REQUEST_CODE_TEXT);
|
|
|
1373 |
|
|
|
1374 |
mLauncher.launch(intent);
|
|
|
1375 |
}
|
|
|
1376 |
|
|
|
1377 |
|
|
|
1378 |
@Override
|
|
|
1379 |
public void launchDocumentViewer(String file)
|
|
|
1380 |
{
|
|
|
1381 |
|
26 |
gabriel |
1382 |
Intent intent = new Intent(getApplicationContext(),PdfActivity.class);
|
1 |
efrain |
1383 |
intent.putExtra("documentUrl",file);
|
|
|
1384 |
intent.putExtra("deviceId", preference.getDeviceUuid());
|
|
|
1385 |
intent.putExtra("password", preference.getPassword());
|
|
|
1386 |
|
|
|
1387 |
//startActivityForResult(intent, Constants.REQUEST_CODE_PDF);
|
|
|
1388 |
|
|
|
1389 |
mLauncher.launch(intent);
|
|
|
1390 |
}
|
|
|
1391 |
|
|
|
1392 |
@Override
|
|
|
1393 |
public void launchQuizViewer(String quizUuid)
|
|
|
1394 |
{
|
44 |
efrain |
1395 |
|
1 |
efrain |
1396 |
ProgressDao progressDao = mAppDatabase.getProgressDao();
|
44 |
efrain |
1397 |
Progress progress = progressDao.selectBySlideUuidAndUserUuid(preference.getSlideUuidActive(), preference.getUserUuid());
|
1 |
efrain |
1398 |
|
|
|
1399 |
boolean launch = false;
|
|
|
1400 |
if(progress != null && progress.getCompleted() == 0) {
|
|
|
1401 |
|
|
|
1402 |
Calendar calendar = Calendar.getInstance();
|
|
|
1403 |
Date date = calendar.getTime();
|
|
|
1404 |
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(Constants.FORMAT_DATETIME_SERVICE);
|
|
|
1405 |
try {
|
|
|
1406 |
Long updateOn = simpleDateFormat.parse(progress.getUpdatedOn()).getTime();
|
|
|
1407 |
|
|
|
1408 |
//30 minutes
|
|
|
1409 |
long mintime = 30 * 60 * 1000;
|
|
|
1410 |
if(date.getTime() - updateOn > mintime ) {
|
|
|
1411 |
launch = true;
|
|
|
1412 |
}
|
|
|
1413 |
|
|
|
1414 |
launch = true;
|
|
|
1415 |
|
|
|
1416 |
} catch(Exception e) {
|
|
|
1417 |
|
|
|
1418 |
}
|
|
|
1419 |
|
|
|
1420 |
|
|
|
1421 |
} else {
|
|
|
1422 |
launch = true;
|
|
|
1423 |
}
|
|
|
1424 |
|
|
|
1425 |
if(launch) {
|
|
|
1426 |
|
|
|
1427 |
QuizDao quizDao = mAppDatabase.getQuizDao();
|
|
|
1428 |
Quiz quiz = quizDao.selectByUuid(quizUuid);
|
|
|
1429 |
|
|
|
1430 |
TopicDao topicDao = mAppDatabase.getTopicDao();
|
|
|
1431 |
Topic topic = topicDao.selectByUuid(preference.getTopicUuidActive());
|
|
|
1432 |
|
|
|
1433 |
CapsuleDao capsuleDao = mAppDatabase.getCapsuleDao();
|
|
|
1434 |
Capsule capsule = capsuleDao.selectByUuid(preference.getCapsuleUuidActive());
|
|
|
1435 |
|
|
|
1436 |
SlideDao slideDao = mAppDatabase.getSlideDao();
|
|
|
1437 |
Slide slide = slideDao.selectByUuid(preference.getSlideUuidActive());
|
|
|
1438 |
|
|
|
1439 |
QuestionDao questionDao = mAppDatabase.getQuestionDao();
|
|
|
1440 |
List<Question> questions = questionDao.selectAllByQuizUuid(quiz.getUuid());
|
|
|
1441 |
|
|
|
1442 |
|
|
|
1443 |
List<Answer> answers;
|
|
|
1444 |
AnswerDao answerDao = mAppDatabase.getAnswerDao();
|
|
|
1445 |
|
26 |
gabriel |
1446 |
Intent intent = new Intent(getApplicationContext(), QuizActivity.class);
|
1 |
efrain |
1447 |
// intent.putExtra("companyUuid", topic.getCompanyUuid());
|
|
|
1448 |
// intent.putExtra("topicUuid", topic.getUuid());
|
|
|
1449 |
//intent.putExtra("capsuleUuid", capsule.getUuid());
|
|
|
1450 |
//intent.putExtra("slideUuid", slide.getUuid());
|
|
|
1451 |
//intent.putExtra("userUuid", preference.getUserUuid());
|
|
|
1452 |
//intent.putExtra("quizUuid", quizUuid);
|
|
|
1453 |
|
|
|
1454 |
|
|
|
1455 |
intent.putExtra("quiz_uuid", quiz.getUuid());
|
|
|
1456 |
intent.putExtra("quiz_company_uuid", quiz.getCompanyUuid());
|
|
|
1457 |
intent.putExtra("quiz_name", quiz.getName());
|
|
|
1458 |
intent.putExtra("quiz_points", quiz.getPoints());
|
|
|
1459 |
intent.putExtra("quiz_max_time", quiz.getMaxTime());
|
|
|
1460 |
intent.putExtra("quiz_minimum_points_required", quiz.getMinimumPointsRequired());
|
|
|
1461 |
intent.putExtra("quiz_failed", quiz.getFailed());
|
|
|
1462 |
intent.putExtra("quiz_text", quiz.getText());
|
|
|
1463 |
|
|
|
1464 |
intent.putExtra("questions", questions.size());
|
|
|
1465 |
int i = 1;
|
|
|
1466 |
int j = 1;
|
|
|
1467 |
for(Question question : questions) {
|
|
|
1468 |
intent.putExtra("question" + i + "_uuid", question.getUuid());
|
|
|
1469 |
intent.putExtra("question" + i + "_text", question.getText());
|
|
|
1470 |
intent.putExtra("question" + i + "_max_length", question.getMaxlength());
|
|
|
1471 |
intent.putExtra("question" + i + "_position", question.getPosition());
|
|
|
1472 |
intent.putExtra("question" + i + "_points", question.getPoints());
|
|
|
1473 |
intent.putExtra("question" + i + "_type", question.getType());
|
|
|
1474 |
|
|
|
1475 |
answers = answerDao.selectAllByQuestionUuid(question.getUuid());
|
|
|
1476 |
intent.putExtra("question" + i + "_answers", answers.size());
|
|
|
1477 |
|
|
|
1478 |
j = 1;
|
|
|
1479 |
for(Answer answer : answers) {
|
|
|
1480 |
intent.putExtra("question" + i + "_answer_uuid" + j, answer.getUuid());
|
|
|
1481 |
intent.putExtra("question" + i + "_answer_text" + j, answer.getText());
|
|
|
1482 |
intent.putExtra("question" + i + "_answer_points" + j, answer.getPoints());
|
|
|
1483 |
intent.putExtra("question" + i + "_answer_correct" + j, answer.getCorrect());
|
|
|
1484 |
j++;
|
|
|
1485 |
}
|
|
|
1486 |
|
|
|
1487 |
i++;
|
|
|
1488 |
}
|
|
|
1489 |
|
|
|
1490 |
|
|
|
1491 |
|
|
|
1492 |
//startActivityForResult(intent, Constants.REQUEST_CODE_QUIZ);
|
|
|
1493 |
|
|
|
1494 |
mLauncher.launch(intent);
|
|
|
1495 |
} else {
|
|
|
1496 |
showMessageSnackBar(getString(R.string.error_retry_quiz_min_time));
|
|
|
1497 |
}
|
|
|
1498 |
}
|
|
|
1499 |
|
|
|
1500 |
|
|
|
1501 |
@Override
|
|
|
1502 |
public Preference getPreference() {
|
|
|
1503 |
return preference;
|
|
|
1504 |
}
|
|
|
1505 |
|
|
|
1506 |
@Override
|
|
|
1507 |
public void reloadNavHeader() {
|
|
|
1508 |
Log.d(TAG, "User Image = " + preference.getImage());
|
|
|
1509 |
navHeaderUserName.setText((preference.getFirstName() + " " + preference.getLastName()).trim());
|
|
|
1510 |
navHeaderUserEmail.setText(preference.getEmail());
|
|
|
1511 |
|
|
|
1512 |
|
|
|
1513 |
|
|
|
1514 |
Log.d(TAG, preference.getImage());
|
|
|
1515 |
if(!TextUtils.isEmpty(preference.getImage())) {
|
|
|
1516 |
|
|
|
1517 |
TimeZone timeZone = TimeZone.getTimeZone("UTC");
|
|
|
1518 |
Calendar calendar = Calendar.getInstance(timeZone);
|
|
|
1519 |
TimeZone tz = calendar.getTimeZone();
|
|
|
1520 |
int created = (int) (calendar.getTimeInMillis() / 1000);
|
|
|
1521 |
|
|
|
1522 |
Random random = new Random(created);
|
|
|
1523 |
int rand = 1000 + random.nextInt(8999);
|
|
|
1524 |
|
|
|
1525 |
|
|
|
1526 |
|
|
|
1527 |
|
|
|
1528 |
Log.d(TAG, "token = " + preference.getDeviceUuid());
|
|
|
1529 |
Log.d(TAG, "created = " + created);
|
|
|
1530 |
Log.d(TAG, "rand = " + rand);
|
|
|
1531 |
Log.d(TAG, "calc = " + preference.getPassword() + ':' + created + ':' + rand);
|
|
|
1532 |
|
|
|
1533 |
String secret = MD5.generar(preference.getPassword() + ':' + created + ':' + rand);
|
|
|
1534 |
|
|
|
1535 |
GlideUrl url = new GlideUrl(preference.getImage(), new LazyHeaders.Builder()
|
|
|
1536 |
.addHeader(Constants.HTTP_HEADER_ACCEPT, Constants.HTTP_HEADER_ACCEPT_VALUE)
|
|
|
1537 |
.addHeader(Constants.HTTP_HEADER_SECURITY_TOKEN, preference.getDeviceUuid())
|
|
|
1538 |
.addHeader(Constants.HTTP_HEADER_SECURITY_SECRET, secret)
|
|
|
1539 |
.addHeader(Constants.HTTP_HEADER_SECURITY_CREATED, String.valueOf(created))
|
|
|
1540 |
.addHeader(Constants.HTTP_HEADER_SECURITY_RAND, String.valueOf(rand))
|
|
|
1541 |
.build());
|
|
|
1542 |
|
|
|
1543 |
RequestOptions options = new RequestOptions()
|
|
|
1544 |
.diskCacheStrategy(DiskCacheStrategy.ALL);
|
|
|
1545 |
|
26 |
gabriel |
1546 |
Glide.with(getApplicationContext()).load(url)
|
1 |
efrain |
1547 |
.thumbnail()
|
|
|
1548 |
.apply(options)
|
|
|
1549 |
.into(navHeaderUserImage);
|
|
|
1550 |
}
|
|
|
1551 |
}
|
|
|
1552 |
|
|
|
1553 |
public void requestCheckChanges()
|
|
|
1554 |
{
|
|
|
1555 |
Log.d(TAG, "requestCheckChanges");
|
|
|
1556 |
try {
|
|
|
1557 |
|
|
|
1558 |
CapsuleDao capsuleDao = mAppDatabase.getCapsuleDao();
|
|
|
1559 |
List<Capsule> capsules = capsuleDao.selectAll();
|
|
|
1560 |
|
|
|
1561 |
if(capsules.size() > 0) {
|
|
|
1562 |
//ArrayList<String> ids = new ArrayList<>();
|
|
|
1563 |
|
|
|
1564 |
TimeZone timeZone = TimeZone.getTimeZone("UTC");
|
|
|
1565 |
Calendar calendar = Calendar.getInstance(timeZone);
|
|
|
1566 |
TimeZone tz = calendar.getTimeZone();
|
|
|
1567 |
int created = (int) (calendar.getTimeInMillis() / 1000);
|
|
|
1568 |
|
|
|
1569 |
Random random = new Random(created);
|
|
|
1570 |
int rand = 1000 + random.nextInt(8999);
|
|
|
1571 |
|
|
|
1572 |
|
|
|
1573 |
//Log.d("requestCheckChanges", "token = " + preference.getDeviceUuid());
|
|
|
1574 |
//Log.d("requestCheckChanges", "created = " + created);
|
|
|
1575 |
// Log.d("requestCheckChanges", "rand = " + rand);
|
|
|
1576 |
//Log.d("requestCheckChanges", "calc = " + preference.password + ':' + created + ':' + rand);
|
|
|
1577 |
|
|
|
1578 |
String secret = MD5.generar(preference.getPassword() + ':' + created + ':' + rand);
|
|
|
1579 |
|
|
|
1580 |
//Log.d("requestCheckChanges", "secret = " + secret);
|
|
|
1581 |
|
|
|
1582 |
|
|
|
1583 |
FormBody.Builder formBodyCheckChangeBuilder = new FormBody.Builder();
|
|
|
1584 |
formBodyCheckChangeBuilder.add(Constants.POST_MICROLEARNING_CHECK_CHANGES_DEVICE_UUID, preference.getDeviceUuid());
|
|
|
1585 |
formBodyCheckChangeBuilder.add(Constants.POST_MICROLEARNING_CHECK_CHANGES_MAX_DATE_CHANGES, preference.getMaxDateChanges());
|
|
|
1586 |
formBodyCheckChangeBuilder.add(Constants.POST_MICROLEARNING_CHECK_CHANGES_IS_FOREGROUND, String.valueOf(isForeground ? 1 : 0));
|
|
|
1587 |
Http http = new Http(this.getCacheDir(), preference.getDeviceUuid(), secret, created, rand);
|
|
|
1588 |
OkHttpClient client = http.getHttpClient(false);
|
|
|
1589 |
|
|
|
1590 |
|
|
|
1591 |
|
|
|
1592 |
formBodyCheckChangeBuilder.add(Constants.POST_MICROLEARNING_CHECK_CHANGES_MAX_IDS, String.valueOf(capsules.size()));
|
|
|
1593 |
//formBodyCheckChangeBuilder.add(Constants.POST_MICROLEARNING_CHECK_CHANGES_MAX_IDS, String.valueOf(0));
|
|
|
1594 |
|
|
|
1595 |
int i = 1;
|
|
|
1596 |
for(Capsule capsule : capsules)
|
|
|
1597 |
{
|
|
|
1598 |
Log.d("requestCheckChanges", "id" + i + " = " + capsule.getTopicUuid() + "|" + capsule.getUuid());
|
|
|
1599 |
|
|
|
1600 |
|
|
|
1601 |
formBodyCheckChangeBuilder.add(Constants.POST_MICROLEARNING_CHECK_CHANGES_ID + i, capsule.getTopicUuid() + "|" + capsule.getUuid());
|
|
|
1602 |
i++;
|
|
|
1603 |
}
|
|
|
1604 |
|
|
|
1605 |
|
|
|
1606 |
|
|
|
1607 |
RequestBody formBody = formBodyCheckChangeBuilder.build();
|
|
|
1608 |
|
|
|
1609 |
Log.d(TAG, "URL = " + Configuration.URL_CHECK_CHANGES);
|
|
|
1610 |
Request request = new Request.Builder()
|
|
|
1611 |
.url(Configuration.URL_CHECK_CHANGES)
|
|
|
1612 |
.post(formBody)
|
|
|
1613 |
.build();
|
|
|
1614 |
|
|
|
1615 |
Call call = client.newCall(request);
|
|
|
1616 |
call.enqueue(new okhttp3.Callback() {
|
|
|
1617 |
public void onResponse(Call call, Response response)
|
|
|
1618 |
throws IOException {
|
|
|
1619 |
|
|
|
1620 |
|
|
|
1621 |
|
|
|
1622 |
processResponseServerChanges(response.body().string());
|
|
|
1623 |
}
|
|
|
1624 |
|
|
|
1625 |
public void onFailure(Call call, IOException e) {
|
|
|
1626 |
Log.d(TAG, "Error : " + e.getMessage());
|
|
|
1627 |
}
|
|
|
1628 |
});
|
|
|
1629 |
}
|
|
|
1630 |
|
|
|
1631 |
|
|
|
1632 |
|
|
|
1633 |
} catch(Exception e) {
|
|
|
1634 |
|
|
|
1635 |
}
|
|
|
1636 |
}
|
|
|
1637 |
|
|
|
1638 |
|
|
|
1639 |
public void syncFromServer(JSONObject data)
|
|
|
1640 |
{
|
|
|
1641 |
try {
|
|
|
1642 |
JSONObject objUser = data.getJSONObject("user");
|
|
|
1643 |
String userUuid = objUser.getString("uuid");
|
|
|
1644 |
|
|
|
1645 |
|
|
|
1646 |
AnswerDao answerDao = mAppDatabase.getAnswerDao();
|
|
|
1647 |
QuestionDao questionDao = mAppDatabase.getQuestionDao();
|
|
|
1648 |
QuizDao quizDao = mAppDatabase.getQuizDao();
|
|
|
1649 |
SlideDao slideDao = mAppDatabase.getSlideDao();
|
|
|
1650 |
CapsuleDao capsuleDao = mAppDatabase.getCapsuleDao();
|
|
|
1651 |
TopicDao topicDao = mAppDatabase.getTopicDao();
|
|
|
1652 |
CompanyDao companyDao = mAppDatabase.getCompanyDao();
|
|
|
1653 |
UserExtendedDao userExtendedDao = mAppDatabase.getUserExtendedDao();
|
|
|
1654 |
|
|
|
1655 |
|
|
|
1656 |
|
|
|
1657 |
ProgressDao progressDao = mAppDatabase.getProgressDao();
|
|
|
1658 |
progressDao.removeAllUserUuidNotEqual(userUuid);
|
|
|
1659 |
|
|
|
1660 |
|
|
|
1661 |
UserLogDao userLogDao = mAppDatabase.getUserLogDao();
|
|
|
1662 |
userLogDao.removeAllUserUuidNotEqual(userUuid);
|
|
|
1663 |
|
|
|
1664 |
JSONArray arrayCapsules;
|
|
|
1665 |
JSONArray arraySlides;
|
|
|
1666 |
JSONArray arrayAnswers;
|
|
|
1667 |
JSONArray arrayQuestions;
|
|
|
1668 |
JSONArray arrayProgress;
|
|
|
1669 |
JSONArray arrayQuizzes;
|
|
|
1670 |
JSONArray arrayUserLog;
|
|
|
1671 |
|
|
|
1672 |
JSONObject objTopic;
|
|
|
1673 |
JSONObject objCapsule;
|
|
|
1674 |
JSONObject objSlide;
|
|
|
1675 |
JSONObject objAnswer;
|
|
|
1676 |
JSONObject objQuestion;
|
|
|
1677 |
JSONObject objQuiz;
|
|
|
1678 |
JSONObject objProgress;
|
|
|
1679 |
JSONObject objUserLog;
|
|
|
1680 |
int i,j,x;
|
|
|
1681 |
|
|
|
1682 |
if(data.has("progress")) {
|
|
|
1683 |
|
|
|
1684 |
arrayProgress = data.getJSONArray("progress");
|
|
|
1685 |
for (i = 0; i < arrayProgress.length(); i++) {
|
|
|
1686 |
objProgress = arrayProgress.getJSONObject(i);
|
|
|
1687 |
|
|
|
1688 |
|
|
|
1689 |
Progress progress = null;
|
|
|
1690 |
|
|
|
1691 |
|
|
|
1692 |
userUuid = objProgress.getString("user_uuid");
|
|
|
1693 |
String type = objProgress.getString("type");
|
|
|
1694 |
String topicUuid = objProgress.getString("topic_uuid");
|
|
|
1695 |
String capsuleUuid = objProgress.getString("capsule_uuid");
|
|
|
1696 |
String slideUuid = objProgress.getString("slide_uuid");
|
|
|
1697 |
|
|
|
1698 |
if(type == Constants.PROGERSS_TYPE_SLIDE) {
|
|
|
1699 |
progress = progressDao.selectBySlideUuidAndUserUuid(slideUuid, userUuid);
|
|
|
1700 |
} else if(type == Constants.PROGERSS_TYPE_CAPSULE) {
|
|
|
1701 |
progress = progressDao.selectByCapsuleUuidAndUserUuid(capsuleUuid, userUuid);
|
|
|
1702 |
} else if(type == Constants.PROGERSS_TYPE_TOPIC) {
|
|
|
1703 |
progress = progressDao.selectByTopicUuidAndUserUuid(topicUuid, userUuid);
|
|
|
1704 |
}
|
|
|
1705 |
|
|
|
1706 |
|
|
|
1707 |
if(progress == null) {
|
|
|
1708 |
progress = new Progress();
|
|
|
1709 |
progress.setUserUuid(userUuid);
|
|
|
1710 |
progress.setCompanyUuid(objProgress.getString("company_uuid"));
|
|
|
1711 |
progress.setTopicUuid(topicUuid);
|
|
|
1712 |
progress.setCapsuleUuid(capsuleUuid);
|
|
|
1713 |
progress.setSlideUuid(slideUuid);
|
|
|
1714 |
progress.setProgress(objProgress.getDouble("progress"));
|
|
|
1715 |
progress.setTotalSlides(objProgress.getInt("total_slides"));
|
|
|
1716 |
progress.setViewSlides(objProgress.getInt("view_slides"));
|
|
|
1717 |
progress.setType(type);
|
|
|
1718 |
progress.setReturning(objProgress.getInt("returning"));
|
|
|
1719 |
progress.setReturningAfterCompleted(objProgress.getInt("returning_after_completed"));
|
|
|
1720 |
progress.setCompleted(objProgress.getInt("completed"));
|
|
|
1721 |
progress.setAddedOn(objProgress.getString("added_on"));
|
|
|
1722 |
progress.setUpdatedOn(objProgress.getString("updated_on"));
|
|
|
1723 |
|
|
|
1724 |
progressDao.insert(progress);
|
|
|
1725 |
}
|
|
|
1726 |
|
|
|
1727 |
|
|
|
1728 |
}
|
|
|
1729 |
}
|
|
|
1730 |
|
|
|
1731 |
if(data.has("userlog")) {
|
|
|
1732 |
arrayUserLog = data.getJSONArray("userlog");
|
|
|
1733 |
for (i = 0; i < arrayUserLog.length(); i++) {
|
|
|
1734 |
objUserLog = arrayUserLog.getJSONObject(i);
|
|
|
1735 |
|
|
|
1736 |
userUuid = objUserLog.getString("user_uuid");
|
|
|
1737 |
String activity = objUserLog.getString("activity");
|
|
|
1738 |
String added_on = objUserLog.getString("added_on");
|
|
|
1739 |
|
|
|
1740 |
UserLog userLog = userLogDao.selectOneByUserUuidAndActivityAndAddedOn(userUuid, activity, added_on);
|
|
|
1741 |
if(userLog == null) {
|
|
|
1742 |
userLog = new UserLog();
|
|
|
1743 |
userLog.setUserUuid(objUserLog.getString("user_uuid"));
|
|
|
1744 |
userLog.setCompanyUuid(objUserLog.getString("company_uuid"));
|
|
|
1745 |
userLog.setTopicUuid(objUserLog.getString("topic_uuid"));
|
|
|
1746 |
userLog.setCapsuleUuid(objUserLog.getString("capsule_uuid"));
|
|
|
1747 |
userLog.setSlideUuid(objUserLog.getString("slide_uuid"));
|
|
|
1748 |
userLog.setActivity(objUserLog.getString("activity"));
|
|
|
1749 |
userLog.setAddedOn(objUserLog.getString("added_on"));
|
|
|
1750 |
userLogDao.insert(userLog);
|
|
|
1751 |
}
|
|
|
1752 |
}
|
|
|
1753 |
}
|
|
|
1754 |
|
43 |
efrain |
1755 |
String uuid;
|
|
|
1756 |
Company company;
|
1 |
efrain |
1757 |
if(data.has("quizzes")) {
|
43 |
efrain |
1758 |
Quiz quiz;
|
|
|
1759 |
Question question;
|
|
|
1760 |
Answer answer;
|
|
|
1761 |
|
1 |
efrain |
1762 |
arrayQuizzes = data.getJSONArray("quizzes");
|
|
|
1763 |
for (i = 0; i < arrayQuizzes.length(); i++) {
|
|
|
1764 |
objQuiz = arrayQuizzes.getJSONObject(i);
|
|
|
1765 |
|
43 |
efrain |
1766 |
|
|
|
1767 |
uuid = objQuiz.getString("company_uuid");
|
|
|
1768 |
company = companyDao.selectByUuid(uuid);
|
1 |
efrain |
1769 |
if (company == null) {
|
|
|
1770 |
company = new Company();
|
|
|
1771 |
company.setUuid(objQuiz.getString("company_uuid"));
|
|
|
1772 |
company.setName(objQuiz.getString("company_name"));
|
|
|
1773 |
company.setImage(objQuiz.getString("company_image"));
|
|
|
1774 |
|
|
|
1775 |
companyDao.insert(company);
|
43 |
efrain |
1776 |
} else {
|
|
|
1777 |
company.setName(objQuiz.getString("company_name"));
|
|
|
1778 |
company.setImage(objQuiz.getString("company_image"));
|
|
|
1779 |
|
|
|
1780 |
companyDao.update(company);
|
1 |
efrain |
1781 |
}
|
|
|
1782 |
|
|
|
1783 |
|
43 |
efrain |
1784 |
uuid = objQuiz.getString("uuid");
|
|
|
1785 |
quiz = quizDao.selectByUuid(uuid);
|
|
|
1786 |
|
|
|
1787 |
if(quiz == null) {
|
|
|
1788 |
quiz = new Quiz();
|
|
|
1789 |
quiz.setUuid( objQuiz.getString("uuid"));
|
|
|
1790 |
quiz.setCompanyUuid( company.getUuid() );
|
|
|
1791 |
quiz.setFailed( objQuiz.getString("failed"));
|
|
|
1792 |
quiz.setName( objQuiz.getString("name"));
|
|
|
1793 |
quiz.setText( objQuiz.getString("text"));
|
|
|
1794 |
quiz.setPoints( objQuiz.getInt("points"));
|
|
|
1795 |
quiz.setMinimumPointsRequired(objQuiz.getInt("minimum_points_required"));
|
|
|
1796 |
quiz.setMaxTime( objQuiz.getInt("max_time"));
|
|
|
1797 |
quizDao.insert(quiz);
|
|
|
1798 |
|
|
|
1799 |
} else {
|
|
|
1800 |
quiz.setCompanyUuid( company.getUuid() );
|
|
|
1801 |
quiz.setFailed( objQuiz.getString("failed"));
|
|
|
1802 |
quiz.setName( objQuiz.getString("name"));
|
|
|
1803 |
quiz.setText( objQuiz.getString("text"));
|
|
|
1804 |
quiz.setPoints( objQuiz.getInt("points"));
|
|
|
1805 |
quiz.setMinimumPointsRequired(objQuiz.getInt("minimum_points_required"));
|
|
|
1806 |
quiz.setMaxTime( objQuiz.getInt("max_time"));
|
|
|
1807 |
quizDao.update(quiz);
|
|
|
1808 |
}
|
|
|
1809 |
|
1 |
efrain |
1810 |
arrayQuestions = objQuiz.getJSONArray("questions");
|
|
|
1811 |
for (j = 0; j < arrayQuestions.length(); j++) {
|
|
|
1812 |
objQuestion = arrayQuestions.getJSONObject(j);
|
|
|
1813 |
|
43 |
efrain |
1814 |
uuid = objQuestion.getString("uuid");
|
|
|
1815 |
question = questionDao.selectByUuid(uuid);
|
|
|
1816 |
if(question == null) {
|
|
|
1817 |
question = new Question();
|
|
|
1818 |
question.setQuizUuid( quiz.getUuid());
|
|
|
1819 |
question.setUuid(uuid) ;
|
|
|
1820 |
question.setText( objQuestion.getString("text"));
|
|
|
1821 |
question.setType( objQuestion.getString("type"));
|
|
|
1822 |
question.setPoints( objQuestion.getInt("points"));
|
|
|
1823 |
question.setMaxlength( objQuestion.getInt("maxlength"));
|
1 |
efrain |
1824 |
|
43 |
efrain |
1825 |
questionDao.insert(question);
|
|
|
1826 |
} else {
|
|
|
1827 |
question.setQuizUuid( quiz.getUuid());
|
|
|
1828 |
question.setText( objQuestion.getString("text"));
|
|
|
1829 |
question.setType( objQuestion.getString("type"));
|
|
|
1830 |
question.setPoints( objQuestion.getInt("points"));
|
|
|
1831 |
question.setMaxlength( objQuestion.getInt("maxlength"));
|
|
|
1832 |
|
|
|
1833 |
questionDao.update(question);
|
|
|
1834 |
}
|
|
|
1835 |
|
|
|
1836 |
|
|
|
1837 |
|
|
|
1838 |
|
1 |
efrain |
1839 |
arrayAnswers = objQuestion.getJSONArray("answers");
|
|
|
1840 |
for (x = 0; x < arrayAnswers.length(); x++) {
|
|
|
1841 |
objAnswer = arrayAnswers.getJSONObject(x);
|
|
|
1842 |
|
43 |
efrain |
1843 |
uuid = objAnswer.getString("uuid");
|
|
|
1844 |
answer = answerDao.selectByUuid(uuid);
|
1 |
efrain |
1845 |
|
43 |
efrain |
1846 |
if(answer == null) {
|
1 |
efrain |
1847 |
|
43 |
efrain |
1848 |
answer = new Answer();
|
|
|
1849 |
answer.setQuestionUuid(question.getUuid());
|
|
|
1850 |
answer.setUuid(uuid);
|
|
|
1851 |
answer.setText(objAnswer.getString("text"));
|
|
|
1852 |
answer.setPoints(objAnswer.getInt("points"));
|
|
|
1853 |
answer.setCorrect(objAnswer.getString("correct"));
|
|
|
1854 |
|
|
|
1855 |
answerDao.insert(answer);
|
|
|
1856 |
} else {
|
|
|
1857 |
answer.setQuestionUuid(question.getUuid());
|
|
|
1858 |
answer.setText(objAnswer.getString("text"));
|
|
|
1859 |
answer.setPoints(objAnswer.getInt("points"));
|
|
|
1860 |
answer.setCorrect(objAnswer.getString("correct"));
|
|
|
1861 |
answerDao.update(answer);
|
|
|
1862 |
}
|
|
|
1863 |
}
|
1 |
efrain |
1864 |
}
|
|
|
1865 |
}
|
|
|
1866 |
}
|
|
|
1867 |
|
|
|
1868 |
|
|
|
1869 |
|
|
|
1870 |
|
|
|
1871 |
|
|
|
1872 |
if(data.has("topics")) {
|
43 |
efrain |
1873 |
Topic topic;
|
|
|
1874 |
Capsule capsule;
|
|
|
1875 |
Slide slide;
|
1 |
efrain |
1876 |
|
|
|
1877 |
JSONArray arrayTopics = data.getJSONArray("topics");
|
|
|
1878 |
for (i = 0; i < arrayTopics.length(); i++) {
|
|
|
1879 |
objTopic = arrayTopics.getJSONObject(i);
|
|
|
1880 |
|
43 |
efrain |
1881 |
uuid = objTopic.getString("company_uuid");
|
|
|
1882 |
company = companyDao.selectByUuid(uuid);
|
1 |
efrain |
1883 |
if (company == null) {
|
|
|
1884 |
company = new Company();
|
|
|
1885 |
company.setUuid(objTopic.getString("company_uuid"));
|
|
|
1886 |
company.setName(objTopic.getString("company_name"));
|
|
|
1887 |
company.setImage(objTopic.getString("company_image"));
|
|
|
1888 |
|
|
|
1889 |
companyDao.insert(company);
|
43 |
efrain |
1890 |
} else {
|
|
|
1891 |
company.setName(objTopic.getString("company_name"));
|
|
|
1892 |
company.setImage(objTopic.getString("company_image"));
|
|
|
1893 |
|
|
|
1894 |
companyDao.update(company);
|
1 |
efrain |
1895 |
}
|
|
|
1896 |
|
43 |
efrain |
1897 |
uuid = objTopic.getString("uuid");
|
|
|
1898 |
topic = topicDao.selectByUuid(uuid);
|
1 |
efrain |
1899 |
|
43 |
efrain |
1900 |
if (topic == null) {
|
|
|
1901 |
topic = new Topic();
|
|
|
1902 |
topic.setUuid(uuid);
|
|
|
1903 |
topic.setCompanyUuid(company.getUuid());
|
|
|
1904 |
topic.setName(objTopic.getString("name"));
|
|
|
1905 |
topic.setDescription(objTopic.getString("description"));
|
|
|
1906 |
topic.setImage(objTopic.getString("image"));
|
|
|
1907 |
topic.setPosition(objTopic.getInt("position"));
|
|
|
1908 |
topicDao.insert(topic);
|
|
|
1909 |
} else {
|
|
|
1910 |
topic.setCompanyUuid(company.getUuid());
|
|
|
1911 |
topic.setName(objTopic.getString("name"));
|
|
|
1912 |
topic.setDescription(objTopic.getString("description"));
|
|
|
1913 |
topic.setImage(objTopic.getString("image"));
|
|
|
1914 |
topic.setPosition(objTopic.getInt("position"));
|
|
|
1915 |
topicDao.update(topic);
|
|
|
1916 |
}
|
|
|
1917 |
|
|
|
1918 |
|
|
|
1919 |
|
|
|
1920 |
|
|
|
1921 |
|
1 |
efrain |
1922 |
arrayCapsules = objTopic.getJSONArray("capsules");
|
|
|
1923 |
for (j = 0; j < arrayCapsules.length(); j++) {
|
|
|
1924 |
objCapsule = arrayCapsules.getJSONObject(j);
|
43 |
efrain |
1925 |
uuid = objCapsule.getString("uuid");
|
|
|
1926 |
capsule = capsuleDao.selectByUuid(uuid);
|
|
|
1927 |
if(capsule == null) {
|
|
|
1928 |
capsule = new Capsule();
|
|
|
1929 |
capsule.setTopicUuid(topic.getUuid());
|
|
|
1930 |
capsule.setUuid(uuid);
|
|
|
1931 |
capsule.setName(objCapsule.getString("name"));
|
|
|
1932 |
capsule.setDescription(objCapsule.getString("description"));
|
|
|
1933 |
capsule.setImage(objCapsule.getString("image"));
|
|
|
1934 |
capsule.setPosition(objCapsule.getInt("position"));
|
|
|
1935 |
capsuleDao.insert(capsule);
|
|
|
1936 |
} else {
|
|
|
1937 |
capsule = new Capsule();
|
|
|
1938 |
capsule.setTopicUuid(topic.getUuid());
|
|
|
1939 |
capsule.setName(objCapsule.getString("name"));
|
|
|
1940 |
capsule.setDescription(objCapsule.getString("description"));
|
|
|
1941 |
capsule.setImage(objCapsule.getString("image"));
|
|
|
1942 |
capsule.setPosition(objCapsule.getInt("position"));
|
|
|
1943 |
capsuleDao.update(capsule);
|
|
|
1944 |
}
|
1 |
efrain |
1945 |
|
43 |
efrain |
1946 |
|
|
|
1947 |
|
|
|
1948 |
|
1 |
efrain |
1949 |
arraySlides = objCapsule.getJSONArray("slides");
|
|
|
1950 |
for (x = 0; x < arraySlides.length(); x++) {
|
|
|
1951 |
objSlide = arraySlides.getJSONObject(x);
|
|
|
1952 |
|
43 |
efrain |
1953 |
uuid = objSlide.getString("uuid");
|
|
|
1954 |
slide = slideDao.selectByUuid(uuid);
|
|
|
1955 |
|
|
|
1956 |
if(slide == null) {
|
|
|
1957 |
|
|
|
1958 |
slide = new Slide();
|
|
|
1959 |
slide.setUuid(uuid);
|
|
|
1960 |
slide.setTopicUuid(capsule.getTopicUuid());
|
|
|
1961 |
slide.setCapsuleUuid(capsule.getUuid());
|
|
|
1962 |
slide.setQuizUuid(objSlide.getString("quiz_uuid"));
|
|
|
1963 |
slide.setName(objSlide.getString("name"));
|
|
|
1964 |
slide.setDescription(objSlide.getString("description"));
|
|
|
1965 |
slide.setPosition(objSlide.getInt("position"));
|
|
|
1966 |
slide.setType(objSlide.getString("type"));
|
|
|
1967 |
slide.setFile(objSlide.getString("file"));
|
|
|
1968 |
slide.setBackground(objSlide.getString("background"));
|
|
|
1969 |
|
|
|
1970 |
slideDao.insert(slide);
|
|
|
1971 |
} else {
|
|
|
1972 |
slide.setTopicUuid(capsule.getTopicUuid());
|
|
|
1973 |
slide.setCapsuleUuid(capsule.getUuid());
|
|
|
1974 |
slide.setQuizUuid(objSlide.getString("quiz_uuid"));
|
|
|
1975 |
slide.setName(objSlide.getString("name"));
|
|
|
1976 |
slide.setDescription(objSlide.getString("description"));
|
|
|
1977 |
slide.setPosition(objSlide.getInt("position"));
|
|
|
1978 |
slide.setType(objSlide.getString("type"));
|
|
|
1979 |
slide.setFile(objSlide.getString("file"));
|
|
|
1980 |
slide.setBackground(objSlide.getString("background"));
|
|
|
1981 |
|
|
|
1982 |
slideDao.update(slide);
|
|
|
1983 |
}
|
1 |
efrain |
1984 |
}
|
|
|
1985 |
|
|
|
1986 |
}
|
|
|
1987 |
|
|
|
1988 |
|
|
|
1989 |
}
|
|
|
1990 |
}
|
|
|
1991 |
|
43 |
efrain |
1992 |
if(data.has( "extended")) {
|
1 |
efrain |
1993 |
|
43 |
efrain |
1994 |
JSONObject objExtended;
|
|
|
1995 |
JSONObject objItem;
|
|
|
1996 |
JSONArray objItems;
|
|
|
1997 |
|
|
|
1998 |
|
|
|
1999 |
|
|
|
2000 |
UserExtended userExtended;
|
|
|
2001 |
|
|
|
2002 |
JSONArray extendedCompanies = data.getJSONArray("extended");
|
|
|
2003 |
for(i = 0 ; i < extendedCompanies.length(); i++)
|
|
|
2004 |
{
|
|
|
2005 |
objExtended = extendedCompanies.getJSONObject(i);
|
|
|
2006 |
if(objExtended.has("details")) {
|
|
|
2007 |
uuid = objExtended.getString("company_uuid");
|
|
|
2008 |
|
|
|
2009 |
|
|
|
2010 |
company = companyDao.selectByUuid(uuid);
|
|
|
2011 |
if (company == null) {
|
|
|
2012 |
company = new Company();
|
|
|
2013 |
company.setUuid(objExtended.getString("company_uuid"));
|
|
|
2014 |
company.setName(objExtended.getString("company_name"));
|
|
|
2015 |
company.setImage(objExtended.getString("company_image"));
|
|
|
2016 |
|
|
|
2017 |
companyDao.insert(company);
|
|
|
2018 |
} else {
|
|
|
2019 |
company.setName(objExtended.getString("company_name"));
|
|
|
2020 |
company.setImage(objExtended.getString("company_image"));
|
|
|
2021 |
|
|
|
2022 |
companyDao.update(company);
|
|
|
2023 |
}
|
|
|
2024 |
|
|
|
2025 |
objItems = objExtended.getJSONArray("details");
|
|
|
2026 |
for(j = 0 ; j < objItems.length(); j++) {
|
|
|
2027 |
objItem = objItems.getJSONObject(j);
|
|
|
2028 |
|
|
|
2029 |
uuid = objItem.getString("uuid");
|
|
|
2030 |
|
|
|
2031 |
userExtended = userExtendedDao.selectByUuid(uuid);
|
|
|
2032 |
if(userExtended == null) {
|
|
|
2033 |
userExtended = new UserExtended();
|
|
|
2034 |
userExtended.setCompanyUuid(company.getUuid());
|
|
|
2035 |
userExtended.setUuid(uuid);
|
|
|
2036 |
userExtended.setLabel(objItem.getString("label"));
|
|
|
2037 |
userExtended.setValue(objItem.getString("value"));
|
|
|
2038 |
userExtendedDao.insert(userExtended);
|
|
|
2039 |
} else {
|
|
|
2040 |
userExtended.setCompanyUuid(company.getUuid());
|
|
|
2041 |
userExtended.setLabel(objItem.getString("label"));
|
|
|
2042 |
userExtended.setValue(objItem.getString("value"));
|
|
|
2043 |
userExtendedDao.update(userExtended);
|
|
|
2044 |
}
|
|
|
2045 |
|
|
|
2046 |
|
|
|
2047 |
|
|
|
2048 |
|
|
|
2049 |
}
|
|
|
2050 |
}
|
|
|
2051 |
}
|
|
|
2052 |
|
|
|
2053 |
}
|
|
|
2054 |
|
|
|
2055 |
|
1 |
efrain |
2056 |
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(Constants.FORMAT_DATETIME_SERVICE);
|
|
|
2057 |
if(data.has("max_date_changes")) {
|
|
|
2058 |
String max_date_changes = data.getString("max_date_changes");
|
|
|
2059 |
Log.d("syncFromServer", "max_date_changes : " + max_date_changes);
|
|
|
2060 |
|
|
|
2061 |
if(!TextUtils.isEmpty(max_date_changes)) {
|
|
|
2062 |
preference.setMaxDateChanges(max_date_changes);
|
|
|
2063 |
}
|
|
|
2064 |
} else {
|
|
|
2065 |
Log.d("syncFromServer", "No max_date_changes");
|
|
|
2066 |
}
|
|
|
2067 |
|
|
|
2068 |
Calendar calendar = Calendar.getInstance();
|
|
|
2069 |
Date date = calendar.getTime();
|
|
|
2070 |
|
|
|
2071 |
String addedOn = simpleDateFormat.format(date);
|
|
|
2072 |
|
|
|
2073 |
List<Company> companies = mAppDatabase.getCompanyDao().selectAll();
|
|
|
2074 |
int companySize = companies.size();
|
|
|
2075 |
|
|
|
2076 |
if(companySize > 0) {
|
|
|
2077 |
|
|
|
2078 |
if(TextUtils.isEmpty(preference.getCompanyUuidActive())) {
|
|
|
2079 |
|
|
|
2080 |
preference.setCompanyUuidActive(companies.get(0).getUuid());
|
|
|
2081 |
|
|
|
2082 |
} else {
|
|
|
2083 |
|
|
|
2084 |
boolean companyExist = false;
|
43 |
efrain |
2085 |
for(i = 0; i < companies.size(); i++) {
|
|
|
2086 |
|
|
|
2087 |
if (companies.get(i).getUuid().equals(preference.getCompanyUuidActive())) {
|
1 |
efrain |
2088 |
companyExist = true;
|
43 |
efrain |
2089 |
break;
|
1 |
efrain |
2090 |
}
|
|
|
2091 |
}
|
|
|
2092 |
|
43 |
efrain |
2093 |
if(!companyExist && companies.size() > 0) {
|
1 |
efrain |
2094 |
preference.setCompanyUuidActive(companies.get(0).getUuid());
|
|
|
2095 |
}
|
|
|
2096 |
}
|
|
|
2097 |
|
|
|
2098 |
} else {
|
|
|
2099 |
preference.setCompanyUuidActive("");
|
|
|
2100 |
}
|
|
|
2101 |
|
|
|
2102 |
|
|
|
2103 |
|
|
|
2104 |
preference.setLastDataRefresh(addedOn);
|
|
|
2105 |
preference.setCompanyCount(companySize);
|
29 |
efrain |
2106 |
preference.save();
|
1 |
efrain |
2107 |
|
|
|
2108 |
} catch (JSONException e) {
|
|
|
2109 |
Log.d(TAG, e.getMessage());
|
|
|
2110 |
}
|
|
|
2111 |
}
|
|
|
2112 |
|
|
|
2113 |
@Override
|
|
|
2114 |
public void requestExecuteSyncAdapter() {
|
|
|
2115 |
// Pass the settings flags by inserting them in a bundle
|
|
|
2116 |
Bundle settingsBundle = new Bundle();
|
|
|
2117 |
settingsBundle.putBoolean(
|
|
|
2118 |
ContentResolver.SYNC_EXTRAS_MANUAL, true);
|
|
|
2119 |
settingsBundle.putBoolean(
|
|
|
2120 |
ContentResolver.SYNC_EXTRAS_EXPEDITED, true);
|
|
|
2121 |
|
|
|
2122 |
ContentResolver.requestSync(mAccount, Constants.AUTHORITY, settingsBundle);
|
|
|
2123 |
}
|
|
|
2124 |
|
|
|
2125 |
|
|
|
2126 |
private void processResponseServerChanges(String dataString)
|
|
|
2127 |
{
|
|
|
2128 |
|
|
|
2129 |
Log.d(TAG, "processResponseServerChanges = " + dataString);
|
|
|
2130 |
|
|
|
2131 |
try {
|
|
|
2132 |
JSONObject objJSON = new JSONObject(dataString);
|
|
|
2133 |
boolean success = objJSON.has("success") ? objJSON.getBoolean("success") : false;
|
|
|
2134 |
|
|
|
2135 |
|
|
|
2136 |
if(success) {
|
|
|
2137 |
Calendar calendar = Calendar.getInstance();
|
|
|
2138 |
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(Constants.FORMAT_DATETIME_SERVICE);
|
|
|
2139 |
preference.setLastDataRefresh(simpleDateFormat.format(calendar.getTime()));
|
29 |
efrain |
2140 |
preference.save();
|
1 |
efrain |
2141 |
|
|
|
2142 |
String max_date_changes = "";
|
|
|
2143 |
boolean processChanges = false;
|
|
|
2144 |
|
|
|
2145 |
JSONObject data = objJSON.getJSONObject("data");
|
|
|
2146 |
if(data.has("max_date_changes") && data.has("new_capsules")) {
|
|
|
2147 |
int new_capsules = data.getInt("new_capsules");
|
|
|
2148 |
max_date_changes = data.getString("max_date_changes");
|
|
|
2149 |
|
|
|
2150 |
|
|
|
2151 |
|
|
|
2152 |
|
|
|
2153 |
processChanges = new_capsules > 0 && !max_date_changes.equals(preference.getMaxDateChanges());
|
|
|
2154 |
} else {
|
|
|
2155 |
processChanges = false;
|
|
|
2156 |
}
|
|
|
2157 |
|
|
|
2158 |
if(processChanges && !max_date_changes.isEmpty()) {
|
|
|
2159 |
int new_capsules = data.getInt("new_capsules");
|
|
|
2160 |
String message = new_capsules == 1
|
|
|
2161 |
? "Hay 1 cápsula nueva disponible"
|
|
|
2162 |
: "Hay " + new_capsules + " cápsulas disponible";
|
|
|
2163 |
|
|
|
2164 |
|
|
|
2165 |
showMessageSnackBarWithClose(message);
|
|
|
2166 |
|
|
|
2167 |
|
|
|
2168 |
preference.setMaxDateChanges(max_date_changes);
|
|
|
2169 |
|
|
|
2170 |
if(!isForeground) {
|
|
|
2171 |
String body = new_capsules == 1
|
|
|
2172 |
? "Hay 1 cápsula nueva disponible"
|
|
|
2173 |
: "Hay " + new_capsules + " cápsulas disponible";
|
|
|
2174 |
showFcmNotification("Nuevo contenido", body, new_capsules);
|
|
|
2175 |
}
|
|
|
2176 |
|
|
|
2177 |
/*
|
|
|
2178 |
if(!isForeground) {
|
|
|
2179 |
String body = new_capsules == 1
|
|
|
2180 |
? "Hay 1 cápsula nueva disponible"
|
|
|
2181 |
: "Hay " + new_capsules + " cápsulas disponible";
|
|
|
2182 |
showFcmNotification("Nuevo contenido", body, new_capsules);
|
|
|
2183 |
|
|
|
2184 |
|
|
|
2185 |
AnswerDao answerDao = mAppDatabase.getAnswerDao();
|
|
|
2186 |
answerDao.removeAll();
|
|
|
2187 |
|
|
|
2188 |
QuestionDao questionDao = mAppDatabase.getQuestionDao();
|
|
|
2189 |
questionDao.removeAll();
|
|
|
2190 |
|
|
|
2191 |
QuizDao quizDao = mAppDatabase.getQuizDao();
|
|
|
2192 |
quizDao.removeAll();
|
|
|
2193 |
|
|
|
2194 |
SlideDao slideDao = mAppDatabase.getSlideDao();
|
|
|
2195 |
slideDao.removeAll();
|
|
|
2196 |
|
|
|
2197 |
CapsuleDao capsuleDao = mAppDatabase.getCapsuleDao();
|
|
|
2198 |
capsuleDao.removeAll();
|
|
|
2199 |
|
|
|
2200 |
TopicDao topicDao = mAppDatabase.getTopicDao();
|
|
|
2201 |
topicDao.removeAll();
|
|
|
2202 |
|
|
|
2203 |
CompanyDao companyDao = mAppDatabase.getCompanyDao();
|
|
|
2204 |
companyDao.removeAll();
|
|
|
2205 |
|
|
|
2206 |
UserExtendedDao userExtendedDao = mAppDatabase.getUserExtendedDao();
|
|
|
2207 |
userExtendedDao.removeAll();
|
|
|
2208 |
|
|
|
2209 |
|
|
|
2210 |
this.syncFromServer(data);
|
|
|
2211 |
|
|
|
2212 |
|
|
|
2213 |
if(!TextUtils.isEmpty(preference.getSlideUuidActive())) {
|
|
|
2214 |
|
|
|
2215 |
Slide slide = mAppDatabase.getSlideDao().selectByUuid(preference.getSlideUuidActive());
|
|
|
2216 |
if(slide == null) {
|
|
|
2217 |
preference.setFragmentIdxActive(Constants.IDX_FRAGMENT_TOPICS);
|
|
|
2218 |
preference.save(this);
|
|
|
2219 |
}
|
|
|
2220 |
|
|
|
2221 |
}
|
|
|
2222 |
}*/
|
|
|
2223 |
}
|
|
|
2224 |
}
|
|
|
2225 |
} catch (JSONException e) {
|
|
|
2226 |
Log.d(TAG, e.getMessage());
|
|
|
2227 |
}
|
|
|
2228 |
}
|
|
|
2229 |
|
|
|
2230 |
@Override
|
|
|
2231 |
public AppDatabase getDatabase() {
|
|
|
2232 |
return mAppDatabase;
|
|
|
2233 |
}
|
|
|
2234 |
|
|
|
2235 |
@Override
|
|
|
2236 |
public void syncToServerOrCheckChanges()
|
|
|
2237 |
{
|
|
|
2238 |
if(TextUtils.isEmpty(preference.getDeviceUuid())) {
|
|
|
2239 |
return;
|
|
|
2240 |
}
|
|
|
2241 |
|
|
|
2242 |
SyncDao syncDao = mAppDatabase.getSyncDao();
|
|
|
2243 |
List<Sync> records = syncDao.selectBatch();
|
|
|
2244 |
|
|
|
2245 |
if(records.size() > 0) {
|
|
|
2246 |
syncToServer(records);
|
|
|
2247 |
} else {
|
|
|
2248 |
|
|
|
2249 |
long timeLast = 0;
|
|
|
2250 |
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(Constants.FORMAT_DATETIME_SERVICE);
|
|
|
2251 |
if (!TextUtils.isEmpty(preference.getLastDataRefresh())) {
|
|
|
2252 |
try {
|
|
|
2253 |
timeLast = simpleDateFormat.parse(preference.getLastDataRefresh()).getTime();
|
|
|
2254 |
} catch (Exception e) {
|
|
|
2255 |
|
|
|
2256 |
}
|
|
|
2257 |
|
|
|
2258 |
}
|
|
|
2259 |
|
|
|
2260 |
|
|
|
2261 |
Calendar calendar = Calendar.getInstance();
|
|
|
2262 |
long timeNow = calendar.getTime().getTime();
|
|
|
2263 |
if (timeNow > (timeLast + Constants.CHECK_CHANGES_INTERVAL)) {
|
|
|
2264 |
requestCheckChanges();
|
|
|
2265 |
}
|
|
|
2266 |
}
|
|
|
2267 |
}
|
|
|
2268 |
|
|
|
2269 |
|
|
|
2270 |
|
|
|
2271 |
public void syncToServer(List<Sync> records)
|
|
|
2272 |
{
|
|
|
2273 |
|
|
|
2274 |
|
|
|
2275 |
|
|
|
2276 |
int maxRecordsSyncBatch = 0;
|
|
|
2277 |
FormBody.Builder formBodyBatchBuilder = new FormBody.Builder();
|
|
|
2278 |
formBodyBatchBuilder.add(Constants.POST_SYNC_BATCH_FIELD_DEVICE_UUID, preference.getDeviceUuid());
|
|
|
2279 |
|
|
|
2280 |
for(Sync record : records)
|
|
|
2281 |
{
|
|
|
2282 |
Log.d(TAG, "SyncRecord ID = " + record.getId() + " Data : " + record.getData() + " Type= " + record.getType());
|
|
|
2283 |
|
|
|
2284 |
if(record.getType() == Constants.SYNC_ADAPTER_TYPE_DEVICE && !isSyncDevice) {
|
|
|
2285 |
Log.d(TAG, "Device");
|
|
|
2286 |
isSyncDevice = true;
|
|
|
2287 |
|
|
|
2288 |
try {
|
|
|
2289 |
Http http = new Http(this.getCacheDir());
|
|
|
2290 |
OkHttpClient client = http.getHttpClient(false);
|
|
|
2291 |
|
|
|
2292 |
RequestBody formBody = new FormBody.Builder()
|
|
|
2293 |
.add(Constants.POST_DEVICE_FIELD_APPLICATION_ID, String.valueOf(Configuration.APPLICATION_ID))
|
|
|
2294 |
.add(Constants.POST_DEVICE_FIELD_DEVICE_UUID, preference.getDeviceUuid())
|
|
|
2295 |
.add(Constants.POST_DEVICE_FIELD_MANUFACTURER, Build.MANUFACTURER)
|
|
|
2296 |
.add(Constants.POST_DEVICE_FIELD_BRAND, Build.BRAND)
|
|
|
2297 |
.add(Constants.POST_DEVICE_FIELD_VERSION, Build.VERSION.RELEASE + " " + Build.VERSION_CODES.class.getFields()[android.os.Build.VERSION.SDK_INT].getName())
|
|
|
2298 |
.add(Constants.POST_DEVICE_FIELD_MODEL, Build.MODEL)
|
|
|
2299 |
.add(Constants.POST_DEVICE_FIELD_PLATFORM, "android")
|
|
|
2300 |
.add(Constants.POST_DEVICE_FIELD_SYNC_ID, String.valueOf(record.getId()))
|
|
|
2301 |
.build();
|
|
|
2302 |
|
|
|
2303 |
Log.d(TAG, "URL = " + Configuration.URL_DEVICE);
|
|
|
2304 |
Request request = new Request.Builder()
|
|
|
2305 |
.url(Configuration.URL_DEVICE)
|
|
|
2306 |
.post(formBody)
|
|
|
2307 |
.build();
|
|
|
2308 |
|
|
|
2309 |
Call call = client.newCall(request);
|
|
|
2310 |
call.enqueue(new okhttp3.Callback() {
|
|
|
2311 |
public void onResponse(Call call, Response response)
|
|
|
2312 |
throws IOException {
|
|
|
2313 |
isSyncDevice = false;
|
|
|
2314 |
Log.d(TAG, "Response Device : " + response.body().toString());
|
|
|
2315 |
|
|
|
2316 |
processResponseSyncToServer(response.body().string());
|
|
|
2317 |
}
|
|
|
2318 |
|
|
|
2319 |
public void onFailure(Call call, IOException e) {
|
|
|
2320 |
isSyncDevice = false;
|
|
|
2321 |
Log.d(TAG, "Error : " + e.getMessage());
|
|
|
2322 |
}
|
|
|
2323 |
});
|
|
|
2324 |
} catch (Exception e) {
|
|
|
2325 |
}
|
|
|
2326 |
}
|
|
|
2327 |
|
|
|
2328 |
if(record.getType() == Constants.SYNC_ADAPTER_TYPE_FCM && !isSyncToken) {
|
|
|
2329 |
isSyncToken = true;
|
|
|
2330 |
Log.d(TAG, "FCM");
|
|
|
2331 |
|
|
|
2332 |
try {
|
|
|
2333 |
Http http = new Http(this.getCacheDir());
|
|
|
2334 |
OkHttpClient client = http.getHttpClient(false);
|
|
|
2335 |
|
|
|
2336 |
RequestBody formBody = new FormBody.Builder()
|
|
|
2337 |
.add(Constants.POST_FCM_FIELD_DEVICE_UUID,preference.getDeviceUuid())
|
|
|
2338 |
.add(Constants.POST_FCM_FIELD_TOKEN, record.getData())
|
|
|
2339 |
.add(Constants.POST_FCM_FIELD_SYNC_ID, String.valueOf(record.getId()))
|
|
|
2340 |
.build();
|
|
|
2341 |
|
|
|
2342 |
Log.d(TAG, "URL = " + Configuration.URL_FCM);
|
|
|
2343 |
Request request = new Request.Builder()
|
|
|
2344 |
.url(Configuration.URL_FCM)
|
|
|
2345 |
.post(formBody)
|
|
|
2346 |
.build();
|
|
|
2347 |
|
|
|
2348 |
Call call = client.newCall(request);
|
|
|
2349 |
call.enqueue(new okhttp3.Callback() {
|
|
|
2350 |
public void onResponse(Call call, Response response)
|
|
|
2351 |
throws IOException {
|
|
|
2352 |
isSyncToken = false;
|
|
|
2353 |
processResponseSyncToServer(response.body().string());
|
|
|
2354 |
}
|
|
|
2355 |
|
|
|
2356 |
public void onFailure(Call call, IOException e) {
|
|
|
2357 |
Log.d(TAG, "Error : " + e.getMessage());
|
|
|
2358 |
isSyncToken = false;
|
|
|
2359 |
}
|
|
|
2360 |
});
|
|
|
2361 |
} catch (Exception e) {
|
|
|
2362 |
|
|
|
2363 |
|
|
|
2364 |
}
|
|
|
2365 |
}
|
|
|
2366 |
|
|
|
2367 |
if(record.getType() == Constants.SYNC_ADAPTER_TYPE_SYNC ) {
|
|
|
2368 |
Log.d(TAG, "SYNC BATCH");
|
|
|
2369 |
maxRecordsSyncBatch++;
|
|
|
2370 |
formBodyBatchBuilder.add(Constants.POST_SYNC_BATCH_FIELD_RECORD_DATA + maxRecordsSyncBatch, record.getData());
|
|
|
2371 |
formBodyBatchBuilder.add(Constants.POST_SYNC_BATCH_FIELD_RECORD_SYNC_ID + maxRecordsSyncBatch, String.valueOf(record.getId()));
|
|
|
2372 |
}
|
|
|
2373 |
}
|
|
|
2374 |
|
|
|
2375 |
|
|
|
2376 |
if(maxRecordsSyncBatch > 0 && !isSyncBatch) {
|
|
|
2377 |
Log.d(TAG, "Sync Batch");
|
|
|
2378 |
isSyncBatch = true;
|
|
|
2379 |
|
|
|
2380 |
try {
|
|
|
2381 |
Http http = new Http(this.getCacheDir());
|
|
|
2382 |
OkHttpClient client = http.getHttpClient(false);
|
|
|
2383 |
|
|
|
2384 |
formBodyBatchBuilder.add(Constants.POST_SYNC_BATCH_FIELD_MAX_RECORDS, String.valueOf(maxRecordsSyncBatch));
|
|
|
2385 |
RequestBody formBody = formBodyBatchBuilder.build();
|
|
|
2386 |
|
|
|
2387 |
Log.d(TAG, "URL = " + Configuration.URL_SYNC_BATCH);
|
|
|
2388 |
Request request = new Request.Builder()
|
|
|
2389 |
.url(Configuration.URL_SYNC_BATCH)
|
|
|
2390 |
.post(formBody)
|
|
|
2391 |
.build();
|
|
|
2392 |
|
|
|
2393 |
Call call = client.newCall(request);
|
|
|
2394 |
call.enqueue(new okhttp3.Callback() {
|
|
|
2395 |
public void onResponse(Call call, Response response) throws IOException {
|
|
|
2396 |
isSyncBatch = false;
|
|
|
2397 |
processResponseServerBatch(response.body().string());
|
|
|
2398 |
}
|
|
|
2399 |
|
|
|
2400 |
public void onFailure(Call call, IOException e) {
|
|
|
2401 |
Log.d(TAG, "Error : " + e.getMessage());
|
|
|
2402 |
isSyncBatch = false;
|
|
|
2403 |
}
|
|
|
2404 |
});
|
|
|
2405 |
} catch (Exception e) {
|
|
|
2406 |
|
|
|
2407 |
|
|
|
2408 |
}
|
|
|
2409 |
}
|
|
|
2410 |
|
|
|
2411 |
|
|
|
2412 |
}
|
|
|
2413 |
|
|
|
2414 |
private void processResponseServerBatch(String dataString)
|
|
|
2415 |
{
|
|
|
2416 |
boolean success = false;
|
|
|
2417 |
long sync_id = 0;
|
|
|
2418 |
|
|
|
2419 |
Log.d(TAG, "processResponseServer = " + dataString);
|
|
|
2420 |
try {
|
|
|
2421 |
JSONObject objJSON = new JSONObject(dataString);
|
|
|
2422 |
success = objJSON.has("success") ? objJSON.getBoolean("success") : false;
|
|
|
2423 |
if(success && objJSON.has("data")) {
|
|
|
2424 |
JSONArray jsonArrayData = objJSON.getJSONArray("data");
|
|
|
2425 |
|
|
|
2426 |
|
|
|
2427 |
JSONObject jsonObjectData;
|
|
|
2428 |
int max = jsonArrayData.length();
|
|
|
2429 |
for(int i = 0; i < max; i++) {
|
|
|
2430 |
jsonObjectData = jsonArrayData.getJSONObject(i);
|
|
|
2431 |
|
|
|
2432 |
if(jsonObjectData.has("success") && jsonObjectData.getBoolean("success")) {
|
|
|
2433 |
sync_id = jsonObjectData.getLong("sync_id");
|
|
|
2434 |
|
|
|
2435 |
mAppDatabase.getSyncDao().remove(sync_id);
|
|
|
2436 |
|
|
|
2437 |
}
|
|
|
2438 |
|
|
|
2439 |
|
|
|
2440 |
}
|
|
|
2441 |
|
|
|
2442 |
|
|
|
2443 |
|
|
|
2444 |
/*
|
|
|
2445 |
if(jsonObjectData.has("message")) {
|
|
|
2446 |
message = jsonObjectData.getString("message");
|
|
|
2447 |
}
|
|
|
2448 |
|
|
|
2449 |
if(jsonObjectData.has("aes")) {
|
|
|
2450 |
preference.setAes(jsonObjectData.getString("aes"));
|
|
|
2451 |
preference.save(this);
|
|
|
2452 |
}
|
|
|
2453 |
|
|
|
2454 |
if(jsonObjectData.has("password")) {
|
|
|
2455 |
preference.setPassword(jsonObjectData.getString("password"));
|
|
|
2456 |
preference.save(this);
|
|
|
2457 |
}
|
|
|
2458 |
*/
|
|
|
2459 |
}
|
|
|
2460 |
Log.d(TAG, "SyncID = " + sync_id);
|
|
|
2461 |
if(success && sync_id > 0) {
|
|
|
2462 |
Log.d(TAG, "DELETE SYNC RECORD : " + sync_id);
|
|
|
2463 |
mAppDatabase.getSyncDao().remove(sync_id);
|
|
|
2464 |
}
|
|
|
2465 |
} catch (JSONException e) {
|
|
|
2466 |
e.printStackTrace();
|
|
|
2467 |
}
|
|
|
2468 |
}
|
|
|
2469 |
|
|
|
2470 |
private void processResponseSyncToServer(String dataString)
|
|
|
2471 |
{
|
|
|
2472 |
boolean success = false;
|
|
|
2473 |
long sync_id = 0;
|
|
|
2474 |
|
|
|
2475 |
Log.d(TAG, "processResponseServer = " + dataString);
|
|
|
2476 |
try {
|
|
|
2477 |
JSONObject objJSON = new JSONObject(dataString);
|
|
|
2478 |
success = objJSON.has("success") ? objJSON.getBoolean("success") : false;
|
|
|
2479 |
if(success && objJSON.has("data")) {
|
|
|
2480 |
JSONObject jsonObjectData = objJSON.getJSONObject("data");
|
|
|
2481 |
|
|
|
2482 |
if(jsonObjectData.has("sync_id")) {
|
|
|
2483 |
sync_id = jsonObjectData.getLong("sync_id");
|
|
|
2484 |
}
|
|
|
2485 |
|
|
|
2486 |
/*
|
|
|
2487 |
if(jsonObjectData.has("message")) {
|
|
|
2488 |
message = jsonObjectData.getString("message");
|
|
|
2489 |
}
|
|
|
2490 |
|
|
|
2491 |
if(jsonObjectData.has("aes")) {
|
|
|
2492 |
preference.setAes(jsonObjectData.getString("aes"));
|
|
|
2493 |
preference.save(this);
|
|
|
2494 |
}
|
|
|
2495 |
|
|
|
2496 |
if(jsonObjectData.has("password")) {
|
|
|
2497 |
preference.setPassword(jsonObjectData.getString("password"));
|
|
|
2498 |
preference.save(this);
|
|
|
2499 |
}
|
|
|
2500 |
*/
|
|
|
2501 |
}
|
|
|
2502 |
Log.d(TAG, "SyncID = " + sync_id);
|
|
|
2503 |
if(success && sync_id > 0) {
|
|
|
2504 |
Log.d(TAG, "DELETE SYNC RECORD : " + sync_id);
|
|
|
2505 |
mAppDatabase.getSyncDao().remove(sync_id);
|
|
|
2506 |
}
|
|
|
2507 |
} catch (JSONException e) {
|
|
|
2508 |
e.printStackTrace();
|
|
|
2509 |
}
|
|
|
2510 |
}
|
|
|
2511 |
|
|
|
2512 |
/*
|
|
|
2513 |
private void processResponseServerCheckChanges(String dataString) {
|
|
|
2514 |
|
|
|
2515 |
Log.d(TAG, "processResponseServerCheckChanges = " + dataString);
|
|
|
2516 |
|
|
|
2517 |
runOnUiThread(new Runnable() {
|
|
|
2518 |
|
|
|
2519 |
@Override
|
|
|
2520 |
public void run() {
|
|
|
2521 |
|
|
|
2522 |
try {
|
|
|
2523 |
JSONObject objJSON = new JSONObject(dataString);
|
|
|
2524 |
boolean success = objJSON.has("success") ? objJSON.getBoolean("success") : false;
|
|
|
2525 |
String message = "";
|
|
|
2526 |
if (objJSON.has("data")) {
|
|
|
2527 |
Object item = objJSON.get("data");
|
|
|
2528 |
if (item instanceof String) {
|
|
|
2529 |
message = item.toString();
|
|
|
2530 |
}
|
|
|
2531 |
}
|
|
|
2532 |
|
|
|
2533 |
if (success) {
|
|
|
2534 |
mAppDatabase.getAnswerDao().removeAll();
|
|
|
2535 |
mAppDatabase.getQuestionDao().removeAll();
|
|
|
2536 |
mAppDatabase.getQuizDao().removeAll();
|
|
|
2537 |
mAppDatabase.getSlideDao().removeAll();
|
|
|
2538 |
mAppDatabase.getCapsuleDao().removeAll();
|
|
|
2539 |
mAppDatabase.getTopicDao().removeAll();
|
|
|
2540 |
|
|
|
2541 |
|
|
|
2542 |
JSONObject data = objJSON.getJSONObject("data");
|
|
|
2543 |
syncFromServer(data);
|
|
|
2544 |
|
|
|
2545 |
|
|
|
2546 |
}
|
|
|
2547 |
|
|
|
2548 |
|
|
|
2549 |
} catch (JSONException e) {
|
|
|
2550 |
Log.d(TAG, e.getMessage());
|
|
|
2551 |
}
|
|
|
2552 |
|
|
|
2553 |
reloadNavHeader();
|
|
|
2554 |
|
|
|
2555 |
|
|
|
2556 |
}
|
|
|
2557 |
});
|
|
|
2558 |
}
|
|
|
2559 |
*/
|
|
|
2560 |
|
|
|
2561 |
|
|
|
2562 |
|
|
|
2563 |
}
|