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
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.paging.PagedListAdapter
import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.RecyclerView
import io.legado.app.R
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 {
@JvmField
@ -23,11 +25,11 @@ class RecentReadAdapter : PagedListAdapter<Book, RecentReadAdapter.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) {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
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) {
private lateinit var recentReadAdapter: RecentReadAdapter
private lateinit var bookshelfAdapter: BookshelfAdapter
private lateinit var bookGroupAdapter: BookGroupAdapter
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?) {
setSupportToolbar(toolbar)
initRecyclerView()
initBookGroupData()
initRecentReadData()
initBookshelfData()
}
override fun onCompatCreateOptionsMenu(menu: Menu) {
@ -35,12 +35,12 @@ class BookshelfFragment : BaseFragment(R.layout.fragment_bookshelf) {
}
private fun initRecyclerView() {
rv_bookshelf.layoutManager = LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false)
rv_book_group.layoutManager = LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false)
bookGroupAdapter = BookGroupAdapter()
rv_bookshelf.adapter = bookGroupAdapter
rv_read_books.layoutManager = LinearLayoutManager(context)
recentReadAdapter = RecentReadAdapter()
rv_read_books.adapter = recentReadAdapter
rv_book_group.adapter = bookGroupAdapter
rv_bookshelf.layoutManager = LinearLayoutManager(context)
bookshelfAdapter = BookshelfAdapter()
rv_bookshelf.adapter = bookshelfAdapter
}
private fun initBookGroupData() {
@ -49,10 +49,10 @@ class BookshelfFragment : BaseFragment(R.layout.fragment_bookshelf) {
bookGroupLiveData?.observe(viewLifecycleOwner, Observer { bookGroupAdapter.submitList(it) })
}
private fun initRecentReadData() {
recentReadLiveData?.removeObservers(viewLifecycleOwner)
recentReadLiveData = LivePagedListBuilder(App.db.bookDao().recentRead(), 20).build()
recentReadLiveData?.observe(viewLifecycleOwner, Observer { recentReadAdapter.submitList(it) })
private fun initBookshelfData() {
bookshelfLiveData?.removeObservers(viewLifecycleOwner)
bookshelfLiveData = LivePagedListBuilder(App.db.bookDao().recentRead(), 20).build()
bookshelfLiveData?.observe(viewLifecycleOwner, Observer { bookshelfAdapter.submitList(it) })
}
}

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