Skip to content

Instantly share code, notes, and snippets.

@vincent-paing
Last active April 9, 2018 04:37
Show Gist options
  • Save vincent-paing/f478d249e49f0292697f0a6969d159fe to your computer and use it in GitHub Desktop.
Save vincent-paing/f478d249e49f0292697f0a6969d159fe to your computer and use it in GitHub Desktop.
val viewModel = viewModelProviders.of(this, newsListingViewModel).get(NewsListingViewModel::class.java)
class NewsListingViewModel constructor(
val getNews: GetNews
) : BaseViewModel() {
//Implementations
}
class NewsListingViewModelFactory @Inject constructor(
private val getNews: GetNews
) : ViewModelProvider.Factory {
override fun <T : ViewModel?> create(modelClass: Class<T>): T {
if (modelClass.isAssignableFrom(NewsListingViewModel::class.java)) {
return NewsListingViewModel(getNews) as T
}
throw IllegalArgumentException("Unknown ViewModel class")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment