mirror of
https://git.mihon.tech/mihonapp/mihon
synced 2024-11-22 05:05:38 +03:00
Use same chapter sorting logic in manga and reader views
This commit is contained in:
parent
ce9fb2f1fe
commit
aefd2bf6f8
6 changed files with 48 additions and 89 deletions
|
@ -1020,23 +1020,11 @@ class MangaController :
|
||||||
|
|
||||||
// OVERFLOW MENU DIALOGS
|
// OVERFLOW MENU DIALOGS
|
||||||
|
|
||||||
private fun getUnreadChaptersSorted(): List<ChapterItem> {
|
|
||||||
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) {
|
private fun downloadChapters(choice: Int) {
|
||||||
val chaptersToDownload = when (choice) {
|
val chaptersToDownload = when (choice) {
|
||||||
R.id.download_next -> getUnreadChaptersSorted().take(1)
|
R.id.download_next -> presenter.getUnreadChaptersSorted().take(1)
|
||||||
R.id.download_next_5 -> getUnreadChaptersSorted().take(5)
|
R.id.download_next_5 -> presenter.getUnreadChaptersSorted().take(5)
|
||||||
R.id.download_next_10 -> getUnreadChaptersSorted().take(10)
|
R.id.download_next_10 -> presenter.getUnreadChaptersSorted().take(10)
|
||||||
R.id.download_custom -> {
|
R.id.download_custom -> {
|
||||||
showCustomDownloadDialog()
|
showCustomDownloadDialog()
|
||||||
return
|
return
|
||||||
|
@ -1059,7 +1047,7 @@ class MangaController :
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun downloadCustomChapters(amount: Int) {
|
override fun downloadCustomChapters(amount: Int) {
|
||||||
val chaptersToDownload = getUnreadChaptersSorted().take(amount)
|
val chaptersToDownload = presenter.getUnreadChaptersSorted().take(amount)
|
||||||
if (chaptersToDownload.isNotEmpty()) {
|
if (chaptersToDownload.isNotEmpty()) {
|
||||||
downloadChapters(chaptersToDownload)
|
downloadChapters(chaptersToDownload)
|
||||||
}
|
}
|
||||||
|
|
|
@ -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.chapter.ChapterItem
|
||||||
import eu.kanade.tachiyomi.ui.manga.track.TrackItem
|
import eu.kanade.tachiyomi.ui.manga.track.TrackItem
|
||||||
import eu.kanade.tachiyomi.util.chapter.ChapterSettingsHelper
|
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.syncChaptersWithSource
|
||||||
import eu.kanade.tachiyomi.util.chapter.syncChaptersWithTrackServiceTwoWay
|
import eu.kanade.tachiyomi.util.chapter.syncChaptersWithTrackServiceTwoWay
|
||||||
import eu.kanade.tachiyomi.util.isLocal
|
import eu.kanade.tachiyomi.util.isLocal
|
||||||
|
@ -433,25 +434,7 @@ class MangaPresenter(
|
||||||
observable = observable.filter { !it.bookmark }
|
observable = observable.filter { !it.bookmark }
|
||||||
}
|
}
|
||||||
|
|
||||||
return observable.toSortedList(getChapterSort())
|
return observable.toSortedList(getChapterSort(manga))
|
||||||
}
|
|
||||||
|
|
||||||
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")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -478,7 +461,7 @@ class MangaPresenter(
|
||||||
* Returns the next unread chapter or null if everything is read.
|
* Returns the next unread chapter or null if everything is read.
|
||||||
*/
|
*/
|
||||||
fun getNextUnreadChapter(): ChapterItem? {
|
fun getNextUnreadChapter(): ChapterItem? {
|
||||||
val chapters = chapters.sortedWith(getChapterSort())
|
val chapters = chapters.sortedWith(getChapterSort(manga))
|
||||||
return if (sortDescending()) {
|
return if (sortDescending()) {
|
||||||
return chapters.findLast { !it.read }
|
return chapters.findLast { !it.read }
|
||||||
} else {
|
} else {
|
||||||
|
@ -486,6 +469,18 @@ class MangaPresenter(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun getUnreadChaptersSorted(): List<ChapterItem> {
|
||||||
|
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.
|
* Mark the selected chapter list as read/unread.
|
||||||
* @param selectedChapters the list of selected chapters.
|
* @param selectedChapters the list of selected chapters.
|
||||||
|
|
|
@ -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<Chapter>): List<Chapter> {
|
|
||||||
return allChapters.sortedByDescending { it.source_order }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Load strategy using unique chapter numbers with same scanlator preference.
|
|
||||||
*/
|
|
||||||
class ChapterLoadByNumber {
|
|
||||||
fun get(allChapters: List<Chapter>, selectedChapter: Chapter): List<Chapter> {
|
|
||||||
val chapters = mutableListOf<Chapter>()
|
|
||||||
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<Chapter>): List<Chapter> {
|
|
||||||
return allChapters.sortedBy { it.date_upload }
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -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.model.ViewerChapters
|
||||||
import eu.kanade.tachiyomi.ui.reader.setting.OrientationType
|
import eu.kanade.tachiyomi.ui.reader.setting.OrientationType
|
||||||
import eu.kanade.tachiyomi.ui.reader.setting.ReadingModeType
|
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.isLocal
|
||||||
import eu.kanade.tachiyomi.util.lang.byteSize
|
import eu.kanade.tachiyomi.util.lang.byteSize
|
||||||
import eu.kanade.tachiyomi.util.lang.launchIO
|
import eu.kanade.tachiyomi.util.lang.launchIO
|
||||||
|
@ -123,12 +124,9 @@ class ReaderPresenter(
|
||||||
else -> dbChapters
|
else -> dbChapters
|
||||||
}
|
}
|
||||||
|
|
||||||
when (manga.sorting) {
|
chaptersForReader
|
||||||
Manga.CHAPTER_SORTING_SOURCE -> ChapterLoadBySource().get(chaptersForReader)
|
.sortedWith(getChapterSort(manga))
|
||||||
Manga.CHAPTER_SORTING_NUMBER -> ChapterLoadByNumber().get(chaptersForReader, selectedChapter)
|
.map(::ReaderChapter)
|
||||||
Manga.CHAPTER_SORTING_UPLOAD_DATE -> ChapterLoadByUploadDate().get(chaptersForReader)
|
|
||||||
else -> error("Unknown sorting method")
|
|
||||||
}.map(::ReaderChapter)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private var hasTrackers: Boolean = false
|
private var hasTrackers: Boolean = false
|
||||||
|
|
|
@ -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")
|
||||||
|
}
|
||||||
|
}
|
|
@ -11,7 +11,7 @@
|
||||||
# The setting is particularly useful for tweaking memory settings.
|
# The setting is particularly useful for tweaking memory settings.
|
||||||
# Default value: -Xmx10248m -XX:MaxPermSize=256m
|
# Default value: -Xmx10248m -XX:MaxPermSize=256m
|
||||||
# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
|
# 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.
|
# When configured, Gradle will run in incubating parallel mode.
|
||||||
# This option should only be used with decoupled projects. More details, visit
|
# This option should only be used with decoupled projects. More details, visit
|
||||||
|
|
Loading…
Reference in a new issue