From 24c026f77e553df69eb1d27ef7e8c01c70bae197 Mon Sep 17 00:00:00 2001 From: gedoor Date: Wed, 16 Sep 2020 10:07:06 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=90=9C=E7=B4=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/ui/book/read/ReadMenu.kt | 13 +++-- .../app/ui/book/searchContent/SearchResult.kt | 13 +++-- app/src/main/res/layout/view_read_menu.xml | 58 +++++++------------ 3 files changed, 35 insertions(+), 49 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadMenu.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadMenu.kt index 26423e701..e56a47066 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadMenu.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadMenu.kt @@ -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 { diff --git a/app/src/main/java/io/legado/app/ui/book/searchContent/SearchResult.kt b/app/src/main/java/io/legado/app/ui/book/searchContent/SearchResult.kt index 3a629839b..2de16020b 100644 --- a/app/src/main/java/io/legado/app/ui/book/searchContent/SearchResult.kt +++ b/app/src/main/java/io/legado/app/ui/book/searchContent/SearchResult.kt @@ -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) + - "($chapterTitle)" + "($chapterTitle)" } - 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 "$sub1" + - "$center" + + "$center" + "$sub2" } diff --git a/app/src/main/res/layout/view_read_menu.xml b/app/src/main/res/layout/view_read_menu.xml index b63fba1ff..d48221169 100644 --- a/app/src/main/res/layout/view_read_menu.xml +++ b/app/src/main/res/layout/view_read_menu.xml @@ -92,6 +92,26 @@ android:paddingStart="32dp" android:paddingEnd="32dp"> + + + + - - - - - - - - - Date: Wed, 16 Sep 2020 10:18:49 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=90=9C=E7=B4=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/io/legado/app/ui/book/read/ReadMenu.kt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadMenu.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadMenu.kt index e56a47066..bef8898ee 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadMenu.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadMenu.kt @@ -65,6 +65,8 @@ class ReadMenu : FrameLayout { brightnessBackground.setColor(ColorUtils.adjustAlpha(bgColor, 0.5f)) ll_brightness.background = brightnessBackground ll_bottom_bg.setBackgroundColor(bgColor) + fabSearch.backgroundTintList = bottomBackgroundList + fabSearch.setColorFilter(textColor) fabAutoPage.backgroundTintList = bottomBackgroundList fabAutoPage.setColorFilter(textColor) fabReplaceRule.backgroundTintList = bottomBackgroundList From 24e87036632c7312393116b6b37a41146c149712 Mon Sep 17 00:00:00 2001 From: gedoor Date: Wed, 16 Sep 2020 14:15:28 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=90=9C=E7=B4=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../book/searchContent/SearchListAdapter.kt | 19 +++--------- .../app/ui/book/searchContent/SearchResult.kt | 31 +++++++------------ 2 files changed, 17 insertions(+), 33 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/searchContent/SearchListAdapter.kt b/app/src/main/java/io/legado/app/ui/book/searchContent/SearchListAdapter.kt index d2c98b955..d68eb85ca 100644 --- a/app/src/main/java/io/legado/app/ui/book/searchContent/SearchListAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/book/searchContent/SearchListAdapter.kt @@ -1,21 +1,12 @@ package io.legado.app.ui.book.searchContent 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.base.adapter.ItemViewHolder 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.utils.getCompatColor -import io.legado.app.utils.visible -import kotlinx.android.synthetic.main.item_bookmark.view.* +import io.legado.app.utils.hexString import kotlinx.android.synthetic.main.item_search_list.view.* import org.jetbrains.anko.sdk27.listeners.onClick @@ -23,15 +14,15 @@ class SearchListAdapter(context: Context, val callback: Callback) : SimpleRecyclerAdapter(context, R.layout.item_search_list) { val cacheFileNames = hashSetOf() + 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) { with(holder.itemView) { val isDur = callback.durChapterIndex() == item.chapterIndex if (payloads.isEmpty()) { - tv_search_result.text = item.parseText(item.presentText) - if (isDur){ - tv_search_result.paint.isFakeBoldText = true - } + tv_search_result.text = item.getHtmlCompat(textColor, accentColor) + tv_search_result.paint.isFakeBoldText = isDur } } } diff --git a/app/src/main/java/io/legado/app/ui/book/searchContent/SearchResult.kt b/app/src/main/java/io/legado/app/ui/book/searchContent/SearchResult.kt index 2de16020b..482afab30 100644 --- a/app/src/main/java/io/legado/app/ui/book/searchContent/SearchResult.kt +++ b/app/src/main/java/io/legado/app/ui/book/searchContent/SearchResult.kt @@ -2,11 +2,6 @@ package io.legado.app.ui.book.searchContent 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 data class SearchResult( var index: Int = 0, @@ -20,16 +15,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() { - return colorPresentText(newPosition, query, text) + - "($chapterTitle)" - } + fun getHtmlCompat(textColor: String, accentColor: String): Spanned { + val html = colorPresentText(newPosition, query, text, textColor, accentColor) + + "($chapterTitle)" + return HtmlCompat.fromHtml(html, HtmlCompat.FROM_HTML_MODE_LEGACY) + } - private 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 sub2 = text.substring(position + center.length, targetText.length) return "$sub1" + @@ -37,10 +36,4 @@ data class SearchResult( "$sub2" } - fun parseText(targetText: String): Spanned { - return HtmlCompat.fromHtml(targetText, HtmlCompat.FROM_HTML_MODE_LEGACY) - } - - - } \ No newline at end of file