Last active
          April 12, 2021 23:33 
        
      - 
      
- 
        Save fvilarino/0e74d04f5185566aca3eb75d9fdc1677 to your computer and use it in GitHub Desktop. 
    MVVM ViewModel Sample
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | 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