pull/32/head
GKF 6 years ago
parent 364ee607d7
commit 81497b7a87
  1. 3
      app/src/main/java/io/legado/app/data/dao/BookDao.kt
  2. 19
      app/src/main/java/io/legado/app/ui/bookshelf/BookshelfActivity.kt

@ -11,6 +11,9 @@ import io.legado.app.data.entities.Book
@Dao @Dao
interface BookDao { interface BookDao {
@Query("SELECT * FROM books")
fun observeAll(): DataSource.Factory<Int, Book>
@Query("SELECT * FROM books WHERE `group` = :group") @Query("SELECT * FROM books WHERE `group` = :group")
fun observeByGroup(group: Int): DataSource.Factory<Int, Book> fun observeByGroup(group: Int): DataSource.Factory<Int, Book>

@ -2,10 +2,16 @@ package io.legado.app.ui.bookshelf
import android.os.Bundle import android.os.Bundle
import android.widget.LinearLayout import android.widget.LinearLayout
import androidx.lifecycle.LiveData
import androidx.lifecycle.Observer
import androidx.paging.LivePagedListBuilder
import androidx.paging.PagedList
import androidx.recyclerview.widget.DividerItemDecoration import androidx.recyclerview.widget.DividerItemDecoration
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import io.legado.app.App
import io.legado.app.R import io.legado.app.R
import io.legado.app.base.BaseActivity import io.legado.app.base.BaseActivity
import io.legado.app.data.entities.Book
import io.legado.app.utils.getViewModel import io.legado.app.utils.getViewModel
import kotlinx.android.synthetic.main.activity_bookshelf.* import kotlinx.android.synthetic.main.activity_bookshelf.*
@ -16,6 +22,7 @@ class BookshelfActivity : BaseActivity<BookshelfViewModel>() {
get() = R.layout.activity_bookshelf get() = R.layout.activity_bookshelf
private lateinit var bookshelfAdapter: BookshelfAdapter private lateinit var bookshelfAdapter: BookshelfAdapter
private var bookshelfLiveData: LiveData<PagedList<Book>>? = null
override fun onViewModelCreated(viewModel: BookshelfViewModel, savedInstanceState: Bundle?) { override fun onViewModelCreated(viewModel: BookshelfViewModel, savedInstanceState: Bundle?) {
if (viewModel.bookGroup == null) { if (viewModel.bookGroup == null) {
@ -38,7 +45,17 @@ class BookshelfActivity : BaseActivity<BookshelfViewModel>() {
private fun upRecyclerData() { private fun upRecyclerData() {
viewModel.bookGroup?.let { viewModel.bookGroup?.let {
when (it.groupId) { when (it.groupId) {
-1 -> {
bookshelfLiveData?.removeObservers(this)
bookshelfLiveData =
LivePagedListBuilder(App.db.bookDao().observeAll(), 10).build()
bookshelfLiveData?.observe(
this,
Observer { pageList -> bookshelfAdapter.submitList(pageList) })
}
else -> {
}
} }
} }
} }

Loading…
Cancel
Save