@@ -41,6 +41,7 @@ class ShowMoreLess private constructor(builder: Builder) {
41
41
private val moreLabelColor: Int
42
42
private val lessLabelColor: Int
43
43
private val labelUnderLine: Boolean
44
+ private val labelBold: Boolean
44
45
private val expandAnimation: Boolean
45
46
private val textClickableInExpand: Boolean
46
47
private val textClickableInCollapse: Boolean
@@ -54,15 +55,16 @@ class ShowMoreLess private constructor(builder: Builder) {
54
55
this .moreLabelColor = builder.moreLabelColor
55
56
this .lessLabelColor = builder.lessLabelColor
56
57
this .labelUnderLine = builder.labelUnderLine
58
+ this .labelBold = builder.labelBold
57
59
this .expandAnimation = builder.expandAnimation
58
60
this .textClickableInExpand = builder.textClickableInExpand
59
61
this .textClickableInCollapse = builder.textClickableInCollapse
60
62
}
61
63
62
64
fun addShowMoreLess (
63
- textView : TextView ,
64
- text : CharSequence ,
65
- isContentExpanded : Boolean
65
+ textView : TextView ,
66
+ text : CharSequence ,
67
+ isContentExpanded : Boolean
66
68
) {
67
69
if (textLengthType == TYPE_CHARACTER ) {
68
70
if (text.length <= textLength) {
@@ -114,16 +116,16 @@ class ShowMoreLess private constructor(builder: Builder) {
114
116
}
115
117
116
118
private fun addShowMore (
117
- textView : TextView ,
118
- trimText : CharSequence
119
+ textView : TextView ,
120
+ trimText : CharSequence
119
121
) {
120
122
try {
121
123
val newSubString: CharSequence
122
124
if (textLengthType == TYPE_LINE ) {
123
125
val lp = textView.layoutParams as ViewGroup .MarginLayoutParams
124
126
val subString = trimText.substring(
125
- startIndex = textView.layout.getLineStart(0 ),
126
- endIndex = textView.layout.getLineEnd(textLength - 1 )
127
+ startIndex = textView.layout.getLineStart(0 ),
128
+ endIndex = textView.layout.getLineEnd(textLength - 1 )
127
129
)
128
130
newSubString = if (! subString.endsWith(" \n " , false )) {
129
131
val startRange = subString.length - (moreLabel.length + 4 + lp.rightMargin / 6 )
@@ -140,7 +142,7 @@ class ShowMoreLess private constructor(builder: Builder) {
140
142
newSubString = trimText.subSequence(0 , textLength)
141
143
}
142
144
val spannableStringBuilder = SpannableStringBuilder (
143
- newSubString
145
+ newSubString
144
146
).apply {
145
147
this .append(" ..." )
146
148
this .append(moreLabel)
@@ -156,6 +158,7 @@ class ShowMoreLess private constructor(builder: Builder) {
156
158
override fun updateDrawState (ds : TextPaint ) {
157
159
super .updateDrawState(ds)
158
160
ds.isUnderlineText = labelUnderLine
161
+ ds.isFakeBoldText = labelBold
159
162
ds.color = moreLabelColor
160
163
}
161
164
}
@@ -205,8 +208,8 @@ class ShowMoreLess private constructor(builder: Builder) {
205
208
}
206
209
207
210
private fun addShowLess (
208
- textView : TextView ,
209
- trimText : CharSequence
211
+ textView : TextView ,
212
+ trimText : CharSequence
210
213
) {
211
214
try {
212
215
textView.maxLines = Integer .MAX_VALUE
@@ -229,6 +232,7 @@ class ShowMoreLess private constructor(builder: Builder) {
229
232
override fun updateDrawState (ds : TextPaint ) {
230
233
super .updateDrawState(ds)
231
234
ds.isUnderlineText = labelUnderLine
235
+ ds.isFakeBoldText = labelBold
232
236
ds.color = lessLabelColor
233
237
}
234
238
}
@@ -313,7 +317,7 @@ class ShowMoreLess private constructor(builder: Builder) {
313
317
}
314
318
315
319
class Builder (// required
316
- val context : Context ) {
320
+ val context : Context ) {
317
321
// optional
318
322
var textLength = 100
319
323
var textLengthType = TYPE_CHARACTER
@@ -322,6 +326,7 @@ class ShowMoreLess private constructor(builder: Builder) {
322
326
var moreLabelColor = Color .parseColor(" #ffffff" )
323
327
var lessLabelColor = Color .parseColor(" #ffffff" )
324
328
var labelUnderLine = false
329
+ var labelBold = false
325
330
var expandAnimation = false
326
331
var textClickableInExpand = false
327
332
var textClickableInCollapse = false
@@ -380,6 +385,14 @@ class ShowMoreLess private constructor(builder: Builder) {
380
385
return this
381
386
}
382
387
388
+ /* *
389
+ * @param labelBold is boolean to enable or disable bold label text
390
+ */
391
+ fun labelBold (labelBold : Boolean ): Builder {
392
+ this .labelBold = labelBold
393
+ return this
394
+ }
395
+
383
396
/* *
384
397
* @param textClickableInCollapse for text collapse condition
385
398
* @param textClickableInExpand for text expand condition
0 commit comments