|
|
@ -18,16 +18,16 @@ import kotlinx.android.synthetic.main.view_title_bar.* |
|
|
|
|
|
|
|
|
|
|
|
class BookshelfFragment : BaseFragment(R.layout.fragment_bookshelf) { |
|
|
|
class BookshelfFragment : BaseFragment(R.layout.fragment_bookshelf) { |
|
|
|
|
|
|
|
|
|
|
|
private lateinit var recentReadAdapter: RecentReadAdapter |
|
|
|
private lateinit var bookshelfAdapter: BookshelfAdapter |
|
|
|
private lateinit var bookGroupAdapter: BookGroupAdapter |
|
|
|
private lateinit var bookGroupAdapter: BookGroupAdapter |
|
|
|
private var bookGroupLiveData: LiveData<PagedList<BookGroup>>? = null |
|
|
|
private var bookGroupLiveData: LiveData<PagedList<BookGroup>>? = null |
|
|
|
private var recentReadLiveData: LiveData<PagedList<Book>>? = null |
|
|
|
private var bookshelfLiveData: LiveData<PagedList<Book>>? = null |
|
|
|
|
|
|
|
|
|
|
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { |
|
|
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { |
|
|
|
setSupportToolbar(toolbar) |
|
|
|
setSupportToolbar(toolbar) |
|
|
|
initRecyclerView() |
|
|
|
initRecyclerView() |
|
|
|
initBookGroupData() |
|
|
|
initBookGroupData() |
|
|
|
initRecentReadData() |
|
|
|
initBookshelfData() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
override fun onCompatCreateOptionsMenu(menu: Menu) { |
|
|
|
override fun onCompatCreateOptionsMenu(menu: Menu) { |
|
|
@ -35,12 +35,12 @@ class BookshelfFragment : BaseFragment(R.layout.fragment_bookshelf) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private fun initRecyclerView() { |
|
|
|
private fun initRecyclerView() { |
|
|
|
rv_bookshelf.layoutManager = LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false) |
|
|
|
rv_book_group.layoutManager = LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false) |
|
|
|
bookGroupAdapter = BookGroupAdapter() |
|
|
|
bookGroupAdapter = BookGroupAdapter() |
|
|
|
rv_bookshelf.adapter = bookGroupAdapter |
|
|
|
rv_book_group.adapter = bookGroupAdapter |
|
|
|
rv_read_books.layoutManager = LinearLayoutManager(context) |
|
|
|
rv_bookshelf.layoutManager = LinearLayoutManager(context) |
|
|
|
recentReadAdapter = RecentReadAdapter() |
|
|
|
bookshelfAdapter = BookshelfAdapter() |
|
|
|
rv_read_books.adapter = recentReadAdapter |
|
|
|
rv_bookshelf.adapter = bookshelfAdapter |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private fun initBookGroupData() { |
|
|
|
private fun initBookGroupData() { |
|
|
@ -49,10 +49,10 @@ class BookshelfFragment : BaseFragment(R.layout.fragment_bookshelf) { |
|
|
|
bookGroupLiveData?.observe(viewLifecycleOwner, Observer { bookGroupAdapter.submitList(it) }) |
|
|
|
bookGroupLiveData?.observe(viewLifecycleOwner, Observer { bookGroupAdapter.submitList(it) }) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private fun initRecentReadData() { |
|
|
|
private fun initBookshelfData() { |
|
|
|
recentReadLiveData?.removeObservers(viewLifecycleOwner) |
|
|
|
bookshelfLiveData?.removeObservers(viewLifecycleOwner) |
|
|
|
recentReadLiveData = LivePagedListBuilder(App.db.bookDao().recentRead(), 20).build() |
|
|
|
bookshelfLiveData = LivePagedListBuilder(App.db.bookDao().recentRead(), 20).build() |
|
|
|
recentReadLiveData?.observe(viewLifecycleOwner, Observer { recentReadAdapter.submitList(it) }) |
|
|
|
bookshelfLiveData?.observe(viewLifecycleOwner, Observer { bookshelfAdapter.submitList(it) }) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |