Last active
December 11, 2018 13:03
-
-
Save florent37/130c148f33ed23628407a95a5a46bf5f to your computer and use it in GitHub Desktop.
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
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