Skip to content

Instantly share code, notes, and snippets.

@jeremyrempel
Created June 29, 2019 17:49
Show Gist options
  • Save jeremyrempel/6d23f51fd70b71e044741f826b5d7c56 to your computer and use it in GitHub Desktop.
Save jeremyrempel/6d23f51fd70b71e044741f826b5d7c56 to your computer and use it in GitHub Desktop.
class MyViewModelFactory @Inject constructor(
private val mainFragModel: Provider<MainFragmentViewModel>
) : ViewModelProvider.Factory {
override fun <T : ViewModel> create(modelClass: Class<T>): T {
return when (modelClass) {
MainFragmentViewModel::class.java -> mainFragModel.get()
else -> TODO("Missing viewModel $modelClass")
} as T
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment