pull/32/head
GKF 6 years ago
parent 81bd481a0d
commit 9dcedd4e29
  1. 41
      app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt

@ -26,7 +26,7 @@ import kotlinx.coroutines.launch
import org.jetbrains.anko.startActivity
import org.jetbrains.anko.textColor
class BookshelfFragment : BaseFragment(R.layout.fragment_bookshelf) {
class BookshelfFragment : BaseFragment(R.layout.fragment_bookshelf), BookGroupAdapter.CallBack {
private lateinit var bookshelfAdapter: BookshelfAdapter
private lateinit var bookGroupAdapter: BookGroupAdapter
@ -53,11 +53,30 @@ class BookshelfFragment : BaseFragment(R.layout.fragment_bookshelf) {
}
private fun initRecyclerView() {
refresh_layout.setColorSchemeColors(ThemeStore.accentColor(refresh_layout.context))
tv_recent_reading.textColor = ThemeStore.accentColor(tv_recent_reading.context)
rv_book_group.layoutManager = LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false)
bookGroupAdapter = BookGroupAdapter()
rv_book_group.adapter = bookGroupAdapter
bookGroupAdapter.callBack = object : BookGroupAdapter.CallBack {
bookGroupAdapter.callBack = this
rv_bookshelf.layoutManager = LinearLayoutManager(context)
rv_bookshelf.addItemDecoration(DividerItemDecoration(rv_bookshelf.context, LinearLayoutManager.VERTICAL))
bookshelfAdapter = BookshelfAdapter()
rv_bookshelf.adapter = bookshelfAdapter
}
private fun initBookGroupData() {
bookGroupLiveData?.removeObservers(viewLifecycleOwner)
bookGroupLiveData = LivePagedListBuilder(App.db.bookGroupDao().observeAll(), 10).build()
bookGroupLiveData?.observe(viewLifecycleOwner, Observer { bookGroupAdapter.submitList(it) })
}
private fun initBookshelfData() {
bookshelfLiveData?.removeObservers(viewLifecycleOwner)
bookshelfLiveData = LivePagedListBuilder(App.db.bookDao().recentRead(), 20).build()
bookshelfLiveData?.observe(viewLifecycleOwner, Observer { bookshelfAdapter.submitList(it) })
}
override fun open(bookGroup: BookGroup) {
when (bookGroup.groupId) {
-10 -> context?.let {
@ -82,23 +101,5 @@ class BookshelfFragment : BaseFragment(R.layout.fragment_bookshelf) {
else -> context?.startActivity<BookshelfActivity>(Pair("data", bookGroup))
}
}
}
rv_bookshelf.layoutManager = LinearLayoutManager(context)
rv_bookshelf.addItemDecoration(DividerItemDecoration(rv_bookshelf.context, LinearLayoutManager.VERTICAL))
bookshelfAdapter = BookshelfAdapter()
rv_bookshelf.adapter = bookshelfAdapter
}
private fun initBookGroupData() {
bookGroupLiveData?.removeObservers(viewLifecycleOwner)
bookGroupLiveData = LivePagedListBuilder(App.db.bookGroupDao().observeAll(), 10).build()
bookGroupLiveData?.observe(viewLifecycleOwner, Observer { bookGroupAdapter.submitList(it) })
}
private fun initBookshelfData() {
bookshelfLiveData?.removeObservers(viewLifecycleOwner)
bookshelfLiveData = LivePagedListBuilder(App.db.bookDao().recentRead(), 20).build()
bookshelfLiveData?.observe(viewLifecycleOwner, Observer { bookshelfAdapter.submitList(it) })
}
}
Loading…
Cancel
Save