Action TextViews bugfix
This commit is contained in:
parent
ee4c4aaa5a
commit
3d01b780be
|
|
@ -76,7 +76,6 @@ fun CharSequence.toClickableSubstringText(
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun updateDrawState(ds: TextPaint) {
|
override fun updateDrawState(ds: TextPaint) {
|
||||||
super.updateDrawState(ds)
|
|
||||||
ds.isUnderlineText = isUnderlineText
|
ds.isUnderlineText = isUnderlineText
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -92,7 +91,9 @@ fun CharSequence.toStyleableSubstringText(
|
||||||
private fun CharSequence.toSubstringSpannable(
|
private fun CharSequence.toSubstringSpannable(
|
||||||
substring: String,
|
substring: String,
|
||||||
span: Any?
|
span: Any?
|
||||||
) = SpannableString(this)
|
) = toSpannable()
|
||||||
.apply {
|
.apply {
|
||||||
indexesOf(substring)?.let { (startSpan, endSpan) -> setSpan(span, startSpan, endSpan, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE) }
|
indexesOf(substring)?.let { (startSpan, endSpan) -> setSpan(span, startSpan, endSpan, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun CharSequence.toSpannable() = if (this is SpannableString) this else SpannableString(this)
|
||||||
|
|
|
||||||
|
|
@ -2,18 +2,13 @@ package ru.touchin.roboswag.views.text_view
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.graphics.Color
|
import android.graphics.Color
|
||||||
import android.text.Spanned
|
|
||||||
import android.text.TextPaint
|
|
||||||
import android.text.style.ClickableSpan
|
|
||||||
import android.text.style.TextAppearanceSpan
|
|
||||||
import android.util.AttributeSet
|
import android.util.AttributeSet
|
||||||
import android.view.View
|
import androidx.annotation.StyleRes
|
||||||
import androidx.annotation.ColorInt
|
|
||||||
import androidx.core.content.withStyledAttributes
|
import androidx.core.content.withStyledAttributes
|
||||||
import androidx.core.text.toSpannable
|
import androidx.core.text.toSpannable
|
||||||
import ru.touchin.extensions.getResourceIdOrNull
|
import ru.touchin.extensions.getResourceIdOrNull
|
||||||
import ru.touchin.extensions.indexesOf
|
|
||||||
import ru.touchin.roboswag.components.utils.movementmethods.ClickableMovementMethod
|
import ru.touchin.roboswag.components.utils.movementmethods.ClickableMovementMethod
|
||||||
|
import ru.touchin.roboswag.components.utils.spans.toClickableSubstringText
|
||||||
import ru.touchin.roboswag.views.R
|
import ru.touchin.roboswag.views.R
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -28,7 +23,7 @@ class MultipleActionTextView @JvmOverloads constructor(
|
||||||
|
|
||||||
private val onClickActions = mutableListOf<SubstringClickAction>()
|
private val onClickActions = mutableListOf<SubstringClickAction>()
|
||||||
|
|
||||||
@ColorInt
|
@StyleRes
|
||||||
private var textStyle: Int? = null
|
private var textStyle: Int? = null
|
||||||
|
|
||||||
private var isUnderlineText = false
|
private var isUnderlineText = false
|
||||||
|
|
@ -52,24 +47,7 @@ class MultipleActionTextView @JvmOverloads constructor(
|
||||||
|
|
||||||
private fun applyActionSpans() {
|
private fun applyActionSpans() {
|
||||||
text = text.toSpannable().apply {
|
text = text.toSpannable().apply {
|
||||||
onClickActions.forEach { (substring, action) ->
|
onClickActions.forEach { (substring, action) -> toClickableSubstringText(substring, action, isUnderlineText, textStyle, context) }
|
||||||
|
|
||||||
indexesOf(substring)?.let { (startSpan, endSpan) ->
|
|
||||||
|
|
||||||
setSpan(object : ClickableSpan() {
|
|
||||||
override fun onClick(widget: View) {
|
|
||||||
action.invoke()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun updateDrawState(ds: TextPaint) {
|
|
||||||
super.updateDrawState(ds)
|
|
||||||
ds.isUnderlineText = isUnderlineText
|
|
||||||
}
|
|
||||||
}, startSpan, endSpan, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
|
|
||||||
|
|
||||||
textStyle?.let { setSpan(TextAppearanceSpan(context, it), startSpan, endSpan, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE) }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue