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

项目:mobile-buy-sdk-android    文件:ProductDetailsActivity.java   
private void initViewModels(final String productId) {
  productViewModel = ViewModelProviders.of(this, new ViewModelProvider.Factory() {
    @SuppressWarnings("unchecked") @Override public <T extends ViewModel> T create(final Class<T> modelClass) {
      if (modelClass.equals(RealProductViewModel.class)) {
        return (T) new RealProductViewModel(productId);
      } else {
        return null;
      }
    }
  }).get(RealProductViewModel.class);
  productViewModel.productLiveData().observe(this, this::renderProduct);
  productViewModel.progressLiveData().observe(this, progress -> {
    if (progress != null) {
      swipeRefreshLayoutView.setRefreshing(progress.show);
    }
  });
  productViewModel.errorErrorCallback().observe(this.getLifecycle(), error -> {
    if (error != null) {
      showDefaultErrorMessage();
    }
  });
}
项目: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);
        }
    };
}
项目:NewAndroidArchitecture    文件:MainActivity.java   
@NonNull
private CountriesViewModel getViewModel() {
    CountriesService service = ApiClient.getCountriesService();
    CountryDao moviesDao = CountriesDatabase.getInstance(this).countryDao();
    ViewModelProvider.Factory factory = new CountriesViewModelProviderFactory(service, moviesDao);
    return ViewModelProviders.of(this, factory).get(CountriesViewModel.class);
}
项目: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);
        }
    };
}
项目:leanback-showcase    文件:PresenterModule.java   
@PerFragment
@Provides
public LiveDataRowPresenter provideLiveDataRowPresenter(ViewModelProvider.Factory factory,
        DataLoadedListener activity) {
    LiveDataRowPresenter rowPresenter = new LiveDataRowPresenter(factory);

    rowPresenter.registerDataLoadedListener(activity);
    return rowPresenter;
}
项目:mobile-buy-sdk-android    文件:ProductListActivity.java   
private void initViewModels(final String collectionId) {
  ProductListViewModel listViewModel = ViewModelProviders.of(this, new ViewModelProvider.Factory() {
    @SuppressWarnings("unchecked")
    @Override
    public <T extends ViewModel> T create(final Class<T> modelClass) {
      if (modelClass.equals(ProductListViewModel.class)) {
        return (T) new ProductListViewModel(collectionId);
      } else {
        return null;
      }
    }
  }).get(ProductListViewModel.class);
  productListView.bindViewModel(listViewModel);
}
项目:CleanArchitechture    文件:SoccerSeasonMvvmFragment.java   
@Override
public void initViewModel(ViewModelProvider.Factory factory) {
    mViewModel = ViewModelProviders.of(this,factory).get(SoccerSeasonFragmentModel.class);
}
项目:CleanArchitechture    文件:TeamMvvmFragment.java   
@Override
public void initViewModel(ViewModelProvider.Factory factory) {
    mViewModel = ViewModelProviders.of(this,factory).get(TeamFragmentModel.class);
}
项目:CleanArchitechture    文件:ViewModelModule.java   
@Binds
abstract ViewModelProvider.Factory bindViewModelFactory(ViewModelFactory factory);
项目:firestore-android-arch-components    文件:ViewModelModule.java   
@Binds
abstract ViewModelProvider.Factory bindViewModelFactory(ViewModelFactory factory);
项目:firebase-chat-android-architecture-components    文件:ViewModelModule.java   
@Binds
abstract ViewModelProvider.Factory bindViewModelFactory(ArchCompViewModelFactory factory);
项目:RoomDemo2017    文件:RoomModule.java   
@Provides
@Singleton
ViewModelProvider.Factory provideViewModelFactory(ListItemRepository repository){
    return new CustomViewModelFactory(repository);
}
项目:android-architecture-components    文件:ViewModelModule.java   
@Binds
abstract ViewModelProvider.Factory bindViewModelFactory(GithubViewModelFactory factory);
项目:mvvm-template    文件:ViewModelModule.java   
@Binds
abstract ViewModelProvider.Factory bindViewModelFactory(GithubViewModelFactory factory);
项目:android-architecture-boilerplate    文件:ApplicationModule.java   
@Provides
@Singleton
ViewModelProvider.Factory provideViewModelFactory() {
    return new ViewModelProvider.NewInstanceFactory();
}
项目:androidthings-kuman-sm9    文件:ViewModelModule.java   
@Binds
abstract ViewModelProvider.Factory bindViewModelFactory(ViewModelFactory factory);
项目:androidthings-kuman-sm9    文件:ViewModelModule.java   
@Binds
abstract ViewModelProvider.Factory bindViewModelFactory(ViewModelFactory factory);
项目:PhotoExample    文件:AppModule.java   
@Provides
@Singleton
ViewModelProvider.Factory provideViewModelFactory(ViewModelSubComponent.Builder builder){
    return new PhotoViewModelFactory(builder.build());
}
项目:android-mvvm-architecture    文件:MainActivityModule.java   
@Provides
ViewModelProvider.Factory mainViewModelProvider(MainViewModel mainViewModel) {
    return new ViewModelProviderFactory<>(mainViewModel);
}
项目:android-mvvm-architecture    文件:BlogFragmentModule.java   
@Provides
ViewModelProvider.Factory provideBlogViewModel(BlogViewModel blogViewModel) {
    return new ViewModelProviderFactory<>(blogViewModel);
}
项目:android-mvvm-architecture    文件:OpenSourceFragmentModule.java   
@Provides
ViewModelProvider.Factory provideOpenSourceViewModel(OpenSourceViewModel openSourceViewModel) {
    return new ViewModelProviderFactory<>(openSourceViewModel);
}
项目:GmArchMvvm    文件:ViewModelFactoryModule.java   
@Binds
abstract ViewModelProvider.Factory bindViewModelFactory(ViewModelFactory factory);
项目:udacity-baking-app-mvvm-rxjava-dagger    文件:ViewModelModule.java   
@Binds
abstract ViewModelProvider.Factory bindViewModelFactory(ViewModelFactory factory);
项目:AndroidBlueprints    文件:ViewModelModule.java   
@Binds
abstract ViewModelProvider.Factory bindViewModelFactory(ViewModelFactory factory);
项目:LabDayApp    文件:AppModule.java   
@Singleton
@Provides
ViewModelProvider.Factory provideViewModelFactory(ViewModelSubComponent.Builder viewModelBuilder){
    return new ViewModelFactory(viewModelBuilder.build());
}
项目:MVVMArms    文件:ViewModelFactoryModule.java   
@Binds
abstract ViewModelProvider.Factory bindViewModelFactory(ViewModelFactory factory);
项目:leanback-showcase    文件:ViewModelModule.java   
@Binds
@Singleton
abstract ViewModelProvider.Factory bindViewModelFactory(ViewModelFactory factory);
项目:leanback-showcase    文件:LiveDataRowPresenter.java   
public LiveDataRowPresenter(ViewModelProvider.Factory factory) {
    super();
    mDataLoadedListeners = new ArrayList<>();
    viewModelFactory = factory;
}
项目:RecipeFinderJavaVersion    文件:ViewModelModule.java   
@Binds
abstract ViewModelProvider.Factory bindViewModelFactory(ViewModelFactory factory);
项目:mobile-buy-sdk-android    文件:CartActivity.java   
private void initViewModels() {
  ShopSettings shopSettings = ((BaseApplication) getApplication()).shopSettings().getValue();
  RealCartViewModel cartViewModel = ViewModelProviders.of(this, new ViewModelProvider.Factory() {
    @Override public <T extends ViewModel> T create(final Class<T> modelClass) {
      if (modelClass.equals(RealCartViewModel.class)) {
        //noinspection unchecked
        return (T) new RealCartViewModel(shopSettings);
      } else {
        return null;
      }
    }
  }).get(RealCartViewModel.class);
  cartHeaderViewModel = cartViewModel;
  cartDetailsViewModel = cartViewModel;

  cartDetailsViewModel.webCheckoutCallback().observe(this.getLifecycle(), checkout -> {
    if (checkout != null) {
      onWebCheckoutConfirmation(checkout);
    }
  });
  cartDetailsViewModel.androidPayStartCheckoutCallback().observe(this.getLifecycle(), payCart -> {
    if (cartHeaderViewModel.googleApiClientConnectionData().getValue() == Boolean.TRUE && payCart != null) {
      PayHelper.requestMaskedWallet(googleApiClient, payCart, BuildConfig.ANDROID_PAY_PUBLIC_KEY);
    }
  });
  cartDetailsViewModel.androidPayCheckoutCallback().observe(this.getLifecycle(), confirmation -> {
    if (confirmation != null) {
      ScreenRouter.route(this, new AndroidPayConfirmationClickActionEvent(confirmation.checkoutId, confirmation.payCart,
        confirmation.maskedWallet));
    }
  });
  cartDetailsViewModel.progressLiveData().observe(this, progress -> {
    if (progress != null) {
      if (progress.show) {
        showProgress(progress.requestId);
      } else {
        hideProgress(progress.requestId);
      }
    }
  });
  cartDetailsViewModel.errorErrorCallback().observe(this.getLifecycle(), error -> {
    if (error != null) {
      showError(error.requestId, error.t, error.message);
    }
  });

  cartHeaderView.bindViewModel(cartHeaderViewModel);

  CartListViewModel cartListViewModel = ViewModelProviders.of(this).get(CartListViewModel.class);
  cartListView.bindViewModel(cartListViewModel);
}
项目:mobile-buy-sdk-android    文件:CheckoutActivity.java   
private void initViewModels() {
  RealCheckoutViewModel realCheckoutViewModel = ViewModelProviders.of(this, new ViewModelProvider.Factory() {
    @SuppressWarnings("unchecked") @Override public <T extends ViewModel> T create(final Class<T> modelClass) {
      if (modelClass.equals(RealCheckoutViewModel.class)) {
        return (T) new RealCheckoutViewModel(checkoutId, payCart, maskedWallet);
      } else {
        return null;
      }
    }
  }).get(RealCheckoutViewModel.class);
  realCheckoutViewModel.progressLiveData().observe(this, progress -> {
    if (progress != null) {
      if (progress.show) {
        showProgress(progress.requestId);
      } else {
        hideProgress(progress.requestId);
      }
    }
  });
  realCheckoutViewModel.errorErrorCallback().observe(this.getLifecycle(), error -> {
    if (error != null) {
      showError(error.requestId, error.t, error.message);
    }
  });
  realCheckoutViewModel.payCartLiveData().observe(this, payCart -> {
    if (payCart == null) {
      totalSummaryView.render(BigDecimal.ZERO, BigDecimal.ZERO, BigDecimal.ZERO, BigDecimal.ZERO);
    } else {
      totalSummaryView.render(payCart.subtotal, payCart.shippingPrice != null ? payCart.shippingPrice : BigDecimal.ZERO,
        payCart.taxPrice != null ? payCart.taxPrice : BigDecimal.ZERO, payCart.totalPrice);
    }
  });
  realCheckoutViewModel.maskedWalletLiveData().observe(this, maskedWallet -> {
    if (maskedWallet != null) {
      updateMaskedWallet(maskedWallet);
    }
  });
  realCheckoutViewModel.successPaymentLiveData().observe(this, payment -> {
    if (payment != null) {
      showCheckoutSuccessMessage();
    }
  });

  checkoutViewModel = realCheckoutViewModel;
  shippingRatesView.bindViewModel(realCheckoutViewModel);
}
项目:Transportr    文件:ViewModelModule.java   
@Binds
abstract ViewModelProvider.Factory bindViewModelFactory(ViewModelFactory factory);
项目:CleanArchitechture    文件:BaseFragmentMvvm.java   
public abstract void initViewModel(ViewModelProvider.Factory factory);
项目:leanback-showcase    文件:LiveDataDetailFragmentSubComponent.java   
ViewModelProvider.Factory viewModelProviderFactory();