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