Chapters FAB doesn't depend on the recognized chapter number. Cloudflare resolver fix

This commit is contained in:
len 2016-05-28 19:10:09 +02:00
parent 6beff242b0
commit 02a697031f
4 changed files with 20 additions and 25 deletions

View File

@ -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

View File

@ -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
}

View File

@ -255,7 +255,7 @@ class ChaptersFragment : BaseRxFragment<ChaptersPresenter>(), ActionMode.Callbac
}
}
if (chapters.size > 0) {
if (!presenter.sortOrder()) {
if (!presenter.sortDescending()) {
chapters.reverse()
}
when (i) {

View File

@ -123,23 +123,18 @@ class ChaptersPresenter : BasePresenter<ChaptersFragment>() {
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<ChaptersFragment>() {
}
fun getNextUnreadChapter(): Chapter? {
return db.getNextUnreadChapter(manga).executeAsBlocking()
return chapters.sortedByDescending { it.source_order }.find { !it.read }
}
fun markChaptersRead(selectedChapters: List<Chapter>, read: Boolean) {
@ -228,7 +223,7 @@ class ChaptersPresenter : BasePresenter<ChaptersFragment>() {
}
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<ChaptersFragment>() {
return manga.readFilter == Manga.SHOW_UNREAD
}
fun sortOrder(): Boolean {
return manga.sortChaptersAZ()
fun sortDescending(): Boolean {
return manga.sortDescending()
}
}