|
|
@ -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,9 +45,19 @@ 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 -> { |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |