pull/2692/head
kunfei 2 years ago
parent f9fefde0fe
commit 6606bd7a21
  1. 8
      app/src/main/java/io/legado/app/data/entities/BookGroup.kt
  2. 7
      app/src/main/java/io/legado/app/ui/main/bookshelf/style1/BookshelfFragment1.kt
  3. 10
      app/src/main/java/io/legado/app/ui/main/bookshelf/style1/books/BooksFragment.kt
  4. 5
      app/src/main/java/io/legado/app/ui/main/bookshelf/style2/BookshelfFragment2.kt

@ -7,6 +7,7 @@ import androidx.room.Entity
import androidx.room.PrimaryKey import androidx.room.PrimaryKey
import io.legado.app.R import io.legado.app.R
import io.legado.app.constant.AppConst import io.legado.app.constant.AppConst
import io.legado.app.help.config.AppConfig
import kotlinx.parcelize.Parcelize import kotlinx.parcelize.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 { override fun hashCode(): Int {
return groupId.hashCode() return groupId.hashCode()
} }

@ -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.ui.main.bookshelf.style1.books.BooksFragment
import io.legado.app.utils.* import io.legado.app.utils.*
import io.legado.app.utils.viewbindingdelegate.viewBinding 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 import kotlin.collections.set
/** /**
@ -140,7 +135,7 @@ class BookshelfFragment1 : BaseBookshelfFragment(R.layout.fragment_bookshelf),
override fun getItem(position: Int): Fragment { override fun getItem(position: Int): Fragment {
val group = bookGroups[position] val group = bookGroups[position]
return BooksFragment(position, group.groupId) return BooksFragment(position, group)
} }
override fun getCount(): Int { override fun getCount(): Int {

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

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

Loading…
Cancel
Save