Skip to content

Instantly share code, notes, and snippets.

@makorowy
Last active October 18, 2020 09:48
Show Gist options
  • Save makorowy/9b48ded9bc13157cea8b0f8850b20248 to your computer and use it in GitHub Desktop.
Save makorowy/9b48ded9bc13157cea8b0f8850b20248 to your computer and use it in GitHub Desktop.
Example of not handling interactions via ViewModel, part 7
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