Advertisement
Guest User

Untitled

a guest
Jan 18th, 2017
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.13 KB | None | 0 0
  1. public void callAPi(String keyword, String subkategori, String kategori, String brand, String min,
  2. String max, String urutan, String hal) {
  3. //Repositories
  4. KategoriBannerRepository mKategoriBannerRepository = new KategoriBannerRepository(GITSApp.getApi());
  5. ListProductRepository mListProductRepository = new ListProductRepository(GITSApp.getApi());
  6. CallMeRepository mRepository = new CallMeRepository(GITSApp.getApi());
  7. //Api KategoriBanner
  8. Observable kategoriBanner = mKategoriBannerRepository.getKategoriBanner(
  9. PreferenceHelper.getStringSP(mActivity, PreferenceHelper.KEY),
  10. PreferenceHelper.getStringSP(mActivity, PreferenceHelper.CODE),
  11. kategori,
  12. brand);
  13. //Api Product
  14. Observable product = mListProductRepository.getProducts(PreferenceHelper.getStringSP(
  15. mActivity, PreferenceHelper.KEY),
  16. PreferenceHelper.getStringSP(mActivity, PreferenceHelper.CODE),
  17. PreferenceHelper.getStringSP(mActivity, PreferenceHelper.USERNAME),
  18. keyword, subkategori, kategori, brand, min, max, urutan, hal);
  19. //Api callMe
  20. Observable callMe = mRepository.getCallMe();
  21. // Call all api using Zip Operator
  22. Observable<ListProductData> combined = Observable.zip(kategoriBanner, product, callMe, new Func3<KategoriBannerDao, BaseApiDao<ProductDao>, CallMeDao, ListProductData>() {
  23. @Override
  24. public ListProductData call(KategoriBannerDao kategoriBannerDao, BaseApiDao<ProductDao> productDao, CallMeDao callMeDao) {
  25. return new ListProductData(kategoriBannerDao, productDao, callMeDao);
  26. }
  27. });
  28. //Set action onSubscribe
  29. combined.subscribeOn(Schedulers.io())
  30. .observeOn(AndroidSchedulers.mainThread())
  31. .subscribe(new Subscriber<ListProductData>() {
  32. @Override
  33. public void onCompleted() {
  34.  
  35. }
  36.  
  37. @Override
  38. public void onError(Throwable e) {
  39. mViewModel.stopProgressAndError("Data tidak ada");
  40. }
  41.  
  42. @Override
  43. public void onNext(ListProductData listProductData) {
  44. //Banner
  45. mViewModel.mListBannerDao.addAll(listProductData.getKategoriBannerDao().getCONTENT());
  46. mViewModel.notifyBanner();
  47. //List Product
  48. if (listProductData.getProductDao().getContent() != null) {
  49. nextPage = listProductData.getProductDao().getContent().getNext_page();
  50. mViewModel.notifyList(listProductData.getProductDao());
  51. mData.addAll(listProductData.getProductDao().getContent().getDATA());
  52. mViewModel.stopProgress();
  53. } else {
  54. mViewModel.isEmpty.set(true);
  55. Snackbar snackbar = Snackbar.make(mViewModel.getView(), listProductData.getProductDao().getMessage(), Snackbar.LENGTH_LONG);
  56. TextView textView = (TextView) snackbar.getView().findViewById(android.support.design.R.id.snackbar_text);
  57. textView.setTextColor(Color.WHITE);
  58. snackbar.show();
  59. mViewModel.stopProgressAndError("Data tidak ada");
  60. }
  61. //CallMe
  62. mViewModel.bImgCall1.set(listProductData.getCallMeDao().getCONTENT().getGambar_kiri());
  63. mViewModel.bImgCall2.set(listProductData.getCallMeDao().getCONTENT().getGambar_kanan());
  64. mViewModel.nomor = listProductData.getCallMeDao().getCONTENT().getAction_kanan();
  65. mViewModel.id_info = String.valueOf(listProductData.getCallMeDao().getCONTENT().getAction_kiri());
  66. }
  67. });
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement