Skip to content

Instantly share code, notes, and snippets.

@wangerekaharun
Created December 10, 2019 14:46
Show Gist options
  • Save wangerekaharun/6cbd13041ecafec81a3c2c29f4b928cb to your computer and use it in GitHub Desktop.
Save wangerekaharun/6cbd13041ecafec81a3c2c29f4b928cb to your computer and use it in GitHub Desktop.
error.kt
//omitted class definations for brevity
private val sessionDataStateMediatorLiveData = MediatorLiveData<SessionsModel>()
private val error = MediatorLiveData<String>()
fun getSessionDetails(dayNumber: String, sessionId: Int) {
viewModelScope.launch {
when (val value = sessionDataRepo.getSessionData(dayNumber, sessionId)) {
is FirebaseResult.Success -> sessionDataStateMediatorLiveData.postValue(value.data)
is FirebaseResult.Error -> error.postValue(value.exception)
}
}
}
fun sendSessionFeedBack(userEventFeedback: SessionsUserFeedback) {
viewModelScope.launch {
when (val value = sessionFeedbackRepo.sendFeedBack(userEventFeedback)) {
is FirebaseResult.Success -> sessionFeedBackMediatorLiveData.postValue(value.data)
is FirebaseResult.Error -> error.postValue(value.exception)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment