Skip to content

Instantly share code, notes, and snippets.

@kozmi55
Created August 2, 2018 14:05
Show Gist options
  • Save kozmi55/31c6989ce600c187367bfa731f1eaede to your computer and use it in GitHub Desktop.
Save kozmi55/31c6989ce600c187367bfa731f1eaede to your computer and use it in GitHub Desktop.
class UserViewModel : BaseObservable() {
@get:Bindable
var userIds: List<Long> = emptyList()
private set(value) {
field = value
notifyPropertyChanged(BR.userIds)
}
private val updateInterval = 1000L
private val updateHandler = Handler()
private val random = Random()
private var updateRunnable: Runnable = object : Runnable {
override fun run() {
updateList()
updateHandler.postDelayed(this, updateInterval)
}
}
private fun updateList() {
userIds = List(30) {
random.nextLong()
}
}
fun startUpdates() {
updateHandler.postDelayed(updateRunnable, updateInterval)
}
fun stopUpdates() {
updateHandler.removeCallbacks(updateRunnable)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment