优化搜索

pull/382/head
gedoor 4 years ago
parent 0bffc3e4f3
commit 24c026f77e
  1. 13
      app/src/main/java/io/legado/app/ui/book/read/ReadMenu.kt
  2. 13
      app/src/main/java/io/legado/app/ui/book/searchContent/SearchResult.kt
  3. 58
      app/src/main/res/layout/view_read_menu.xml

@ -170,6 +170,13 @@ class ReadMenu : FrameLayout {
}
})
//搜索
fabSearch.onClick {
runMenuOut {
callBack?.openSearchList()
}
}
//自动翻页
fabAutoPage.onClick {
runMenuOut {
@ -200,12 +207,6 @@ class ReadMenu : FrameLayout {
}
}
ll_search.onClick {
runMenuOut {
callBack?.openSearchList()
}
}
//朗读
ll_read_aloud.onClick {
runMenuOut {

@ -4,6 +4,7 @@ import android.text.Spanned
import androidx.core.text.HtmlCompat
import io.legado.app.App
import io.legado.app.R
import io.legado.app.lib.theme.accentColor
import io.legado.app.utils.getCompatColor
import io.legado.app.utils.hexString
@ -19,18 +20,20 @@ data class SearchResult(
var newPosition: Int = 0,
var contentPosition: Int =0
) {
val textColor = App.INSTANCE.getCompatColor(R.color.primaryText).hexString
val accentColor = App.INSTANCE.accentColor.hexString
val presentText: String
get(){
get() {
return colorPresentText(newPosition, query, text) +
"<font color=#0000ff>($chapterTitle)</font>"
"<font color=#${accentColor}>($chapterTitle)</font>"
}
fun colorPresentText(position: Int, center: String, targetText: String): String {
private fun colorPresentText(position: Int, center: String, targetText: String): String {
val sub1 = text.substring(0, position)
val sub2 = text.substring(position + center.length, targetText.length)
val textColor = App.INSTANCE.getCompatColor(R.color.primaryText).hexString
return "<font color=#${textColor}>$sub1</font>" +
"<font color=#ff0000>$center</font>" +
"<font color=#${accentColor}>$center</font>" +
"<font color=#${textColor}>$sub2</font>"
}

@ -92,6 +92,26 @@
android:paddingStart="32dp"
android:paddingEnd="32dp">
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/fabSearch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:contentDescription="@string/search_content"
android:src="@drawable/ic_search"
android:tint="@color/primaryText"
android:tooltipText="@string/search_content"
app:backgroundTint="@color/background_menu"
app:elevation="2dp"
app:fabSize="mini"
app:pressedTranslationZ="2dp"
tools:ignore="UnusedAttribute" />
<Space
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/fabAutoPage"
android:layout_width="wrap_content"
@ -265,44 +285,6 @@
android:layout_height="match_parent"
android:layout_weight="2" />
<!--搜索按钮-->
<LinearLayout
android:id="@+id/ll_search"
android:layout_width="60dp"
android:layout_height="50dp"
android:background="?android:attr/selectableItemBackgroundBorderless"
android:clickable="true"
android:contentDescription="@string/search_content"
android:focusable="true"
android:orientation="vertical"
android:paddingBottom="7dp">
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/iv_search"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:contentDescription="@string/search_content"
android:src="@drawable/ic_search"
app:tint="@color/primaryText"
tools:ignore="NestedWeights" />
<TextView
android:id="@+id/tv_search"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="3dp"
android:maxLines="1"
android:text="@string/search_content"
android:textColor="@color/primaryText"
android:textSize="12sp" />
</LinearLayout>
<View
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="2" />
<!--调节按钮-->
<LinearLayout
android:id="@+id/ll_read_aloud"

Loading…
Cancel
Save