mirror of
https://github.com/gedoor/legado.git
synced 2024-09-01 09:34:25 +08:00
优化
This commit is contained in:
parent
3ad8aba2d5
commit
98492c3249
@ -27,6 +27,7 @@ import io.legado.app.utils.putPrefInt
|
||||
import io.legado.app.utils.setEdgeEffectColor
|
||||
import io.legado.app.utils.toastOnUi
|
||||
import io.legado.app.utils.viewbindingdelegate.viewBinding
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.flow.collect
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
@ -44,7 +45,7 @@ class BookshelfFragment1 : BaseBookshelfFragment(R.layout.fragment_bookshelf),
|
||||
}
|
||||
private val bookGroups = mutableListOf<BookGroup>()
|
||||
private val fragmentMap = hashMapOf<Long, BooksFragment>()
|
||||
|
||||
private var groupsFlowJob: Job? = null
|
||||
override val groupId: Long get() = selectedGroup.groupId
|
||||
|
||||
override val books: List<Book>
|
||||
@ -73,7 +74,8 @@ class BookshelfFragment1 : BaseBookshelfFragment(R.layout.fragment_bookshelf),
|
||||
}
|
||||
|
||||
private fun initBookGroupData() {
|
||||
launch {
|
||||
groupsFlowJob?.cancel()
|
||||
groupsFlowJob = launch {
|
||||
appDb.bookGroupDao.flowShow().collect {
|
||||
upGroup(it)
|
||||
}
|
||||
|
@ -45,9 +45,17 @@ class BooksFragment() : BaseFragment(R.layout.fragment_books),
|
||||
}
|
||||
|
||||
private val binding by viewBinding(FragmentBooksBinding::bind)
|
||||
private val activityViewModel: MainViewModel
|
||||
by activityViewModels()
|
||||
private lateinit var booksAdapter: BaseBooksAdapter<*>
|
||||
private val activityViewModel by activityViewModels<MainViewModel>()
|
||||
private val bookshelfLayout by lazy {
|
||||
getPrefInt(PreferKey.bookshelfLayout)
|
||||
}
|
||||
private val booksAdapter: BaseBooksAdapter<*> by lazy {
|
||||
if (bookshelfLayout == 0) {
|
||||
BooksAdapterList(requireContext(), this)
|
||||
} else {
|
||||
BooksAdapterGrid(requireContext(), this)
|
||||
}
|
||||
}
|
||||
private var booksFlowJob: Job? = null
|
||||
private var position = 0
|
||||
private var groupId = -1L
|
||||
@ -68,13 +76,10 @@ class BooksFragment() : BaseFragment(R.layout.fragment_books),
|
||||
binding.refreshLayout.isRefreshing = false
|
||||
activityViewModel.upToc(booksAdapter.getItems())
|
||||
}
|
||||
val bookshelfLayout = getPrefInt(PreferKey.bookshelfLayout)
|
||||
if (bookshelfLayout == 0) {
|
||||
binding.rvBookshelf.layoutManager = LinearLayoutManager(context)
|
||||
booksAdapter = BooksAdapterList(requireContext(), this)
|
||||
} else {
|
||||
binding.rvBookshelf.layoutManager = GridLayoutManager(context, bookshelfLayout + 2)
|
||||
booksAdapter = BooksAdapterGrid(requireContext(), this)
|
||||
}
|
||||
binding.rvBookshelf.adapter = booksAdapter
|
||||
booksAdapter.registerAdapterDataObserver(object : RecyclerView.AdapterDataObserver() {
|
||||
|
@ -41,10 +41,20 @@ class BookshelfFragment2 : BaseBookshelfFragment(R.layout.fragment_bookshelf1),
|
||||
BaseBooksAdapter.CallBack {
|
||||
|
||||
private val binding by viewBinding(FragmentBookshelf1Binding::bind)
|
||||
private lateinit var booksAdapter: BaseBooksAdapter<*>
|
||||
override var groupId = AppConst.bookGroupNoneId
|
||||
private var booksFlowJob: Job? = null
|
||||
private val bookshelfLayout by lazy {
|
||||
getPrefInt(PreferKey.bookshelfLayout)
|
||||
}
|
||||
private val booksAdapter: BaseBooksAdapter<*> by lazy {
|
||||
if (bookshelfLayout == 0) {
|
||||
BooksAdapterList(requireContext(), this)
|
||||
} else {
|
||||
BooksAdapterGrid(requireContext(), this)
|
||||
}
|
||||
}
|
||||
private var bookGroups: List<BookGroup> = emptyList()
|
||||
private var groupsFlowJob: Job? = null
|
||||
private var booksFlowJob: Job? = null
|
||||
override var groupId = AppConst.bookGroupNoneId
|
||||
override var books: List<Book> = emptyList()
|
||||
|
||||
override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) {
|
||||
@ -61,13 +71,10 @@ class BookshelfFragment2 : BaseBookshelfFragment(R.layout.fragment_bookshelf1),
|
||||
binding.refreshLayout.isRefreshing = false
|
||||
activityViewModel.upToc(books)
|
||||
}
|
||||
val bookshelfLayout = getPrefInt(PreferKey.bookshelfLayout)
|
||||
if (bookshelfLayout == 0) {
|
||||
binding.rvBookshelf.layoutManager = LinearLayoutManager(context)
|
||||
booksAdapter = BooksAdapterList(requireContext(), this)
|
||||
} else {
|
||||
binding.rvBookshelf.layoutManager = GridLayoutManager(context, bookshelfLayout + 2)
|
||||
booksAdapter = BooksAdapterGrid(requireContext(), this)
|
||||
}
|
||||
binding.rvBookshelf.adapter = booksAdapter
|
||||
booksAdapter.registerAdapterDataObserver(object : RecyclerView.AdapterDataObserver() {
|
||||
@ -91,7 +98,8 @@ class BookshelfFragment2 : BaseBookshelfFragment(R.layout.fragment_bookshelf1),
|
||||
|
||||
@SuppressLint("NotifyDataSetChanged")
|
||||
private fun initGroupData() {
|
||||
launch {
|
||||
groupsFlowJob?.cancel()
|
||||
groupsFlowJob = launch {
|
||||
appDb.bookGroupDao.flowShow().collect {
|
||||
if (it != bookGroups) {
|
||||
bookGroups = it
|
||||
|
@ -41,6 +41,7 @@ class RssFragment : VMBaseFragment<RssSourceViewModel>(R.layout.fragment_rss),
|
||||
private val searchView: SearchView by lazy {
|
||||
binding.titleBar.findViewById(R.id.search_view)
|
||||
}
|
||||
private var groupsFlowJob: Job? = null
|
||||
private var rssFlowJob: Job? = null
|
||||
private val groups = linkedSetOf<String>()
|
||||
private var groupsMenu: SubMenu? = null
|
||||
@ -117,7 +118,8 @@ class RssFragment : VMBaseFragment<RssSourceViewModel>(R.layout.fragment_rss),
|
||||
}
|
||||
|
||||
private fun initGroupData() {
|
||||
launch {
|
||||
groupsFlowJob?.cancel()
|
||||
groupsFlowJob = launch {
|
||||
appDb.rssSourceDao.flowGroup().collect {
|
||||
groups.clear()
|
||||
it.map { group ->
|
||||
|
Loading…
Reference in New Issue
Block a user