Last active
August 4, 2018 22:26
-
-
Save paulocns/1bec4964b8bd813a92bb5fa50fc8c889 to your computer and use it in GitHub Desktop.
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
class QueryViewModelArc @Inject | |
constructor(private val searchShows: SearchShows?) : ViewModel() { | |
val result = MutableLiveData<String>() | |
val query = MutableLiveData<String>() | |
val showLoading = MutableLiveData<Boolean>() | |
val searchEnabled = MutableLiveData<Boolean>() | |
private val queryObserver: Observer<String> | |
init { | |
showLoading.value = false | |
searchEnabled.value = false | |
result.value = "" | |
query.value = "" | |
queryObserver = Observer { query -> searchEnabled.value = !TextUtils.isEmpty(query) } | |
query.observeForever(queryObserver) | |
} | |
override fun onCleared() { | |
super.onCleared() | |
query.removeObserver(queryObserver) | |
} | |
//your ViewModel Stuff | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment