android.arch.lifecycle.ViewModel Java Examples

The following examples show how to use android.arch.lifecycle.ViewModel. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AppModule.java    From WanAndroid with GNU General Public License v3.0 6 votes vote down vote up
@Singleton
@Provides
static Map<Class<?>, Callable<Lazy<? extends ViewModel>>> providesViewModel(ViewModelSubComponent.Builder viewModelSubComponent) {
    ViewModelSubComponent vmsc = viewModelSubComponent.build();
    Map<Class<?>, Callable<Lazy<? extends ViewModel>>> creators = new HashMap<>();

    creators.put(MainViewModel.class, vmsc::viewModelMain);

    creators.put(MainBlogPostsViewModel.class, vmsc::viewModelMainBlogPosts);
    creators.put(MainProjectsViewModel.class, vmsc::viewModelMainProjects);
    creators.put(MainBoxesViewModel.class, vmsc::viewModelMainBoxes);

    creators.put(ReadViewModel.class, vmsc::viewModelRead);
    creators.put(LoginViewModel.class, vmsc::viewModelLogin);

    creators.put(OpenAPISViewModel.class, vmsc::viewModelOpenAPIS);
    creators.put(PostTreeViewModel.class, vmsc::viewModelPostTree);
    creators.put(WebNavViewModel.class, vmsc::viewModelWebNav);
    creators.put(FriendLinkViewModel.class, vmsc::viewModelFriendLink);
    creators.put(ProjectCategoryViewModel.class, vmsc::viewModelProjectCategory);
    creators.put(LikeViewModel.class, vmsc::viewModelLike);
    creators.put(LicenseViewModel.class, vmsc::viewModelLicense);
    creators.put(SettingsViewModel.class, vmsc::viewModelSettings);
    creators.put(CategoryDetailViewModel.class, vmsc::viewModelCategoryDetail);
    return creators;
}
 
Example #2
Source File: ViewModelFactory.java    From firestore-android-arch-components with Apache License 2.0 6 votes vote down vote up
@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);
    }
}
 
Example #3
Source File: ViewModelFactory.java    From MVVMArms with Apache License 2.0 6 votes vote down vote up
@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);
    }
}
 
Example #4
Source File: TransactionsViewModelFactory.java    From ETHWallet with GNU General Public License v3.0 6 votes vote down vote up
@NonNull
@Override
public <T extends ViewModel> T create(@NonNull Class<T> modelClass) {
    return (T) new MainViewModel(
            findDefaultNetworkInteract,
            findDefaultWalletInteract,
            fetchTransactionsInteract,
            getDefaultWalletBalance,
            manageWalletsRouter,
            settingsRouter,
            sendRouter,
            transactionDetailRouter,
            myAddressRouter,
            myTokensRouter,
            externalBrowserRouter);
}
 
Example #5
Source File: ViewModelFactory.java    From AndroidBlueprints with Apache License 2.0 6 votes vote down vote up
@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);
    }
}
 
Example #6
Source File: TransactionsViewModelFactory.java    From trust-wallet-android-source with GNU General Public License v3.0 6 votes vote down vote up
@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);
}
 
Example #7
Source File: HomeViewModelFactory.java    From alpha-wallet-android with MIT License 6 votes vote down vote up
@NonNull
@Override
public <T extends ViewModel> T create(@NonNull Class<T> modelClass) {
    return (T) new HomeViewModel(
            preferenceRepository,
            localeRepository,
            importTokenRouter,
            addTokenRouter,
            assetDefinitionService,
            genericWalletInteract,
            fetchWalletsInteract,
            currencyRepository,
            ethereumNetworkRepository,
            context
            );
}
 
Example #8
Source File: WalletsViewModelFactory.java    From alpha-wallet-android with MIT License 6 votes vote down vote up
@NonNull
@Override
public <T extends ViewModel> T create(@NonNull Class<T> modelClass) {
    return (T) new WalletsViewModel(
            setDefaultWalletInteract,
            fetchWalletsInteract,
            genericWalletInteract,
            importWalletRouter,
            homeRouter,
            fetchTokensInteract,
            findDefaultNetworkInteract,
            keyService,
            gasService,
            tokensService,
            context);
}
 
Example #9
Source File: MyAddressViewModelFactory.java    From alpha-wallet-android with MIT License 5 votes vote down vote up
@NonNull
@Override
public <T extends ViewModel> T create(@NonNull Class<T> modelClass) {
    return (T) new MyAddressViewModel(
            findDefaultNetworkInteract,
            ethereumNetworkRepository,
            tokenRepository
            );
}
 
Example #10
Source File: TokensViewModelFactory.java    From Upchain-wallet with GNU Affero General Public License v3.0 5 votes vote down vote up
@NonNull
@Override
public <T extends ViewModel> T create(@NonNull Class<T> modelClass) {
    return (T) new TokensViewModel(
            ethereumNetworkRepository,
            new FetchWalletInteract(),
            fetchTokensInteract
            );
}
 
Example #11
Source File: ViewModelProviderFactory.java    From triviums with MIT License 5 votes vote down vote up
@Override
public <T extends ViewModel> T create(Class<T> modelClass) {
    if (modelClass.isAssignableFrom(viewModel.getClass())) {
        return (T) viewModel;
    }
    throw new IllegalArgumentException("Unknown class name");
}
 
Example #12
Source File: TransactionDetailViewModelFactory.java    From ETHWallet with GNU General Public License v3.0 5 votes vote down vote up
@NonNull
@Override
public <T extends ViewModel> T create(@NonNull Class<T> modelClass) {
    return (T) new TransactionDetailViewModel(
            findDefaultNetworkInteract,
            findDefaultWalletInteract,
            externalBrowserRouter);
}
 
Example #13
Source File: WalletsViewModelFactory.java    From ETHWallet with GNU General Public License v3.0 5 votes vote down vote up
@NonNull
@Override
public <T extends ViewModel> T create(@NonNull Class<T> modelClass) {
	return (T) new WalletsViewModel(
               createWalletInteract,
               setDefaultWalletInteract,
               deleteWalletInteract,
               fetchWalletsInteract,
               findDefaultWalletInteract,
               exportWalletInteract,
               importWalletRouter,
			mainRouter);
}
 
Example #14
Source File: ViewModelFactory.java    From Fairy with Apache License 2.0 5 votes vote down vote up
@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);
    }
}
 
Example #15
Source File: TokensViewModelFactory.java    From ETHWallet with GNU General Public License v3.0 5 votes vote down vote up
@NonNull
@Override
public <T extends ViewModel> T create(@NonNull Class<T> modelClass) {
    return (T) new TokensViewModel(
            findDefaultNetworkInteract,
            fetchTokensInteract,
            addTokenRouter,
            sendTokenRouter,
            mainRouter);
}
 
Example #16
Source File: TransactionsViewModelFactory.java    From alpha-wallet-android with MIT License 5 votes vote down vote up
@NonNull
@Override
public <T extends ViewModel> T create(@NonNull Class<T> modelClass) {
    return (T) new TransactionsViewModel(
            findDefaultNetworkInteract,
            genericWalletInteract,
            fetchTransactionsInteract,
            setupTokensInteract,
            addTokenInteract,
            transactionDetailRouter,
            assetDefinitionService,
            tokensService);
}
 
Example #17
Source File: TransactionDetailViewModelFactory.java    From trust-wallet-android-source with GNU General Public License v3.0 5 votes vote down vote up
@NonNull
@Override
public <T extends ViewModel> T create(@NonNull Class<T> modelClass) {
    return (T) new TransactionDetailViewModel(
            findDefaultNetworkInteract,
            findDefaultWalletInteract,
            externalBrowserRouter);
}
 
Example #18
Source File: BackupKeyViewModelFactory.java    From alpha-wallet-android with MIT License 5 votes vote down vote up
@NonNull
@Override
public <T extends ViewModel> T create(@NonNull Class<T> modelClass) {
    return (T) new BackupKeyViewModel(
            keyService,
            exportWalletInteract,
            fetchWalletsInteract);
}
 
Example #19
Source File: WalletsViewModelFactory.java    From trust-wallet-android-source with GNU General Public License v3.0 5 votes vote down vote up
@NonNull
@Override
public <T extends ViewModel> T create(@NonNull Class<T> modelClass) {
	return (T) new WalletsViewModel(
               createWalletInteract,
               setDefaultWalletInteract,
               deleteWalletInteract,
               fetchWalletsInteract,
               findDefaultWalletInteract,
               exportWalletInteract,
               importWalletRouter,
               transactionsRouter);
}
 
Example #20
Source File: SplashViewModelFactory.java    From alpha-wallet-android with MIT License 5 votes vote down vote up
@NonNull
@Override
public <T extends ViewModel> T create(@NonNull Class<T> modelClass) {
    return (T) new SplashViewModel(
            fetchWalletsInteract,
            preferenceRepository,
            localeRepository,
            keyService,
            assetDefinitionService,
            currencyRepository);
}
 
Example #21
Source File: AdvancedSettingsViewModelFactory.java    From alpha-wallet-android with MIT License 5 votes vote down vote up
@NonNull
@Override
public <T extends ViewModel> T create(@NonNull Class<T> modelClass) {
    return (T) new AdvancedSettingsViewModel(
            localeRepository,
            currencyRepository,
            assetDefinitionService
    );
}
 
Example #22
Source File: DappBrowserViewModelFactory.java    From alpha-wallet-android with MIT License 5 votes vote down vote up
@NonNull
@Override
public <T extends ViewModel> T create(@NonNull Class<T> modelClass) {
    return (T) new DappBrowserViewModel(
            findDefaultNetworkInteract,
            genericWalletInteract,
            assetDefinitionService,
            createTransactionInteract,
            fetchTokensInteract,
            confirmationRouter,
            ethereumNetworkRepository,
            gasService,
            keyService);
}
 
Example #23
Source File: ViewModelFactory.java    From RxCommand with MIT License 5 votes vote down vote up
@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");
}
 
Example #24
Source File: NewSettingsViewModelFactory.java    From alpha-wallet-android with MIT License 5 votes vote down vote up
@NonNull
@Override
public <T extends ViewModel> T create(@NonNull Class<T> modelClass) {
    return (T) new NewSettingsViewModel(
            genericWalletInteract,
            getDefaultWalletBalance,
            myAddressRouter,
            ethereumNetworkRepository,
            manageWalletsRouter,
            preferenceRepository,
            localeRepository,
            tokensService,
            currencyRepository
    );
}
 
Example #25
Source File: WalletActionsViewModelFactory.java    From alpha-wallet-android with MIT License 5 votes vote down vote up
@NonNull
@Override
public <T extends ViewModel> T create(@NonNull Class<T> modelClass) {
    return (T) new WalletActionsViewModel(
            homeRouter,
            deleteWalletInteract,
            exportWalletInteract,
            fetchWalletsInteract);
}
 
Example #26
Source File: TransactionDetailViewModelFactory.java    From Upchain-wallet with GNU Affero General Public License v3.0 5 votes vote down vote up
@NonNull
@Override
public <T extends ViewModel> T create(@NonNull Class<T> modelClass) {
    return (T) new TransactionDetailViewModel(
            EthereumNetworkRepository,
            findDefaultWalletInteract
            );
}
 
Example #27
Source File: ViewModelModule.java    From firestore-android-arch-components with Apache License 2.0 4 votes vote down vote up
@Binds
@IntoMap
@ViewModelKey(MainViewModel.class)
abstract ViewModel bindMainViewModel(MainViewModel viewModel);
 
Example #28
Source File: ConfirmationViewModelFactory.java    From alpha-wallet-android with MIT License 4 votes vote down vote up
@NonNull
@Override
public <T extends ViewModel> T create(@NonNull Class<T> modelClass) {
    return (T) new ConfirmationViewModel(genericWalletInteract, gasService, createTransactionInteract, gasSettingsRouter, tokensService, findDefaultNetworkInteract, keyService);
}
 
Example #29
Source File: GasSettingsViewModelFactory.java    From alpha-wallet-android with MIT License 4 votes vote down vote up
@NonNull
@Override
public <T extends ViewModel> T create(@NonNull Class<T> modelClass) {
    return (T) new GasSettingsViewModel(findDefaultNetworkInteract);
}
 
Example #30
Source File: WeatherViewModelModule.java    From MVVMArms with Apache License 2.0 4 votes vote down vote up
@Binds
@IntoMap
@ViewModelScope(WeatherViewModel.class)
abstract ViewModel bindWeatherViewModel(WeatherViewModel weatherViewModel);