pull/1705/head
kunfei 3 years ago
parent 4dd156b9cd
commit 5dfb829320
  1. 12
      app/src/main/java/io/legado/app/ui/book/searchContent/SearchResult.kt

@ -17,17 +17,21 @@ data class SearchResult(
) { ) {
fun getHtmlCompat(textColor: String, accentColor: String): Spanned { fun getHtmlCompat(textColor: String, accentColor: String): Spanned {
if (!query.isBlank()) { return if (query.isNotBlank()) {
val queryIndexInSurrounding = resultText.indexOf(query) val queryIndexInSurrounding = resultText.indexOf(query)
val leftString = resultText.substring(0, queryIndexInSurrounding) val leftString = resultText.substring(0, queryIndexInSurrounding)
val rightString = resultText.substring(queryIndexInSurrounding + query.length, resultText.length) val rightString =
resultText.substring(queryIndexInSurrounding + query.length, resultText.length)
val html = leftString.colorTextForHtml(textColor) + val html = leftString.colorTextForHtml(textColor) +
query.colorTextForHtml(accentColor) + query.colorTextForHtml(accentColor) +
rightString.colorTextForHtml(textColor) + rightString.colorTextForHtml(textColor) +
chapterTitle.colorTextForHtml(accentColor) chapterTitle.colorTextForHtml(accentColor)
return HtmlCompat.fromHtml(html, HtmlCompat.FROM_HTML_MODE_LEGACY) HtmlCompat.fromHtml(html, HtmlCompat.FROM_HTML_MODE_LEGACY)
} else { } else {
return HtmlCompat.fromHtml(resultText.colorTextForHtml(textColor), HtmlCompat.FROM_HTML_MODE_LEGACY) HtmlCompat.fromHtml(
resultText.colorTextForHtml(textColor),
HtmlCompat.FROM_HTML_MODE_LEGACY
)
} }
} }

Loading…
Cancel
Save