androidx
Zhanty 5 years ago
parent caf510c998
commit bdd29f115a
  1. 2
      lib_base/src/main/java/com/android/base/kotlin/TextViewEx.kt
  2. 14
      lib_base/src/main/java/com/android/base/kotlin/ViewEx.kt

@ -111,7 +111,7 @@ fun TextView.clearComponentDrawable() {
this.setCompoundDrawablesWithIntrinsicBounds(null, null, null, null) this.setCompoundDrawablesWithIntrinsicBounds(null, null, null, null)
} }
fun Button.enable(et: EditText, checker: (s: CharSequence?) -> Boolean) { fun Button.enableByEditText(et: EditText, checker: (s: CharSequence?) -> Boolean = { it -> !it.isNullOrEmpty() }) {
val btn = this val btn = this
et.addTextChangedListener(object : TextWatcherAdapter { et.addTextChangedListener(object : TextWatcherAdapter {
override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) { override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {

@ -44,10 +44,14 @@ fun View.gone() {
this.visibility = View.GONE this.visibility = View.GONE
} }
fun View.isVisible() = this.visibility == View.VISIBLE
fun View.isInvisible() = this.visibility == View.INVISIBLE
fun View.isGone() = this.visibility == View.GONE
fun View.realContext() = ViewUtils.getRealContext(this) fun View.realContext() = ViewUtils.getRealContext(this)
inline fun View.doOnLayoutAvailable(crossinline block: () -> Unit) { inline fun View.doOnLayoutAvailable(crossinline block: () -> Unit) {
//如果 view 已经通过至少一个布局,则返回true,因为它最后一次附加到窗口或从窗口分离。 //isLaidOut 方法作用:如果 view 已经通过至少一个布局,则返回true,因为它最后一次附加到窗口或从窗口分离。
ViewCompat.isLaidOut(this).yes { ViewCompat.isLaidOut(this).yes {
block() block()
}.otherwise { }.otherwise {
@ -76,7 +80,7 @@ inline fun <T : View> T.onGlobalLayoutOnce(crossinline action: T.() -> Unit) {
}) })
} }
fun View.paddingAll(padding: Int) { fun View.setPaddingAll(padding: Int) {
this.setPadding(padding, padding, padding, padding) this.setPadding(padding, padding, padding, padding)
} }
@ -126,7 +130,7 @@ fun View.setSize(width: Int, height: Int) {
} }
fun View.onDebouncedClick(onClick: (View) -> Unit) { fun View.onDebouncedClick(onClick: (View) -> Unit) {
onClickObservable(300) onClickObservable(500)
.subscribeIgnoreError { onClick(this) } .subscribeIgnoreError { onClick(this) }
} }
@ -136,12 +140,12 @@ fun View.onDebouncedClick(milliseconds: Long, onClick: (View) -> Unit) {
} }
fun View.onClickObservable(): Observable<Any> { fun View.onClickObservable(): Observable<Any> {
return onClickObservable(300) return onClickObservable(500)
} }
fun View.onClickObservable(milliseconds: Long): Observable<Any> { fun View.onClickObservable(milliseconds: Long): Observable<Any> {
return RxView.clicks(this) return RxView.clicks(this)
.debounce(milliseconds, TimeUnit.MILLISECONDS) .throttleFirst(milliseconds, TimeUnit.MILLISECONDS)
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
} }

Loading…
Cancel
Save