Last active
October 18, 2020 09:48
-
-
Save makorowy/9b48ded9bc13157cea8b0f8850b20248 to your computer and use it in GitHub Desktop.
Example of not handling interactions via ViewModel, part 7
This file contains 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
data class ModelData( | |
val progressVisible: Boolean, | |
) | |
class ViewModel( | |
repository: Repository | |
) : ViewModel() { | |
private val _liveData = MutableLiveData<ModelData>() | |
val liveData: LiveData<ModelData> = _liveData | |
private val observer: (RepositoryData) -> Unit = { repositoryData -> | |
//some logic based on repository data | |
_liveData.postValue(ModelData) | |
} | |
init { | |
repository.observeChanges(observer) | |
} | |
fun submitProgressState(visible: Boolean) { | |
_liveData.postValue(ModelData(progressVisible = visible)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment