Skip to content

Instantly share code, notes, and snippets.

@shahbazahmed1269
Created June 10, 2017 06:13
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 shahbazahmed1269/5ca0dbb7162b8ca2f09a53cabfd1ba2b to your computer and use it in GitHub Desktop.
Save shahbazahmed1269/5ca0dbb7162b8ca2f09a53cabfd1ba2b to your computer and use it in GitHub Desktop.
Part of my 2nd blog post on architecture components and MVVM
public class ViewModelFactory implements ViewModelProvider.Factory {
private ListIssuesViewModel mViewModel;
@Inject
public ViewModelFactory(ListIssuesViewModel viewModel) {
this.mViewModel = viewModel;
}
@Override
public <T extends ViewModel> T create(Class<T> modelClass) {
if (modelClass.isAssignableFrom(ListIssuesViewModel.class)) {
return (T) mViewModel;
}
throw new IllegalArgumentException("Unknown class name");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment