Skip to content

Instantly share code, notes, and snippets.

@jraska
Last active July 22, 2019 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jraska/071e28ced67c7ca7da77e4c50b98af7e to your computer and use it in GitHub Desktop.
Save jraska/071e28ced67c7ca7da77e4c50b98af7e to your computer and use it in GitHub Desktop.
class ContactsViewModel(val getContactsUseCase: GetContactsUseCase, parameters: Parameters) : ViewModel() {
private val contactsLiveData: LiveData<Contacts> by lazy {
val liveData = MutableLiveData<Contacts>()
getContactsUseCase.loadContacts(parameters) { liveData.value = it }
return@lazy liveData
}
fun contacts(parameters: Parameters): LiveData<Contacts> = contactsLiveData
}
class ContactsViewModelFactory(val getContactsUseCase: GetContactsUseCase, val parameters: Parameters)
: ViewModelProvider.Factory {
override fun <T : ViewModel> create(modelClass: Class<T>): T {
return ContactsViewModel(getContactsUseCase, parameters) as T
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment