willyrs
01/29/2021, 12:55 PMPatrick Jackson
01/29/2021, 1:06 PMwillyrs
01/29/2021, 1:08 PMPatrick Jackson
01/29/2021, 1:26 PMwillyrs
01/29/2021, 1:31 PMfun <T> LiveData<T>.debounce(duration: Long = 250L) = MediatorLiveData<T>().also { mld ->
val source = this
val handler = Handler(Looper.getMainLooper())
val runnable = Runnable {
mld.value = source.value
}
mld.addSource(source) {
handler.removeCallbacks(runnable)
handler.postDelayed(runnable, duration)
}
}
val data: MutableLiveData<AppState> = MutableLiveData()
store.subscribe {
data.postValue(it)
}
data.debounce().observe(this) {
adapter.blablabla()
adapter.notifyDataSetChanged()
}
It's a bit odd but it seems to do the trick