From 8dd6a0b0d0070f55f297d2605c65bd04438c8702 Mon Sep 17 00:00:00 2001 From: adhu2018 <41824074+adhu2018@users.noreply.github.com> Date: Sat, 7 Oct 2023 16:06:43 +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/bookshelf/BaseBookshelfFragment.kt | 3 +-- .../bookshelf/style1/BookshelfFragment1.kt | 3 +-- .../bookshelf/style1/books/BooksFragment.kt | 5 +---- .../bookshelf/style2/BookshelfFragment2.kt | 21 ++++++++++--------- 4 files changed, 14 insertions(+), 18 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/BaseBookshelfFragment.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/BaseBookshelfFragment.kt index c4a18d6fa947..bdc5d5f4ee9c 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/BaseBookshelfFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/BaseBookshelfFragment.kt @@ -9,7 +9,6 @@ import androidx.lifecycle.LiveData import io.legado.app.R import io.legado.app.base.VMBaseFragment 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 @@ -137,7 +136,7 @@ abstract class BaseBookshelfFragment(layoutId: Int) : VMBaseFragment() - private val bookshelfLayout by lazy { - getPrefInt(PreferKey.bookshelfLayout) - } + private val bookshelfLayout by lazy { AppConfig.bookshelfLayout } private val booksAdapter: BaseBooksAdapter<*> by lazy { if (bookshelfLayout == 0) { BooksAdapterList(requireContext(), this) 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 38fcf7c3bb9b..a3bdf239b08c 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 @@ -12,7 +12,6 @@ import androidx.recyclerview.widget.RecyclerView import io.legado.app.R import io.legado.app.constant.AppLog 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 @@ -53,9 +52,7 @@ class BookshelfFragment2() : BaseBookshelfFragment(R.layout.fragment_bookshelf2) } private val binding by viewBinding(FragmentBookshelf2Binding::bind) - private val bookshelfLayout by lazy { - getPrefInt(PreferKey.bookshelfLayout) - } + private val bookshelfLayout by lazy { AppConfig.bookshelfLayout } private val booksAdapter: BaseBooksAdapter<*> by lazy { if (bookshelfLayout == 0) { BooksAdapterList(requireContext(), this) @@ -123,8 +120,10 @@ class BookshelfFragment2() : BaseBookshelfFragment(R.layout.fragment_bookshelf2) @SuppressLint("NotifyDataSetChanged") private fun initBooksData() { if (groupId == -100L) { - binding.titleBar.title = getString(R.string.bookshelf) - binding.refreshLayout.isEnabled = true + if (isAdded) { + binding.titleBar.title = getString(R.string.bookshelf) + binding.refreshLayout.isEnabled = true + } } else { bookGroups.firstOrNull { groupId == it.groupId @@ -156,10 +155,12 @@ class BookshelfFragment2() : BaseBookshelfFragment(R.layout.fragment_bookshelf2) }.flowOn(Dispatchers.Default).catch { AppLog.put("书架更新出错", it) }.conflate().collect { list -> - books = list - booksAdapter.notifyDataSetChanged() - binding.tvEmptyMsg.isGone = getItemCount() > 0 - delay(100) + if (isAdded) { + books = list + booksAdapter.notifyDataSetChanged() + binding.tvEmptyMsg.isGone = getItemCount() > 0 + delay(100) + } } } }