From 02a697031f9fa315b9648a0182bf963ce2da4e2e Mon Sep 17 00:00:00 2001 From: len Date: Sat, 28 May 2016 19:10:09 +0200 Subject: [PATCH] Chapters FAB doesn't depend on the recognized chapter number. Cloudflare resolver fix --- .../tachiyomi/data/database/models/Manga.java | 8 ++--- .../data/network/CloudflareInterceptor.kt | 2 +- .../ui/manga/chapter/ChaptersFragment.kt | 2 +- .../ui/manga/chapter/ChaptersPresenter.kt | 33 ++++++++----------- 4 files changed, 20 insertions(+), 25 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/database/models/Manga.java b/app/src/main/java/eu/kanade/tachiyomi/data/database/models/Manga.java index f9afa3bba7..7068a42259 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/database/models/Manga.java +++ b/app/src/main/java/eu/kanade/tachiyomi/data/database/models/Manga.java @@ -68,8 +68,8 @@ public class Manga implements Serializable { public static final int COMPLETED = 2; public static final int LICENSED = 3; - public static final int SORT_AZ = 0x00000000; - public static final int SORT_ZA = 0x00000001; + public static final int SORT_DESC = 0x00000000; + public static final int SORT_ASC = 0x00000001; public static final int SORT_MASK = 0x00000001; // Generic filter that does not filter anything @@ -174,8 +174,8 @@ public class Manga implements Serializable { chapter_flags = (chapter_flags & ~mask) | (flag & mask); } - public boolean sortChaptersAZ() { - return (chapter_flags & SORT_MASK) == SORT_AZ; + public boolean sortDescending() { + return (chapter_flags & SORT_MASK) == SORT_DESC; } // Used to display the chapter's title one way or another diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/network/CloudflareInterceptor.kt b/app/src/main/java/eu/kanade/tachiyomi/data/network/CloudflareInterceptor.kt index 0ff0ea567c..be7926f33e 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/network/CloudflareInterceptor.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/network/CloudflareInterceptor.kt @@ -21,7 +21,7 @@ class CloudflareInterceptor(private val cookies: PersistentCookieStore) : Interc val response = chain.proceed(chain.request()) // Check if we already solved a challenge - if (response.code() != 502 && + if (response.code() != 503 && cookies.get(response.request().url()).any { it.name() == "cf_clearance" }) { return response } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersFragment.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersFragment.kt index ddd107e051..fb7329cf73 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersFragment.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersFragment.kt @@ -255,7 +255,7 @@ class ChaptersFragment : BaseRxFragment(), ActionMode.Callbac } } if (chapters.size > 0) { - if (!presenter.sortOrder()) { + if (!presenter.sortDescending()) { chapters.reverse() } when (i) { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersPresenter.kt index 9c5b9e4221..d6b71aa032 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersPresenter.kt @@ -123,23 +123,18 @@ class ChaptersPresenter : BasePresenter() { if (onlyDownloaded()) { observable = observable.filter { chapter -> chapter.status == Download.DOWNLOADED } } - return observable.toSortedList { chapter1, chapter2 -> - when (manga.sorting) { - Manga.SORTING_NUMBER -> { - if (sortOrder()) - chapter2.chapter_number.compareTo(chapter1.chapter_number) - else - chapter1.chapter_number.compareTo(chapter2.chapter_number) - } - Manga.SORTING_SOURCE -> { - if (sortOrder()) - chapter1.source_order.compareTo(chapter2.source_order) - else - chapter2.source_order.compareTo(chapter1.source_order) - } - else -> throw AssertionError("Unknown sorting method") + val sortFunction: (Chapter, Chapter) -> Int = when (manga.sorting) { + Manga.SORTING_SOURCE -> when (sortDescending()) { + true -> { c1, c2 -> c1.source_order.compareTo(c2.source_order) } + false -> { c1, c2 -> c2.source_order.compareTo(c1.source_order) } } + Manga.SORTING_NUMBER -> when (sortDescending()) { + true -> { c1, c2 -> c2.chapter_number.compareTo(c1.chapter_number) } + false -> { c1, c2 -> c1.chapter_number.compareTo(c2.chapter_number) } + } + else -> throw NotImplementedError("Unimplemented sorting method") } + return observable.toSortedList(sortFunction) } private fun setChapterStatus(chapter: Chapter) { @@ -169,7 +164,7 @@ class ChaptersPresenter : BasePresenter() { } fun getNextUnreadChapter(): Chapter? { - return db.getNextUnreadChapter(manga).executeAsBlocking() + return chapters.sortedByDescending { it.source_order }.find { !it.read } } fun markChaptersRead(selectedChapters: List, read: Boolean) { @@ -228,7 +223,7 @@ class ChaptersPresenter : BasePresenter() { } fun revertSortOrder() { - manga.setChapterOrder(if (sortOrder()) Manga.SORT_ZA else Manga.SORT_AZ) + manga.setChapterOrder(if (sortDescending()) Manga.SORT_ASC else Manga.SORT_DESC) db.insertManga(manga).executeAsBlocking() refreshChapters() } @@ -264,8 +259,8 @@ class ChaptersPresenter : BasePresenter() { return manga.readFilter == Manga.SHOW_UNREAD } - fun sortOrder(): Boolean { - return manga.sortChaptersAZ() + fun sortDescending(): Boolean { + return manga.sortDescending() } }