Skip to content

Commit 14ac5e0

Browse files
committed
Update Version
- Modified code
1 parent da4505a commit 14ac5e0

File tree

3 files changed

+24
-16
lines changed

3 files changed

+24
-16
lines changed

expandable-textview/src/main/java/com/wayne/expandabletextview/ExpandableTextView.kt

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import android.view.View
1414
import android.widget.LinearLayout
1515
import androidx.annotation.Px
1616
import androidx.core.content.res.ResourcesCompat
17-
import androidx.core.view.isVisible
1817
import kotlinx.android.synthetic.main.expandable_textview_layout.view.*
1918

2019
class ExpandableTextView @JvmOverloads constructor(
@@ -25,17 +24,24 @@ class ExpandableTextView @JvmOverloads constructor(
2524

2625
var stateChangeListener: OnStateChangeListener? = null
2726

28-
var currentState = State.EXPANDED
27+
var currentState = State.COLLAPSED
2928
private set(value) {
3029
field = value
30+
when (value) {
31+
State.EXPANDED -> {
32+
tv_origin_text.maxLines = Int.MAX_VALUE
33+
view_gradient.visibility = View.GONE
34+
}
35+
State.COLLAPSED -> {
36+
tv_origin_text.maxLines = collapsedLines
37+
view_gradient.visibility = View.VISIBLE
38+
}
39+
}
3140
stateChangeListener?.onStateChanged(value)
3241
}
3342

34-
private var isActivateExpansion = false
35-
set(value) {
36-
field = value
37-
view_gradient.isVisible = value
38-
}
43+
var isActivateExpansion = false
44+
private set
3945

4046
val isExpanded
4147
get() = currentState == State.EXPANDED
@@ -155,29 +161,32 @@ class ExpandableTextView @JvmOverloads constructor(
155161
}
156162
}
157163

158-
private fun updateText(value: String) {
164+
private fun updateText(value: String?) {
159165
tv_origin_text.maxLines = Int.MAX_VALUE
160166
tv_origin_text.text = value
161167
isActivateExpansion = tv_origin_text.lineCount > collapsedLines
162-
toggle()
168+
169+
if (!isActivateExpansion || isExpanded || tv_origin_text.text.isNullOrEmpty()) {
170+
view_gradient.visibility = View.GONE
171+
return
172+
}
173+
174+
tv_origin_text.maxLines = collapsedLines
175+
view_gradient.visibility = View.VISIBLE
163176
}
164177

165178
fun expand() {
166179
if (!isActivateExpansion || isExpanded || text.isEmpty()) {
167180
return
168181
}
169182
currentState = State.EXPANDED
170-
tv_origin_text.maxLines = Int.MAX_VALUE
171-
view_gradient.visibility = View.GONE
172183
}
173184

174185
fun collapse() {
175186
if (!isActivateExpansion || isCollapsed || text.isEmpty()) {
176187
return
177188
}
178189
currentState = State.COLLAPSED
179-
tv_origin_text.maxLines = collapsedLines
180-
view_gradient.visibility = View.VISIBLE
181190
}
182191

183192
enum class State {

expandable-textview/src/main/res/layout/expandable_textview_layout.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,5 @@
1818
android:layout_width="wrap_content"
1919
android:layout_height="16dp"
2020
android:layout_gravity="bottom"
21-
android:background="@drawable/bg_more_textview_gradient"
22-
android:visibility="gone" />
21+
android:background="@drawable/bg_more_textview_gradient" />
2322
</FrameLayout>

publish.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ publish {
55
userOrg = 'kiyong48'
66
groupId = 'com.wayne.expandabletextview'
77
artifactId = 'expandable-textview'
8-
publishVersion = '1.1.2'
8+
publishVersion = '1.1.3'
99
desc = 'https://github.com/YKW93/ExpandableTextview'
1010
website = 'https://github.com/YKW93/ExpandableTextview'
1111
issueTracker = 'https://github.com/YKW93/ExpandableTextview/issues'

0 commit comments

Comments
 (0)