Fix PR comments

This commit is contained in:
Kirill Nayduik 2021-06-25 09:50:20 +03:00
parent 120dc10f6a
commit 1a8b57de88
2 changed files with 11 additions and 6 deletions

View File

@ -8,6 +8,7 @@ import android.text.style.ForegroundColorSpan
import android.text.style.URLSpan
import android.text.util.Linkify
import android.view.View
import androidx.annotation.ColorInt
import androidx.core.text.HtmlCompat
import ru.touchin.extensions.indexesOf
@ -56,7 +57,12 @@ private data class UrlSpanWithBorders(val span: URLSpan, val start: Int, val end
/**
* Find substring inside string (for example in TextView) and fill it with ClickableSpan
*/
fun CharSequence.getClickableSubstring(substring: String, clickAction: () -> Unit, color: Int? = null) = SpannableString(this)
fun CharSequence.toClickableSubstringText(
substring: String,
clickAction: () -> Unit,
@ColorInt color: Int? = null,
isUnderlineText: Boolean = false
) = SpannableString(this)
.apply {
indexesOf(substring)?.let { (startSpan, endSpan) ->
setSpan(object : ClickableSpan() {
@ -66,10 +72,9 @@ fun CharSequence.getClickableSubstring(substring: String, clickAction: () -> Uni
override fun updateDrawState(ds: TextPaint) {
super.updateDrawState(ds)
ds.isUnderlineText = false
ds.isUnderlineText = isUnderlineText
if (color != null) ds.color = color
}
}, startSpan, endSpan, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
color?.let { setSpan(ForegroundColorSpan(it), startSpan, endSpan, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE) }
}
}

View File

@ -6,7 +6,7 @@ import android.util.AttributeSet
import androidx.appcompat.widget.AppCompatTextView
import androidx.core.content.withStyledAttributes
import ru.touchin.roboswag.components.utils.movementmethods.ClickableMovementMethod
import ru.touchin.roboswag.components.utils.spans.getClickableSubstring
import ru.touchin.roboswag.components.utils.spans.toClickableSubstringText
class ActionTextView @JvmOverloads constructor(
context: Context,
@ -27,7 +27,7 @@ class ActionTextView @JvmOverloads constructor(
val actionText = getString(R.styleable.ActionTextView_actionText).orEmpty()
val actionColor = getColor(R.styleable.ActionTextView_actionColor, currentTextColor)
text = text.getClickableSubstring(
text = text.toClickableSubstringText(
substring = actionText,
clickAction = { onClickAction.invoke() },
color = actionColor