Skip to content

Instantly share code, notes, and snippets.

@fvilarino
Last active April 12, 2021 23:19
Show Gist options
  • Save fvilarino/ecc86170d488582173b1b603b670d872 to your computer and use it in GitHub Desktop.
Save fvilarino/ecc86170d488582173b1b603b670d872 to your computer and use it in GitHub Desktop.
Sample MVI ViewModel with LiveData
enum class LoadState {
IDLE,
LOADING,
LOADED,
ERROR
}
data class CitiesState(
val loadState: LoadState,
val cities: List<CityResultModel>,
val errorMessage: CharSequence,
) {
companion object {
val initial = CitiesState(
loadState = LoadState.IDLE,
cities = emptyList(),
errorMessage = "",
)
}
}
@HiltViewModel
class CityViewModel @Inject constructor(
private val getCitiesInteractor: GetCitiesInteractor,
private val navigator: Navigator,
) {
private val _state = MutableLiveData<CitiesState>(CitiesState.initial)
val state: LiveData<CitiesState>
get() = _state
// implementation follows
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment