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
| queryViewModelArc.searchEnabled.bind(searchButton::setEnabled) | |
| queryViewModelArc.showLoading.bind { loadinLayout.present = it } | |
| queryViewModelArc.queryValue.twoWayBind(queryEditText.bindableText) |
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
| fun onRestResult(response:Response){ | |
| if (response.data != null){ | |
| showItensOnScreen(response.data) | |
| }else{ | |
| showError() | |
| } | |
| } | |
| fun showItensOnScreen(model:RestModel){ | |
| livedataName.value = model.name |
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
| abstract class BaseViewModel: ViewModel() { | |
| protected operator fun <T> LiveData<T>.invoke(value: T) { | |
| if (this is ViewModelLiveData) { | |
| val viewModelLiveData = this | |
| viewModelLiveData.setValue(value) | |
| } | |
| } | |
| protected fun <T> liveData(value: T) = lazy { | |
| ViewModelLiveData(value) as LiveData<T> |
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
| interface ViewModelLiveDataExtension { | |
| operator fun <T> LiveData<T>.invoke(value: T) { | |
| if (this is ViewModelLiveData) { | |
| val viewModelLiveData = this | |
| viewModelLiveData.setValue(value) | |
| } | |
| } | |
| fun <T> ViewModel.liveData(value: T? = null) = lazy { | |
| ViewModelLiveData<T>().apply { value?.let { setValue(value) } } as LiveData<T> |
OlderNewer