mirror of
https://github.com/mihonapp/mihon.git
synced 2025-11-16 14:07:28 +01:00
Library View: Add latest chapter sorting and revert last updated sorting changes (#2563)
* Library View: Add latest chapter sorting and revert last updated sorting changes Latest chapter is as it sounds Last update is now any changes to the chapter list (addition, removal, rename, etc.) * Change latest chapter sort string to "Latest chapter" instead of "Last chapter"
This commit is contained in:
@@ -117,7 +117,9 @@ class LibraryNavigationView @JvmOverloads constructor(context: Context, attrs: A
|
||||
|
||||
private val source = Item.MultiSort(R.string.manga_info_source_label, this)
|
||||
|
||||
override val items = listOf(alphabetically, lastRead, lastUpdated, unread, total, source)
|
||||
private val latestChapter = Item.MultiSort(R.string.action_sort_latest_chapter, this)
|
||||
|
||||
override val items = listOf(alphabetically, lastRead, lastUpdated, unread, total, source, latestChapter)
|
||||
|
||||
override val header = Item.Header(R.string.action_sort)
|
||||
|
||||
@@ -134,6 +136,7 @@ class LibraryNavigationView @JvmOverloads constructor(context: Context, attrs: A
|
||||
unread.state = if (sorting == LibrarySort.UNREAD) order else SORT_NONE
|
||||
total.state = if (sorting == LibrarySort.TOTAL) order else SORT_NONE
|
||||
source.state = if (sorting == LibrarySort.SOURCE) order else SORT_NONE
|
||||
latestChapter.state = if (sorting == LibrarySort.LATEST_CHAPTER) order else SORT_NONE
|
||||
}
|
||||
|
||||
override fun onItemClicked(item: Item) {
|
||||
@@ -155,6 +158,7 @@ class LibraryNavigationView @JvmOverloads constructor(context: Context, attrs: A
|
||||
unread -> LibrarySort.UNREAD
|
||||
total -> LibrarySort.TOTAL
|
||||
source -> LibrarySort.SOURCE
|
||||
latestChapter -> LibrarySort.LATEST_CHAPTER
|
||||
else -> throw Exception("Unknown sorting")
|
||||
})
|
||||
preferences.librarySortingAscending().set(if (item.state == SORT_ASC) true else false)
|
||||
|
||||
@@ -185,6 +185,10 @@ class LibraryPresenter(
|
||||
var counter = 0
|
||||
db.getTotalChapterManga().executeAsBlocking().associate { it.id!! to counter++ }
|
||||
}
|
||||
val latestChapterManga by lazy {
|
||||
var counter = 0
|
||||
db.getLatestChapterManga().executeAsBlocking().associate { it.id!! to counter++ }
|
||||
}
|
||||
|
||||
val sortFn: (LibraryItem, LibraryItem) -> Int = { i1, i2 ->
|
||||
when (sortingMode) {
|
||||
@@ -207,6 +211,11 @@ class LibraryPresenter(
|
||||
val source2Name = sourceManager.getOrStub(i2.manga.source).name
|
||||
source1Name.compareTo(source2Name)
|
||||
}
|
||||
LibrarySort.LATEST_CHAPTER -> {
|
||||
val manga1latestChapter = latestChapterManga[i1.manga.id!!] ?: 0
|
||||
val manga2latestChapter = latestChapterManga[i2.manga.id!!] ?: 0
|
||||
manga1latestChapter.compareTo(manga2latestChapter)
|
||||
}
|
||||
else -> throw Exception("Unknown sorting mode")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,4 +8,5 @@ object LibrarySort {
|
||||
const val UNREAD = 3
|
||||
const val TOTAL = 4
|
||||
const val SOURCE = 5
|
||||
const val LATEST_CHAPTER = 6
|
||||
}
|
||||
Reference in New Issue
Block a user