2016-06-29 15:47:52 +02:00
|
|
|
package org.mariotaku.ktextension
|
|
|
|
|
2017-01-28 08:15:35 +01:00
|
|
|
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-01-28 08:15:35 +01:00
|
|
|
|
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
|
|
|
|
2017-01-28 08:15:35 +01: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-01-28 08:15:35 +01:00
|
|
|
}
|
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
|
|
|
|
}
|
2017-01-28 08:15:35 +01:00
|
|
|
}
|