Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
class SearchViewModel(application: Application) : AndroidViewModel(application), CoroutineScope {
private val job = Job()
override val coroutineContext: CoroutineContext
get() = job + Dispatchers.Main
private val mutableViewState = MutableLiveData<SearchViewState>()
val viewState : LiveData<SearchViewState> = mutableViewState
private val repository by lazy {
mainApplication.omdbRepository
}
init {
start()
}
private fun start(){
search("avengers")
}
fun search(name : String) {
launch {
val movies = repository.searchMovies(name)
mutableViewState.postValue(SearchViewState(movies))
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment