From c376702b53fb38b8d6f20835201203b85b7f1efa Mon Sep 17 00:00:00 2001 From: Maxime Biais Date: Wed, 18 Nov 2015 12:04:18 +0100 Subject: [PATCH 1/2] Use long instead of int for note ids Note: sqlite "int" type is 64bits. This is a quick and dirty fix. A better fix: replace int ids with String ids, but in that case a change in the DB table is necessary and that would be too complex to manage several DB histories. --- src/org/wordpress/android/WordPressDB.java | 2 +- .../ui/notifications/NotificationsActivity.java | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/org/wordpress/android/WordPressDB.java b/src/org/wordpress/android/WordPressDB.java index adc10159d962..7f474ab77d90 100644 --- a/src/org/wordpress/android/WordPressDB.java +++ b/src/org/wordpress/android/WordPressDB.java @@ -1785,7 +1785,7 @@ public void saveNotes(List notes, boolean clearBeforeSaving) { } } - public Note getNoteById(int id) { + public Note getNoteById(long id) { Cursor cursor = db.query(NOTES_TABLE, new String[] {"raw_note_data"}, "id=" + id, null, null, null, null); cursor.moveToFirst(); diff --git a/src/org/wordpress/android/ui/notifications/NotificationsActivity.java b/src/org/wordpress/android/ui/notifications/NotificationsActivity.java index e94de3772c1c..7361a76760e8 100644 --- a/src/org/wordpress/android/ui/notifications/NotificationsActivity.java +++ b/src/org/wordpress/android/ui/notifications/NotificationsActivity.java @@ -59,7 +59,7 @@ public class NotificationsActivity extends WPActionBarActivity private static final String KEY_SELECTED_COMMENT_ID = "selected_comment_id"; private static final String KEY_SELECTED_POST_ID = "selected_post_id"; - private static final int UNSPECIFIED_NOTE_ID = -1; + private static final long UNSPECIFIED_NOTE_ID = -1; private NotificationsListFragment mNotesList; private boolean mLoadingMore = false; @@ -110,7 +110,7 @@ public void onCreate(Bundle savedInstanceState) { private void restoreSavedInstance(final Bundle savedInstanceState) { if (savedInstanceState != null) { mHasPerformedInitialUpdate = savedInstanceState.getBoolean(KEY_INITIAL_UPDATE); - int noteId = savedInstanceState.getInt(NOTE_ID_EXTRA, UNSPECIFIED_NOTE_ID); + long noteId = savedInstanceState.getLong(NOTE_ID_EXTRA, UNSPECIFIED_NOTE_ID); LoadNotesCallback notesLoadedCallback = new LoadNotesCallback() { @Override @@ -143,7 +143,7 @@ public void notesLoaded() { } } - private void loadNotes(final boolean launchWithNoteId, final int noteId, final LoadNotesCallback callback) { + private void loadNotes(final boolean launchWithNoteId, final long noteId, final LoadNotesCallback callback) { new Thread() { @Override public void run() { @@ -226,11 +226,11 @@ public void onBackStackChanged() { /** * Detect if Intent has a noteId extra and display that specific note detail fragment */ - private void launchWithNoteId(int noteId) { + private void launchWithNoteId(long noteId) { final Intent intent = getIntent(); if (noteId == UNSPECIFIED_NOTE_ID) { if (intent.hasExtra(NOTE_ID_EXTRA)) { - noteId = Integer.valueOf(intent.getStringExtra(NOTE_ID_EXTRA)); + noteId = Long.valueOf(intent.getStringExtra(NOTE_ID_EXTRA)); } } if (noteId != UNSPECIFIED_NOTE_ID) { @@ -240,7 +240,7 @@ private void launchWithNoteId(int noteId) { } else { // find it/load it etc Map params = new HashMap(); - params.put("ids", Integer.toString(noteId)); + params.put("ids", Long.toString(noteId)); NotesResponseHandler handler = new NotesResponseHandler() { @Override public void onNotes(List notes) { From 164222b5fb9ff74daa791b62d0d9144ef4e50533 Mon Sep 17 00:00:00 2001 From: Maxime Biais Date: Wed, 18 Nov 2015 12:11:30 +0100 Subject: [PATCH 2/2] int2long on mSelectedNoteId --- .../ui/notifications/NotificationsActivity.java | 8 ++++---- src/org/wordpress/android/util/StringUtils.java | 15 ++++++++++++++- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/org/wordpress/android/ui/notifications/NotificationsActivity.java b/src/org/wordpress/android/ui/notifications/NotificationsActivity.java index 7361a76760e8..0a407776087f 100644 --- a/src/org/wordpress/android/ui/notifications/NotificationsActivity.java +++ b/src/org/wordpress/android/ui/notifications/NotificationsActivity.java @@ -66,7 +66,7 @@ public class NotificationsActivity extends WPActionBarActivity private boolean mFirstLoadComplete = false; private BroadcastReceiver mBroadcastReceiver; private boolean mDualPane; - private int mSelectedNoteId; + private long mSelectedNoteId; private boolean mHasPerformedInitialUpdate; private BlogPairId mTmpSelectedComment; private BlogPairId mTmpSelectedReaderPost; @@ -364,8 +364,8 @@ private void openNote(final Note note, boolean scrollToNote) { if (note == null || isFinishing() || isActivityDestroyed()) { return; } - - mSelectedNoteId = StringUtils.stringToInt(note.getId()); + + mSelectedNoteId = StringUtils.stringToLong(note.getId()); mNotesList.setNoteSelected(note, scrollToNote); // mark the note as read if it's unread @@ -587,7 +587,7 @@ public void onSaveInstanceState(Bundle outState) { outState.putBoolean("bug_19917_fix", true); } outState.putBoolean(KEY_INITIAL_UPDATE, mHasPerformedInitialUpdate); - outState.putInt(NOTE_ID_EXTRA, mSelectedNoteId); + outState.putLong(NOTE_ID_EXTRA, mSelectedNoteId); if (mSelectedReaderPost != null) { outState.putSerializable(KEY_SELECTED_POST_ID, mSelectedReaderPost); } diff --git a/src/org/wordpress/android/util/StringUtils.java b/src/org/wordpress/android/util/StringUtils.java index 562c560c3132..5e4804af9dc4 100644 --- a/src/org/wordpress/android/util/StringUtils.java +++ b/src/org/wordpress/android/util/StringUtils.java @@ -277,4 +277,17 @@ public static int stringToInt(String s, int defaultValue) { return defaultValue; } } -} \ No newline at end of file + + public static long stringToLong(String s) { + return stringToLong(s, 0); + } + public static long stringToLong(String s, long defaultValue) { + if (s == null) + return defaultValue; + try { + return Long.valueOf(s); + } catch (NumberFormatException e) { + return defaultValue; + } + } +}