From 6606bd7a21c2d78be1fdbd4d2ed686cd655008bc Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 6 Jan 2023 22:52:06 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/io/legado/app/data/entities/BookGroup.kt | 8 ++++++++ .../app/ui/main/bookshelf/style1/BookshelfFragment1.kt | 7 +------ .../ui/main/bookshelf/style1/books/BooksFragment.kt | 10 +++++++--- .../app/ui/main/bookshelf/style2/BookshelfFragment2.kt | 5 ++++- 4 files changed, 20 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/io/legado/app/data/entities/BookGroup.kt b/app/src/main/java/io/legado/app/data/entities/BookGroup.kt index 6653653fa..e3c0862fb 100644 --- a/app/src/main/java/io/legado/app/data/entities/BookGroup.kt +++ b/app/src/main/java/io/legado/app/data/entities/BookGroup.kt @@ -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() } diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/style1/BookshelfFragment1.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/style1/BookshelfFragment1.kt index 1ebb01717..ca6f18346 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/style1/BookshelfFragment1.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/style1/BookshelfFragment1.kt @@ -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 { diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/style1/books/BooksFragment.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/style1/books/BooksFragment.kt index 3d4d87a0a..d8e578899 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/style1/books/BooksFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/style1/books/BooksFragment.kt @@ -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) diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/style2/BookshelfFragment2.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/style2/BookshelfFragment2.kt index a2cf0d9ff..6848d6748 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/style2/BookshelfFragment2.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/style2/BookshelfFragment2.kt @@ -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 }