Showing
3 changed files
with
87 additions
and
15 deletions
... | @@ -5,7 +5,7 @@ android.buildFeatures.buildConfig = true | ... | @@ -5,7 +5,7 @@ android.buildFeatures.buildConfig = true |
5 | 5 | ||
6 | ext { | 6 | ext { |
7 | PUBLISH_GROUP_ID = 'ly.warp' | 7 | PUBLISH_GROUP_ID = 'ly.warp' |
8 | - PUBLISH_VERSION = '4.5.5.4m5' | 8 | + PUBLISH_VERSION = '4.5.5.4m6' |
9 | PUBLISH_ARTIFACT_ID = 'warply-android-sdk' | 9 | PUBLISH_ARTIFACT_ID = 'warply-android-sdk' |
10 | } | 10 | } |
11 | 11 | ... | ... |
... | @@ -151,8 +151,8 @@ public enum Warply { | ... | @@ -151,8 +151,8 @@ public enum Warply { |
151 | private static void initInternal(Context context, boolean isNew) { | 151 | private static void initInternal(Context context, boolean isNew) { |
152 | if (context != null) { | 152 | if (context != null) { |
153 | INSTANCE.check(context); | 153 | INSTANCE.check(context); |
154 | - if (INSTANCE.mRequestQueue == null) | 154 | +// if (INSTANCE.mRequestQueue == null) |
155 | - INSTANCE.mRequestQueue = Volley.newRequestQueue(context); | 155 | + INSTANCE.mRequestQueue = Volley.newRequestQueue(context); |
156 | INSTANCE.mContext = context.getApplicationContext(); | 156 | INSTANCE.mContext = context.getApplicationContext(); |
157 | WarpConstants.DEBUG = WarplyProperty.isDebugMode(INSTANCE.mContext); | 157 | WarpConstants.DEBUG = WarplyProperty.isDebugMode(INSTANCE.mContext); |
158 | INSTANCE.isInitializedOrThrow(); | 158 | INSTANCE.isInitializedOrThrow(); |
... | @@ -1031,6 +1031,9 @@ public enum Warply { | ... | @@ -1031,6 +1031,9 @@ public enum Warply { |
1031 | WarpUtils.log("**********************************************************"); | 1031 | WarpUtils.log("**********************************************************"); |
1032 | WarplyJsonObjectRequest request = new WarplyJsonObjectRequest(method, url, data, vt, vt); | 1032 | WarplyJsonObjectRequest request = new WarplyJsonObjectRequest(method, url, data, vt, vt); |
1033 | request.setTag(tag); | 1033 | request.setTag(tag); |
1034 | + if (mRequestQueue == null) { | ||
1035 | + mRequestQueue = Volley.newRequestQueue(mContext); | ||
1036 | + } | ||
1034 | mRequestQueue.add(request); | 1037 | mRequestQueue.add(request); |
1035 | } | 1038 | } |
1036 | 1039 | ... | ... |
... | @@ -212,6 +212,12 @@ public class WarplyDBHelper extends SQLiteOpenHelper { | ... | @@ -212,6 +212,12 @@ public class WarplyDBHelper extends SQLiteOpenHelper { |
212 | return mDb; | 212 | return mDb; |
213 | } | 213 | } |
214 | 214 | ||
215 | + private SQLiteDatabase getReadableDbInner() { | ||
216 | + if (mDb == null) | ||
217 | + mDb = getReadableDatabase(KEY_CIPHER); | ||
218 | + return mDb; | ||
219 | + } | ||
220 | + | ||
215 | /** | 221 | /** |
216 | * Close database connection - should only be called when app is being destroyed | 222 | * Close database connection - should only be called when app is being destroyed |
217 | * or when database won't be used for a long time | 223 | * or when database won't be used for a long time |
... | @@ -439,6 +445,7 @@ public class WarplyDBHelper extends SQLiteOpenHelper { | ... | @@ -439,6 +445,7 @@ public class WarplyDBHelper extends SQLiteOpenHelper { |
439 | } | 445 | } |
440 | 446 | ||
441 | //------------------------------ Api requests -----------------------------// | 447 | //------------------------------ Api requests -----------------------------// |
448 | + | ||
442 | /** | 449 | /** |
443 | * Gets all requests from the database. | 450 | * Gets all requests from the database. |
444 | * NOTE: The caller is responsible for closing the returned Cursor when done with it. | 451 | * NOTE: The caller is responsible for closing the returned Cursor when done with it. |
... | @@ -518,24 +525,86 @@ public class WarplyDBHelper extends SQLiteOpenHelper { | ... | @@ -518,24 +525,86 @@ public class WarplyDBHelper extends SQLiteOpenHelper { |
518 | } | 525 | } |
519 | 526 | ||
520 | public synchronized long getRequestsInQueueCount() { | 527 | public synchronized long getRequestsInQueueCount() { |
521 | - SQLiteDatabase db = getReadableDb(); | 528 | + SQLiteDatabase db = getReadableDbInner(); |
522 | - long count = DatabaseUtils.queryNumEntries(db, TABLE_REQUESTS); | 529 | + if (db == null) { |
523 | - // Don't close the database here to improve performance | 530 | + Log.e("WarplyDBHelper", "Database is null in getRequestsInQueueCount()"); |
524 | - return count; | 531 | + return 0; |
532 | + } | ||
533 | +// long count = DatabaseUtils.queryNumEntries(db, TABLE_REQUESTS); | ||
534 | +// // Don't close the database here to improve performance | ||
535 | +// return count; | ||
536 | + | ||
537 | + | ||
538 | + | ||
539 | + Cursor cursor = null; | ||
540 | + try { | ||
541 | + cursor = db.rawQuery("SELECT COUNT(*) FROM " + TABLE_REQUESTS, null); | ||
542 | + if (cursor != null && cursor.moveToFirst()) { | ||
543 | + return cursor.getLong(0); | ||
544 | + } | ||
545 | + return 0; | ||
546 | + } catch (Exception e) { | ||
547 | + Log.e("WarplyDBHelper", "Error counting getRequestsInQueueCount", e); | ||
548 | + return 0; | ||
549 | + } finally { | ||
550 | + if (cursor != null) { | ||
551 | + cursor.close(); | ||
552 | + } | ||
553 | + } | ||
525 | } | 554 | } |
526 | 555 | ||
527 | public synchronized long getPushRequestsInQueueCount() { | 556 | public synchronized long getPushRequestsInQueueCount() { |
528 | - SQLiteDatabase db = getReadableDb(); | 557 | + SQLiteDatabase db = getReadableDbInner(); |
529 | - long count = DatabaseUtils.queryNumEntries(db, TABLE_PUSH_REQUESTS); | 558 | + if (db == null) { |
530 | - // Don't close the database here to improve performance | 559 | + Log.e("WarplyDBHelper", "Database is null in getPushRequestsInQueueCount()"); |
531 | - return count; | 560 | + return 0; |
561 | + } | ||
562 | +// long count = DatabaseUtils.queryNumEntries(db, TABLE_PUSH_REQUESTS); | ||
563 | +// // Don't close the database here to improve performance | ||
564 | +// return count; | ||
565 | + | ||
566 | + Cursor cursor = null; | ||
567 | + try { | ||
568 | + cursor = db.rawQuery("SELECT COUNT(*) FROM " + TABLE_PUSH_REQUESTS, null); | ||
569 | + if (cursor != null && cursor.moveToFirst()) { | ||
570 | + return cursor.getLong(0); | ||
571 | + } | ||
572 | + return 0; | ||
573 | + } catch (Exception e) { | ||
574 | + Log.e("WarplyDBHelper", "Error counting getPushRequestsInQueueCount", e); | ||
575 | + return 0; | ||
576 | + } finally { | ||
577 | + if (cursor != null) { | ||
578 | + cursor.close(); | ||
579 | + } | ||
580 | + } | ||
532 | } | 581 | } |
533 | 582 | ||
534 | public synchronized long getPushAckRequestsInQueueCount() { | 583 | public synchronized long getPushAckRequestsInQueueCount() { |
535 | - SQLiteDatabase db = getReadableDb(); | 584 | + SQLiteDatabase db = getReadableDbInner(); |
536 | - long count = DatabaseUtils.queryNumEntries(db, TABLE_PUSH_ACK_REQUESTS); | 585 | + if (db == null) { |
537 | - // Don't close the database here to improve performance | 586 | + Log.e("WarplyDBHelper", "Database is null in getPushAckRequestsInQueueCount()"); |
538 | - return count; | 587 | + return 0; |
588 | + } | ||
589 | +// long count = DatabaseUtils.queryNumEntries(db, TABLE_PUSH_ACK_REQUESTS); | ||
590 | +// // Don't close the database here to improve performance | ||
591 | +// return count; | ||
592 | + | ||
593 | + Cursor cursor = null; | ||
594 | + try { | ||
595 | + cursor = db.rawQuery("SELECT COUNT(*) FROM " + TABLE_PUSH_ACK_REQUESTS, null); | ||
596 | + if (cursor != null && cursor.moveToFirst()) { | ||
597 | + return cursor.getLong(0); | ||
598 | + } | ||
599 | + return 0; | ||
600 | + } catch (Exception e) { | ||
601 | + Log.e("WarplyDBHelper", "Error counting getPushAckRequestsInQueueCount", e); | ||
602 | + return 0; | ||
603 | + } finally { | ||
604 | + if (cursor != null) { | ||
605 | + cursor.close(); | ||
606 | + } | ||
607 | + } | ||
539 | } | 608 | } |
540 | 609 | ||
541 | public synchronized void deleteRequests(Long... ids) { | 610 | public synchronized void deleteRequests(Long... ids) { | ... | ... |
-
Please register or login to post a comment