优化书架界面显示
This commit is contained in:
@@ -3,9 +3,7 @@ package io.legato.kazusa.ui.main.bookshelf
|
|||||||
import android.content.res.Configuration
|
import android.content.res.Configuration
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import androidx.core.view.isVisible
|
|
||||||
import androidx.fragment.app.activityViewModels
|
import androidx.fragment.app.activityViewModels
|
||||||
import androidx.transition.TransitionManager
|
|
||||||
import com.google.android.material.chip.Chip
|
import com.google.android.material.chip.Chip
|
||||||
import io.legato.kazusa.R
|
import io.legato.kazusa.R
|
||||||
import io.legato.kazusa.base.BaseBottomSheetDialogFragment
|
import io.legato.kazusa.base.BaseBottomSheetDialogFragment
|
||||||
@@ -81,10 +79,6 @@ class BookshelfConfigBottomSheet : BaseBottomSheetDialogFragment(R.layout.dialog
|
|||||||
chipGrid.isChecked = isGrid
|
chipGrid.isChecked = isGrid
|
||||||
chipGridCompact.isChecked = isGridCompact
|
chipGridCompact.isChecked = isGridCompact
|
||||||
chipGridCover.isChecked = isGridCover
|
chipGridCover.isChecked = isGridCover
|
||||||
|
|
||||||
val showSlider = isGrid || isGridCompact || isGridCover
|
|
||||||
sliderText.isVisible = showSlider
|
|
||||||
sliderGridCount.isVisible = showSlider
|
|
||||||
sliderGridCount.value = columnCount.toFloat()
|
sliderGridCount.value = columnCount.toFloat()
|
||||||
|
|
||||||
|
|
||||||
@@ -93,16 +87,6 @@ class BookshelfConfigBottomSheet : BaseBottomSheetDialogFragment(R.layout.dialog
|
|||||||
1 -> binding.chipGroupOrder.check(binding.chipDesc.id)
|
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 {
|
btnOk.setOnClickListener {
|
||||||
var notifyMain = false
|
var notifyMain = false
|
||||||
var recreate = false
|
var recreate = false
|
||||||
|
|||||||
@@ -132,13 +132,8 @@ class BooksFragment() : BaseFragment(R.layout.fragment_books),
|
|||||||
binding.refreshLayout.isRefreshing = false
|
binding.refreshLayout.isRefreshing = false
|
||||||
activityViewModel.upToc(booksAdapter.getItems())
|
activityViewModel.upToc(booksAdapter.getItems())
|
||||||
}
|
}
|
||||||
if (bookshelfLayoutMode == 0 ||bookshelfLayoutMode == 4) {
|
binding.rvBookshelf.layoutManager = GridLayoutManager(context, bookshelfLayoutGrid)
|
||||||
binding.rvBookshelf.layoutManager = LinearLayoutManager(context)
|
binding.rvBookshelf.setRecycledViewPool(activityViewModel.booksGridRecycledViewPool)
|
||||||
binding.rvBookshelf.setRecycledViewPool(activityViewModel.booksListRecycledViewPool)
|
|
||||||
} else {
|
|
||||||
binding.rvBookshelf.layoutManager = GridLayoutManager(context, bookshelfLayoutGrid)
|
|
||||||
binding.rvBookshelf.setRecycledViewPool(activityViewModel.booksGridRecycledViewPool)
|
|
||||||
}
|
|
||||||
booksAdapter.stateRestorationPolicy = StateRestorationPolicy.PREVENT_WHEN_EMPTY
|
booksAdapter.stateRestorationPolicy = StateRestorationPolicy.PREVENT_WHEN_EMPTY
|
||||||
binding.rvBookshelf.adapter = booksAdapter
|
binding.rvBookshelf.adapter = booksAdapter
|
||||||
booksAdapter.registerAdapterDataObserver(object : RecyclerView.AdapterDataObserver() {
|
booksAdapter.registerAdapterDataObserver(object : RecyclerView.AdapterDataObserver() {
|
||||||
@@ -237,7 +232,7 @@ class BooksFragment() : BaseFragment(R.layout.fragment_books),
|
|||||||
|
|
||||||
private fun startLastUpdateTimeJob() {
|
private fun startLastUpdateTimeJob() {
|
||||||
upLastUpdateTimeJob?.cancel()
|
upLastUpdateTimeJob?.cancel()
|
||||||
if (!AppConfig.showLastUpdateTime || bookshelfLayoutMode != 0 ||bookshelfLayoutMode != 4) {
|
if (!AppConfig.showLastUpdateTime || (bookshelfLayoutMode != 0 && bookshelfLayoutMode != 4)) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
upLastUpdateTimeJob = lifecycleScope.launch {
|
upLastUpdateTimeJob = lifecycleScope.launch {
|
||||||
@@ -271,6 +266,8 @@ class BooksFragment() : BaseFragment(R.layout.fragment_books),
|
|||||||
/**
|
/**
|
||||||
* 将 RecyclerView 中的视图全部回收到 RecycledViewPool 中
|
* 将 RecyclerView 中的视图全部回收到 RecycledViewPool 中
|
||||||
*/
|
*/
|
||||||
|
upLastUpdateTimeJob?.cancel()
|
||||||
|
booksFlowJob?.cancel()
|
||||||
binding.rvBookshelf.setItemViewCacheSize(0)
|
binding.rvBookshelf.setItemViewCacheSize(0)
|
||||||
binding.rvBookshelf.adapter = null
|
binding.rvBookshelf.adapter = null
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -116,11 +116,8 @@ class BookshelfFragment2() : BaseBookshelfFragment(R.layout.fragment_bookshelf2)
|
|||||||
binding.refreshLayout.isRefreshing = false
|
binding.refreshLayout.isRefreshing = false
|
||||||
activityViewModel.upToc(books)
|
activityViewModel.upToc(books)
|
||||||
}
|
}
|
||||||
if (bookshelfLayoutMode == 0 || bookshelfLayoutMode == 4) {
|
|
||||||
binding.rvBookshelf.layoutManager = LinearLayoutManager(context)
|
binding.rvBookshelf.layoutManager = GridLayoutManager(context, bookshelfLayoutGrid)
|
||||||
} else {
|
|
||||||
binding.rvBookshelf.layoutManager = GridLayoutManager(context, bookshelfLayoutGrid)
|
|
||||||
}
|
|
||||||
binding.rvBookshelf.itemAnimator = null
|
binding.rvBookshelf.itemAnimator = null
|
||||||
binding.rvBookshelf.adapter = booksAdapter
|
binding.rvBookshelf.adapter = booksAdapter
|
||||||
booksAdapter.registerAdapterDataObserver(object : RecyclerView.AdapterDataObserver() {
|
booksAdapter.registerAdapterDataObserver(object : RecyclerView.AdapterDataObserver() {
|
||||||
|
|||||||
+2
-3
@@ -16,8 +16,7 @@ abstract class BaseBooksAdapter<VB : ViewBinding>(context: Context) :
|
|||||||
object : DiffUtil.ItemCallback<Book>() {
|
object : DiffUtil.ItemCallback<Book>() {
|
||||||
|
|
||||||
override fun areItemsTheSame(oldItem: Book, newItem: Book): Boolean {
|
override fun areItemsTheSame(oldItem: Book, newItem: Book): Boolean {
|
||||||
return oldItem.name == newItem.name
|
return oldItem.bookUrl == newItem.bookUrl
|
||||||
&& oldItem.author == newItem.author
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun areContentsTheSame(oldItem: Book, newItem: Book): Boolean {
|
override fun areContentsTheSame(oldItem: Book, newItem: Book): Boolean {
|
||||||
@@ -76,7 +75,7 @@ abstract class BaseBooksAdapter<VB : ViewBinding>(context: Context) :
|
|||||||
fun notification(bookUrl: String) {
|
fun notification(bookUrl: String) {
|
||||||
getItems().forEachIndexed { i, it ->
|
getItems().forEachIndexed { i, it ->
|
||||||
if (it.bookUrl == bookUrl) {
|
if (it.bookUrl == bookUrl) {
|
||||||
notifyItemChanged(i, bundleOf(Pair("refresh", null), Pair("lastUpdateTime", null)))
|
notifyItemChanged(i, bundleOf("refresh" to true, "lastUpdateTime" to true))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-1
@@ -88,9 +88,10 @@ class BooksAdapterList(
|
|||||||
val time = item.latestChapterTime.toTimeAgo()
|
val time = item.latestChapterTime.toTimeAgo()
|
||||||
if (binding.tvLastUpdateTime.text != time) {
|
if (binding.tvLastUpdateTime.text != time) {
|
||||||
binding.tvLastUpdateTime.text = time
|
binding.tvLastUpdateTime.text = time
|
||||||
|
binding.tvLastUpdateTime.isVisible = true
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
binding.tvLastUpdateTime.text = ""
|
binding.tvLastUpdateTime.isVisible = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
-1
@@ -92,9 +92,10 @@ class BooksAdapterListCompact(
|
|||||||
val time = item.latestChapterTime.toTimeAgo()
|
val time = item.latestChapterTime.toTimeAgo()
|
||||||
if (binding.tvLastUpdateTime.text != time) {
|
if (binding.tvLastUpdateTime.text != time) {
|
||||||
binding.tvLastUpdateTime.text = time
|
binding.tvLastUpdateTime.text = time
|
||||||
|
binding.tvLastUpdateTime.isVisible = true
|
||||||
}
|
}
|
||||||
} else {
|
} 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 {
|
override fun areItemsTheSame(oldItem: Any, newItem: Any): Boolean {
|
||||||
return when {
|
return when {
|
||||||
oldItem is Book && newItem is Book -> {
|
oldItem is Book && newItem is Book -> {
|
||||||
oldItem.name == newItem.name
|
oldItem.bookUrl == newItem.bookUrl
|
||||||
&& oldItem.author == newItem.author
|
|
||||||
}
|
}
|
||||||
|
|
||||||
oldItem is BookGroup && newItem is BookGroup -> {
|
oldItem is BookGroup && newItem is BookGroup -> {
|
||||||
|
|||||||
+2
-1
@@ -105,9 +105,10 @@ class BooksAdapterList(context: Context, callBack: CallBack) :
|
|||||||
val time = item.latestChapterTime.toTimeAgo()
|
val time = item.latestChapterTime.toTimeAgo()
|
||||||
if (binding.tvLastUpdateTime.text != time) {
|
if (binding.tvLastUpdateTime.text != time) {
|
||||||
binding.tvLastUpdateTime.text = time
|
binding.tvLastUpdateTime.text = time
|
||||||
|
binding.tvLastUpdateTime.visible()
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
binding.tvLastUpdateTime.text = ""
|
binding.tvLastUpdateTime.gone()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
-1
@@ -103,9 +103,10 @@ class BooksAdapterListCompact(context: Context, callBack: CallBack) :
|
|||||||
val time = item.latestChapterTime.toTimeAgo()
|
val time = item.latestChapterTime.toTimeAgo()
|
||||||
if (binding.tvLastUpdateTime.text != time) {
|
if (binding.tvLastUpdateTime.text != time) {
|
||||||
binding.tvLastUpdateTime.text = time
|
binding.tvLastUpdateTime.text = time
|
||||||
|
binding.tvLastUpdateTime.visible()
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
binding.tvLastUpdateTime.text = ""
|
binding.tvLastUpdateTime.gone()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -207,35 +207,36 @@
|
|||||||
app:chipSpacingVertical="0dp"
|
app:chipSpacingVertical="0dp"
|
||||||
app:selectionRequired="true"
|
app:selectionRequired="true"
|
||||||
app:singleSelection="true" />
|
app:singleSelection="true" />
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="horizontal"
|
||||||
|
android:layout_marginVertical="16dp">
|
||||||
|
|
||||||
|
<View
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:layout_weight="1" />
|
||||||
|
|
||||||
|
<com.google.android.material.button.MaterialButton
|
||||||
|
android:id="@+id/btnCancel"
|
||||||
|
style="@style/Widget.Material3Expressive.Button.OutlinedButton"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginEnd="8dp"
|
||||||
|
android:text="@string/cancel" />
|
||||||
|
|
||||||
|
<com.google.android.material.button.MaterialButton
|
||||||
|
android:id="@+id/btnOk"
|
||||||
|
style="@style/Widget.Material3Expressive.Button"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/confirm" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
</androidx.core.widget.NestedScrollView>
|
</androidx.core.widget.NestedScrollView>
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:orientation="horizontal"
|
|
||||||
android:paddingVertical="16dp">
|
|
||||||
|
|
||||||
<View
|
|
||||||
android:layout_width="0dp"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
android:layout_weight="1" />
|
|
||||||
|
|
||||||
<com.google.android.material.button.MaterialButton
|
|
||||||
android:id="@+id/btnCancel"
|
|
||||||
style="@style/Widget.Material3Expressive.Button.OutlinedButton"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginEnd="8dp"
|
|
||||||
android:text="@string/cancel" />
|
|
||||||
|
|
||||||
<com.google.android.material.button.MaterialButton
|
|
||||||
android:id="@+id/btnOk"
|
|
||||||
style="@style/Widget.Material3Expressive.Button"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:text="@string/confirm" />
|
|
||||||
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|||||||
@@ -155,10 +155,7 @@
|
|||||||
android:singleLine="true"
|
android:singleLine="true"
|
||||||
android:text="@string/text"
|
android:text="@string/text"
|
||||||
android:textSize="13sp"
|
android:textSize="13sp"
|
||||||
android:textColor="?attr/colorPrimary"
|
android:textColor="?attr/colorPrimary" />
|
||||||
app:layout_constraintBottom_toTopOf="@id/iv_last"
|
|
||||||
app:layout_constraintStart_toEndOf="@+id/iv_last"
|
|
||||||
app:layout_constraintTop_toBottomOf="@+id/iv_last" />
|
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/tv_last"
|
android:id="@+id/tv_last"
|
||||||
@@ -168,12 +165,7 @@
|
|||||||
android:scrollbars="none"
|
android:scrollbars="none"
|
||||||
android:singleLine="true"
|
android:singleLine="true"
|
||||||
android:text="@string/lasted_show"
|
android:text="@string/lasted_show"
|
||||||
android:textSize="13sp"
|
android:textSize="13sp" />
|
||||||
tools:ignore="TextContrastCheck"
|
|
||||||
app:layout_constraintBottom_toTopOf="@id/iv_last"
|
|
||||||
app:layout_constraintStart_toEndOf="@+id/tv_last_update_time"
|
|
||||||
app:layout_constraintTop_toBottomOf="@+id/iv_last"
|
|
||||||
app:layout_constraintEnd_toEndOf="parent"/>
|
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
|||||||
@@ -140,10 +140,7 @@
|
|||||||
android:singleLine="true"
|
android:singleLine="true"
|
||||||
android:text="@string/text"
|
android:text="@string/text"
|
||||||
android:textSize="13sp"
|
android:textSize="13sp"
|
||||||
android:textColor="?attr/colorSecondary"
|
android:textColor="?attr/colorSecondary" />
|
||||||
app:layout_constraintBottom_toTopOf="@id/iv_last"
|
|
||||||
app:layout_constraintStart_toEndOf="@+id/iv_last"
|
|
||||||
app:layout_constraintTop_toBottomOf="@+id/iv_last" />
|
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/tv_last"
|
android:id="@+id/tv_last"
|
||||||
@@ -153,12 +150,7 @@
|
|||||||
android:scrollbars="none"
|
android:scrollbars="none"
|
||||||
android:singleLine="true"
|
android:singleLine="true"
|
||||||
android:text="@string/lasted_show"
|
android:text="@string/lasted_show"
|
||||||
android:textSize="13sp"
|
android:textSize="13sp" />
|
||||||
tools:ignore="TextContrastCheck"
|
|
||||||
app:layout_constraintBottom_toTopOf="@id/iv_last"
|
|
||||||
app:layout_constraintStart_toEndOf="@+id/tv_last_update_time"
|
|
||||||
app:layout_constraintTop_toBottomOf="@+id/iv_last"
|
|
||||||
app:layout_constraintEnd_toEndOf="parent"/>
|
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user