书架排序问题 #120

This commit is contained in:
HapeLee
2025-10-23 00:43:39 +08:00
parent 676315e9f6
commit 714ceec548
5 changed files with 24 additions and 20 deletions
@@ -83,22 +83,24 @@ class GroupEditDialog() : BaseBottomSheetDialogFragment(R.layout.dialog_book_gro
}
binding.cbEnableRefresh.isChecked = group.enableRefresh
selectedSortIndex = if (group.bookSort in sortOptions.indices) {
group.bookSort
selectedSortIndex = group.bookSort
val displayIndex = selectedSortIndex + 1
if (displayIndex in sortOptions.indices) {
binding.actvSortMenu.setText(sortOptions[displayIndex], false)
} else {
0
binding.actvSortMenu.setText(sortOptions[0], false)
selectedSortIndex = -1
}
binding.actvSortMenu.setText(sortOptions[selectedSortIndex], false)
} ?: run {
binding.btnDelete.gone()
binding.ivCover.load()
selectedSortIndex = 0
binding.actvSortMenu.setText(sortOptions[selectedSortIndex], false)
selectedSortIndex = -1
binding.actvSortMenu.setText(sortOptions[0], false)
}
binding.actvSortMenu.setOnItemClickListener { _, _, position, _ ->
selectedSortIndex = position
selectedSortIndex = position - 1
}
binding.run {
@@ -167,9 +167,12 @@ class BooksFragment() : BaseFragment(R.layout.fragment_books),
}
}
fun upBookSort() {
bookSort = AppConfig.bookshelfSort
upRecyclerData()
fun upBookSort(sort: Int) {
binding.root.post {
arguments?.putInt("bookSort", sort)
bookSort = sort
upRecyclerData()
}
}
fun setEnableRefresh(enable: Boolean) {
@@ -116,7 +116,7 @@ class BookshelfFragment1() : BaseBookshelfFragment(R.layout.fragment_bookshelf1)
val position = it.position
val group = bookGroups.getOrNull(position) ?: return@forEach
it.setEnableRefresh(group.enableRefresh)
it.upBookSort()
it.upBookSort(group.getRealBookSort())
}
}
}
@@ -170,11 +170,13 @@ class BookshelfFragment2() : BaseBookshelfFragment(R.layout.fragment_bookshelf2)
allBooksFlowJob?.cancel()
allBooksFlowJob = viewLifecycleOwner.lifecycleScope.launch {
appDb.bookDao.flowAll().map { list ->
when (AppConfig.getBookSortByGroupId(BookGroup.Companion.IdRoot)) {
val sortType = BookGroup(BookGroup.Companion.IdRoot, "").getRealBookSort()
when (sortType) {
1 -> list.sortedByDescending { it.latestChapterTime }
2 -> list.sortedWith { o1, o2 -> o1.name.cnCompare(o2.name) }
3 -> list.sortedBy { it.order }
4 -> list.sortedByDescending { max(it.latestChapterTime, it.durChapterTime) }
5 -> list.sortedWith { o1, o2 -> o1.author.cnCompare(o2.author) }
else -> list.sortedByDescending { it.durChapterTime }
}
}.flowWithLifecycleAndDatabaseChangeFirst(
@@ -213,7 +215,8 @@ class BookshelfFragment2() : BaseBookshelfFragment(R.layout.fragment_bookshelf2)
//排序
val isDescending = AppConfig.bookshelfSortOrder == 1
when (AppConfig.getBookSortByGroupId(groupId)) {
val sortType = AppConfig.getBookSortByGroupId(groupId)
when (sortType) {
1 -> if (isDescending) list.sortedByDescending { it.latestChapterTime }
else list.sortedBy { it.latestChapterTime }
@@ -226,12 +229,8 @@ class BookshelfFragment2() : BaseBookshelfFragment(R.layout.fragment_bookshelf2)
else list.sortedBy { it.order }
4 -> if (isDescending) list.sortedByDescending {
max(
it.latestChapterTime,
it.durChapterTime
)
}
else list.sortedBy { max(it.latestChapterTime, it.durChapterTime) }
max(it.latestChapterTime, it.durChapterTime)
} else list.sortedBy { max(it.latestChapterTime, it.durChapterTime) }
5 -> if (isDescending)
list.sortedWith { o1, o2 -> o2.author.cnCompare(o1.author) }
@@ -109,7 +109,7 @@ class BookshelfFragment3() : BaseBookshelfFragment(R.layout.fragment_bookshelf3)
val position = it.position
val group = bookGroups.getOrNull(position) ?: return@forEach
it.setEnableRefresh(group.enableRefresh)
it.upBookSort()
it.upBookSort(group.getRealBookSort())
}
}
}