书架排序问题 #120
This commit is contained in:
@@ -83,22 +83,24 @@ class GroupEditDialog() : BaseBottomSheetDialogFragment(R.layout.dialog_book_gro
|
|||||||
}
|
}
|
||||||
binding.cbEnableRefresh.isChecked = group.enableRefresh
|
binding.cbEnableRefresh.isChecked = group.enableRefresh
|
||||||
|
|
||||||
selectedSortIndex = if (group.bookSort in sortOptions.indices) {
|
selectedSortIndex = group.bookSort
|
||||||
group.bookSort
|
val displayIndex = selectedSortIndex + 1
|
||||||
|
if (displayIndex in sortOptions.indices) {
|
||||||
|
binding.actvSortMenu.setText(sortOptions[displayIndex], false)
|
||||||
} else {
|
} else {
|
||||||
0
|
binding.actvSortMenu.setText(sortOptions[0], false)
|
||||||
|
selectedSortIndex = -1
|
||||||
}
|
}
|
||||||
binding.actvSortMenu.setText(sortOptions[selectedSortIndex], false)
|
|
||||||
|
|
||||||
} ?: run {
|
} ?: run {
|
||||||
binding.btnDelete.gone()
|
binding.btnDelete.gone()
|
||||||
binding.ivCover.load()
|
binding.ivCover.load()
|
||||||
selectedSortIndex = 0
|
selectedSortIndex = -1
|
||||||
binding.actvSortMenu.setText(sortOptions[selectedSortIndex], false)
|
binding.actvSortMenu.setText(sortOptions[0], false)
|
||||||
}
|
}
|
||||||
|
|
||||||
binding.actvSortMenu.setOnItemClickListener { _, _, position, _ ->
|
binding.actvSortMenu.setOnItemClickListener { _, _, position, _ ->
|
||||||
selectedSortIndex = position
|
selectedSortIndex = position - 1
|
||||||
}
|
}
|
||||||
|
|
||||||
binding.run {
|
binding.run {
|
||||||
|
|||||||
@@ -167,10 +167,13 @@ class BooksFragment() : BaseFragment(R.layout.fragment_books),
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun upBookSort() {
|
fun upBookSort(sort: Int) {
|
||||||
bookSort = AppConfig.bookshelfSort
|
binding.root.post {
|
||||||
|
arguments?.putInt("bookSort", sort)
|
||||||
|
bookSort = sort
|
||||||
upRecyclerData()
|
upRecyclerData()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun setEnableRefresh(enable: Boolean) {
|
fun setEnableRefresh(enable: Boolean) {
|
||||||
enableRefresh = enable
|
enableRefresh = enable
|
||||||
|
|||||||
@@ -116,7 +116,7 @@ class BookshelfFragment1() : BaseBookshelfFragment(R.layout.fragment_bookshelf1)
|
|||||||
val position = it.position
|
val position = it.position
|
||||||
val group = bookGroups.getOrNull(position) ?: return@forEach
|
val group = bookGroups.getOrNull(position) ?: return@forEach
|
||||||
it.setEnableRefresh(group.enableRefresh)
|
it.setEnableRefresh(group.enableRefresh)
|
||||||
it.upBookSort()
|
it.upBookSort(group.getRealBookSort())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -170,11 +170,13 @@ class BookshelfFragment2() : BaseBookshelfFragment(R.layout.fragment_bookshelf2)
|
|||||||
allBooksFlowJob?.cancel()
|
allBooksFlowJob?.cancel()
|
||||||
allBooksFlowJob = viewLifecycleOwner.lifecycleScope.launch {
|
allBooksFlowJob = viewLifecycleOwner.lifecycleScope.launch {
|
||||||
appDb.bookDao.flowAll().map { list ->
|
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 }
|
1 -> list.sortedByDescending { it.latestChapterTime }
|
||||||
2 -> list.sortedWith { o1, o2 -> o1.name.cnCompare(o2.name) }
|
2 -> list.sortedWith { o1, o2 -> o1.name.cnCompare(o2.name) }
|
||||||
3 -> list.sortedBy { it.order }
|
3 -> list.sortedBy { it.order }
|
||||||
4 -> list.sortedByDescending { max(it.latestChapterTime, it.durChapterTime) }
|
4 -> list.sortedByDescending { max(it.latestChapterTime, it.durChapterTime) }
|
||||||
|
5 -> list.sortedWith { o1, o2 -> o1.author.cnCompare(o2.author) }
|
||||||
else -> list.sortedByDescending { it.durChapterTime }
|
else -> list.sortedByDescending { it.durChapterTime }
|
||||||
}
|
}
|
||||||
}.flowWithLifecycleAndDatabaseChangeFirst(
|
}.flowWithLifecycleAndDatabaseChangeFirst(
|
||||||
@@ -213,7 +215,8 @@ class BookshelfFragment2() : BaseBookshelfFragment(R.layout.fragment_bookshelf2)
|
|||||||
//排序
|
//排序
|
||||||
val isDescending = AppConfig.bookshelfSortOrder == 1
|
val isDescending = AppConfig.bookshelfSortOrder == 1
|
||||||
|
|
||||||
when (AppConfig.getBookSortByGroupId(groupId)) {
|
val sortType = AppConfig.getBookSortByGroupId(groupId)
|
||||||
|
when (sortType) {
|
||||||
1 -> if (isDescending) list.sortedByDescending { it.latestChapterTime }
|
1 -> if (isDescending) list.sortedByDescending { it.latestChapterTime }
|
||||||
else list.sortedBy { it.latestChapterTime }
|
else list.sortedBy { it.latestChapterTime }
|
||||||
|
|
||||||
@@ -226,12 +229,8 @@ class BookshelfFragment2() : BaseBookshelfFragment(R.layout.fragment_bookshelf2)
|
|||||||
else list.sortedBy { it.order }
|
else list.sortedBy { it.order }
|
||||||
|
|
||||||
4 -> if (isDescending) list.sortedByDescending {
|
4 -> if (isDescending) list.sortedByDescending {
|
||||||
max(
|
max(it.latestChapterTime, it.durChapterTime)
|
||||||
it.latestChapterTime,
|
} else list.sortedBy { max(it.latestChapterTime, it.durChapterTime) }
|
||||||
it.durChapterTime
|
|
||||||
)
|
|
||||||
}
|
|
||||||
else list.sortedBy { max(it.latestChapterTime, it.durChapterTime) }
|
|
||||||
|
|
||||||
5 -> if (isDescending)
|
5 -> if (isDescending)
|
||||||
list.sortedWith { o1, o2 -> o2.author.cnCompare(o1.author) }
|
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 position = it.position
|
||||||
val group = bookGroups.getOrNull(position) ?: return@forEach
|
val group = bookGroups.getOrNull(position) ?: return@forEach
|
||||||
it.setEnableRefresh(group.enableRefresh)
|
it.setEnableRefresh(group.enableRefresh)
|
||||||
it.upBookSort()
|
it.upBookSort(group.getRealBookSort())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user