Quellcode durchsuchen

优化书架界面显示

HapeLee vor 1 Jahr
Ursprung
Commit
5aff77d836

+ 0 - 16
app/src/main/java/io/legato/kazusa/ui/main/bookshelf/BookshelfConfigBottomSheet.kt

@@ -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

+ 5 - 8
app/src/main/java/io/legato/kazusa/ui/main/bookshelf/books/BooksFragment.kt

@@ -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 = 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
         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
     }
     }

+ 2 - 5
app/src/main/java/io/legato/kazusa/ui/main/bookshelf/books/BookshelfFragment2.kt

@@ -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)
-        } else {
-            binding.rvBookshelf.layoutManager = GridLayoutManager(context, bookshelfLayoutGrid)
-        }
+
+        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
app/src/main/java/io/legato/kazusa/ui/main/bookshelf/books/styleDefalut/BaseBooksAdapter.kt

@@ -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
-                        && oldItem.author == newItem.author
+                return oldItem.bookUrl == newItem.bookUrl
             }
             }
 
 
             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
app/src/main/java/io/legato/kazusa/ui/main/bookshelf/books/styleDefalut/BooksAdapterList.kt

@@ -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
app/src/main/java/io/legato/kazusa/ui/main/bookshelf/books/styleDefalut/BooksAdapterListCompact.kt

@@ -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
app/src/main/java/io/legato/kazusa/ui/main/bookshelf/books/styleFold/BaseBooksAdapter.kt

@@ -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.author == newItem.author
+                    oldItem.bookUrl == newItem.bookUrl
                 }
                 }
 
 
                 oldItem is BookGroup && newItem is BookGroup -> {
                 oldItem is BookGroup && newItem is BookGroup -> {

+ 2 - 1
app/src/main/java/io/legato/kazusa/ui/main/bookshelf/books/styleFold/BooksAdapterList.kt

@@ -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
app/src/main/java/io/legato/kazusa/ui/main/bookshelf/books/styleFold/BooksAdapterListCompact.kt

@@ -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()
             }
             }
         }
         }
 
 

+ 26 - 25
app/src/main/res/layout/dialog_bookshelf_config.xml

@@ -207,35 +207,36 @@
                 app:chipSpacingVertical="0dp"
                 app:chipSpacingVertical="0dp"
                 app:selectionRequired="true"
                 app:selectionRequired="true"
                 app:singleSelection="true" />
                 app:singleSelection="true" />
-        </LinearLayout>
-    </androidx.core.widget.NestedScrollView>
 
 
-    <LinearLayout
-        android:layout_width="match_parent"
-        android:layout_height="wrap_content"
-        android:orientation="horizontal"
-        android:paddingVertical="16dp">
+            <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" />
 
 
-        <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/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" />
 
 
-        <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>
 
 
 </LinearLayout>
 </LinearLayout>

+ 2 - 10
app/src/main/res/layout/item_bookshelf_list.xml

@@ -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"
-                    app:layout_constraintBottom_toTopOf="@id/iv_last"
-                    app:layout_constraintStart_toEndOf="@+id/iv_last"
-                    app:layout_constraintTop_toBottomOf="@+id/iv_last" />
+                    android:textColor="?attr/colorPrimary" />
 
 
                 <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"
-                    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"/>
+                    android:textSize="13sp" />
 
 
             </LinearLayout>
             </LinearLayout>
 
 

+ 2 - 10
app/src/main/res/layout/item_bookshelf_list_compact.xml

@@ -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"
-                    app:layout_constraintBottom_toTopOf="@id/iv_last"
-                    app:layout_constraintStart_toEndOf="@+id/iv_last"
-                    app:layout_constraintTop_toBottomOf="@+id/iv_last" />
+                    android:textColor="?attr/colorSecondary" />
 
 
                 <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"
-                    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"/>
+                    android:textSize="13sp" />
 
 
             </LinearLayout>
             </LinearLayout>