pull/32/head
gedoor 6 years ago
parent 9b8176ed17
commit a3ac41f5ff
  1. 8
      app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfAdapter.kt
  2. 24
      app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt
  3. 4
      app/src/main/res/layout/fragment_bookshelf.xml

@ -1,13 +1,15 @@
package io.legado.app.ui.main.bookshelf package io.legado.app.ui.main.bookshelf
import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import androidx.paging.PagedListAdapter import androidx.paging.PagedListAdapter
import androidx.recyclerview.widget.DiffUtil import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import io.legado.app.R
import io.legado.app.data.entities.Book import io.legado.app.data.entities.Book
class RecentReadAdapter : PagedListAdapter<Book, RecentReadAdapter.MyViewHolder>(DIFF_CALLBACK) { class BookshelfAdapter : PagedListAdapter<Book, BookshelfAdapter.MyViewHolder>(DIFF_CALLBACK) {
companion object { companion object {
@JvmField @JvmField
@ -23,11 +25,11 @@ class RecentReadAdapter : PagedListAdapter<Book, RecentReadAdapter.MyViewHolder>
} }
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyViewHolder { override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyViewHolder {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates. return MyViewHolder(LayoutInflater.from(parent.context).inflate(R.layout.item_bookshelf_list, parent, false))
} }
override fun onBindViewHolder(holder: MyViewHolder, position: Int) { override fun onBindViewHolder(holder: MyViewHolder, position: Int) {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
} }
class MyViewHolder(view: View) : RecyclerView.ViewHolder(view) { class MyViewHolder(view: View) : RecyclerView.ViewHolder(view) {

@ -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) })
} }
} }

@ -13,12 +13,12 @@
app:title="@string/bookshelf" /> app:title="@string/bookshelf" />
<androidx.recyclerview.widget.RecyclerView <androidx.recyclerview.widget.RecyclerView
android:id="@+id/rv_bookshelf" android:id="@+id/rv_book_group"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" /> android:layout_height="wrap_content" />
<androidx.recyclerview.widget.RecyclerView <androidx.recyclerview.widget.RecyclerView
android:id="@+id/rv_read_books" android:id="@+id/rv_bookshelf"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" /> android:layout_height="match_parent" />
</LinearLayout> </LinearLayout>
Loading…
Cancel
Save