Created
August 2, 2018 14:05
-
-
Save kozmi55/31c6989ce600c187367bfa731f1eaede to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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