|
|
@ -26,7 +26,7 @@ import kotlinx.coroutines.launch |
|
|
|
import org.jetbrains.anko.startActivity |
|
|
|
import org.jetbrains.anko.startActivity |
|
|
|
import org.jetbrains.anko.textColor |
|
|
|
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 bookshelfAdapter: BookshelfAdapter |
|
|
|
private lateinit var bookGroupAdapter: BookGroupAdapter |
|
|
|
private lateinit var bookGroupAdapter: BookGroupAdapter |
|
|
@ -53,11 +53,30 @@ class BookshelfFragment : BaseFragment(R.layout.fragment_bookshelf) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private fun initRecyclerView() { |
|
|
|
private fun initRecyclerView() { |
|
|
|
|
|
|
|
refresh_layout.setColorSchemeColors(ThemeStore.accentColor(refresh_layout.context)) |
|
|
|
tv_recent_reading.textColor = ThemeStore.accentColor(tv_recent_reading.context) |
|
|
|
tv_recent_reading.textColor = ThemeStore.accentColor(tv_recent_reading.context) |
|
|
|
rv_book_group.layoutManager = LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false) |
|
|
|
rv_book_group.layoutManager = LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false) |
|
|
|
bookGroupAdapter = BookGroupAdapter() |
|
|
|
bookGroupAdapter = BookGroupAdapter() |
|
|
|
rv_book_group.adapter = 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) { |
|
|
|
override fun open(bookGroup: BookGroup) { |
|
|
|
when (bookGroup.groupId) { |
|
|
|
when (bookGroup.groupId) { |
|
|
|
-10 -> context?.let { |
|
|
|
-10 -> context?.let { |
|
|
@ -82,23 +101,5 @@ class BookshelfFragment : BaseFragment(R.layout.fragment_bookshelf) { |
|
|
|
else -> context?.startActivity<BookshelfActivity>(Pair("data", bookGroup)) |
|
|
|
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) }) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |