From 5dcaeffa0ba23a032ae0ac7a2ba7f17689b0f3bf Mon Sep 17 00:00:00 2001 From: inorichi Date: Sat, 28 Nov 2015 19:01:26 +0100 Subject: [PATCH] Fix an issue where the next chapter was the same as the current. Fix a NPE when page list throws --- .../mangafeed/data/database/DatabaseHelper.java | 12 ++++++++++-- .../kanade/mangafeed/ui/reader/ReaderActivity.java | 6 ++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/eu/kanade/mangafeed/data/database/DatabaseHelper.java b/app/src/main/java/eu/kanade/mangafeed/data/database/DatabaseHelper.java index 54d4ff1cd0..b05e3c7920 100644 --- a/app/src/main/java/eu/kanade/mangafeed/data/database/DatabaseHelper.java +++ b/app/src/main/java/eu/kanade/mangafeed/data/database/DatabaseHelper.java @@ -188,6 +188,10 @@ public class DatabaseHelper { } public PreparedGetListOfObjects getNextChapter(Chapter chapter) { + // Add a delta to the chapter number, because binary decimal representation + // can retrieve the same chapter again + double chapterNumber = chapter.chapter_number + 0.00001; + return db.get() .listOfObjects(Chapter.class) .withQuery(Query.builder() @@ -195,7 +199,7 @@ public class DatabaseHelper { .where(ChapterTable.COLUMN_MANGA_ID + "=? AND " + ChapterTable.COLUMN_CHAPTER_NUMBER + ">? AND " + ChapterTable.COLUMN_CHAPTER_NUMBER + "<=?") - .whereArgs(chapter.manga_id, chapter.chapter_number, chapter.chapter_number + 1) + .whereArgs(chapter.manga_id, chapterNumber, chapterNumber + 1) .orderBy(ChapterTable.COLUMN_CHAPTER_NUMBER) .limit(1) .build()) @@ -203,6 +207,10 @@ public class DatabaseHelper { } public PreparedGetListOfObjects getPreviousChapter(Chapter chapter) { + // Add a delta to the chapter number, because binary decimal representation + // can retrieve the same chapter again + double chapterNumber = chapter.chapter_number - 0.00001; + return db.get() .listOfObjects(Chapter.class) .withQuery(Query.builder() @@ -210,7 +218,7 @@ public class DatabaseHelper { .where(ChapterTable.COLUMN_MANGA_ID + "=? AND " + ChapterTable.COLUMN_CHAPTER_NUMBER + "=?") - .whereArgs(chapter.manga_id, chapter.chapter_number, chapter.chapter_number - 1) + .whereArgs(chapter.manga_id, chapterNumber, chapterNumber - 1) .orderBy(ChapterTable.COLUMN_CHAPTER_NUMBER + " DESC") .limit(1) .build()) diff --git a/app/src/main/java/eu/kanade/mangafeed/ui/reader/ReaderActivity.java b/app/src/main/java/eu/kanade/mangafeed/ui/reader/ReaderActivity.java index acfa8f21e0..9a9c84331d 100644 --- a/app/src/main/java/eu/kanade/mangafeed/ui/reader/ReaderActivity.java +++ b/app/src/main/java/eu/kanade/mangafeed/ui/reader/ReaderActivity.java @@ -85,7 +85,8 @@ public class ReaderActivity extends BaseRxActivity { @Override protected void onDestroy() { readerMenu.destroy(); - viewer.destroy(); + if (viewer != null) + viewer.destroy(); super.onDestroy(); } @@ -97,7 +98,8 @@ public class ReaderActivity extends BaseRxActivity { @Override protected void onPause() { - getPresenter().setCurrentPage(viewer.getCurrentPosition()); + if (viewer != null) + getPresenter().setCurrentPage(viewer.getCurrentPosition()); super.onPause(); }