chanjungskim
04/14/2023, 2:18 AMrook
04/14/2023, 10:05 AMsealed interface ResultUiState {
object Prepping : ResultUiState
object Loading : ResultUiState
object Idle : ResultUiState
data class ResultData(
val a: String,
val b: Int,
) : ResultUiState
}
at the call-site, you’d do something like this
fun processResult(result: ResultUiState) {
when(result) {
is Prepping -> // do prepping
is Loading -> // do loading
is Idle -> // do idling
is ResultData -> updateUi(result)
}
}
fun updateUi(result: ResultData) {
// update your ui
}
chanjungskim
04/15/2023, 2:45 AMrook
04/15/2023, 9:21 AMchanjungskim
04/15/2023, 11:04 AMrook
04/15/2023, 11:05 AMchanjungskim
04/15/2023, 11:05 AMrook
04/15/2023, 11:43 AMResultData
in a Result
state model and cache the ResultData
in your view model. That way, you can put the field on all the states as an optional and build them with the cached value if it’s present.chanjungskim
04/16/2023, 11:03 AM