From ff11cbe780c15536569e146e0fae30e0460bbeec Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 8 Jan 2023 22:01:05 +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 --- app/src/main/java/io/legado/app/help/config/AppConfig.kt | 6 ++++++ .../main/java/io/legado/app/ui/book/cache/CacheActivity.kt | 2 +- .../io/legado/app/ui/book/manage/BookshelfManageActivity.kt | 2 +- .../app/ui/main/bookshelf/style2/BookshelfFragment2.kt | 5 +---- 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/io/legado/app/help/config/AppConfig.kt b/app/src/main/java/io/legado/app/help/config/AppConfig.kt index 74af052c6..dd281fae7 100644 --- a/app/src/main/java/io/legado/app/help/config/AppConfig.kt +++ b/app/src/main/java/io/legado/app/help/config/AppConfig.kt @@ -6,6 +6,7 @@ import android.os.Build import io.legado.app.BuildConfig import io.legado.app.constant.AppConst import io.legado.app.constant.PreferKey +import io.legado.app.data.appDb import io.legado.app.utils.* import splitties.init.appCtx @@ -388,6 +389,11 @@ object AppConfig : SharedPreferences.OnSharedPreferenceChangeListener { appCtx.putPrefInt(PreferKey.bookshelfSort, value) } + fun getBookSortByGroupId(groupId: Long): Int { + return appDb.bookGroupDao.getByID(groupId)?.getRealBookSort() + ?: bookshelfSort + } + private fun getPrefUserAgent(): String { val ua = appCtx.getPrefString(PreferKey.userAgent) if (ua.isNullOrBlank()) { diff --git a/app/src/main/java/io/legado/app/ui/book/cache/CacheActivity.kt b/app/src/main/java/io/legado/app/ui/book/cache/CacheActivity.kt index b66432541..81c1e6df4 100644 --- a/app/src/main/java/io/legado/app/ui/book/cache/CacheActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/cache/CacheActivity.kt @@ -165,7 +165,7 @@ class CacheActivity : VMBaseActivity() val booksDownload = books.filter { !it.isAudio } - when (AppConfig.bookshelfSort) { + when (AppConfig.getBookSortByGroupId(groupId)) { 1 -> booksDownload.sortedByDescending { it.latestChapterTime } 2 -> booksDownload.sortedWith { o1, o2 -> o1.name.cnCompare(o2.name) diff --git a/app/src/main/java/io/legado/app/ui/book/manage/BookshelfManageActivity.kt b/app/src/main/java/io/legado/app/ui/book/manage/BookshelfManageActivity.kt index 6803fa8e3..f1c01c38a 100644 --- a/app/src/main/java/io/legado/app/ui/book/manage/BookshelfManageActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/manage/BookshelfManageActivity.kt @@ -195,7 +195,7 @@ class BookshelfManageActivity : AppConst.bookGroupErrorId -> appDb.bookDao.flowUpdateError() else -> appDb.bookDao.flowByGroup(viewModel.groupId) }.conflate().map { list -> - when (AppConfig.bookshelfSort) { + when (AppConfig.getBookSortByGroupId(viewModel.groupId)) { 1 -> list.sortedByDescending { it.latestChapterTime } 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 6848d6748..1b8c66054 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,10 +133,7 @@ class BookshelfFragment2 : BaseBookshelfFragment(R.layout.fragment_bookshelf1), AppConst.bookGroupErrorId -> appDb.bookDao.flowUpdateError() else -> appDb.bookDao.flowByGroup(groupId) }.conflate().map { list -> - when ( - appDb.bookGroupDao.getByID(groupId)?.getRealBookSort() - ?: AppConfig.bookshelfSort - ) { + when (AppConfig.getBookSortByGroupId(groupId)) { 1 -> list.sortedByDescending { it.latestChapterTime }