pull/1395/head
gedoor 3 years ago
parent 3ad8aba2d5
commit 98492c3249
  1. 6
      app/src/main/java/io/legado/app/ui/main/bookshelf/style1/BookshelfFragment1.kt
  2. 17
      app/src/main/java/io/legado/app/ui/main/bookshelf/style1/books/BooksFragment.kt
  3. 22
      app/src/main/java/io/legado/app/ui/main/bookshelf/style2/BookshelfFragment2.kt
  4. 4
      app/src/main/java/io/legado/app/ui/main/rss/RssFragment.kt

@ -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…
Cancel
Save