Skip to content

Instantly share code, notes, and snippets.

@igorwojda
Last active January 7, 2019 19:48
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 igorwojda/5673dbdbe0f046e14dde1cafe28c19c6 to your computer and use it in GitHub Desktop.
Save igorwojda/5673dbdbe0f046e14dde1cafe28c19c6 to your computer and use it in GitHub Desktop.
Register ViewModel Factory
class RegisterViewModelFactory @Inject constructor(
private val repository: UserRepository
): ViewModelProvider.Factory {
@Suppress("UNCHECKED_CAST")
override fun <T : ViewModel> create(modelClass: Class<T>): T {
return if (modelClass.isAssignableFrom(RegisterViewModel::class.java!!)) {
RegisterViewModel(repository) as T
} else {
throw IllegalArgumentException("ViewModel Not Found")
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment