Merge pull request #220 from TouchInstinct/simple_text_watcher
Add SimpleTextWatcher for listening text changes
This commit is contained in:
commit
d9a9957cd4
|
|
@ -0,0 +1,24 @@
|
|||
package ru.touchin.roboswag.components.utils
|
||||
|
||||
import android.text.Editable
|
||||
import android.text.TextWatcher
|
||||
|
||||
class SimpleTextWatcher(private val onTextChanged: (Editable) -> Unit) : TextWatcher {
|
||||
|
||||
private var ignore = false
|
||||
|
||||
override fun afterTextChanged(s: Editable) {
|
||||
doPreventListenerLoop { onTextChanged(s) }
|
||||
}
|
||||
|
||||
override fun beforeTextChanged(s: CharSequence, start: Int, count: Int, after: Int) = Unit
|
||||
|
||||
override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) = Unit
|
||||
|
||||
private fun doPreventListenerLoop(callback: () -> Unit) {
|
||||
if (ignore) return
|
||||
ignore = true
|
||||
callback()
|
||||
ignore = false
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue