Răsfoiți Sursa

正文搜索百分比 #272

HapeLee 1 an în urmă
părinte
comite
5fbdcf54d8

+ 12 - 0
app/src/main/java/io/legado/app/ui/book/read/SearchMenu.kt

@@ -108,6 +108,7 @@ class SearchMenu @JvmOverloads constructor(
                 "${context.getString(R.string.search_content_size)}: ${searchResultList.size}"
                 "${context.getString(R.string.search_content_size)}: ${searchResultList.size}"
             binding.tvCurrentChapter.text = "当前章节: ${it.title}"
             binding.tvCurrentChapter.text = "当前章节: ${it.title}"
         }
         }
+        updateSearchProgress()
     }
     }
 
 
     fun updateSearchResultIndex(updateIndex: Int) {
     fun updateSearchResultIndex(updateIndex: Int) {
@@ -117,6 +118,17 @@ class SearchMenu @JvmOverloads constructor(
             updateIndex >= searchResultList.size -> searchResultList.size - 1
             updateIndex >= searchResultList.size -> searchResultList.size - 1
             else -> updateIndex
             else -> updateIndex
         }
         }
+        updateSearchProgress()
+    }
+
+    private fun updateSearchProgress() {
+        val total = searchResultList.size
+        if (total == 0) {
+            binding.tvSearchProgress.text = "0%"
+        } else {
+            val progress = ((currentSearchResultIndex + 1) * 100 / total)
+            binding.tvSearchProgress.text = "$progress%"
+        }
     }
     }
 
 
     private fun bindEvent() = binding.run {
     private fun bindEvent() = binding.run {

+ 34 - 7
app/src/main/res/layout/view_search_menu.xml

@@ -63,14 +63,41 @@
             app:cardBackgroundColor="?attr/colorSecondaryContainer"
             app:cardBackgroundColor="?attr/colorSecondaryContainer"
             android:layout_marginHorizontal="16dp">
             android:layout_marginHorizontal="16dp">
 
 
-            <TextView
-                android:id="@+id/tv_current_search_info"
+            <LinearLayout
                 android:layout_width="wrap_content"
                 android:layout_width="wrap_content"
-                android:layout_height="match_parent"
-                android:textColor="?attr/colorOnSecondaryContainer"
-                android:padding="8dp"
-                android:singleLine="true"
-                android:textSize="18sp" />
+                android:layout_height="wrap_content"
+                android:orientation="horizontal">
+                <TextView
+                    android:id="@+id/tv_current_search_info"
+                    android:layout_width="wrap_content"
+                    android:layout_height="wrap_content"
+                    android:textColor="?attr/colorOnSecondaryContainer"
+                    android:textStyle="bold"
+                    android:layout_margin="8dp"
+                    android:singleLine="true"
+                    android:textSize="16sp" />
+
+                <TextView
+                    android:layout_width="wrap_content"
+                    android:layout_height="wrap_content"
+                    android:text="@string/default_version"
+                    android:textColor="?attr/colorOnSecondaryContainer"
+                    android:layout_marginStart="2dp"
+                    android:layout_marginVertical="8dp"
+                    android:singleLine="true"
+                    android:textSize="12sp" />
+
+                <TextView
+                    android:id="@+id/tvSearchProgress"
+                    android:layout_width="wrap_content"
+                    android:layout_height="wrap_content"
+                    android:textColor="?attr/colorOnSecondaryContainer"
+                    android:singleLine="true"
+                    android:layout_marginVertical="8dp"
+                    android:layout_marginEnd="8dp"
+                    android:textSize="12sp" />
+
+            </LinearLayout>
 
 
         </com.google.android.material.card.MaterialCardView>
         </com.google.android.material.card.MaterialCardView>