Skip to content

Instantly share code, notes, and snippets.

@ar-android
Created October 15, 2017 02:08
Show Gist options
  • Save ar-android/8558d8a590ae356f0e23bfa4d2a19bcb to your computer and use it in GitHub Desktop.
Save ar-android/8558d8a590ae356f0e23bfa4d2a19bcb to your computer and use it in GitHub Desktop.
class HomeViewModel: ViewModel(){
// Initialize LiveData and MutableLiveData
private val actor = actor<Action>(UI, Channel.CONFLATED) {
for (action in this) when (action) {
is Loadjadwal -> {
mutableLoading.value = true
try {
mutableJadwal.value = JadwalSholatRepository.getJadwalDefault()
} catch (e: Exception) {
mutableMessage.value = e.message.toString()
}
mutableLoading.value = false
}
}
}
init {
action(Loadjadwal("0"))
}
private fun action(action: Action) = actor.offer(action)
override fun onCleared() = actor.cancel().unit
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment