This commit is contained in:
kunfei
2023-01-06 22:52:06 +08:00
parent f9fefde0fe
commit 6606bd7a21
4 changed files with 20 additions and 10 deletions

View File

@@ -7,6 +7,7 @@ import androidx.room.Entity
import androidx.room.PrimaryKey
import io.legado.app.R
import io.legado.app.constant.AppConst
import io.legado.app.help.config.AppConfig
import kotlinx.parcelize.Parcelize
@Parcelize
@@ -34,6 +35,13 @@ data class BookGroup(
}
}
fun getRealBookSort(): Int {
if (bookSort < 0) {
return AppConfig.bookshelfSort
}
return bookSort
}
override fun hashCode(): Int {
return groupId.hashCode()
}

View File

@@ -25,11 +25,6 @@ import io.legado.app.ui.main.bookshelf.BaseBookshelfFragment
import io.legado.app.ui.main.bookshelf.style1.books.BooksFragment
import io.legado.app.utils.*
import io.legado.app.utils.viewbindingdelegate.viewBinding
import kotlin.collections.List
import kotlin.collections.emptyList
import kotlin.collections.getOrNull
import kotlin.collections.hashMapOf
import kotlin.collections.mutableListOf
import kotlin.collections.set
/**
@@ -140,7 +135,7 @@ class BookshelfFragment1 : BaseBookshelfFragment(R.layout.fragment_bookshelf),
override fun getItem(position: Int): Fragment {
val group = bookGroups[position]
return BooksFragment(position, group.groupId)
return BooksFragment(position, group)
}
override fun getCount(): Int {

View File

@@ -16,6 +16,7 @@ import io.legado.app.constant.EventBus
import io.legado.app.constant.PreferKey
import io.legado.app.data.appDb
import io.legado.app.data.entities.Book
import io.legado.app.data.entities.BookGroup
import io.legado.app.databinding.FragmentBooksBinding
import io.legado.app.help.book.isAudio
import io.legado.app.help.config.AppConfig
@@ -40,10 +41,11 @@ import kotlin.math.max
class BooksFragment() : BaseFragment(R.layout.fragment_books),
BaseBooksAdapter.CallBack {
constructor(position: Int, groupId: Long) : this() {
constructor(position: Int, group: BookGroup) : this() {
val bundle = Bundle()
bundle.putInt("position", position)
bundle.putLong("groupId", groupId)
bundle.putLong("groupId", group.groupId)
bundle.putInt("bookSort", group.getRealBookSort())
arguments = bundle
}
@@ -63,6 +65,7 @@ class BooksFragment() : BaseFragment(R.layout.fragment_books),
private var savedInstanceState: Bundle? = null
private var position = 0
private var groupId = -1L
private var bookSort = 0
private var upLastUpdateTimeJob : Job? = null
override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) {
@@ -70,6 +73,7 @@ class BooksFragment() : BaseFragment(R.layout.fragment_books),
arguments?.let {
position = it.getInt("position", 0)
groupId = it.getLong("groupId", -1)
bookSort = it.getInt("bookSort", 0)
}
initRecyclerView()
upRecyclerData()
@@ -120,7 +124,7 @@ class BooksFragment() : BaseFragment(R.layout.fragment_books),
AppConst.bookGroupErrorId -> appDb.bookDao.flowUpdateError()
else -> appDb.bookDao.flowByGroup(groupId)
}.conflate().map { list ->
when (AppConfig.bookshelfSort) {
when (bookSort) {
1 -> list.sortedByDescending { it.latestChapterTime }
2 -> list.sortedWith { o1, o2 ->
o1.name.cnCompare(o2.name)

View File

@@ -133,7 +133,10 @@ class BookshelfFragment2 : BaseBookshelfFragment(R.layout.fragment_bookshelf1),
AppConst.bookGroupErrorId -> appDb.bookDao.flowUpdateError()
else -> appDb.bookDao.flowByGroup(groupId)
}.conflate().map { list ->
when (AppConfig.bookshelfSort) {
when (
appDb.bookGroupDao.getByID(groupId)?.getRealBookSort()
?: AppConfig.bookshelfSort
) {
1 -> list.sortedByDescending {
it.latestChapterTime
}