Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

优化 #3401

Merged
merged 1 commit into from
Oct 7, 2023
Merged

优化 #3401

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -137,7 +136,7 @@ abstract class BaseBookshelfFragment(layoutId: Int) : VMBaseFragment<BookshelfVi
@SuppressLint("InflateParams")
fun configBookshelf() {
alert(titleResource = R.string.bookshelf_layout) {
val bookshelfLayout = getPrefInt(PreferKey.bookshelfLayout)
val bookshelfLayout = AppConfig.bookshelfLayout
val bookshelfSort = AppConfig.bookshelfSort
val alertBinding =
DialogBookshelfConfigBinding.inflate(layoutInflater)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import androidx.fragment.app.FragmentManager
import androidx.fragment.app.FragmentStatePagerAdapter
import com.google.android.material.tabs.TabLayout
import io.legado.app.R
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
Expand Down Expand Up @@ -126,7 +125,7 @@ class BookshelfFragment1() : BaseBookshelfFragment(R.layout.fragment_bookshelf1)
override fun onTabUnselected(tab: TabLayout.Tab) = Unit

override fun onTabSelected(tab: TabLayout.Tab) {
putPrefInt(PreferKey.saveTabPosition, tab.position)
AppConfig.saveTabPosition = tab.position
}

override fun gotoTop() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import io.legado.app.R
import io.legado.app.base.BaseFragment
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
Expand Down Expand Up @@ -52,9 +51,7 @@ class BooksFragment() : BaseFragment(R.layout.fragment_books),

private val binding by viewBinding(FragmentBooksBinding::bind)
private val activityViewModel by activityViewModels<MainViewModel>()
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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
}
}
}
Expand Down