From bdd29f115af461ead4e0049afb8ee3bcee8e2cb4 Mon Sep 17 00:00:00 2001 From: Zhanty Date: Fri, 2 Aug 2019 11:15:08 +0800 Subject: [PATCH] optimize --- .../java/com/android/base/kotlin/TextViewEx.kt | 2 +- .../main/java/com/android/base/kotlin/ViewEx.kt | 14 +++++++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/lib_base/src/main/java/com/android/base/kotlin/TextViewEx.kt b/lib_base/src/main/java/com/android/base/kotlin/TextViewEx.kt index 8587bc5..0cfe957 100644 --- a/lib_base/src/main/java/com/android/base/kotlin/TextViewEx.kt +++ b/lib_base/src/main/java/com/android/base/kotlin/TextViewEx.kt @@ -111,7 +111,7 @@ fun TextView.clearComponentDrawable() { 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 et.addTextChangedListener(object : TextWatcherAdapter { override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) { diff --git a/lib_base/src/main/java/com/android/base/kotlin/ViewEx.kt b/lib_base/src/main/java/com/android/base/kotlin/ViewEx.kt index 9b9ca68..98d1ec3 100644 --- a/lib_base/src/main/java/com/android/base/kotlin/ViewEx.kt +++ b/lib_base/src/main/java/com/android/base/kotlin/ViewEx.kt @@ -44,10 +44,14 @@ fun 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) inline fun View.doOnLayoutAvailable(crossinline block: () -> Unit) { - //如果 view 已经通过至少一个布局,则返回true,因为它最后一次附加到窗口或从窗口分离。 + //isLaidOut 方法作用:如果 view 已经通过至少一个布局,则返回true,因为它最后一次附加到窗口或从窗口分离。 ViewCompat.isLaidOut(this).yes { block() }.otherwise { @@ -76,7 +80,7 @@ inline fun T.onGlobalLayoutOnce(crossinline action: T.() -> Unit) { }) } -fun View.paddingAll(padding: Int) { +fun View.setPaddingAll(padding: Int) { this.setPadding(padding, padding, padding, padding) } @@ -126,7 +130,7 @@ fun View.setSize(width: Int, height: Int) { } fun View.onDebouncedClick(onClick: (View) -> Unit) { - onClickObservable(300) + onClickObservable(500) .subscribeIgnoreError { onClick(this) } } @@ -136,12 +140,12 @@ fun View.onDebouncedClick(milliseconds: Long, onClick: (View) -> Unit) { } fun View.onClickObservable(): Observable { - return onClickObservable(300) + return onClickObservable(500) } fun View.onClickObservable(milliseconds: Long): Observable { return RxView.clicks(this) - .debounce(milliseconds, TimeUnit.MILLISECONDS) + .throttleFirst(milliseconds, TimeUnit.MILLISECONDS) .observeOn(AndroidSchedulers.mainThread()) }