diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaController.kt index c0209f352..5650b1b80 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaController.kt @@ -1020,23 +1020,11 @@ class MangaController : // OVERFLOW MENU DIALOGS - private fun getUnreadChaptersSorted(): List { - val chapters = presenter.chapters - .sortedWith(presenter.getChapterSort()) - .filter { !it.read && it.status == Download.State.NOT_DOWNLOADED } - .distinctBy { it.name } - return if (presenter.sortDescending()) { - chapters.reversed() - } else { - chapters - } - } - private fun downloadChapters(choice: Int) { val chaptersToDownload = when (choice) { - R.id.download_next -> getUnreadChaptersSorted().take(1) - R.id.download_next_5 -> getUnreadChaptersSorted().take(5) - R.id.download_next_10 -> getUnreadChaptersSorted().take(10) + R.id.download_next -> presenter.getUnreadChaptersSorted().take(1) + R.id.download_next_5 -> presenter.getUnreadChaptersSorted().take(5) + R.id.download_next_10 -> presenter.getUnreadChaptersSorted().take(10) R.id.download_custom -> { showCustomDownloadDialog() return @@ -1059,7 +1047,7 @@ class MangaController : } override fun downloadCustomChapters(amount: Int) { - val chaptersToDownload = getUnreadChaptersSorted().take(amount) + val chaptersToDownload = presenter.getUnreadChaptersSorted().take(amount) if (chaptersToDownload.isNotEmpty()) { downloadChapters(chaptersToDownload) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaPresenter.kt index 87c6452d7..40f79fe10 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaPresenter.kt @@ -26,6 +26,7 @@ import eu.kanade.tachiyomi.ui.base.presenter.BasePresenter import eu.kanade.tachiyomi.ui.manga.chapter.ChapterItem import eu.kanade.tachiyomi.ui.manga.track.TrackItem import eu.kanade.tachiyomi.util.chapter.ChapterSettingsHelper +import eu.kanade.tachiyomi.util.chapter.getChapterSort import eu.kanade.tachiyomi.util.chapter.syncChaptersWithSource import eu.kanade.tachiyomi.util.chapter.syncChaptersWithTrackServiceTwoWay import eu.kanade.tachiyomi.util.isLocal @@ -433,25 +434,7 @@ class MangaPresenter( observable = observable.filter { !it.bookmark } } - return observable.toSortedList(getChapterSort()) - } - - fun getChapterSort(): (Chapter, Chapter) -> Int { - return when (manga.sorting) { - Manga.CHAPTER_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.CHAPTER_SORTING_NUMBER -> when (sortDescending()) { - true -> { c1, c2 -> c2.chapter_number.compareTo(c1.chapter_number) } - false -> { c1, c2 -> c1.chapter_number.compareTo(c2.chapter_number) } - } - Manga.CHAPTER_SORTING_UPLOAD_DATE -> when (sortDescending()) { - true -> { c1, c2 -> c2.date_upload.compareTo(c1.date_upload) } - false -> { c1, c2 -> c1.date_upload.compareTo(c2.date_upload) } - } - else -> throw NotImplementedError("Unimplemented sorting method") - } + return observable.toSortedList(getChapterSort(manga)) } /** @@ -478,7 +461,7 @@ class MangaPresenter( * Returns the next unread chapter or null if everything is read. */ fun getNextUnreadChapter(): ChapterItem? { - val chapters = chapters.sortedWith(getChapterSort()) + val chapters = chapters.sortedWith(getChapterSort(manga)) return if (sortDescending()) { return chapters.findLast { !it.read } } else { @@ -486,6 +469,18 @@ class MangaPresenter( } } + fun getUnreadChaptersSorted(): List { + val chapters = chapters + .sortedWith(getChapterSort(manga)) + .filter { !it.read && it.status == Download.State.NOT_DOWNLOADED } + .distinctBy { it.name } + return if (sortDescending()) { + chapters.reversed() + } else { + chapters + } + } + /** * Mark the selected chapter list as read/unread. * @param selectedChapters the list of selected chapters. diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ChapterLoadStrategy.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ChapterLoadStrategy.kt deleted file mode 100644 index 0d5d18d60..000000000 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ChapterLoadStrategy.kt +++ /dev/null @@ -1,46 +0,0 @@ -package eu.kanade.tachiyomi.ui.reader - -import eu.kanade.tachiyomi.data.database.models.Chapter - -/** - * Load strategy using the source order. This is the default ordering. - */ -class ChapterLoadBySource { - fun get(allChapters: List): List { - return allChapters.sortedByDescending { it.source_order } - } -} - -/** - * Load strategy using unique chapter numbers with same scanlator preference. - */ -class ChapterLoadByNumber { - fun get(allChapters: List, selectedChapter: Chapter): List { - val chapters = mutableListOf() - val chaptersByNumber = allChapters.groupBy { it.chapter_number } - - for ((number, chaptersForNumber) in chaptersByNumber) { - val preferredChapter = when { - // Make sure the selected chapter is always present - number == selectedChapter.chapter_number -> selectedChapter - // If there is only one chapter for this number, use it - chaptersForNumber.size == 1 -> chaptersForNumber.first() - // Prefer a chapter of the same scanlator as the selected - else -> - chaptersForNumber.find { it.scanlator == selectedChapter.scanlator } - ?: chaptersForNumber.first() - } - chapters.add(preferredChapter) - } - return chapters.sortedBy { it.chapter_number } - } -} - -/** - * Load strategy using the chapter upload date. This ordering ignores scanlators - */ -class ChapterLoadByUploadDate { - fun get(allChapters: List): List { - return allChapters.sortedBy { it.date_upload } - } -} diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPresenter.kt index 674f1140e..1bf3e53cb 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPresenter.kt @@ -23,6 +23,7 @@ import eu.kanade.tachiyomi.ui.reader.model.ReaderPage import eu.kanade.tachiyomi.ui.reader.model.ViewerChapters import eu.kanade.tachiyomi.ui.reader.setting.OrientationType import eu.kanade.tachiyomi.ui.reader.setting.ReadingModeType +import eu.kanade.tachiyomi.util.chapter.getChapterSort import eu.kanade.tachiyomi.util.isLocal import eu.kanade.tachiyomi.util.lang.byteSize import eu.kanade.tachiyomi.util.lang.launchIO @@ -123,12 +124,9 @@ class ReaderPresenter( else -> dbChapters } - when (manga.sorting) { - Manga.CHAPTER_SORTING_SOURCE -> ChapterLoadBySource().get(chaptersForReader) - Manga.CHAPTER_SORTING_NUMBER -> ChapterLoadByNumber().get(chaptersForReader, selectedChapter) - Manga.CHAPTER_SORTING_UPLOAD_DATE -> ChapterLoadByUploadDate().get(chaptersForReader) - else -> error("Unknown sorting method") - }.map(::ReaderChapter) + chaptersForReader + .sortedWith(getChapterSort(manga)) + .map(::ReaderChapter) } private var hasTrackers: Boolean = false diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/chapter/ChapterSorter.kt b/app/src/main/java/eu/kanade/tachiyomi/util/chapter/ChapterSorter.kt new file mode 100644 index 000000000..6b6395fa7 --- /dev/null +++ b/app/src/main/java/eu/kanade/tachiyomi/util/chapter/ChapterSorter.kt @@ -0,0 +1,24 @@ +package eu.kanade.tachiyomi.util.chapter + +import eu.kanade.tachiyomi.data.database.models.Chapter +import eu.kanade.tachiyomi.data.database.models.Manga + +fun getChapterSort(manga: Manga): (Chapter, Chapter) -> Int { + val sortDescending = manga.sortDescending() + + return when (manga.sorting) { + Manga.CHAPTER_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.CHAPTER_SORTING_NUMBER -> when (sortDescending) { + true -> { c1, c2 -> c2.chapter_number.compareTo(c1.chapter_number) } + false -> { c1, c2 -> c1.chapter_number.compareTo(c2.chapter_number) } + } + Manga.CHAPTER_SORTING_UPLOAD_DATE -> when (sortDescending) { + true -> { c1, c2 -> c2.date_upload.compareTo(c1.date_upload) } + false -> { c1, c2 -> c1.date_upload.compareTo(c2.date_upload) } + } + else -> throw NotImplementedError("Unimplemented sorting method") + } +} diff --git a/gradle.properties b/gradle.properties index 5204dbd92..ff77efb1c 100644 --- a/gradle.properties +++ b/gradle.properties @@ -11,7 +11,7 @@ # The setting is particularly useful for tweaking memory settings. # Default value: -Xmx10248m -XX:MaxPermSize=256m # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 -org.gradle.jvmargs=-Xmx3072m +org.gradle.jvmargs=-Xmx4096m # When configured, Gradle will run in incubating parallel mode. # This option should only be used with decoupled projects. More details, visit