Merge pull request #244 from TouchInstinct/fix/stylable_text_view

Make StyleableSubTextView open class
This commit is contained in:
Kirill Nayduik 2022-02-02 20:04:31 +03:00 committed by GitHub
commit 226f7d164f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 4 deletions

View File

@ -10,13 +10,13 @@ import ru.touchin.roboswag.views.R
/**
* A [android.widget.TextView] which support styling substrings of text
*/
class StyleableSubTextView @JvmOverloads constructor(
open class StyleableSubTextView @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0
) : EllipsizeSpannableTextView(context, attrs, defStyleAttr) {
private var styleId = typeface.style
protected var substringStyleId = typeface.style
var substring: String? = null
set(value) {
@ -27,7 +27,7 @@ class StyleableSubTextView @JvmOverloads constructor(
init {
context.withStyledAttributes(attrs, R.styleable.StyleableSubTextView, defStyleAttr, 0) {
getResourceIdOrNull(R.styleable.StyleableSubTextView_subtextStyle)?.let { styleId = it }
getResourceIdOrNull(R.styleable.StyleableSubTextView_subtextStyle)?.let { substringStyleId = it }
substring = getString(R.styleable.StyleableSubTextView_subtext)
}
}
@ -35,7 +35,7 @@ class StyleableSubTextView @JvmOverloads constructor(
override fun setText(text: CharSequence?, type: BufferType?) {
val spannableText = when (substring == null) {
true -> text
false -> text?.toStyleableSubstringText(substring.orEmpty(), styleId, context)
false -> text?.toStyleableSubstringText(substring.orEmpty(), substringStyleId, context)
}
super.setText(spannableText, type)