@@ -15,6 +15,13 @@ import com.sanjayprajapat.showmoretextview.enums.TextState
15
15
import com.sanjayprajapat.showmoretextview.listener.StateChangeListener
16
16
import com.sanjayprajapat.showmoretextview.utils.safeToInt
17
17
18
+ /* *
19
+ * @author : Sanjay Prajapat
20
+ * Created On: 09-4-2022
21
+ * Github:https://github.com/sanjaydraws
22
+ * Blog: https://dev.to/sanjayprajapat
23
+ * https://sanjayprajapat.hashnode.dev/
24
+ ***/
18
25
19
26
class ShowMoreTextView @JvmOverloads constructor(
20
27
context : Context ,
@@ -35,6 +42,9 @@ class ShowMoreTextView @JvmOverloads constructor(
35
42
* this is Original text
36
43
* */
37
44
private var expendedText: CharSequence = " "
45
+ /* *
46
+ *
47
+ * */
38
48
private var collapsedText: CharSequence = " "
39
49
40
50
@@ -74,11 +84,11 @@ class ShowMoreTextView @JvmOverloads constructor(
74
84
private fun setUpListener (){
75
85
super .setOnClickListener{
76
86
// Toast.makeText(context,"click",Toast.LENGTH_LONG).show()
77
- switchText ()
87
+ switchTextState ()
78
88
}
79
89
}
80
90
81
- private fun switchText (){
91
+ private fun switchTextState (){
82
92
when (textState) {
83
93
TextState .EXPANDED -> doOnCollapse()
84
94
TextState .COLLAPSED -> doOnExpand()
@@ -105,17 +115,17 @@ class ShowMoreTextView @JvmOverloads constructor(
105
115
* otherwise the action will be performed after the view is next laid out
106
116
* */
107
117
doOnLayout {
108
- // post{
118
+ post{
109
119
setUpShowMoreTextView()
110
- // }
120
+ }
111
121
}
112
122
}
113
123
private fun setUpShowMoreTextView (){
114
124
if (ifNeedToSkipSetup()){
115
125
return
116
126
}
117
127
expendedText = text
118
- val adjustCutCount = getAdjustCutCount(maxLine = showMoreMaxLine, showMoreText)
128
+ val adjustCutCount = getAdjustCutCount(maxLine = showMoreMaxLine, showMoreText) // 6
119
129
val maxTextIndex = layout.getLineVisibleEnd(showMoreMaxLine?.minus(1 ).safeToInt())
120
130
val originalSubText = expendedText.substring(0 , maxTextIndex - 1 - adjustCutCount)
121
131
@@ -133,10 +143,10 @@ class ShowMoreTextView @JvmOverloads constructor(
133
143
private fun getAdjustCutCount (maxLine : Int? , readMoreText : String? ):Int {
134
144
val lastLineStartIndex = layout.getLineVisibleEnd(maxLine?.minus(2 )? : 0 ) + 1
135
145
val lastLineEndIndex = layout.getLineVisibleEnd(maxLine?.minus(1 )? : 0 )
136
- val lastLineText = text.substring(lastLineStartIndex, lastLineEndIndex)
146
+ val lastLineText = text.substring(lastLineStartIndex, lastLineEndIndex)// available, but the majority have suffered alteration in
137
147
138
148
val bounds = Rect ()
139
- paint.getTextBounds(lastLineText, 0 , lastLineText.length, bounds)
149
+ paint.getTextBounds(lastLineText, 0 , lastLineText.length, bounds)// Rect(1, -22 - 647, 6)
140
150
var adjustCutCount = - 1
141
151
do {
142
152
adjustCutCount++
@@ -146,8 +156,6 @@ class ShowMoreTextView @JvmOverloads constructor(
146
156
val replacedTextWidth = bounds.width()
147
157
}while (replacedTextWidth> width)
148
158
return adjustCutCount
149
-
150
- return 0
151
159
}
152
160
153
161
public fun addOnStateChangeListener (stateChangeListener : StateChangeListener ) {
0 commit comments