Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void callAPi(String keyword, String subkategori, String kategori, String brand, String min,
- String max, String urutan, String hal) {
- //Repositories
- KategoriBannerRepository mKategoriBannerRepository = new KategoriBannerRepository(GITSApp.getApi());
- ListProductRepository mListProductRepository = new ListProductRepository(GITSApp.getApi());
- CallMeRepository mRepository = new CallMeRepository(GITSApp.getApi());
- //Api KategoriBanner
- Observable kategoriBanner = mKategoriBannerRepository.getKategoriBanner(
- PreferenceHelper.getStringSP(mActivity, PreferenceHelper.KEY),
- PreferenceHelper.getStringSP(mActivity, PreferenceHelper.CODE),
- kategori,
- brand);
- //Api Product
- Observable product = mListProductRepository.getProducts(PreferenceHelper.getStringSP(
- mActivity, PreferenceHelper.KEY),
- PreferenceHelper.getStringSP(mActivity, PreferenceHelper.CODE),
- PreferenceHelper.getStringSP(mActivity, PreferenceHelper.USERNAME),
- keyword, subkategori, kategori, brand, min, max, urutan, hal);
- //Api callMe
- Observable callMe = mRepository.getCallMe();
- // Call all api using Zip Operator
- Observable<ListProductData> combined = Observable.zip(kategoriBanner, product, callMe, new Func3<KategoriBannerDao, BaseApiDao<ProductDao>, CallMeDao, ListProductData>() {
- @Override
- public ListProductData call(KategoriBannerDao kategoriBannerDao, BaseApiDao<ProductDao> productDao, CallMeDao callMeDao) {
- return new ListProductData(kategoriBannerDao, productDao, callMeDao);
- }
- });
- //Set action onSubscribe
- combined.subscribeOn(Schedulers.io())
- .observeOn(AndroidSchedulers.mainThread())
- .subscribe(new Subscriber<ListProductData>() {
- @Override
- public void onCompleted() {
- }
- @Override
- public void onError(Throwable e) {
- mViewModel.stopProgressAndError("Data tidak ada");
- }
- @Override
- public void onNext(ListProductData listProductData) {
- //Banner
- mViewModel.mListBannerDao.addAll(listProductData.getKategoriBannerDao().getCONTENT());
- mViewModel.notifyBanner();
- //List Product
- if (listProductData.getProductDao().getContent() != null) {
- nextPage = listProductData.getProductDao().getContent().getNext_page();
- mViewModel.notifyList(listProductData.getProductDao());
- mData.addAll(listProductData.getProductDao().getContent().getDATA());
- mViewModel.stopProgress();
- } else {
- mViewModel.isEmpty.set(true);
- Snackbar snackbar = Snackbar.make(mViewModel.getView(), listProductData.getProductDao().getMessage(), Snackbar.LENGTH_LONG);
- TextView textView = (TextView) snackbar.getView().findViewById(android.support.design.R.id.snackbar_text);
- textView.setTextColor(Color.WHITE);
- snackbar.show();
- mViewModel.stopProgressAndError("Data tidak ada");
- }
- //CallMe
- mViewModel.bImgCall1.set(listProductData.getCallMeDao().getCONTENT().getGambar_kiri());
- mViewModel.bImgCall2.set(listProductData.getCallMeDao().getCONTENT().getGambar_kanan());
- mViewModel.nomor = listProductData.getCallMeDao().getCONTENT().getAction_kanan();
- mViewModel.id_info = String.valueOf(listProductData.getCallMeDao().getCONTENT().getAction_kiri());
- }
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement