Replace DefaultTextWatcher with extensions in core-ktx (#3401)

* Replace DefaultTextWatcher with extensions in core-ktx

* Fix positiveButton.isEnabled

* editable!! for highlightSpans

* Fix style

* Put noteWatcher back
This commit is contained in:
Goooler 2023-03-11 03:27:24 +08:00 committed by GitHub
commit 43ea59ab2f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 26 additions and 75 deletions

View file

@ -16,11 +16,8 @@
package com.keylesspalace.tusky.util
import android.text.Editable
import android.text.TextWatcher
import android.util.Log
import android.view.View
import android.widget.EditText
import androidx.recyclerview.widget.RecyclerView
import androidx.viewpager2.widget.ViewPager2
@ -36,37 +33,6 @@ fun View.visible(visible: Boolean, or: Int = View.GONE) {
this.visibility = if (visible) View.VISIBLE else or
}
open class DefaultTextWatcher : TextWatcher {
override fun afterTextChanged(s: Editable) {
}
override fun beforeTextChanged(s: CharSequence, start: Int, count: Int, after: Int) {
}
override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) {
}
}
inline fun EditText.onTextChanged(
crossinline callback: (s: CharSequence, start: Int, before: Int, count: Int) -> Unit
) {
addTextChangedListener(object : DefaultTextWatcher() {
override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) {
callback(s, start, before, count)
}
})
}
inline fun EditText.afterTextChanged(
crossinline callback: (s: Editable) -> Unit
) {
addTextChangedListener(object : DefaultTextWatcher() {
override fun afterTextChanged(s: Editable) {
callback(s)
}
})
}
/**
* Reduce ViewPager2's sensitivity to horizontal swipes.
*/