Twidere-App-Android-Twitter.../twidere/src/main/kotlin/org/mariotaku/ktextension/TextViewExtensions.kt

40 lines
873 B
Kotlin
Raw Normal View History

2016-06-29 15:47:52 +02:00
package org.mariotaku.ktextension
import android.graphics.Typeface
2017-04-20 07:28:57 +02:00
import android.view.View
2016-06-29 15:47:52 +02:00
import android.widget.TextView
2017-05-13 08:19:23 +02:00
inline val TextView.empty: Boolean
2016-06-29 15:47:52 +02:00
get() = length() <= 0
2017-05-13 08:19:23 +02:00
inline var TextView.string: String?
2017-04-18 15:19:07 +02:00
get() = text?.toString()
2017-04-23 15:02:04 +02:00
set(value) {
text = value
}
2017-05-13 08:19:23 +02:00
inline var TextView.spannable: CharSequence?
get() = text
set(value) {
setText(value, TextView.BufferType.SPANNABLE)
}
inline var TextView.charSequence: CharSequence?
2017-04-23 15:02:04 +02:00
get() = text
set(value) {
text = value
}
2017-04-18 15:19:07 +02:00
fun TextView.applyFontFamily(lightFont: Boolean) {
if (lightFont) {
2017-02-02 11:18:34 +01:00
typeface = Typeface.create("sans-serif-light", typeface?.style ?: Typeface.NORMAL)
}
2017-04-20 07:28:57 +02:00
}
2017-05-13 08:19:23 +02:00
fun TextView.hideIfEmpty(hideVisibility: Int = View.GONE) {
2017-04-20 07:28:57 +02:00
visibility = if (empty) {
2017-05-13 08:19:23 +02:00
hideVisibility
2017-04-20 07:28:57 +02:00
} else {
View.VISIBLE
}
}