Skip to content

Instantly share code, notes, and snippets.

@0phelia
Created November 15, 2019 11:23
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 0phelia/da7b0a4752f24dfbb0341f3c2039cfbd to your computer and use it in GitHub Desktop.
Save 0phelia/da7b0a4752f24dfbb0341f3c2039cfbd to your computer and use it in GitHub Desktop.
class ViewModelFactory(private val mApplication: App,
private val irepo: IRepo) : ViewModelProvider.Factory {
override fun <T : ViewModel> create(modelClass: Class<T>): T {
return when (modelClass) {
GVM::class.java -> GVM(irepo) as T
VVM::class.java -> VVM(mApplication, irepo) as T
AVM::class.java -> AVM(irepo) as T
else -> throw IllegalArgumentException("Use standard ViewModelProvider to retrieve this ViewModel")
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment