Java 类android.arch.lifecycle.ViewModel 实例源码

项目:CleanArchitechture    文件:ViewModelFactory.java   
@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);
    }
}
项目:firestore-android-arch-components    文件:ViewModelFactory.java   
@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);
    }
}
项目:CricKotlin    文件:AppViewModelFactory.java   
@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);
    }
}
项目:firebase-chat-android-architecture-components    文件:ArchCompViewModelFactory.java   
@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);
    }
}
项目:android-architecture-components    文件:GithubViewModelFactory.java   
@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);
    }
}
项目:igrow-android    文件:ViewModelFactory.java   
@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());
}
项目:mvvm-template    文件:GithubViewModelFactory.java   
@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);
    }
}
项目:androidthings-kuman-sm9    文件:ViewModelFactory.java   
@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);
    }
}
项目:PhotoExample    文件:PhotoViewModelFactory.java   
@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);
    }
}
项目:GmArchMvvm    文件:ViewModelFactory.java   
@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);
    }
}
项目:trust-wallet-android    文件:TransactionsViewModelFactory.java   
@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);
}
项目:LabDayApp    文件:ViewModelFactory.java   
/**
 * 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);
    }
}
项目:udacity-baking-app-mvvm-rxjava-dagger    文件:ViewModelFactory.java   
@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);
    }
}
项目:AndroidBlueprints    文件:ViewModelFactory.java   
@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);
    }
}
项目:MVVMArms    文件:ViewModelFactory.java   
@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);
    }
}
项目:RxRedux    文件:ViewModelFactory.java   
@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());
}
项目:Android-Code-Demos    文件:ViewModelFactory.java   
@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());
}
项目:Fairy    文件:ViewModelFactory.java   
@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);
    }
}
项目:RxCommand    文件:ViewModelFactory.java   
@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");
}
项目:RoomDemo2017    文件:CustomViewModelFactory.java   
@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");
    }
}
项目:android-architecture-components    文件:ViewModelUtil.java   
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);
        }
    };
}
项目:Android-CleanArchitecture-Java    文件:ViewModelUtil.java   
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);
        }
    };
}
项目:NewAndroidArchitecture    文件:CountriesViewModelProviderFactory.java   
@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);
}
项目:android-mvvm-architecture    文件:ViewModelProviderFactory.java   
@Override
public <T extends ViewModel> T create(Class<T> modelClass) {
    if (modelClass.isAssignableFrom(viewModel.getClass())) {
        return (T) viewModel;
    }
    throw new IllegalArgumentException("Unknown class name");
}
项目:DaggerAndroidMVVM    文件:LobbyViewModelFactory.java   
@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");
}
项目:trust-wallet-android    文件:WalletsViewModelFactory.java   
@NonNull
@Override
public <T extends ViewModel> T create(@NonNull Class<T> modelClass) {
    return (T) new WalletsViewModel(
               createWalletInteract,
               setDefaultWalletInteract,
               deleteWalletInteract,
               fetchWalletsInteract,
               findDefaultWalletInteract,
               exportWalletInteract,
               importWalletRouter,
               transactionsRouter);
}
项目:trust-wallet-android    文件:TransactionDetailViewModelFactory.java   
@NonNull
@Override
public <T extends ViewModel> T create(@NonNull Class<T> modelClass) {
    return (T) new TransactionDetailViewModel(
            findDefaultNetworkInteract,
            findDefaultWalletInteract,
            externalBrowserRouter);
}
项目:trust-wallet-android    文件:TokensViewModelFactory.java   
@NonNull
@Override
public <T extends ViewModel> T create(@NonNull Class<T> modelClass) {
    return (T) new TokensViewModel(
            findDefaultNetworkInteract,
            fetchTokensInteract,
            addTokenRouter,
            sendTokenRouter,
            transactionsRouter);
}
项目:OfflineSampleApp    文件:CommentsViewModelFactory.java   
@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");
}
项目:CleanArchitechture    文件:ViewModelFactory.java   
@Inject
ViewModelFactory(Map<Class<? extends ViewModel>, Provider<ViewModel>> creators) {
    this.creators = creators;
}
项目:CleanArchitechture    文件:ViewModelModule.java   
@Binds
@IntoMap
@ViewModelKey(MvvmActivityModel.class)
abstract ViewModel bindActivitySoccerSeasonViewModel(MvvmActivityModel model);
项目:CleanArchitechture    文件:ViewModelModule.java   
@Binds
@IntoMap
@ViewModelKey(SoccerSeasonFragmentModel.class)
abstract ViewModel bindFragmentSoccerSeasonViewModel(SoccerSeasonFragmentModel model);
项目:CleanArchitechture    文件:ViewModelModule.java   
@Binds
@IntoMap
@ViewModelKey(TeamFragmentModel.class)
abstract ViewModel bindFragmentTeamViewModel(TeamFragmentModel model);
项目:SampleAppArch    文件:FeedEntryListViewModelFactory.java   
@Override
public <T extends ViewModel> T create(Class<T> modelClass) {
  return (T) new FeedEntryListViewModel(feedEntryRepository);
}
项目:SampleAppArch    文件:AppArchNavViewModelFactory.java   
@Override
public <T extends ViewModel> T create(Class<T> modelClass) {
  return (T) new AppArchNavViewModel(sharedPreferences);
}
项目:SampleAppArch    文件:SimpleMasterDetailShareViewModelFactory.java   
@Override
public <T extends ViewModel> T create(Class<T> modelClass) {
  return (T) new SimpleMasterDetailShareViewModel(gitRepoRepository);
}
项目:SampleAppArch    文件:ShoppingActivityViewModelFactory.java   
@NonNull
@Override
public <T extends ViewModel> T create(@NonNull Class<T> modelClass) {
  return (T) new ShoppingActivityViewModel();
}
项目:SampleAppArch    文件:ArtistDetailActivityViewModelFactory.java   
@NonNull
@Override
public <T extends ViewModel> T create(@NonNull Class<T> modelClass) {
  return (T) new ArtistDetailActivityViewModel();
}
项目:SampleAppArch    文件:ArtistFragmentViewModelFactory.java   
@Override
public <T extends ViewModel> T create(Class<T> modelClass) {
  return (T) new ArtistFragmentViewModel(itunesRepository);
}
项目:SampleAppArch    文件:AlbumFragmentViewModelFactory.java   
@NonNull
@Override
public <T extends ViewModel> T create(@NonNull Class<T> modelClass) {
  return (T) new AlbumFragmentViewModel(this.itunesRepository);
}