Showing
10 changed files
with
210 additions
and
108 deletions
... | @@ -2,25 +2,15 @@ package warp.ly.android_sdk.activities; | ... | @@ -2,25 +2,15 @@ package warp.ly.android_sdk.activities; |
2 | 2 | ||
3 | import android.content.Intent; | 3 | import android.content.Intent; |
4 | import android.os.Bundle; | 4 | import android.os.Bundle; |
5 | -import android.widget.Toast; | ||
6 | - | ||
7 | -import org.json.JSONObject; | ||
8 | 5 | ||
9 | import java.util.Timer; | 6 | import java.util.Timer; |
10 | import java.util.TimerTask; | 7 | import java.util.TimerTask; |
11 | 8 | ||
12 | import ly.warp.sdk.Warply; | 9 | import ly.warp.sdk.Warply; |
13 | import ly.warp.sdk.activities.BaseFragmentActivity; | 10 | import ly.warp.sdk.activities.BaseFragmentActivity; |
14 | -import ly.warp.sdk.db.WarplyDBHelper; | ||
15 | -import ly.warp.sdk.io.callbacks.CallbackReceiver; | ||
16 | import ly.warp.sdk.io.callbacks.SimpleCallbackReceiver; | 11 | import ly.warp.sdk.io.callbacks.SimpleCallbackReceiver; |
17 | import ly.warp.sdk.io.callbacks.WarplyReadyCallback; | 12 | import ly.warp.sdk.io.callbacks.WarplyReadyCallback; |
18 | -import ly.warp.sdk.io.request.WarplyConsumerRequest; | ||
19 | -import ly.warp.sdk.io.request.WarplyCosmoteUserRequest; | ||
20 | -import ly.warp.sdk.io.request.WarplyLoginRequest; | ||
21 | -import ly.warp.sdk.io.request.WarplyVerifyTicketRequest; | ||
22 | import ly.warp.sdk.utils.WarplyInitializer; | 13 | import ly.warp.sdk.utils.WarplyInitializer; |
23 | -import ly.warp.sdk.utils.managers.WarplyManager; | ||
24 | import warp.ly.android_sdk.R; | 14 | import warp.ly.android_sdk.R; |
25 | 15 | ||
26 | public class SplashActivity extends BaseActivity { | 16 | public class SplashActivity extends BaseActivity { |
... | @@ -35,15 +25,8 @@ public class SplashActivity extends BaseActivity { | ... | @@ -35,15 +25,8 @@ public class SplashActivity extends BaseActivity { |
35 | mWarplyInitializer = Warply.getInitializer(this, new WarplyReadyCallback() { | 25 | mWarplyInitializer = Warply.getInitializer(this, new WarplyReadyCallback() { |
36 | @Override | 26 | @Override |
37 | public void onWarplyReady() { | 27 | public void onWarplyReady() { |
38 | - if (!WarplyDBHelper.getInstance(SplashActivity.this).isTableNotEmpty("auth")) { | ||
39 | - //6012049321, 6012049322, 6012049323, 7000000831 history, 7000000826, 7000000831 shared coupons | ||
40 | - //prod 6006552990, prod 6005892749, live 3000184910,prod 7000070282, live 3000136179 | ||
41 | - WarplyManager.getCosmoteUser("7000001053", mLoginReceiver); | ||
42 | -// WarplyManager.verifyTicket("", "7000023699", mLoginReceiver); | ||
43 | - } else { | ||
44 | startNextActivity(); | 28 | startNextActivity(); |
45 | } | 29 | } |
46 | - } | ||
47 | 30 | ||
48 | @Override | 31 | @Override |
49 | public void onWarplyInitTimeOut() { | 32 | public void onWarplyInitTimeOut() { |
... | @@ -93,19 +76,4 @@ public class SplashActivity extends BaseActivity { | ... | @@ -93,19 +76,4 @@ public class SplashActivity extends BaseActivity { |
93 | }, MIN_SPLASH_TIME); | 76 | }, MIN_SPLASH_TIME); |
94 | } | 77 | } |
95 | } | 78 | } |
96 | - | ||
97 | - private final CallbackReceiver<JSONObject> mLoginReceiver = new CallbackReceiver<JSONObject>() { | ||
98 | - @Override | ||
99 | - public void onSuccess(JSONObject result) { | ||
100 | - if (result != null && result.optInt("status") == 1) { | ||
101 | - startNextActivity(); | ||
102 | - } | ||
103 | - } | ||
104 | - | ||
105 | - @Override | ||
106 | - public void onFailure(int errorCode) { | ||
107 | -// startNextActivity(); | ||
108 | - Toast.makeText(SplashActivity.this, "LOGIN ERROR", Toast.LENGTH_SHORT).show(); | ||
109 | - } | ||
110 | - }; | ||
111 | } | 79 | } | ... | ... |
... | @@ -19,6 +19,7 @@ import com.google.android.material.navigation.NavigationBarView; | ... | @@ -19,6 +19,7 @@ import com.google.android.material.navigation.NavigationBarView; |
19 | import java.util.ArrayList; | 19 | import java.util.ArrayList; |
20 | 20 | ||
21 | import ly.warp.sdk.R; | 21 | import ly.warp.sdk.R; |
22 | +import ly.warp.sdk.db.WarplyDBHelper; | ||
22 | import ly.warp.sdk.fragments.HomeFragment; | 23 | import ly.warp.sdk.fragments.HomeFragment; |
23 | import ly.warp.sdk.fragments.LoyaltyFragment; | 24 | import ly.warp.sdk.fragments.LoyaltyFragment; |
24 | import ly.warp.sdk.fragments.MyRewardsFragment; | 25 | import ly.warp.sdk.fragments.MyRewardsFragment; |
... | @@ -53,9 +54,11 @@ public class BaseFragmentActivity extends FragmentActivity implements Navigation | ... | @@ -53,9 +54,11 @@ public class BaseFragmentActivity extends FragmentActivity implements Navigation |
53 | 54 | ||
54 | mBottomNavigationView = findViewById(R.id.bt_tabs); | 55 | mBottomNavigationView = findViewById(R.id.bt_tabs); |
55 | 56 | ||
57 | + if (WarplyDBHelper.getInstance(this).isTableNotEmpty("auth")) { | ||
56 | WarplyManager.getUserCouponsWithCouponsets(mUserCouponsReceiver); | 58 | WarplyManager.getUserCouponsWithCouponsets(mUserCouponsReceiver); |
57 | WarplyManager.getCampaigns(mCampaignsCallback); | 59 | WarplyManager.getCampaigns(mCampaignsCallback); |
58 | WarplyManager.getUnifiedCouponsDeals(mUnifiedCallback); | 60 | WarplyManager.getUnifiedCouponsDeals(mUnifiedCallback); |
61 | + } | ||
59 | 62 | ||
60 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { | 63 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { |
61 | if (!hasNotificationPermission()) { | 64 | if (!hasNotificationPermission()) { | ... | ... |
... | @@ -40,7 +40,7 @@ public class WarplyDBHelper extends SQLiteOpenHelper { | ... | @@ -40,7 +40,7 @@ public class WarplyDBHelper extends SQLiteOpenHelper { |
40 | } | 40 | } |
41 | 41 | ||
42 | private static final String DB_NAME = "warply.db"; | 42 | private static final String DB_NAME = "warply.db"; |
43 | - private static final int DB_VERSION = 10; | 43 | + private static final int DB_VERSION = 12; |
44 | private static final String KEY_CIPHER = "tn#mpOl3v3Dy1pr@W"; | 44 | private static final String KEY_CIPHER = "tn#mpOl3v3Dy1pr@W"; |
45 | 45 | ||
46 | //------------------------------ Fields -----------------------------// | 46 | //------------------------------ Fields -----------------------------// |
... | @@ -154,6 +154,19 @@ public class WarplyDBHelper extends SQLiteOpenHelper { | ... | @@ -154,6 +154,19 @@ public class WarplyDBHelper extends SQLiteOpenHelper { |
154 | return mDb; | 154 | return mDb; |
155 | } | 155 | } |
156 | 156 | ||
157 | + private SQLiteDatabase getReadableDb() { | ||
158 | + if (mDb == null) | ||
159 | + mDb = getReadableDatabase(KEY_CIPHER); | ||
160 | + return mDb; | ||
161 | + } | ||
162 | + | ||
163 | + private void closeDb() { | ||
164 | + if (mDb != null && mDb.isOpen()) { | ||
165 | + mDb.close(); | ||
166 | + mDb = null; | ||
167 | + } | ||
168 | + } | ||
169 | + | ||
157 | @Override | 170 | @Override |
158 | public void onCreate(SQLiteDatabase db) { | 171 | public void onCreate(SQLiteDatabase db) { |
159 | db.execSQL(CREATE_TABLE_REQUESTS); | 172 | db.execSQL(CREATE_TABLE_REQUESTS); |
... | @@ -215,28 +228,37 @@ public class WarplyDBHelper extends SQLiteOpenHelper { | ... | @@ -215,28 +228,37 @@ public class WarplyDBHelper extends SQLiteOpenHelper { |
215 | public synchronized void clearTable(String tableName) { | 228 | public synchronized void clearTable(String tableName) { |
216 | SQLiteDatabase db = getDb(); | 229 | SQLiteDatabase db = getDb(); |
217 | db.delete(tableName, null, null); | 230 | db.delete(tableName, null, null); |
231 | + | ||
232 | + closeDb(); | ||
218 | } | 233 | } |
219 | 234 | ||
220 | public synchronized void insert(String tableName, ContentValues values) { | 235 | public synchronized void insert(String tableName, ContentValues values) { |
221 | SQLiteDatabase db = getDb(); | 236 | SQLiteDatabase db = getDb(); |
222 | db.insert(tableName, null, values); | 237 | db.insert(tableName, null, values); |
238 | + | ||
239 | + closeDb(); | ||
223 | } | 240 | } |
224 | 241 | ||
225 | public synchronized void update(String tableName, ContentValues values) { | 242 | public synchronized void update(String tableName, ContentValues values) { |
226 | SQLiteDatabase db = getDb(); | 243 | SQLiteDatabase db = getDb(); |
227 | db.update(tableName, values, null, null); | 244 | db.update(tableName, values, null, null); |
245 | + | ||
246 | + closeDb(); | ||
228 | } | 247 | } |
229 | 248 | ||
230 | public synchronized boolean isTableNotEmpty(String tableName) { | 249 | public synchronized boolean isTableNotEmpty(String tableName) { |
231 | - Cursor cursor = getDb().rawQuery("SELECT COUNT(*) FROM " + tableName, | 250 | + Cursor cursor = getReadableDb().rawQuery("SELECT COUNT(*) FROM " + tableName, |
232 | null); | 251 | null); |
233 | if (cursor != null && cursor.moveToFirst()) { | 252 | if (cursor != null && cursor.moveToFirst()) { |
234 | boolean isNotEmpty = cursor.getInt(0) > 0; | 253 | boolean isNotEmpty = cursor.getInt(0) > 0; |
235 | cursor.close(); | 254 | cursor.close(); |
255 | + closeDb(); | ||
236 | return isNotEmpty; | 256 | return isNotEmpty; |
237 | - } else | 257 | + } else { |
258 | + closeDb(); | ||
238 | return false; | 259 | return false; |
239 | } | 260 | } |
261 | + } | ||
240 | 262 | ||
241 | //------------------------------ Auth -----------------------------// | 263 | //------------------------------ Auth -----------------------------// |
242 | public synchronized void saveClientAccess(String clientId, String clientSecret) { | 264 | public synchronized void saveClientAccess(String clientId, String clientSecret) { |
... | @@ -266,24 +288,30 @@ public class WarplyDBHelper extends SQLiteOpenHelper { | ... | @@ -266,24 +288,30 @@ public class WarplyDBHelper extends SQLiteOpenHelper { |
266 | @Nullable | 288 | @Nullable |
267 | public synchronized String getAuthValue(String columnName) { | 289 | public synchronized String getAuthValue(String columnName) { |
268 | String columnValue = ""; | 290 | String columnValue = ""; |
269 | - Cursor cursor = getDb().query(TABLE_AUTH, new String[]{columnName}, null, null, null, null, null); | 291 | + Cursor cursor = getReadableDb().query(TABLE_AUTH, new String[]{columnName}, null, null, null, null, null); |
270 | if (cursor != null && cursor.moveToFirst()) { | 292 | if (cursor != null && cursor.moveToFirst()) { |
271 | cursor.moveToFirst(); | 293 | cursor.moveToFirst(); |
272 | columnValue = cursor.getString(cursor.getColumnIndex(columnName)); | 294 | columnValue = cursor.getString(cursor.getColumnIndex(columnName)); |
273 | cursor.close(); | 295 | cursor.close(); |
274 | } | 296 | } |
297 | + | ||
298 | + closeDb(); | ||
299 | + | ||
275 | return columnValue; | 300 | return columnValue; |
276 | } | 301 | } |
277 | 302 | ||
278 | @Nullable | 303 | @Nullable |
279 | public synchronized String getClientValue(String columnName) { | 304 | public synchronized String getClientValue(String columnName) { |
280 | String columnValue = ""; | 305 | String columnValue = ""; |
281 | - Cursor cursor = getDb().query(TABLE_CLIENT, new String[]{columnName}, null, null, null, null, null); | 306 | + Cursor cursor = getReadableDb().query(TABLE_CLIENT, new String[]{columnName}, null, null, null, null, null); |
282 | if (cursor != null && cursor.moveToFirst()) { | 307 | if (cursor != null && cursor.moveToFirst()) { |
283 | cursor.moveToFirst(); | 308 | cursor.moveToFirst(); |
284 | columnValue = cursor.getString(cursor.getColumnIndex(columnName)); | 309 | columnValue = cursor.getString(cursor.getColumnIndex(columnName)); |
285 | cursor.close(); | 310 | cursor.close(); |
286 | } | 311 | } |
312 | + | ||
313 | + closeDb(); | ||
314 | + | ||
287 | return columnValue; | 315 | return columnValue; |
288 | } | 316 | } |
289 | 317 | ||
... | @@ -297,24 +325,21 @@ public class WarplyDBHelper extends SQLiteOpenHelper { | ... | @@ -297,24 +325,21 @@ public class WarplyDBHelper extends SQLiteOpenHelper { |
297 | 325 | ||
298 | //------------------------------ Api requests -----------------------------// | 326 | //------------------------------ Api requests -----------------------------// |
299 | public synchronized Cursor getAllRequests() { | 327 | public synchronized Cursor getAllRequests() { |
300 | - | 328 | + return getReadableDb().query(TABLE_REQUESTS, |
301 | - return getDb().query(TABLE_REQUESTS, | ||
302 | new String[]{KEY_REQUESTS_ID, | 329 | new String[]{KEY_REQUESTS_ID, |
303 | KEY_REQUESTS_MICROAPP, KEY_REQUESTS_ENTITY}, null, null, null, null, | 330 | KEY_REQUESTS_MICROAPP, KEY_REQUESTS_ENTITY}, null, null, null, null, |
304 | KEY_REQUESTS_DATE_ADDED + " asc", "20"); | 331 | KEY_REQUESTS_DATE_ADDED + " asc", "20"); |
305 | } | 332 | } |
306 | 333 | ||
307 | public synchronized Cursor getAllPushRequests() { | 334 | public synchronized Cursor getAllPushRequests() { |
308 | - | 335 | + return getReadableDb().query(TABLE_PUSH_REQUESTS, |
309 | - return getDb().query(TABLE_PUSH_REQUESTS, | ||
310 | new String[]{KEY_REQUESTS_ID, | 336 | new String[]{KEY_REQUESTS_ID, |
311 | KEY_REQUESTS_MICROAPP, KEY_REQUESTS_ENTITY}, null, null, null, null, | 337 | KEY_REQUESTS_MICROAPP, KEY_REQUESTS_ENTITY}, null, null, null, null, |
312 | KEY_REQUESTS_DATE_ADDED + " asc", "20"); | 338 | KEY_REQUESTS_DATE_ADDED + " asc", "20"); |
313 | } | 339 | } |
314 | 340 | ||
315 | public synchronized Cursor getAllPushAckRequests() { | 341 | public synchronized Cursor getAllPushAckRequests() { |
316 | - | 342 | + return getReadableDb().query(TABLE_PUSH_ACK_REQUESTS, |
317 | - return getDb().query(TABLE_PUSH_ACK_REQUESTS, | ||
318 | new String[]{KEY_REQUESTS_ID, | 343 | new String[]{KEY_REQUESTS_ID, |
319 | KEY_REQUESTS_MICROAPP, KEY_REQUESTS_ENTITY}, null, null, null, null, | 344 | KEY_REQUESTS_MICROAPP, KEY_REQUESTS_ENTITY}, null, null, null, null, |
320 | KEY_REQUESTS_DATE_ADDED + " asc", "20"); | 345 | KEY_REQUESTS_DATE_ADDED + " asc", "20"); |
... | @@ -375,7 +400,6 @@ public class WarplyDBHelper extends SQLiteOpenHelper { | ... | @@ -375,7 +400,6 @@ public class WarplyDBHelper extends SQLiteOpenHelper { |
375 | } | 400 | } |
376 | 401 | ||
377 | public synchronized void deleteRequests(Long... ids) { | 402 | public synchronized void deleteRequests(Long... ids) { |
378 | - | ||
379 | StringBuilder strFilter = new StringBuilder(); | 403 | StringBuilder strFilter = new StringBuilder(); |
380 | for (int i = 0; i < ids.length; i++) { | 404 | for (int i = 0; i < ids.length; i++) { |
381 | if (i > 0) { | 405 | if (i > 0) { |
... | @@ -386,10 +410,11 @@ public class WarplyDBHelper extends SQLiteOpenHelper { | ... | @@ -386,10 +410,11 @@ public class WarplyDBHelper extends SQLiteOpenHelper { |
386 | strFilter.append(ids[i]); | 410 | strFilter.append(ids[i]); |
387 | } | 411 | } |
388 | getDb().delete(TABLE_REQUESTS, strFilter.toString(), null); | 412 | getDb().delete(TABLE_REQUESTS, strFilter.toString(), null); |
413 | + | ||
414 | + closeDb(); | ||
389 | } | 415 | } |
390 | 416 | ||
391 | public synchronized void deletePushRequests(Long... ids) { | 417 | public synchronized void deletePushRequests(Long... ids) { |
392 | - | ||
393 | StringBuilder strFilter = new StringBuilder(); | 418 | StringBuilder strFilter = new StringBuilder(); |
394 | for (int i = 0; i < ids.length; i++) { | 419 | for (int i = 0; i < ids.length; i++) { |
395 | if (i > 0) { | 420 | if (i > 0) { |
... | @@ -400,10 +425,11 @@ public class WarplyDBHelper extends SQLiteOpenHelper { | ... | @@ -400,10 +425,11 @@ public class WarplyDBHelper extends SQLiteOpenHelper { |
400 | strFilter.append(ids[i]); | 425 | strFilter.append(ids[i]); |
401 | } | 426 | } |
402 | getDb().delete(TABLE_PUSH_REQUESTS, strFilter.toString(), null); | 427 | getDb().delete(TABLE_PUSH_REQUESTS, strFilter.toString(), null); |
428 | + | ||
429 | + closeDb(); | ||
403 | } | 430 | } |
404 | 431 | ||
405 | public synchronized void deletePushAckRequests(Long... ids) { | 432 | public synchronized void deletePushAckRequests(Long... ids) { |
406 | - | ||
407 | StringBuilder strFilter = new StringBuilder(); | 433 | StringBuilder strFilter = new StringBuilder(); |
408 | for (int i = 0; i < ids.length; i++) { | 434 | for (int i = 0; i < ids.length; i++) { |
409 | if (i > 0) { | 435 | if (i > 0) { |
... | @@ -414,45 +440,55 @@ public class WarplyDBHelper extends SQLiteOpenHelper { | ... | @@ -414,45 +440,55 @@ public class WarplyDBHelper extends SQLiteOpenHelper { |
414 | strFilter.append(ids[i]); | 440 | strFilter.append(ids[i]); |
415 | } | 441 | } |
416 | getDb().delete(TABLE_PUSH_ACK_REQUESTS, strFilter.toString(), null); | 442 | getDb().delete(TABLE_PUSH_ACK_REQUESTS, strFilter.toString(), null); |
443 | + | ||
444 | + closeDb(); | ||
417 | } | 445 | } |
418 | 446 | ||
419 | public synchronized boolean isForceRequestsExist() { | 447 | public synchronized boolean isForceRequestsExist() { |
420 | - Cursor cursor = getDb().query(TABLE_REQUESTS, null, KEY_REQUESTS_FORCE + "=1", | 448 | + Cursor cursor = getReadableDb().query(TABLE_REQUESTS, null, KEY_REQUESTS_FORCE + "=1", |
421 | null, null, null, null); | 449 | null, null, null, null); |
422 | boolean result = false; | 450 | boolean result = false; |
423 | if (cursor != null) { | 451 | if (cursor != null) { |
424 | result = cursor.getCount() > 0; | 452 | result = cursor.getCount() > 0; |
425 | cursor.close(); | 453 | cursor.close(); |
426 | } | 454 | } |
455 | + | ||
456 | + closeDb(); | ||
457 | + | ||
427 | return result; | 458 | return result; |
428 | } | 459 | } |
429 | 460 | ||
430 | public synchronized boolean isForcePushRequestsExist() { | 461 | public synchronized boolean isForcePushRequestsExist() { |
431 | - Cursor cursor = getDb().query(TABLE_PUSH_REQUESTS, null, KEY_REQUESTS_FORCE + "=1", | 462 | + Cursor cursor = getReadableDb().query(TABLE_PUSH_REQUESTS, null, KEY_REQUESTS_FORCE + "=1", |
432 | null, null, null, null); | 463 | null, null, null, null); |
433 | boolean result = false; | 464 | boolean result = false; |
434 | if (cursor != null) { | 465 | if (cursor != null) { |
435 | result = cursor.getCount() > 0; | 466 | result = cursor.getCount() > 0; |
436 | cursor.close(); | 467 | cursor.close(); |
437 | } | 468 | } |
469 | + | ||
470 | + closeDb(); | ||
471 | + | ||
438 | return result; | 472 | return result; |
439 | } | 473 | } |
440 | 474 | ||
441 | public synchronized boolean isForcePushAckRequestsExist() { | 475 | public synchronized boolean isForcePushAckRequestsExist() { |
442 | - Cursor cursor = getDb().query(TABLE_PUSH_ACK_REQUESTS, null, KEY_REQUESTS_FORCE + "=1", | 476 | + Cursor cursor = getReadableDb().query(TABLE_PUSH_ACK_REQUESTS, null, KEY_REQUESTS_FORCE + "=1", |
443 | null, null, null, null); | 477 | null, null, null, null); |
444 | boolean result = false; | 478 | boolean result = false; |
445 | if (cursor != null) { | 479 | if (cursor != null) { |
446 | result = cursor.getCount() > 0; | 480 | result = cursor.getCount() > 0; |
447 | cursor.close(); | 481 | cursor.close(); |
448 | } | 482 | } |
483 | + | ||
484 | + closeDb(); | ||
485 | + | ||
449 | return result; | 486 | return result; |
450 | } | 487 | } |
451 | 488 | ||
452 | //------------------------------ Tags -----------------------------// | 489 | //------------------------------ Tags -----------------------------// |
453 | public synchronized void saveTags(String[] tags) { | 490 | public synchronized void saveTags(String[] tags) { |
454 | if (tags != null && tags.length > 0) { | 491 | if (tags != null && tags.length > 0) { |
455 | - | ||
456 | try { | 492 | try { |
457 | getDb().beginTransaction(); | 493 | getDb().beginTransaction(); |
458 | ContentValues values = new ContentValues(); | 494 | ContentValues values = new ContentValues(); |
... | @@ -464,11 +500,14 @@ public class WarplyDBHelper extends SQLiteOpenHelper { | ... | @@ -464,11 +500,14 @@ public class WarplyDBHelper extends SQLiteOpenHelper { |
464 | getDb().setTransactionSuccessful(); | 500 | getDb().setTransactionSuccessful(); |
465 | 501 | ||
466 | } catch (SQLException e) { | 502 | } catch (SQLException e) { |
503 | + closeDb(); | ||
467 | if (WarpConstants.DEBUG) { | 504 | if (WarpConstants.DEBUG) { |
468 | e.printStackTrace(); | 505 | e.printStackTrace(); |
469 | } | 506 | } |
470 | } finally { | 507 | } finally { |
471 | getDb().endTransaction(); | 508 | getDb().endTransaction(); |
509 | + | ||
510 | + closeDb(); | ||
472 | } | 511 | } |
473 | } | 512 | } |
474 | } | 513 | } |
... | @@ -505,6 +544,7 @@ public class WarplyDBHelper extends SQLiteOpenHelper { | ... | @@ -505,6 +544,7 @@ public class WarplyDBHelper extends SQLiteOpenHelper { |
505 | strFilter.append("'"); | 544 | strFilter.append("'"); |
506 | } | 545 | } |
507 | getDb().delete(TABLE_TAGS, strFilter.toString(), null); | 546 | getDb().delete(TABLE_TAGS, strFilter.toString(), null); |
547 | + closeDb(); | ||
508 | } | 548 | } |
509 | 549 | ||
510 | public synchronized void removeAllTags() { | 550 | public synchronized void removeAllTags() { |
... | @@ -515,7 +555,7 @@ public class WarplyDBHelper extends SQLiteOpenHelper { | ... | @@ -515,7 +555,7 @@ public class WarplyDBHelper extends SQLiteOpenHelper { |
515 | public synchronized String[] getTags() { | 555 | public synchronized String[] getTags() { |
516 | 556 | ||
517 | List<String> tags = null; | 557 | List<String> tags = null; |
518 | - Cursor cursor = getDb().query(TABLE_TAGS, null, null, null, null, null, null); | 558 | + Cursor cursor = getReadableDb().query(TABLE_TAGS, null, null, null, null, null, null); |
519 | if (cursor != null) { | 559 | if (cursor != null) { |
520 | 560 | ||
521 | tags = new ArrayList<>(cursor.getCount()); | 561 | tags = new ArrayList<>(cursor.getCount()); |
... | @@ -525,6 +565,9 @@ public class WarplyDBHelper extends SQLiteOpenHelper { | ... | @@ -525,6 +565,9 @@ public class WarplyDBHelper extends SQLiteOpenHelper { |
525 | } | 565 | } |
526 | cursor.close(); | 566 | cursor.close(); |
527 | } | 567 | } |
568 | + | ||
569 | + closeDb(); | ||
570 | + | ||
528 | return tags != null ? tags.toArray(new String[tags.size()]) : null; | 571 | return tags != null ? tags.toArray(new String[tags.size()]) : null; |
529 | } | 572 | } |
530 | 573 | ... | ... |
... | @@ -5,6 +5,7 @@ import android.os.Bundle; | ... | @@ -5,6 +5,7 @@ import android.os.Bundle; |
5 | import android.view.LayoutInflater; | 5 | import android.view.LayoutInflater; |
6 | import android.view.View; | 6 | import android.view.View; |
7 | import android.view.ViewGroup; | 7 | import android.view.ViewGroup; |
8 | +import android.widget.EditText; | ||
8 | import android.widget.ImageView; | 9 | import android.widget.ImageView; |
9 | import android.widget.LinearLayout; | 10 | import android.widget.LinearLayout; |
10 | import android.widget.RelativeLayout; | 11 | import android.widget.RelativeLayout; |
... | @@ -12,10 +13,7 @@ import android.widget.TextView; | ... | @@ -12,10 +13,7 @@ import android.widget.TextView; |
12 | import android.widget.Toast; | 13 | import android.widget.Toast; |
13 | 14 | ||
14 | import androidx.annotation.NonNull; | 15 | import androidx.annotation.NonNull; |
15 | -import androidx.constraintlayout.widget.ConstraintLayout; | ||
16 | import androidx.fragment.app.Fragment; | 16 | import androidx.fragment.app.Fragment; |
17 | -import androidx.recyclerview.widget.LinearLayoutManager; | ||
18 | -import androidx.recyclerview.widget.RecyclerView; | ||
19 | import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; | 17 | import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; |
20 | 18 | ||
21 | import org.json.JSONObject; | 19 | import org.json.JSONObject; |
... | @@ -23,28 +21,24 @@ import org.json.JSONObject; | ... | @@ -23,28 +21,24 @@ import org.json.JSONObject; |
23 | import java.util.ArrayList; | 21 | import java.util.ArrayList; |
24 | 22 | ||
25 | import ly.warp.sdk.R; | 23 | import ly.warp.sdk.R; |
26 | -import ly.warp.sdk.activities.ActiveCouponsActivity; | ||
27 | -import ly.warp.sdk.activities.BaseFragmentActivity; | ||
28 | import ly.warp.sdk.activities.TelematicsActivity; | 24 | import ly.warp.sdk.activities.TelematicsActivity; |
29 | import ly.warp.sdk.activities.TelematicsHistoryActivity; | 25 | import ly.warp.sdk.activities.TelematicsHistoryActivity; |
30 | -import ly.warp.sdk.activities.WarpViewActivity; | 26 | +import ly.warp.sdk.db.WarplyDBHelper; |
31 | import ly.warp.sdk.io.callbacks.CallbackReceiver; | 27 | import ly.warp.sdk.io.callbacks.CallbackReceiver; |
32 | import ly.warp.sdk.io.models.Campaign; | 28 | import ly.warp.sdk.io.models.Campaign; |
33 | import ly.warp.sdk.io.models.CouponList; | 29 | import ly.warp.sdk.io.models.CouponList; |
34 | import ly.warp.sdk.io.models.UnifiedCoupon; | 30 | import ly.warp.sdk.io.models.UnifiedCoupon; |
35 | -import ly.warp.sdk.io.request.WarplyGetCampaignsRequest; | ||
36 | import ly.warp.sdk.utils.WarplyManagerHelper; | 31 | import ly.warp.sdk.utils.WarplyManagerHelper; |
37 | import ly.warp.sdk.utils.managers.WarplyManager; | 32 | import ly.warp.sdk.utils.managers.WarplyManager; |
38 | -import ly.warp.sdk.views.adapters.HomeCampaignAdapter; | ||
39 | 33 | ||
40 | public class HomeFragment extends Fragment implements View.OnClickListener, SwipeRefreshLayout.OnRefreshListener { | 34 | public class HomeFragment extends Fragment implements View.OnClickListener, SwipeRefreshLayout.OnRefreshListener { |
41 | 35 | ||
42 | - private RelativeLayout mOptionOne, mOptionTwo, mOptionThree, mRlDriving, mRlDrivingHistory; | 36 | + private RelativeLayout mOptionOne, mOptionTwo, mOptionThree, mRlDriving, |
43 | - private LinearLayout mLlBillPayment; | 37 | + mRlDrivingHistory, mPbLoading; |
44 | - private TextView mTvUsername, mTvActiveCoupons; | 38 | + private TextView mTvUsername; |
45 | - private ConstraintLayout mClActiveCoupons; | ||
46 | - private ImageView mIvStepsActivity; | ||
47 | private SwipeRefreshLayout mSwipeRefresh; | 39 | private SwipeRefreshLayout mSwipeRefresh; |
40 | + private EditText mEtGuid; | ||
41 | + private LinearLayout mLlAuthLogin, mLlAuthLogout; | ||
48 | 42 | ||
49 | @Override | 43 | @Override |
50 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { | 44 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { |
... | @@ -74,17 +68,6 @@ public class HomeFragment extends Fragment implements View.OnClickListener, Swip | ... | @@ -74,17 +68,6 @@ public class HomeFragment extends Fragment implements View.OnClickListener, Swip |
74 | mOptionThreeText.setText("1"); | 68 | mOptionThreeText.setText("1"); |
75 | mOptionThreeImage.setImageResource(R.drawable.tv_option); | 69 | mOptionThreeImage.setImageResource(R.drawable.tv_option); |
76 | 70 | ||
77 | - mClActiveCoupons = view.findViewById(R.id.cl_coupon); | ||
78 | - mTvActiveCoupons = mClActiveCoupons.findViewById(R.id.tv_active_coupons); | ||
79 | - mTvActiveCoupons.setText(String.format(getResources().getString(R.string.cos_active_coupons), String.valueOf(WarplyManagerHelper.getCouponList().size()))); | ||
80 | - mClActiveCoupons.setOnClickListener(this); | ||
81 | - | ||
82 | - mLlBillPayment = view.findViewById(R.id.ll_bill_payment); | ||
83 | - mLlBillPayment.setOnClickListener(this); | ||
84 | - | ||
85 | - mIvStepsActivity = view.findViewById(R.id.iv_settings); | ||
86 | - mIvStepsActivity.setOnClickListener(this); | ||
87 | - | ||
88 | mTvUsername = view.findViewById(R.id.welcome_user_txt); | 71 | mTvUsername = view.findViewById(R.id.welcome_user_txt); |
89 | if (WarplyManagerHelper.getConsumer() != null) | 72 | if (WarplyManagerHelper.getConsumer() != null) |
90 | mTvUsername.setText(String.format(getResources().getString(R.string.welcome_user), | 73 | mTvUsername.setText(String.format(getResources().getString(R.string.welcome_user), |
... | @@ -94,6 +77,25 @@ public class HomeFragment extends Fragment implements View.OnClickListener, Swip | ... | @@ -94,6 +77,25 @@ public class HomeFragment extends Fragment implements View.OnClickListener, Swip |
94 | mRlDriving.setOnClickListener(this); | 77 | mRlDriving.setOnClickListener(this); |
95 | mRlDrivingHistory = view.findViewById(R.id.rl_driving_history); | 78 | mRlDrivingHistory = view.findViewById(R.id.rl_driving_history); |
96 | mRlDrivingHistory.setOnClickListener(this); | 79 | mRlDrivingHistory.setOnClickListener(this); |
80 | + | ||
81 | + mPbLoading = view.findViewById(R.id.pb_loading); | ||
82 | + mPbLoading.setOnTouchListener((v, event) -> true); | ||
83 | + | ||
84 | + mEtGuid = view.findViewById(R.id.et_login); | ||
85 | + mLlAuthLogin = view.findViewById(R.id.ll_auth_login); | ||
86 | + mLlAuthLogin.setOnClickListener(this); | ||
87 | + mLlAuthLogout = view.findViewById(R.id.ll_auth_logout); | ||
88 | + mLlAuthLogout.setOnClickListener(this); | ||
89 | + | ||
90 | + if (!WarplyDBHelper.getInstance(getActivity()).isTableNotEmpty("auth")) { | ||
91 | + mLlAuthLogout.setVisibility(View.GONE); | ||
92 | + mLlAuthLogin.setVisibility(View.VISIBLE); | ||
93 | + mEtGuid.setVisibility(View.VISIBLE); | ||
94 | + } else { | ||
95 | + mEtGuid.setVisibility(View.GONE); | ||
96 | + mLlAuthLogin.setVisibility(View.GONE); | ||
97 | + mLlAuthLogout.setVisibility(View.VISIBLE); | ||
98 | + } | ||
97 | } | 99 | } |
98 | 100 | ||
99 | @Override | 101 | @Override |
... | @@ -111,12 +113,6 @@ public class HomeFragment extends Fragment implements View.OnClickListener, Swip | ... | @@ -111,12 +113,6 @@ public class HomeFragment extends Fragment implements View.OnClickListener, Swip |
111 | 113 | ||
112 | @Override | 114 | @Override |
113 | public void onClick(View view) { | 115 | public void onClick(View view) { |
114 | - if (view.getId() == R.id.cl_coupon) { | ||
115 | - Intent intent = new Intent(getContext(), ActiveCouponsActivity.class); | ||
116 | - intent.putExtra("couponlist", WarplyManagerHelper.getCouponList()); | ||
117 | - startActivity(intent); | ||
118 | - return; | ||
119 | - } | ||
120 | if (view.getId() == R.id.rl_driving) { | 116 | if (view.getId() == R.id.rl_driving) { |
121 | Intent intent = new Intent(getContext(), TelematicsActivity.class); | 117 | Intent intent = new Intent(getContext(), TelematicsActivity.class); |
122 | startActivity(intent); | 118 | startActivity(intent); |
... | @@ -127,7 +123,15 @@ public class HomeFragment extends Fragment implements View.OnClickListener, Swip | ... | @@ -127,7 +123,15 @@ public class HomeFragment extends Fragment implements View.OnClickListener, Swip |
127 | startActivity(intent); | 123 | startActivity(intent); |
128 | return; | 124 | return; |
129 | } | 125 | } |
130 | - if (view.getId() == R.id.iv_settings) { | 126 | + if (view.getId() == R.id.ll_auth_login) { |
127 | + //6012049321, 6012049322, 6012049323, 7000000831 history, 7000000826, 7000000831 shared coupons | ||
128 | + //prod 6006552990, prod 6005892749, live 3000184910,prod 7000070282, live 3000136179 | ||
129 | + mPbLoading.setVisibility(View.VISIBLE); | ||
130 | + WarplyManager.getCosmoteUser(mEtGuid.getText().toString(), mLoginReceiver); | ||
131 | + return; | ||
132 | + } | ||
133 | + if (view.getId() == R.id.ll_auth_logout) { | ||
134 | + mPbLoading.setVisibility(View.VISIBLE); | ||
131 | WarplyManager.logout(mLogoutReceiver); | 135 | WarplyManager.logout(mLogoutReceiver); |
132 | } | 136 | } |
133 | } | 137 | } |
... | @@ -177,12 +181,38 @@ public class HomeFragment extends Fragment implements View.OnClickListener, Swip | ... | @@ -177,12 +181,38 @@ public class HomeFragment extends Fragment implements View.OnClickListener, Swip |
177 | private final CallbackReceiver<JSONObject> mLogoutReceiver = new CallbackReceiver<JSONObject>() { | 181 | private final CallbackReceiver<JSONObject> mLogoutReceiver = new CallbackReceiver<JSONObject>() { |
178 | @Override | 182 | @Override |
179 | public void onSuccess(JSONObject result) { | 183 | public void onSuccess(JSONObject result) { |
184 | + mPbLoading.setVisibility(View.GONE); | ||
185 | + mLlAuthLogout.setVisibility(View.GONE); | ||
186 | + mLlAuthLogin.setVisibility(View.VISIBLE); | ||
187 | + mEtGuid.setVisibility(View.VISIBLE); | ||
180 | Toast.makeText(getActivity(), "LOGOUT SUCCESS", Toast.LENGTH_SHORT).show(); | 188 | Toast.makeText(getActivity(), "LOGOUT SUCCESS", Toast.LENGTH_SHORT).show(); |
181 | } | 189 | } |
182 | 190 | ||
183 | @Override | 191 | @Override |
184 | public void onFailure(int errorCode) { | 192 | public void onFailure(int errorCode) { |
193 | + mPbLoading.setVisibility(View.GONE); | ||
185 | Toast.makeText(getActivity(), "LOGOUT ERROR", Toast.LENGTH_SHORT).show(); | 194 | Toast.makeText(getActivity(), "LOGOUT ERROR", Toast.LENGTH_SHORT).show(); |
186 | } | 195 | } |
187 | }; | 196 | }; |
197 | + | ||
198 | + private final CallbackReceiver<JSONObject> mLoginReceiver = new CallbackReceiver<JSONObject>() { | ||
199 | + @Override | ||
200 | + public void onSuccess(JSONObject result) { | ||
201 | + mPbLoading.setVisibility(View.GONE); | ||
202 | + mLlAuthLogin.setVisibility(View.GONE); | ||
203 | + mEtGuid.setVisibility(View.GONE); | ||
204 | + mLlAuthLogout.setVisibility(View.VISIBLE); | ||
205 | + if (result != null && result.optInt("status") == 1) { | ||
206 | + WarplyManager.getUserCouponsWithCouponsets(mUserCouponsReceiver); | ||
207 | + WarplyManager.getCampaigns(mCampaignsCallback); | ||
208 | + WarplyManager.getUnifiedCouponsDeals(mUnifiedCallback); | ||
209 | + } | ||
210 | + } | ||
211 | + | ||
212 | + @Override | ||
213 | + public void onFailure(int errorCode) { | ||
214 | + mPbLoading.setVisibility(View.GONE); | ||
215 | + Toast.makeText(getActivity(), "LOGIN ERROR", Toast.LENGTH_SHORT).show(); | ||
216 | + } | ||
217 | + }; | ||
188 | } | 218 | } |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
... | @@ -25,7 +25,6 @@ | ... | @@ -25,7 +25,6 @@ |
25 | 25 | ||
26 | package ly.warp.sdk.io.callbacks; | 26 | package ly.warp.sdk.io.callbacks; |
27 | 27 | ||
28 | -import org.json.JSONException; | ||
29 | import org.json.JSONObject; | 28 | import org.json.JSONObject; |
30 | 29 | ||
31 | import ly.warp.sdk.Warply; | 30 | import ly.warp.sdk.Warply; |
... | @@ -42,6 +41,8 @@ import ly.warp.sdk.utils.WarpUtils; | ... | @@ -42,6 +41,8 @@ import ly.warp.sdk.utils.WarpUtils; |
42 | 41 | ||
43 | import static ly.warp.sdk.Warply.getWarplyContext; | 42 | import static ly.warp.sdk.Warply.getWarplyContext; |
44 | 43 | ||
44 | +import android.text.TextUtils; | ||
45 | + | ||
45 | public class VolleyTransformer implements Listener<JSONObject>, ErrorListener { | 46 | public class VolleyTransformer implements Listener<JSONObject>, ErrorListener { |
46 | 47 | ||
47 | public VolleyTransformer(CallbackReceiver<JSONObject> listener) { | 48 | public VolleyTransformer(CallbackReceiver<JSONObject> listener) { |
... | @@ -81,30 +82,42 @@ public class VolleyTransformer implements Listener<JSONObject>, ErrorListener { | ... | @@ -81,30 +82,42 @@ public class VolleyTransformer implements Listener<JSONObject>, ErrorListener { |
81 | @Override | 82 | @Override |
82 | public void onResponse(JSONObject response) { | 83 | public void onResponse(JSONObject response) { |
83 | if (response != null) { | 84 | if (response != null) { |
84 | - if (response.optJSONObject("context") != null) { | 85 | + JSONObject contextObj = response.optJSONObject("context"); |
85 | - if (response.optJSONObject("context").optJSONObject("device_status") != null) { | 86 | + if (contextObj != null) { |
86 | - WarpUtils.setIsWarped(getWarplyContext(), response.optJSONObject("context").optJSONObject("device_status").optBoolean("warped")); | 87 | + JSONObject deviceStatusObj = contextObj.optJSONObject("device_status"); |
87 | -// WarpUtils.setDeviceToken(getWarplyContext(), response.optJSONObject("context").optJSONObject("device_status").optString("device_token")); | 88 | + |
88 | -// WarpUtils.setHasApplicationInfo(getWarplyContext(), response.optJSONObject("context").optJSONObject("device_status").optBoolean("application_info_saved")); | 89 | + if (deviceStatusObj != null) { |
89 | - WarpUtils.setDeviceId(getWarplyContext(), response.optJSONObject("context").optJSONObject("device_status").optString("device_id")); | 90 | + WarpUtils.setIsWarped(getWarplyContext(), deviceStatusObj.optBoolean("warped")); |
90 | - WarpUtils.setIsDeviceIdSaved(getWarplyContext(), response.optJSONObject("context").optJSONObject("device_status").optBoolean("device_id_saved")); | 91 | + WarpUtils.setDeviceId(getWarplyContext(), deviceStatusObj.optString("device_id")); |
91 | -// WarpUtils.setIsDeviceInfoSaved(getWarplyContext(), response.optJSONObject("context").optJSONObject("device_status").optBoolean("device_info_saved")); | 92 | + WarpUtils.setIsDeviceIdSaved(getWarplyContext(), deviceStatusObj.optBoolean("device_id_saved")); |
92 | - if (response.optJSONObject("context").optJSONObject("device_status").optJSONObject("application_info") != null) { | 93 | + |
93 | - WarpUtils.setAppDataObject(getWarplyContext(), response.optJSONObject("context").optJSONObject("device_status").optJSONObject("application_info")); | 94 | + JSONObject applicationInfoObj = deviceStatusObj.optJSONObject("application_info"); |
94 | - WarpUtils.setSDKVersion(getWarplyContext(), response.optJSONObject("context").optJSONObject("device_status").optJSONObject("application_info").optString("sdk_version")); | 95 | + if (applicationInfoObj != null) { |
95 | - WarpUtils.setAppVersion(getWarplyContext(), response.optJSONObject("context").optJSONObject("device_status").optJSONObject("application_info").optString("app_version")); | 96 | + WarpUtils.setAppDataObject(getWarplyContext(), applicationInfoObj); |
96 | - } | 97 | + WarpUtils.setSDKVersion(getWarplyContext(), applicationInfoObj.optString("sdk_version")); |
97 | - if (response.optJSONObject("context").optJSONObject("device_status").optJSONObject("device_info") != null) { | 98 | + WarpUtils.setAppVersion(getWarplyContext(), applicationInfoObj.optString("app_version")); |
98 | - WarpUtils.setDeviceInfoObject(getWarplyContext(), response.optJSONObject("context").optJSONObject("device_status").optJSONObject("device_info")); | 99 | + } |
99 | - WarpUtils.setOSVersion(getWarplyContext(), response.optJSONObject("context").optJSONObject("device_status").optJSONObject("device_info").optString("os_version")); | 100 | + |
100 | - WarpUtils.setDeviceBrand(getWarplyContext(), response.optJSONObject("context").optJSONObject("device_status").optJSONObject("device_info").optString("manufacturer")); | 101 | + JSONObject deviceInfoObj = deviceStatusObj.optJSONObject("device_info"); |
101 | - WarpUtils.setCarrierName(getWarplyContext(), response.optJSONObject("context").optJSONObject("device_status").optJSONObject("device_info").optString("carrier_name")); | 102 | + if (deviceInfoObj != null) { |
102 | - } | 103 | + WarpUtils.setDeviceInfoObject(getWarplyContext(), deviceInfoObj); |
103 | - } | 104 | + WarpUtils.setOSVersion(getWarplyContext(), deviceInfoObj.optString("os_version")); |
104 | - if (response.optJSONObject("context").optJSONObject("application_data") != null) { | 105 | + WarpUtils.setDeviceBrand(getWarplyContext(), deviceInfoObj.optString("manufacturer")); |
105 | - WarpUtils.setIsAPPDATAENABLED(getWarplyContext(), response.optJSONObject("context").optJSONObject("application_data").optBoolean("APPLICATION_DATA_ENABLED")); | 106 | + WarpUtils.setCarrierName(getWarplyContext(), deviceInfoObj.optString("carrier_name")); |
106 | - WarpUtils.setIsDEVICEINFOENABLED(getWarplyContext(), response.optJSONObject("context").optJSONObject("application_data").optBoolean("DEVICE_INFO_ENABLED")); | 107 | + } |
107 | - WarpUtils.setIsLIFECYCLEANALYTICSENABLED(getWarplyContext(), response.optJSONObject("context").optJSONObject("application_data").optBoolean("LIFECYCLE_ANALYTICS_ENABLED", true)); | 108 | + } |
109 | + | ||
110 | + JSONObject applicationDataObj = contextObj.optJSONObject("application_data"); | ||
111 | + if (applicationDataObj != null) { | ||
112 | + WarpUtils.setIsAPPDATAENABLED(getWarplyContext(), applicationDataObj.optBoolean("APPLICATION_DATA_ENABLED")); | ||
113 | + WarpUtils.setIsDEVICEINFOENABLED(getWarplyContext(), applicationDataObj.optBoolean("DEVICE_INFO_ENABLED")); | ||
114 | + WarpUtils.setIsLIFECYCLEANALYTICSENABLED(getWarplyContext(), applicationDataObj.optBoolean("LIFECYCLE_ANALYTICS_ENABLED", true)); | ||
115 | + if (applicationDataObj.has("AUTHENTICATION")) { | ||
116 | + String jwtAuth = applicationDataObj.optString("AUTHENTICATION", ""); | ||
117 | + WarpUtils.setIsJWTEnabled(getWarplyContext(), !TextUtils.isEmpty(jwtAuth) && jwtAuth.equals("JWT")); | ||
118 | + } else { | ||
119 | + WarpUtils.setIsJWTEnabled(getWarplyContext(), false); | ||
120 | + } | ||
108 | } | 121 | } |
109 | } | 122 | } |
110 | } | 123 | } | ... | ... |
... | @@ -77,6 +77,17 @@ public interface ApiService { | ... | @@ -77,6 +77,17 @@ public interface ApiService { |
77 | @Header(WarpConstants.HEADER_SIGNATURE) String signature); | 77 | @Header(WarpConstants.HEADER_SIGNATURE) String signature); |
78 | 78 | ||
79 | @Headers("Content-Type: application/json") | 79 | @Headers("Content-Type: application/json") |
80 | + @POST("/user/v5/{appUuid}/logout") | ||
81 | + Call<ResponseBody> logoutUserJwt(@Path("appUuid") String appUuid, | ||
82 | + @Body RequestBody request, | ||
83 | + @Header(WarpConstants.HEADER_DATE) String timeStamp, | ||
84 | + @Header(WarpConstants.HEADER_LOYALTY_BUNDLE_ID) String bundleId, | ||
85 | + @Header(WarpConstants.HEADER_UNIQUE_DEVICE_ID) String deviceId, | ||
86 | + @Header(WarpConstants.HEADER_CHANNEL) String channel, | ||
87 | + @Header(WarpConstants.HEADER_WEB_ID) String webId, | ||
88 | + @Header(WarpConstants.HEADER_SIGNATURE) String signature); | ||
89 | + | ||
90 | + @Headers("Content-Type: application/json") | ||
80 | @POST("/oauth/{appUuid}/context") | 91 | @POST("/oauth/{appUuid}/context") |
81 | Call<ResponseBody> getCouponsets(@Path("appUuid") String appUuid, | 92 | Call<ResponseBody> getCouponsets(@Path("appUuid") String appUuid, |
82 | @Body RequestBody request, | 93 | @Body RequestBody request, | ... | ... |
... | @@ -159,6 +159,8 @@ public class WarpUtils { | ... | @@ -159,6 +159,8 @@ public class WarpUtils { |
159 | + "steps"; | 159 | + "steps"; |
160 | private static final String PREFERENCES_KEY_STEPS_MANUALLY_STOPPED = PREFERENCES_PREFIX | 160 | private static final String PREFERENCES_KEY_STEPS_MANUALLY_STOPPED = PREFERENCES_PREFIX |
161 | + "steps_manually_stopped"; | 161 | + "steps_manually_stopped"; |
162 | + private static final String PREFERENCES_KEY_JWT_ENABLED = PREFERENCES_PREFIX | ||
163 | + + "jwt_enabled"; | ||
162 | 164 | ||
163 | private static SharedPreferences _prefs; | 165 | private static SharedPreferences _prefs; |
164 | 166 | ||
... | @@ -639,6 +641,17 @@ public class WarpUtils { | ... | @@ -639,6 +641,17 @@ public class WarpUtils { |
639 | editor.apply(); | 641 | editor.apply(); |
640 | } | 642 | } |
641 | 643 | ||
644 | + public static boolean isJWTEnabled(Context context) { | ||
645 | + SharedPreferences prefs = getPreferences(context); | ||
646 | + return prefs.getBoolean(PREFERENCES_KEY_JWT_ENABLED, true); | ||
647 | + } | ||
648 | + | ||
649 | + public static void setIsJWTEnabled(Context context, boolean jwtEnabled) { | ||
650 | + SharedPreferences.Editor editor = getPreferences(context).edit(); | ||
651 | + editor.putBoolean(PREFERENCES_KEY_JWT_ENABLED, jwtEnabled); | ||
652 | + editor.apply(); | ||
653 | + } | ||
654 | + | ||
642 | public static JSONObject getAppDataObject(Context context) { | 655 | public static JSONObject getAppDataObject(Context context) { |
643 | SharedPreferences prefs = getPreferences(context); | 656 | SharedPreferences prefs = getPreferences(context); |
644 | try { | 657 | try { | ... | ... |
... | @@ -595,12 +595,30 @@ public class WarplyManager { | ... | @@ -595,12 +595,30 @@ public class WarplyManager { |
595 | String webId = WarpUtils.getWebId(Warply.getWarplyContext()); | 595 | String webId = WarpUtils.getWebId(Warply.getWarplyContext()); |
596 | 596 | ||
597 | Map<String, Object> jsonParams = new ArrayMap<>(); | 597 | Map<String, Object> jsonParams = new ArrayMap<>(); |
598 | + if (WarpUtils.isJWTEnabled(Warply.getWarplyContext())) { | ||
598 | jsonParams.put("access_token", WarplyDBHelper.getInstance(Warply.getWarplyContext()).getAuthValue("access_token")); | 599 | jsonParams.put("access_token", WarplyDBHelper.getInstance(Warply.getWarplyContext()).getAuthValue("access_token")); |
599 | jsonParams.put("refresh_token", WarplyDBHelper.getInstance(Warply.getWarplyContext()).getAuthValue("refresh_token")); | 600 | jsonParams.put("refresh_token", WarplyDBHelper.getInstance(Warply.getWarplyContext()).getAuthValue("refresh_token")); |
601 | + } else { | ||
602 | + jsonParams.put("token", WarplyDBHelper.getInstance(Warply.getWarplyContext()).getAuthValue("access_token")); | ||
603 | + jsonParams.put("client_id", WarplyDBHelper.getInstance(Warply.getWarplyContext()).getClientValue("client_id")); | ||
604 | + jsonParams.put("client_secret", WarplyDBHelper.getInstance(Warply.getWarplyContext()).getClientValue("client_secret")); | ||
605 | + } | ||
600 | 606 | ||
601 | RequestBody loginRequest = RequestBody.create(MediaType.get("application/json; charset=utf-8"), (new JSONObject(jsonParams)).toString()); | 607 | RequestBody loginRequest = RequestBody.create(MediaType.get("application/json; charset=utf-8"), (new JSONObject(jsonParams)).toString()); |
602 | 608 | ||
603 | - Call<ResponseBody> logoutCall = service.logoutUser( | 609 | + Call<ResponseBody> logoutCall = WarpUtils.isJWTEnabled(Warply.getWarplyContext()) ? |
610 | + service.logoutUserJwt( | ||
611 | + WarplyProperty.getAppUuid(Warply.getWarplyContext()), | ||
612 | + loginRequest, | ||
613 | + timeStamp, | ||
614 | + "android:" + Warply.getWarplyContext().getPackageName(), | ||
615 | + new WarplyDeviceInfoCollector(Warply.getWarplyContext()).getUniqueDeviceId(), | ||
616 | + "mobile", | ||
617 | + webId, | ||
618 | + WarpUtils.produceSignature(apiKey + timeStamp) | ||
619 | + ) | ||
620 | + : | ||
621 | + service.logoutUser( | ||
604 | WarplyProperty.getAppUuid(Warply.getWarplyContext()), | 622 | WarplyProperty.getAppUuid(Warply.getWarplyContext()), |
605 | loginRequest, | 623 | loginRequest, |
606 | timeStamp, | 624 | timeStamp, | ... | ... |
This diff is collapsed. Click to expand it.
... | @@ -213,6 +213,7 @@ | ... | @@ -213,6 +213,7 @@ |
213 | <string name="lbl_take_photo_decline">Άκυρο</string> | 213 | <string name="lbl_take_photo_decline">Άκυρο</string> |
214 | <string name="lbl_gps_enabled">Θέλετε να ενεργοποιήσετε το GPS;</string> | 214 | <string name="lbl_gps_enabled">Θέλετε να ενεργοποιήσετε το GPS;</string> |
215 | <string name="cos_telematics">Safe Driving</string> | 215 | <string name="cos_telematics">Safe Driving</string> |
216 | + <string name="cos_hint">GUID</string> | ||
216 | <string name="cos_telematics_metrics">Ανάλυση</string> | 217 | <string name="cos_telematics_metrics">Ανάλυση</string> |
217 | <string name="cos_dlg_start_trip">Έναρξη</string> | 218 | <string name="cos_dlg_start_trip">Έναρξη</string> |
218 | <string name="cos_dlg_stop_trip">Παύση</string> | 219 | <string name="cos_dlg_stop_trip">Παύση</string> |
... | @@ -244,6 +245,8 @@ | ... | @@ -244,6 +245,8 @@ |
244 | <string name="cos_vouchers_info_title_disabled">Διαθέσιμο υπόλοιπο</string> | 245 | <string name="cos_vouchers_info_title_disabled">Διαθέσιμο υπόλοιπο</string> |
245 | <string name="cos_vouchers_info_title_disabled_en">Available balance</string> | 246 | <string name="cos_vouchers_info_title_disabled_en">Available balance</string> |
246 | <string name="cos_coupons_header">Κουπόνια</string> | 247 | <string name="cos_coupons_header">Κουπόνια</string> |
248 | + <string name="cos_login_text">Σύνδεση</string> | ||
249 | + <string name="cos_logout_text">Αποσύνδεση</string> | ||
247 | 250 | ||
248 | <string-array name="coupons_array"> | 251 | <string-array name="coupons_array"> |
249 | <item>Κουπόνια</item> | 252 | <item>Κουπόνια</item> | ... | ... |
-
Please register or login to post a comment