Merge pull request #36 from gedoor/master

merge
pull/386/head
口口吕 4 years ago committed by GitHub
commit 4812e57b31
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 15
      app/src/main/java/io/legado/app/ui/book/read/ReadMenu.kt
  2. 19
      app/src/main/java/io/legado/app/ui/book/searchContent/SearchListAdapter.kt
  3. 30
      app/src/main/java/io/legado/app/ui/book/searchContent/SearchResult.kt
  4. 58
      app/src/main/res/layout/view_read_menu.xml

@ -65,6 +65,8 @@ class ReadMenu : FrameLayout {
brightnessBackground.setColor(ColorUtils.adjustAlpha(bgColor, 0.5f)) brightnessBackground.setColor(ColorUtils.adjustAlpha(bgColor, 0.5f))
ll_brightness.background = brightnessBackground ll_brightness.background = brightnessBackground
ll_bottom_bg.setBackgroundColor(bgColor) ll_bottom_bg.setBackgroundColor(bgColor)
fabSearch.backgroundTintList = bottomBackgroundList
fabSearch.setColorFilter(textColor)
fabAutoPage.backgroundTintList = bottomBackgroundList fabAutoPage.backgroundTintList = bottomBackgroundList
fabAutoPage.setColorFilter(textColor) fabAutoPage.setColorFilter(textColor)
fabReplaceRule.backgroundTintList = bottomBackgroundList fabReplaceRule.backgroundTintList = bottomBackgroundList
@ -170,6 +172,13 @@ class ReadMenu : FrameLayout {
} }
}) })
//搜索
fabSearch.onClick {
runMenuOut {
callBack?.openSearchList()
}
}
//自动翻页 //自动翻页
fabAutoPage.onClick { fabAutoPage.onClick {
runMenuOut { runMenuOut {
@ -200,12 +209,6 @@ class ReadMenu : FrameLayout {
} }
} }
ll_search.onClick {
runMenuOut {
callBack?.openSearchList()
}
}
//朗读 //朗读
ll_read_aloud.onClick { ll_read_aloud.onClick {
runMenuOut { runMenuOut {

@ -1,21 +1,12 @@
package io.legado.app.ui.book.searchContent package io.legado.app.ui.book.searchContent
import android.content.Context import android.content.Context
import android.os.Build
import android.text.Html
import android.util.Log
import android.view.View
import androidx.annotation.RequiresApi
import androidx.core.text.HtmlCompat
import io.legado.app.R import io.legado.app.R
import io.legado.app.base.adapter.ItemViewHolder import io.legado.app.base.adapter.ItemViewHolder
import io.legado.app.base.adapter.SimpleRecyclerAdapter import io.legado.app.base.adapter.SimpleRecyclerAdapter
import io.legado.app.data.entities.BookChapter
import io.legado.app.help.BookHelp
import io.legado.app.lib.theme.accentColor import io.legado.app.lib.theme.accentColor
import io.legado.app.utils.getCompatColor import io.legado.app.utils.getCompatColor
import io.legado.app.utils.visible import io.legado.app.utils.hexString
import kotlinx.android.synthetic.main.item_bookmark.view.*
import kotlinx.android.synthetic.main.item_search_list.view.* import kotlinx.android.synthetic.main.item_search_list.view.*
import org.jetbrains.anko.sdk27.listeners.onClick import org.jetbrains.anko.sdk27.listeners.onClick
@ -23,15 +14,15 @@ class SearchListAdapter(context: Context, val callback: Callback) :
SimpleRecyclerAdapter<SearchResult>(context, R.layout.item_search_list) { SimpleRecyclerAdapter<SearchResult>(context, R.layout.item_search_list) {
val cacheFileNames = hashSetOf<String>() val cacheFileNames = hashSetOf<String>()
val textColor = context.getCompatColor(R.color.primaryText).hexString.substring(2)
val accentColor = context.accentColor.hexString.substring(2)
override fun convert(holder: ItemViewHolder, item: SearchResult, payloads: MutableList<Any>) { override fun convert(holder: ItemViewHolder, item: SearchResult, payloads: MutableList<Any>) {
with(holder.itemView) { with(holder.itemView) {
val isDur = callback.durChapterIndex() == item.chapterIndex val isDur = callback.durChapterIndex() == item.chapterIndex
if (payloads.isEmpty()) { if (payloads.isEmpty()) {
tv_search_result.text = item.parseText(item.presentText) tv_search_result.text = item.getHtmlCompat(textColor, accentColor)
if (isDur){ tv_search_result.paint.isFakeBoldText = isDur
tv_search_result.paint.isFakeBoldText = true
}
} }
} }
} }

@ -2,10 +2,6 @@ package io.legado.app.ui.book.searchContent
import android.text.Spanned import android.text.Spanned
import androidx.core.text.HtmlCompat import androidx.core.text.HtmlCompat
import io.legado.app.App
import io.legado.app.R
import io.legado.app.utils.getCompatColor
import io.legado.app.utils.hexString
data class SearchResult( data class SearchResult(
var index: Int = 0, var index: Int = 0,
@ -19,25 +15,25 @@ data class SearchResult(
var newPosition: Int = 0, var newPosition: Int = 0,
var contentPosition: Int =0 var contentPosition: Int =0
) { ) {
val presentText: String
get(){ fun getHtmlCompat(textColor: String, accentColor: String): Spanned {
return colorPresentText(newPosition, query, text) + val html = colorPresentText(newPosition, query, text, textColor, accentColor) +
"<font color=#0000ff>($chapterTitle)</font>" "<font color=#${accentColor}>($chapterTitle)</font>"
return HtmlCompat.fromHtml(html, HtmlCompat.FROM_HTML_MODE_LEGACY)
} }
fun colorPresentText(position: Int, center: String, targetText: String): String { private fun colorPresentText(
position: Int,
center: String,
targetText: String,
textColor: String,
accentColor: String
): String {
val sub1 = text.substring(0, position) val sub1 = text.substring(0, position)
val sub2 = text.substring(position + center.length, targetText.length) val sub2 = text.substring(position + center.length, targetText.length)
val textColor = App.INSTANCE.getCompatColor(R.color.primaryText).hexString
return "<font color=#${textColor}>$sub1</font>" + return "<font color=#${textColor}>$sub1</font>" +
"<font color=#ff0000>$center</font>" + "<font color=#${accentColor}>$center</font>" +
"<font color=#${textColor}>$sub2</font>" "<font color=#${textColor}>$sub2</font>"
} }
fun parseText(targetText: String): Spanned {
return HtmlCompat.fromHtml(targetText, HtmlCompat.FROM_HTML_MODE_LEGACY)
}
} }

@ -92,6 +92,26 @@
android:paddingStart="32dp" android:paddingStart="32dp"
android:paddingEnd="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 <com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/fabAutoPage" android:id="@+id/fabAutoPage"
android:layout_width="wrap_content" android:layout_width="wrap_content"
@ -265,44 +285,6 @@
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_weight="2" /> 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 <LinearLayout
android:id="@+id/ll_read_aloud" android:id="@+id/ll_read_aloud"

Loading…
Cancel
Save