Last active
January 7, 2019 19:48
-
-
Save igorwojda/5673dbdbe0f046e14dde1cafe28c19c6 to your computer and use it in GitHub Desktop.
Register ViewModel Factory
This file contains hidden or 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 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