Skip to content

Commit

Permalink
优化
Browse files Browse the repository at this point in the history
  • Loading branch information
adhu2018 committed Oct 7, 2023
1 parent d61d30c commit 8dd6a0b
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 18 deletions.
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

0 comments on commit 8dd6a0b

Please sign in to comment.