Skip to content

Instantly share code, notes, and snippets.

@CostaFot
Last active March 31, 2019 13:50
Show Gist options
  • Save CostaFot/884922961ee612025a6e510ded142c01 to your computer and use it in GitHub Desktop.
Save CostaFot/884922961ee612025a6e510ded142c01 to your computer and use it in GitHub Desktop.
/**
* Copy pasta how to ViewModelFactory
* Google says you cannot pass stuff in the ViewModel constructor like normal
* Just do this I guess, who am I to judge
*/
class NowPlayingMoviesViewModelFactory(
private val placeholderApi: MovieApi,
private val apiKey: String,
private val scheduler: Scheduler
) : ViewModelProvider.Factory {
override fun <T : ViewModel?> create(modelClass: Class<T>): T {
@Suppress("UNCHECKED_CAST")
return NowPlayingMoviesViewModel(
placeholderApi,
apiKey,
scheduler
) as T
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment