Showing
1 changed file
with
64 additions
and
100 deletions
| ... | @@ -35,7 +35,7 @@ public class WarplyDBHelper extends SQLiteOpenHelper { | ... | @@ -35,7 +35,7 @@ public class WarplyDBHelper extends SQLiteOpenHelper { | 
| 35 | } | 35 | } | 
| 36 | 36 | ||
| 37 | private static final String DB_NAME = "warply.db"; | 37 | private static final String DB_NAME = "warply.db"; | 
| 38 | - private static final int DB_VERSION = 6; | 38 | + private static final int DB_VERSION = 7; | 
| 39 | private static final String KEY_CIPHER = "tn#mpOl3v3Dy1pr@W"; | 39 | private static final String KEY_CIPHER = "tn#mpOl3v3Dy1pr@W"; | 
| 40 | 40 | ||
| 41 | //------------------------------ Fields -----------------------------// | 41 | //------------------------------ Fields -----------------------------// | 
| ... | @@ -222,15 +222,10 @@ public class WarplyDBHelper extends SQLiteOpenHelper { | ... | @@ -222,15 +222,10 @@ public class WarplyDBHelper extends SQLiteOpenHelper { | 
| 222 | values.put(KEY_CLIENT_ID, clientId); | 222 | values.put(KEY_CLIENT_ID, clientId); | 
| 223 | if (!TextUtils.isEmpty(clientSecret)) | 223 | if (!TextUtils.isEmpty(clientSecret)) | 
| 224 | values.put(KEY_CLIENT_SECRET, clientSecret); | 224 | values.put(KEY_CLIENT_SECRET, clientSecret); | 
| 225 | - if (isTableNotEmpty(TABLE_CLIENT)) { | 225 | + if (isTableNotEmpty(TABLE_CLIENT)) | 
| 226 | - new Thread(() -> { | 226 | + update(TABLE_CLIENT, values); | 
| 227 | - update(TABLE_CLIENT, values); | 227 | + else | 
| 228 | - }).start(); | 228 | + insert(TABLE_CLIENT, values); | 
| 229 | - } else { | ||
| 230 | - new Thread(() -> { | ||
| 231 | - insert(TABLE_CLIENT, values); | ||
| 232 | - }).start(); | ||
| 233 | - } | ||
| 234 | } | 229 | } | 
| 235 | 230 | ||
| 236 | public synchronized void saveAuthAccess(String accessToken, String refreshToken) { | 231 | public synchronized void saveAuthAccess(String accessToken, String refreshToken) { | 
| ... | @@ -239,15 +234,10 @@ public class WarplyDBHelper extends SQLiteOpenHelper { | ... | @@ -239,15 +234,10 @@ public class WarplyDBHelper extends SQLiteOpenHelper { | 
| 239 | values.put(KEY_ACCESS_TOKEN, accessToken); | 234 | values.put(KEY_ACCESS_TOKEN, accessToken); | 
| 240 | if (!TextUtils.isEmpty(refreshToken)) | 235 | if (!TextUtils.isEmpty(refreshToken)) | 
| 241 | values.put(KEY_REFRESH_TOKEN, refreshToken); | 236 | values.put(KEY_REFRESH_TOKEN, refreshToken); | 
| 242 | - if (isTableNotEmpty(TABLE_AUTH)) { | 237 | + if (isTableNotEmpty(TABLE_AUTH)) | 
| 243 | - new Thread(() -> { | 238 | + update(TABLE_AUTH, values); | 
| 244 | - update(TABLE_AUTH, values); | 239 | + else | 
| 245 | - }).start(); | 240 | + insert(TABLE_AUTH, values); | 
| 246 | - } else { | ||
| 247 | - new Thread(() -> { | ||
| 248 | - insert(TABLE_AUTH, values); | ||
| 249 | - }).start(); | ||
| 250 | - } | ||
| 251 | } | 241 | } | 
| 252 | 242 | ||
| 253 | @Nullable | 243 | @Nullable | 
| ... | @@ -275,15 +265,11 @@ public class WarplyDBHelper extends SQLiteOpenHelper { | ... | @@ -275,15 +265,11 @@ public class WarplyDBHelper extends SQLiteOpenHelper { | 
| 275 | } | 265 | } | 
| 276 | 266 | ||
| 277 | public synchronized void deleteClient() { | 267 | public synchronized void deleteClient() { | 
| 278 | - new Thread(() -> { | 268 | + clearTable(TABLE_CLIENT); | 
| 279 | - clearTable(TABLE_CLIENT); | ||
| 280 | - }).start(); | ||
| 281 | } | 269 | } | 
| 282 | 270 | ||
| 283 | public synchronized void deleteAuth() { | 271 | public synchronized void deleteAuth() { | 
| 284 | - new Thread(() -> { | 272 | + clearTable(TABLE_AUTH); | 
| 285 | - clearTable(TABLE_AUTH); | ||
| 286 | - }).start(); | ||
| 287 | } | 273 | } | 
| 288 | 274 | ||
| 289 | //------------------------------ Api requests -----------------------------// | 275 | //------------------------------ Api requests -----------------------------// | 
| ... | @@ -312,56 +298,44 @@ public class WarplyDBHelper extends SQLiteOpenHelper { | ... | @@ -312,56 +298,44 @@ public class WarplyDBHelper extends SQLiteOpenHelper { | 
| 312 | } | 298 | } | 
| 313 | 299 | ||
| 314 | public synchronized void deleteAllRequests() { | 300 | public synchronized void deleteAllRequests() { | 
| 315 | - new Thread(() -> { | 301 | + clearTable(TABLE_REQUESTS); | 
| 316 | - clearTable(TABLE_REQUESTS); | ||
| 317 | - }).start(); | ||
| 318 | } | 302 | } | 
| 319 | 303 | ||
| 320 | public synchronized void deleteAllPushRequests() { | 304 | public synchronized void deleteAllPushRequests() { | 
| 321 | - new Thread(() -> { | 305 | + clearTable(TABLE_PUSH_REQUESTS); | 
| 322 | - clearTable(TABLE_PUSH_REQUESTS); | ||
| 323 | - }).start(); | ||
| 324 | } | 306 | } | 
| 325 | 307 | ||
| 326 | public synchronized void deleteAllPushAckRequests() { | 308 | public synchronized void deleteAllPushAckRequests() { | 
| 327 | - new Thread(() -> { | 309 | + clearTable(TABLE_PUSH_ACK_REQUESTS); | 
| 328 | - clearTable(TABLE_PUSH_ACK_REQUESTS); | ||
| 329 | - }).start(); | ||
| 330 | } | 310 | } | 
| 331 | 311 | ||
| 332 | public synchronized long addRequest(String microapp, String entity, boolean force) { | 312 | public synchronized long addRequest(String microapp, String entity, boolean force) { | 
| 333 | - new Thread(() -> { | 313 | + ContentValues values = new ContentValues(); | 
| 334 | - ContentValues values = new ContentValues(); | 314 | + values.put(KEY_REQUESTS_MICROAPP, microapp); | 
| 335 | - values.put(KEY_REQUESTS_MICROAPP, microapp); | 315 | + values.put(KEY_REQUESTS_ENTITY, entity); | 
| 336 | - values.put(KEY_REQUESTS_ENTITY, entity); | 316 | + values.put(KEY_REQUESTS_FORCE, force ? 1 : 0); | 
| 337 | - values.put(KEY_REQUESTS_FORCE, force ? 1 : 0); | 317 | + values.put(KEY_REQUESTS_DATE_ADDED, System.currentTimeMillis()); | 
| 338 | - values.put(KEY_REQUESTS_DATE_ADDED, System.currentTimeMillis()); | 318 | + insert(TABLE_REQUESTS, values); | 
| 339 | - insert(TABLE_REQUESTS, values); | ||
| 340 | - }).start(); | ||
| 341 | return getRequestsInQueueCount(); | 319 | return getRequestsInQueueCount(); | 
| 342 | } | 320 | } | 
| 343 | 321 | ||
| 344 | public synchronized long addPushRequest(String microapp, String entity, boolean force) { | 322 | public synchronized long addPushRequest(String microapp, String entity, boolean force) { | 
| 345 | - new Thread(() -> { | 323 | + ContentValues values = new ContentValues(); | 
| 346 | - ContentValues values = new ContentValues(); | 324 | + values.put(KEY_REQUESTS_MICROAPP, microapp); | 
| 347 | - values.put(KEY_REQUESTS_MICROAPP, microapp); | 325 | + values.put(KEY_REQUESTS_ENTITY, entity); | 
| 348 | - values.put(KEY_REQUESTS_ENTITY, entity); | 326 | + values.put(KEY_REQUESTS_FORCE, force ? 1 : 0); | 
| 349 | - values.put(KEY_REQUESTS_FORCE, force ? 1 : 0); | 327 | + values.put(KEY_REQUESTS_DATE_ADDED, System.currentTimeMillis()); | 
| 350 | - values.put(KEY_REQUESTS_DATE_ADDED, System.currentTimeMillis()); | 328 | + insert(TABLE_PUSH_REQUESTS, values); | 
| 351 | - insert(TABLE_PUSH_REQUESTS, values); | ||
| 352 | - }).start(); | ||
| 353 | return getPushRequestsInQueueCount(); | 329 | return getPushRequestsInQueueCount(); | 
| 354 | } | 330 | } | 
| 355 | 331 | ||
| 356 | public synchronized long addPushAckRequest(String microapp, String entity, boolean force) { | 332 | public synchronized long addPushAckRequest(String microapp, String entity, boolean force) { | 
| 357 | - new Thread(() -> { | 333 | + ContentValues values = new ContentValues(); | 
| 358 | - ContentValues values = new ContentValues(); | 334 | + values.put(KEY_REQUESTS_MICROAPP, microapp); | 
| 359 | - values.put(KEY_REQUESTS_MICROAPP, microapp); | 335 | + values.put(KEY_REQUESTS_ENTITY, entity); | 
| 360 | - values.put(KEY_REQUESTS_ENTITY, entity); | 336 | + values.put(KEY_REQUESTS_FORCE, force ? 1 : 0); | 
| 361 | - values.put(KEY_REQUESTS_FORCE, force ? 1 : 0); | 337 | + values.put(KEY_REQUESTS_DATE_ADDED, System.currentTimeMillis()); | 
| 362 | - values.put(KEY_REQUESTS_DATE_ADDED, System.currentTimeMillis()); | 338 | + insert(TABLE_PUSH_ACK_REQUESTS, values); | 
| 363 | - insert(TABLE_PUSH_ACK_REQUESTS, values); | ||
| 364 | - }).start(); | ||
| 365 | return getPushAckRequestsInQueueCount(); | 339 | return getPushAckRequestsInQueueCount(); | 
| 366 | } | 340 | } | 
| 367 | 341 | ||
| ... | @@ -388,9 +362,7 @@ public class WarplyDBHelper extends SQLiteOpenHelper { | ... | @@ -388,9 +362,7 @@ public class WarplyDBHelper extends SQLiteOpenHelper { | 
| 388 | strFilter.append("="); | 362 | strFilter.append("="); | 
| 389 | strFilter.append(ids[i]); | 363 | strFilter.append(ids[i]); | 
| 390 | } | 364 | } | 
| 391 | - new Thread(() -> { | 365 | + getDb().delete(TABLE_REQUESTS, strFilter.toString(), null); | 
| 392 | - getDb().delete(TABLE_REQUESTS, strFilter.toString(), null); | ||
| 393 | - }).start(); | ||
| 394 | } | 366 | } | 
| 395 | 367 | ||
| 396 | public synchronized void deletePushRequests(Long... ids) { | 368 | public synchronized void deletePushRequests(Long... ids) { | 
| ... | @@ -404,9 +376,7 @@ public class WarplyDBHelper extends SQLiteOpenHelper { | ... | @@ -404,9 +376,7 @@ public class WarplyDBHelper extends SQLiteOpenHelper { | 
| 404 | strFilter.append("="); | 376 | strFilter.append("="); | 
| 405 | strFilter.append(ids[i]); | 377 | strFilter.append(ids[i]); | 
| 406 | } | 378 | } | 
| 407 | - new Thread(() -> { | 379 | + getDb().delete(TABLE_PUSH_REQUESTS, strFilter.toString(), null); | 
| 408 | - getDb().delete(TABLE_PUSH_REQUESTS, strFilter.toString(), null); | ||
| 409 | - }).start(); | ||
| 410 | } | 380 | } | 
| 411 | 381 | ||
| 412 | public synchronized void deletePushAckRequests(Long... ids) { | 382 | public synchronized void deletePushAckRequests(Long... ids) { | 
| ... | @@ -420,9 +390,7 @@ public class WarplyDBHelper extends SQLiteOpenHelper { | ... | @@ -420,9 +390,7 @@ public class WarplyDBHelper extends SQLiteOpenHelper { | 
| 420 | strFilter.append("="); | 390 | strFilter.append("="); | 
| 421 | strFilter.append(ids[i]); | 391 | strFilter.append(ids[i]); | 
| 422 | } | 392 | } | 
| 423 | - new Thread(() -> { | 393 | + getDb().delete(TABLE_PUSH_ACK_REQUESTS, strFilter.toString(), null); | 
| 424 | - getDb().delete(TABLE_PUSH_ACK_REQUESTS, strFilter.toString(), null); | ||
| 425 | - }).start(); | ||
| 426 | } | 394 | } | 
| 427 | 395 | ||
| 428 | public synchronized boolean isForceRequestsExist() { | 396 | public synchronized boolean isForceRequestsExist() { | 
| ... | @@ -460,45 +428,41 @@ public class WarplyDBHelper extends SQLiteOpenHelper { | ... | @@ -460,45 +428,41 @@ public class WarplyDBHelper extends SQLiteOpenHelper { | 
| 460 | 428 | ||
| 461 | //------------------------------ Tags -----------------------------// | 429 | //------------------------------ Tags -----------------------------// | 
| 462 | public synchronized void saveTags(String[] tags) { | 430 | public synchronized void saveTags(String[] tags) { | 
| 463 | - new Thread(() -> { | 431 | + if (tags != null && tags.length > 0) { | 
| 464 | - if (tags != null && tags.length > 0) { | 432 | + | 
| 465 | - | 433 | + try { | 
| 466 | - try { | 434 | + getDb().beginTransaction(); | 
| 467 | - getDb().beginTransaction(); | 435 | + ContentValues values = new ContentValues(); | 
| 468 | - ContentValues values = new ContentValues(); | 436 | + for (String tag : tags) { | 
| 469 | - for (String tag : tags) { | 437 | + values.put(KEY_TAG, tag); | 
| 470 | - values.put(KEY_TAG, tag); | 438 | + values.put(KEY_TAG_LAST_ADD_DATE, System.currentTimeMillis()); | 
| 471 | - values.put(KEY_TAG_LAST_ADD_DATE, System.currentTimeMillis()); | 439 | + insert(TABLE_TAGS, values); | 
| 472 | - insert(TABLE_TAGS, values); | 440 | + } | 
| 473 | - } | 441 | + getDb().setTransactionSuccessful(); | 
| 474 | - getDb().setTransactionSuccessful(); | 442 | + | 
| 475 | - | 443 | + } catch (SQLException e) { | 
| 476 | - } catch (SQLException e) { | 444 | + if (WarpConstants.DEBUG) { | 
| 477 | - if (WarpConstants.DEBUG) { | 445 | + e.printStackTrace(); | 
| 478 | - e.printStackTrace(); | ||
| 479 | - } | ||
| 480 | - } finally { | ||
| 481 | - getDb().endTransaction(); | ||
| 482 | } | 446 | } | 
| 447 | + } finally { | ||
| 448 | + getDb().endTransaction(); | ||
| 483 | } | 449 | } | 
| 484 | - }).start(); | 450 | + } | 
| 485 | } | 451 | } | 
| 486 | 452 | ||
| 487 | public synchronized void removeTags(String[] tags) { | 453 | public synchronized void removeTags(String[] tags) { | 
| 488 | - new Thread(() -> { | 454 | + StringBuilder strFilter = new StringBuilder(); | 
| 489 | - StringBuilder strFilter = new StringBuilder(); | 455 | + for (int i = 0; i < tags.length; i++) { | 
| 490 | - for (int i = 0; i < tags.length; i++) { | 456 | + if (i > 0) { | 
| 491 | - if (i > 0) { | 457 | + strFilter.append(" OR "); | 
| 492 | - strFilter.append(" OR "); | ||
| 493 | - } | ||
| 494 | - strFilter.append(KEY_TAG); | ||
| 495 | - strFilter.append("="); | ||
| 496 | - strFilter.append("'"); | ||
| 497 | - strFilter.append(tags[i]); | ||
| 498 | - strFilter.append("'"); | ||
| 499 | } | 458 | } | 
| 500 | - getDb().delete(TABLE_TAGS, strFilter.toString(), null); | 459 | + strFilter.append(KEY_TAG); | 
| 501 | - }).start(); | 460 | + strFilter.append("="); | 
| 461 | + strFilter.append("'"); | ||
| 462 | + strFilter.append(tags[i]); | ||
| 463 | + strFilter.append("'"); | ||
| 464 | + } | ||
| 465 | + getDb().delete(TABLE_TAGS, strFilter.toString(), null); | ||
| 502 | } | 466 | } | 
| 503 | 467 | ||
| 504 | public synchronized void removeAllTags() { | 468 | public synchronized void removeAllTags() { | ... | ... | 
- 
Please register or login to post a comment