@@ -33,6 +33,7 @@ class FormatTextView : BaseTextView {
3333 private var isClickSpanItem = false
3434 var isSetOnClick = false
3535 private var isDrawGradient = false
36+ private var isClearTexts = true
3637 private val underLineTexts: ArrayList <LineText > = ArrayList ()
3738 private val deleteLineTexts: ArrayList <LineText > = ArrayList ()
3839 private val gradientTexts: ArrayList <LineText > = ArrayList ()
@@ -52,10 +53,10 @@ class FormatTextView : BaseTextView {
5253 setFormatTextBean(resources.getString(formatTextRes), * args)
5354 }
5455
55- fun setFormatTextBean (formatTextValue : String , vararg args : BaseFormat ? ) {
56- var textValue = formatTextValue.replace(" \\ r\\ n" .toRegex(), " <br>" )
57- textValue = textValue.replace(" \\ n" .toRegex(), " <br>" )
58- textValue = textValue.replace(" \\ r" .toRegex(), " <br>" )
56+ fun setFormatTextBean (formatTextValue : String? , vararg args : BaseFormat ? ) {
57+ var textValue = formatTextValue? .replace(" \\ r\\ n" .toRegex(), " <br>" )
58+ textValue = textValue? .replace(" \\ n" .toRegex(), " <br>" )
59+ textValue = textValue? .replace(" \\ r" .toRegex(), " <br>" )
5960 val strings = arrayOfNulls<String >(args.size)
6061 var isContainGradient = false
6162 for (i in args.indices) { // %1$s
@@ -84,28 +85,48 @@ class FormatTextView : BaseTextView {
8485
8586
8687 }
87- val richText = String .format(textValue, * strings)
88- formatArgs = args
89- this .richText = richText
88+ if (textValue == null ){
89+ isClearTexts = true
90+ text = " "
91+ return
92+ }
9093 isDrawGradient = ! isContainGradient
9194 underLineTexts.clear()
9295 deleteLineTexts.clear()
9396 gradientTexts.clear()
9497 gradientDrawTexts.clear()
98+ val richText = String .format(textValue, * strings)
99+ formatArgs = args
100+ this .richText = richText
101+ isClearTexts = false
95102 text = getCustomStyleHtml(richText, * args)
96103 highlightColor = Color .TRANSPARENT
97104 autoLinkMask = Linkify .WEB_URLS
98105 }
99106
107+ override fun setText (text : CharSequence? , type : BufferType ? ) {
108+ if (isClearTexts){
109+ isDrawGradient = true
110+ underLineTexts.clear()
111+ deleteLineTexts.clear()
112+ gradientTexts.clear()
113+ gradientDrawTexts.clear()
114+ formatArgs = null
115+ this .richText = null
116+ }
117+ super .setText(text, type)
118+ }
119+
100120 private fun resetText (){
121+ isClearTexts = false
101122 text = richText?.let { formatArgs?.let { it1 -> getCustomStyleHtml(it, * it1) } }
102123 }
103124
104125 fun setFormatText (@StringRes formatTextRes : Int , vararg args : Int ) {
105126 setFormatText(resources.getString(formatTextRes), * args)
106127 }
107128
108- fun setFormatText (formatTextValue : String , vararg args : Int ) {
129+ fun setFormatText (formatTextValue : String? , vararg args : Int ) {
109130 val formatTexts: Array <FormatText ?> = arrayOfNulls(args.size)
110131 for (i in args.indices) {
111132 formatTexts[i] = FormatText ().setResValue(args[i])
@@ -117,7 +138,7 @@ class FormatTextView : BaseTextView {
117138 setFormatText(resources.getString(formatTextRes), * args)
118139 }
119140
120- fun setFormatText (formatTextValue : String , vararg args : String ) {
141+ fun setFormatText (formatTextValue : String? , vararg args : String ) {
121142 val formatTexts: Array <FormatText ?> = arrayOfNulls(args.size)
122143 for (i in args.indices) {
123144 formatTexts[i] = FormatText ().setStrValue(args[i])
@@ -492,6 +513,7 @@ class FormatTextView : BaseTextView {
492513 drawUnderline(canvas)
493514 drawDeleteLine(canvas)
494515 getGradient()
516+ isClearTexts = true
495517 }
496518 private fun getGradient () {
497519 if (gradientTexts.size == 0 || isDrawGradient) {
0 commit comments