优化书架界面显示
This commit is contained in:
@@ -3,9 +3,7 @@ package io.legato.kazusa.ui.main.bookshelf
|
||||
import android.content.res.Configuration
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import androidx.core.view.isVisible
|
||||
import androidx.fragment.app.activityViewModels
|
||||
import androidx.transition.TransitionManager
|
||||
import com.google.android.material.chip.Chip
|
||||
import io.legato.kazusa.R
|
||||
import io.legato.kazusa.base.BaseBottomSheetDialogFragment
|
||||
@@ -81,10 +79,6 @@ class BookshelfConfigBottomSheet : BaseBottomSheetDialogFragment(R.layout.dialog
|
||||
chipGrid.isChecked = isGrid
|
||||
chipGridCompact.isChecked = isGridCompact
|
||||
chipGridCover.isChecked = isGridCover
|
||||
|
||||
val showSlider = isGrid || isGridCompact || isGridCover
|
||||
sliderText.isVisible = showSlider
|
||||
sliderGridCount.isVisible = showSlider
|
||||
sliderGridCount.value = columnCount.toFloat()
|
||||
|
||||
|
||||
@@ -93,16 +87,6 @@ class BookshelfConfigBottomSheet : BaseBottomSheetDialogFragment(R.layout.dialog
|
||||
1 -> binding.chipGroupOrder.check(binding.chipDesc.id)
|
||||
}
|
||||
|
||||
chipGroupLayout.setOnCheckedStateChangeListener { _, checkedIds ->
|
||||
val checkedId = checkedIds.firstOrNull()
|
||||
val showSlider = checkedId == R.id.chip_grid ||
|
||||
checkedId == R.id.chip_grid_compact ||
|
||||
checkedId == R.id.chip_grid_cover
|
||||
TransitionManager.beginDelayedTransition(root)
|
||||
sliderText.isVisible = showSlider
|
||||
sliderGridCount.isVisible = showSlider
|
||||
}
|
||||
|
||||
btnOk.setOnClickListener {
|
||||
var notifyMain = false
|
||||
var recreate = false
|
||||
|
||||
@@ -132,13 +132,8 @@ class BooksFragment() : BaseFragment(R.layout.fragment_books),
|
||||
binding.refreshLayout.isRefreshing = false
|
||||
activityViewModel.upToc(booksAdapter.getItems())
|
||||
}
|
||||
if (bookshelfLayoutMode == 0 ||bookshelfLayoutMode == 4) {
|
||||
binding.rvBookshelf.layoutManager = LinearLayoutManager(context)
|
||||
binding.rvBookshelf.setRecycledViewPool(activityViewModel.booksListRecycledViewPool)
|
||||
} else {
|
||||
binding.rvBookshelf.layoutManager = GridLayoutManager(context, bookshelfLayoutGrid)
|
||||
binding.rvBookshelf.setRecycledViewPool(activityViewModel.booksGridRecycledViewPool)
|
||||
}
|
||||
binding.rvBookshelf.layoutManager = GridLayoutManager(context, bookshelfLayoutGrid)
|
||||
binding.rvBookshelf.setRecycledViewPool(activityViewModel.booksGridRecycledViewPool)
|
||||
booksAdapter.stateRestorationPolicy = StateRestorationPolicy.PREVENT_WHEN_EMPTY
|
||||
binding.rvBookshelf.adapter = booksAdapter
|
||||
booksAdapter.registerAdapterDataObserver(object : RecyclerView.AdapterDataObserver() {
|
||||
@@ -237,7 +232,7 @@ class BooksFragment() : BaseFragment(R.layout.fragment_books),
|
||||
|
||||
private fun startLastUpdateTimeJob() {
|
||||
upLastUpdateTimeJob?.cancel()
|
||||
if (!AppConfig.showLastUpdateTime || bookshelfLayoutMode != 0 ||bookshelfLayoutMode != 4) {
|
||||
if (!AppConfig.showLastUpdateTime || (bookshelfLayoutMode != 0 && bookshelfLayoutMode != 4)) {
|
||||
return
|
||||
}
|
||||
upLastUpdateTimeJob = lifecycleScope.launch {
|
||||
@@ -271,6 +266,8 @@ class BooksFragment() : BaseFragment(R.layout.fragment_books),
|
||||
/**
|
||||
* 将 RecyclerView 中的视图全部回收到 RecycledViewPool 中
|
||||
*/
|
||||
upLastUpdateTimeJob?.cancel()
|
||||
booksFlowJob?.cancel()
|
||||
binding.rvBookshelf.setItemViewCacheSize(0)
|
||||
binding.rvBookshelf.adapter = null
|
||||
}
|
||||
|
||||
@@ -116,11 +116,8 @@ class BookshelfFragment2() : BaseBookshelfFragment(R.layout.fragment_bookshelf2)
|
||||
binding.refreshLayout.isRefreshing = false
|
||||
activityViewModel.upToc(books)
|
||||
}
|
||||
if (bookshelfLayoutMode == 0 || bookshelfLayoutMode == 4) {
|
||||
binding.rvBookshelf.layoutManager = LinearLayoutManager(context)
|
||||
} else {
|
||||
binding.rvBookshelf.layoutManager = GridLayoutManager(context, bookshelfLayoutGrid)
|
||||
}
|
||||
|
||||
binding.rvBookshelf.layoutManager = GridLayoutManager(context, bookshelfLayoutGrid)
|
||||
binding.rvBookshelf.itemAnimator = null
|
||||
binding.rvBookshelf.adapter = booksAdapter
|
||||
booksAdapter.registerAdapterDataObserver(object : RecyclerView.AdapterDataObserver() {
|
||||
|
||||
+2
-3
@@ -16,8 +16,7 @@ abstract class BaseBooksAdapter<VB : ViewBinding>(context: Context) :
|
||||
object : DiffUtil.ItemCallback<Book>() {
|
||||
|
||||
override fun areItemsTheSame(oldItem: Book, newItem: Book): Boolean {
|
||||
return oldItem.name == newItem.name
|
||||
&& oldItem.author == newItem.author
|
||||
return oldItem.bookUrl == newItem.bookUrl
|
||||
}
|
||||
|
||||
override fun areContentsTheSame(oldItem: Book, newItem: Book): Boolean {
|
||||
@@ -76,7 +75,7 @@ abstract class BaseBooksAdapter<VB : ViewBinding>(context: Context) :
|
||||
fun notification(bookUrl: String) {
|
||||
getItems().forEachIndexed { i, it ->
|
||||
if (it.bookUrl == bookUrl) {
|
||||
notifyItemChanged(i, bundleOf(Pair("refresh", null), Pair("lastUpdateTime", null)))
|
||||
notifyItemChanged(i, bundleOf("refresh" to true, "lastUpdateTime" to true))
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
+2
-1
@@ -88,9 +88,10 @@ class BooksAdapterList(
|
||||
val time = item.latestChapterTime.toTimeAgo()
|
||||
if (binding.tvLastUpdateTime.text != time) {
|
||||
binding.tvLastUpdateTime.text = time
|
||||
binding.tvLastUpdateTime.isVisible = true
|
||||
}
|
||||
} else {
|
||||
binding.tvLastUpdateTime.text = ""
|
||||
binding.tvLastUpdateTime.isVisible = false
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+2
-1
@@ -92,9 +92,10 @@ class BooksAdapterListCompact(
|
||||
val time = item.latestChapterTime.toTimeAgo()
|
||||
if (binding.tvLastUpdateTime.text != time) {
|
||||
binding.tvLastUpdateTime.text = time
|
||||
binding.tvLastUpdateTime.isVisible = true
|
||||
}
|
||||
} else {
|
||||
binding.tvLastUpdateTime.text = ""
|
||||
binding.tvLastUpdateTime.isVisible = false
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-2
@@ -22,8 +22,7 @@ abstract class BaseBooksAdapter<VH : RecyclerView.ViewHolder>(
|
||||
override fun areItemsTheSame(oldItem: Any, newItem: Any): Boolean {
|
||||
return when {
|
||||
oldItem is Book && newItem is Book -> {
|
||||
oldItem.name == newItem.name
|
||||
&& oldItem.author == newItem.author
|
||||
oldItem.bookUrl == newItem.bookUrl
|
||||
}
|
||||
|
||||
oldItem is BookGroup && newItem is BookGroup -> {
|
||||
|
||||
+2
-1
@@ -105,9 +105,10 @@ class BooksAdapterList(context: Context, callBack: CallBack) :
|
||||
val time = item.latestChapterTime.toTimeAgo()
|
||||
if (binding.tvLastUpdateTime.text != time) {
|
||||
binding.tvLastUpdateTime.text = time
|
||||
binding.tvLastUpdateTime.visible()
|
||||
}
|
||||
} else {
|
||||
binding.tvLastUpdateTime.text = ""
|
||||
binding.tvLastUpdateTime.gone()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+2
-1
@@ -103,9 +103,10 @@ class BooksAdapterListCompact(context: Context, callBack: CallBack) :
|
||||
val time = item.latestChapterTime.toTimeAgo()
|
||||
if (binding.tvLastUpdateTime.text != time) {
|
||||
binding.tvLastUpdateTime.text = time
|
||||
binding.tvLastUpdateTime.visible()
|
||||
}
|
||||
} else {
|
||||
binding.tvLastUpdateTime.text = ""
|
||||
binding.tvLastUpdateTime.gone()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user