Skip to content

Instantly share code, notes, and snippets.

@fvilarino
Last active April 12, 2021 23:33
Show Gist options
  • Save fvilarino/0e74d04f5185566aca3eb75d9fdc1677 to your computer and use it in GitHub Desktop.
Save fvilarino/0e74d04f5185566aca3eb75d9fdc1677 to your computer and use it in GitHub Desktop.
MVVM ViewModel Sample
enum class LoadState {
IDLE,
LOADING,
LOADED,
ERROR
}
@HiltViewModel
class CityViewModel @Inject constructor(
private val getCitiesInteractor: GetCitiesInteractor,
private val navigator: Navigator,
) {
private val _loadState = MutableLiveData<LoadState>(LoadState.IDLE)
val loadState: LiveData<LoadState>
get() = _loadState
private val _cityList = MutableLiveData<List<CityResultModel>>()
val cityList: LiveData<List<CityResultModel>>
get() = _cityList
private val _errorMessage = MutableLiveData<CharSequence>()
val errorMessage: LiveData<CharSequence>
get() = errorMessage
// implementation follows
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment