mirror of
https://github.com/gedoor/legado.git
synced 2025-08-10 00:52:30 +00:00
优化
This commit is contained in:
@@ -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<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)
|
||||
|
||||
@@ -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
|
||||
@@ -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() {
|
||||
|
||||
@@ -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
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user