@SuppressWarnings("unchecked") @Override public <T extends ViewModel> T create(Class<T> modelClass) { Provider<? extends ViewModel> creator = creators.get(modelClass); if (creator == null) { for (Map.Entry<Class<? extends ViewModel>, Provider<ViewModel>> entry : creators.entrySet()) { if (modelClass.isAssignableFrom(entry.getKey())) { creator = entry.getValue(); break; } } } if (creator == null) { throw new IllegalArgumentException("unknown model class " + modelClass); } try { return (T) creator.get(); } catch (Exception e) { throw new RuntimeException(e); } }
@NonNull @SuppressWarnings("unchecked") @Override public <T extends ViewModel> T create(@NonNull Class<T> modelClass) { Provider<? extends ViewModel> creator = creators.get(modelClass); if (creator == null) { for (Map.Entry<Class<? extends ViewModel>, Provider<ViewModel>> entry : creators.entrySet()) { if (modelClass.isAssignableFrom(entry.getKey())) { creator = entry.getValue(); break; } } } if (creator == null) { throw new IllegalArgumentException("unknown model class " + modelClass); } try { return (T) creator.get(); } catch (Exception e) { throw new RuntimeException(e); } }
@Override public <T extends ViewModel> T create(Class<T> modelClass) { Callable<? extends ViewModel> creator = creators.get(modelClass); if (creator == null) { for (Map.Entry<Class, Callable<? extends ViewModel>> entry : creators.entrySet()) { if (modelClass.isAssignableFrom(entry.getKey())) { creator = entry.getValue(); break; } } } if (creator == null) { throw new IllegalArgumentException("unknown model class " + modelClass); } try { return (T) creator.call(); } catch (Exception e) { throw new RuntimeException(e); } }
@Override public <T extends ViewModel> T create(Class<T> modelClass) { if (modelClass.isAssignableFrom(EnvironmentalSensorsViewModel.class)) { //noinspection unchecked return (T) new EnvironmentalSensorsViewModel(mApplication, mEnvironmentalSensorsRepository); } /*else if (modelClass.isAssignableFrom(TaskDetailViewModel.class)) { //noinspection unchecked return (T) new TaskDetailViewModel(mApplication, mEnvironmentalSensorsRepository); } else if (modelClass.isAssignableFrom(AddEditTaskViewModel.class)) { //noinspection unchecked return (T) new AddEditTaskViewModel(mApplication, mEnvironmentalSensorsRepository); } else if (modelClass.isAssignableFrom(EnvironmentalSensorsViewModel.class)) { //noinspection unchecked return (T) new EnvironmentalSensorsViewModel(mApplication, mEnvironmentalSensorsRepository); }*/ throw new IllegalArgumentException("Unknown ViewModel class: " + modelClass.getName()); }
@NonNull @SuppressWarnings("unchecked") @Override public <T extends ViewModel> T create(@NonNull Class<T> modelClass) { Provider<? extends ViewModel> creator = mCreators.get(modelClass); if (creator == null) { for (Map.Entry<Class<? extends ViewModel>, Provider<ViewModel>> entry : mCreators.entrySet()) { if (modelClass.isAssignableFrom(entry.getKey())) { creator = entry.getValue(); break; } } } if (creator == null) { throw new IllegalArgumentException("Unknown model class " + modelClass); } try { return (T) creator.get(); } catch (Exception e) { throw new RuntimeException(e); } }
@NonNull @Override public <T extends ViewModel> T create(@NonNull Class<T> modelClass) { return (T) new TransactionsViewModel( findDefaultNetworkInteract, findDefaultWalletInteract, fetchTransactionsInteract, getDefaultWalletBalance, manageWalletsRouter, settingsRouter, sendRouter, transactionDetailRouter, myAddressRouter, myTokensRouter, externalBrowserRouter); }
/** * creates ViewModels * @param modelClass (viewModelChildName).class * @param <T> class * @return ViewModel custom instance */ @NonNull @Override public <T extends ViewModel> T create(@NonNull Class<T> modelClass) { Callable<? extends ViewModel> creator = creators.get(modelClass); if(creator == null){ for(Map.Entry<Class, Callable<? extends ViewModel>> entry : creators.entrySet()){ if(modelClass.isAssignableFrom(entry.getKey())){ creator = entry.getValue(); break; } } } if(creator == null){ throw new IllegalArgumentException("Model class not found" + modelClass); } try { return (T) creator.call(); } catch (Exception e){ throw new RuntimeException(e); } }
@SuppressWarnings("unchecked") @Override public <T extends ViewModel> T create(Class<T> modelClass) { Provider<? extends ViewModel> creator = creators.get(modelClass); if (creator == null) { for (Map.Entry<Class<? extends ViewModel>, Provider<ViewModel>> entry : creators.entrySet()) { if (modelClass.isAssignableFrom(entry.getKey())) { creator = entry.getValue(); break; } } } if (creator == null) { throw new IllegalArgumentException("Unknown model class " + modelClass); } try { return (T) creator.get(); } catch (Exception e) { throw new RuntimeException(e); } }
@NonNull @Override public <T extends ViewModel> T create(@NonNull Class<T> modelClass) { if (modelClass.isAssignableFrom(UserListVM.class)) { return (T) new UserListVM(dataService); } else if (modelClass.isAssignableFrom(UserDetailVM.class)) { return (T) new UserDetailVM(dataService); } throw new IllegalArgumentException("Unknown ViewModel class: " + modelClass.getSimpleName()); }
@Override public <T extends ViewModel> T create(Class<T> modelClass) { if (modelClass.isAssignableFrom(LoginViewModel.class)) { return (T) new LoginViewModel(mApplication); } throw new IllegalArgumentException("Unknown ViewModel class: " + modelClass.getName()); }
@NonNull @Override public <T extends ViewModel> T create(@NonNull Class<T> modelClass) { if (modelClass.isAssignableFrom(LogcatItemViewModel.class)) { return (T) new LogcatItemViewModel(application, repositoryInjection.provideItemRepo()); } else if (modelClass.isAssignableFrom(LogcatContentViewModel.class)) { return (T) new LogcatContentViewModel(application, repositoryInjection.provideContentRepo()); } else { throw new IllegalArgumentException("Unkonw viewmodel type: " + modelClass); } }
@Override public <T extends ViewModel> T create(Class<T> modelClass) { if (modelClass.isAssignableFrom(LoginViewModel.class)) { return (T) new LoginViewModel(); } throw new IllegalArgumentException("Unknown ViewModel class"); }
@Override public <T extends ViewModel> T create(Class<T> modelClass) { if (modelClass.isAssignableFrom(ListItemCollectionViewModel.class)) return (T) new ListItemCollectionViewModel(repository); else if (modelClass.isAssignableFrom(ListItemViewModel.class)) return (T) new ListItemViewModel(repository); else if (modelClass.isAssignableFrom(NewListItemViewModel.class)) return (T) new NewListItemViewModel(repository); else { throw new IllegalArgumentException("ViewModel Not Found"); } }
public static <T extends ViewModel> ViewModelProvider.Factory createFor(T model) { return new ViewModelProvider.Factory() { @Override public <T extends ViewModel> T create(Class<T> modelClass) { if (modelClass.isAssignableFrom(model.getClass())) { return (T) model; } throw new IllegalArgumentException("unexpected model class " + modelClass); } }; }
@NonNull @Override public <T extends ViewModel> T create(@NonNull Class<T> modelClass) { if (modelClass.equals(CountriesViewModel.class)) { //noinspection unchecked return (T) new CountriesViewModel(repository); } return super.create(modelClass); }
@Override public <T extends ViewModel> T create(Class<T> modelClass) { if (modelClass.isAssignableFrom(viewModel.getClass())) { return (T) viewModel; } throw new IllegalArgumentException("Unknown class name"); }
@Override public <T extends ViewModel> T create(Class<T> modelClass) { if (modelClass.isAssignableFrom(LobbyViewModel.class)) { return (T) new LobbyViewModel(loadCommonGreetingUseCase, loadLobbyGreetingUseCase, schedulersFacade); } throw new IllegalArgumentException("Unknown ViewModel class"); }
@NonNull @Override public <T extends ViewModel> T create(@NonNull Class<T> modelClass) { return (T) new WalletsViewModel( createWalletInteract, setDefaultWalletInteract, deleteWalletInteract, fetchWalletsInteract, findDefaultWalletInteract, exportWalletInteract, importWalletRouter, transactionsRouter); }
@NonNull @Override public <T extends ViewModel> T create(@NonNull Class<T> modelClass) { return (T) new TransactionDetailViewModel( findDefaultNetworkInteract, findDefaultWalletInteract, externalBrowserRouter); }
@NonNull @Override public <T extends ViewModel> T create(@NonNull Class<T> modelClass) { return (T) new TokensViewModel( findDefaultNetworkInteract, fetchTokensInteract, addTokenRouter, sendTokenRouter, transactionsRouter); }
@Override public <T extends ViewModel> T create(Class<T> modelClass) { if (modelClass.isAssignableFrom(CommentsViewModel.class)) { return (T) new CommentsViewModel(getCommentsUseCase, addCommentUseCase); } throw new IllegalArgumentException("Unknown ViewModel class"); }
@Inject ViewModelFactory(Map<Class<? extends ViewModel>, Provider<ViewModel>> creators) { this.creators = creators; }
@Binds @IntoMap @ViewModelKey(MvvmActivityModel.class) abstract ViewModel bindActivitySoccerSeasonViewModel(MvvmActivityModel model);
@Binds @IntoMap @ViewModelKey(SoccerSeasonFragmentModel.class) abstract ViewModel bindFragmentSoccerSeasonViewModel(SoccerSeasonFragmentModel model);
@Binds @IntoMap @ViewModelKey(TeamFragmentModel.class) abstract ViewModel bindFragmentTeamViewModel(TeamFragmentModel model);
@Override public <T extends ViewModel> T create(Class<T> modelClass) { return (T) new FeedEntryListViewModel(feedEntryRepository); }
@Override public <T extends ViewModel> T create(Class<T> modelClass) { return (T) new AppArchNavViewModel(sharedPreferences); }
@Override public <T extends ViewModel> T create(Class<T> modelClass) { return (T) new SimpleMasterDetailShareViewModel(gitRepoRepository); }
@NonNull @Override public <T extends ViewModel> T create(@NonNull Class<T> modelClass) { return (T) new ShoppingActivityViewModel(); }
@NonNull @Override public <T extends ViewModel> T create(@NonNull Class<T> modelClass) { return (T) new ArtistDetailActivityViewModel(); }
@Override public <T extends ViewModel> T create(Class<T> modelClass) { return (T) new ArtistFragmentViewModel(itunesRepository); }
@NonNull @Override public <T extends ViewModel> T create(@NonNull Class<T> modelClass) { return (T) new AlbumFragmentViewModel(this.itunesRepository); }