io.reactivex.observers.DisposableObserver Java Examples

The following examples show how to use io.reactivex.observers.DisposableObserver. 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: CollectionFragment.java    From Capstone-Project with MIT License 7 votes vote down vote up
private void getLatestCollections() {
    PredatorAccount.getAuthToken(getActivity(),
            Constants.Authenticator.PREDATOR_ACCOUNT_TYPE,
            PredatorSharedPreferences.getAuthTokenType(getContext().getApplicationContext()))
            .subscribeOn(Schedulers.newThread())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(new DisposableObserver<String>() {
                @Override
                public void onComplete() {
                    // Done
                }

                @Override
                public void onError(Throwable e) {
                    Logger.e(TAG, "onError: " + e.getMessage(), e);
                    unableToFetchCollections(false,
                            false,
                            getString(R.string.authentication_failure));
                }

                @Override
                public void onNext(String s) {
                    mCollectionsPresenter.getLatestCollections(s, true);
                }
            });
}
 
Example #2
Source File: CollectionFragment.java    From Capstone-Project with MIT License 6 votes vote down vote up
private void loadMoreCollections() {
    PredatorAccount.getAuthToken(getActivity(),
            Constants.Authenticator.PREDATOR_ACCOUNT_TYPE,
            PredatorSharedPreferences.getAuthTokenType(getContext().getApplicationContext()))
            .subscribeOn(Schedulers.newThread())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(new DisposableObserver<String>() {
                @Override
                public void onComplete() {
                    // Done
                }

                @Override
                public void onError(Throwable e) {
                    Logger.e(TAG, "onError: " + e.getMessage(), e);
                    unableToFetchCollections(true,
                            false,
                            getString(R.string.authentication_failure));
                }

                @Override
                public void onNext(String s) {
                    mCollectionsPresenter.loadMoreCollections(s);
                }
            });
}
 
Example #3
Source File: WorkflowDetailPresenter.java    From incubator-taverna-mobile with Apache License 2.0 6 votes vote down vote up
public void getFavourite(String id) {
    checkViewAttached();
    compositeDisposable.add(mDataManager.getFavoriteWorkflow(id)
            .observeOn(AndroidSchedulers.mainThread())
            .subscribeOn(Schedulers.io())
            .subscribeWith(new DisposableObserver<Boolean>() {
                @Override
                public void onNext(Boolean favoriteStatus) {
                    getMvpView().getFavouriteIcon(favoriteStatus);
                }

                @Override
                public void onError(Throwable e) {
                    getMvpView().showErrorSnackBar("Something went wrong please try after " +
                            "sometime");
                }

                @Override
                public void onComplete() {

                }
            }));
}
 
Example #4
Source File: MercuryWalletTickerService.java    From ETHWallet with GNU General Public License v3.0 6 votes vote down vote up
@Override
public Observer<? super Response<T>> apply(Observer<? super T> observer) throws Exception {
    return new DisposableObserver<Response<T>>() {
        @Override
        public void onNext(Response<T> response) {
            observer.onNext(response.body());
            observer.onComplete();
        }

        @Override
        public void onError(Throwable e) {
            observer.onError(e);
        }

        @Override
        public void onComplete() {
            observer.onComplete();
        }
    };
}
 
Example #5
Source File: SearchPresenter.java    From WanAndroid with Apache License 2.0 6 votes vote down vote up
@Override
public void searchArticles(@NonNull int page, @NonNull String keyWords, final boolean forceUpdate, final boolean clearCache) {
    Disposable disposable = articlesDataRepository.queryArticles(page, keyWords, forceUpdate, clearCache)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribeWith(new DisposableObserver<List<ArticleDetailData>>() {

                @Override
                public void onNext(List<ArticleDetailData> value) {
                    if (view.isActive()) {
                        view.showArticles(value);
                    }
                }

                @Override
                public void onError(Throwable e) {
                    view.showEmptyView(true);
                }

                @Override
                public void onComplete() {

                }
            });
    compositeDisposable.add(disposable);
}
 
Example #6
Source File: TransferActivity.java    From 1Rramp-Android with MIT License 6 votes vote down vote up
private DisposableObserver<TextViewTextChangeEvent> userNameTextWatcher() {
  return new DisposableObserver<TextViewTextChangeEvent>() {
    @Override
    public void onNext(TextViewTextChangeEvent textViewTextChangeEvent) {
      String searchTerm = textViewTextChangeEvent.text().toString().trim().toLowerCase();
      if (searchTerm.length() > 0 && usernameEt.getSelectionEnd() > 0) {
        onSearchingUser();
        publishSubject.onNext(searchTerm);
      } else {
        userMentionsSuggestionsView.setVisibility(View.GONE);
      }
    }

    @Override
    public void onError(Throwable e) {

    }

    @Override
    public void onComplete() {

    }
  };
}
 
Example #7
Source File: UserProfileActivity.java    From Capstone-Project with MIT License 6 votes vote down vote up
private void loadLatestDetails(final int userId, final boolean refresh) {
    PredatorAccount.getAuthToken(UserProfileActivity.this,
            Constants.Authenticator.PREDATOR_ACCOUNT_TYPE,
            PredatorSharedPreferences.getAuthTokenType(getApplicationContext()))
            .subscribeOn(Schedulers.newThread())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(new DisposableObserver<String>() {
                @Override
                public void onComplete() {
                    // Done
                }

                @Override
                public void onError(Throwable e) {
                    Logger.e(TAG, "onError: " + e.getMessage(), e);
                    unableToFetchDataOnline(getString(R.string.authentication_failure));
                }

                @Override
                public void onNext(String s) {
                    Logger.d(TAG, "onNext: token fetched ; Thread: " + Thread.currentThread().getName());
                    mUserProfilePresenter.getLatestData(s, userId, refresh);
                }
            });
}
 
Example #8
Source File: SubscriptionProxy.java    From RxGroups with Apache License 2.0 6 votes vote down vote up
DisposableObserver<? super T> disposableWrapper(final ObservableEmitter<? super T> emitter) {
  return new DisposableObserver<T>() {
    @Override public void onNext(@NonNull T t) {
      if (!emitter.isDisposed()) {
        emitter.onNext(t);
      }
    }

    @Override public void onError(@NonNull Throwable e) {
      if (!emitter.isDisposed()) {
        emitter.onError(e);
      }
    }

    @Override public void onComplete() {
      if (!emitter.isDisposed()) {
        emitter.onComplete();
      }
    }
  };
}
 
Example #9
Source File: CommonPresenter.java    From JReadHub with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void doLoadMore(@Constants.Type String type, Long lastCursor) {
    addSubscribe(mDataManager.getNewsList(type, lastCursor, Constants.TOPIC_PAGE_SIZE)
            .compose(RxSchedulers.observableIo2Main())
            .subscribeWith(new DisposableObserver<DataListBean<NewsBean>>() {
                @Override
                public void onNext(DataListBean<NewsBean> newsBeanDataListBean) {
                    getView().bindData(newsBeanDataListBean, false);
                }

                @Override
                public void onError(Throwable e) {
                    getView().bindData(null, false);
                }

                @Override
                public void onComplete() {
                }
            }));
}
 
Example #10
Source File: OnboardActivity.java    From Capstone-Project with MIT License 6 votes vote down vote up
@Override
public void onAuthTokenRetrieved(Bundle args, String message) {
    PredatorAccount.getAuthToken(this,
            Constants.Authenticator.PREDATOR_ACCOUNT_TYPE,
            PredatorSharedPreferences.getAuthTokenType(getApplicationContext()))
            .subscribeOn(Schedulers.newThread())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(new DisposableObserver<String>() {
                @Override
                public void onComplete() {
                    // Done
                }

                @Override
                public void onError(Throwable e) {
                    Logger.e(TAG, "onError: " + e.getMessage(), e);
                    unableToFetchAuthToken(getString(R.string.authentication_failure));
                }

                @Override
                public void onNext(String s) {
                    mCategoriesPresenter.fetchCategories(getApplicationContext(), s);
                }
            });
}
 
Example #11
Source File: InstantReadPresenter.java    From JReadHub with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void getTopicInstantRead(String topicId) {
    addSubscribe(mDataManager.getTopicInstantRead(topicId)
            .compose(RxSchedulers.observableIo2Main())
            .doOnSubscribe(disposable -> getView().onRequestStart())
            .subscribeWith(new DisposableObserver<InstantReadBean>() {
                @Override
                public void onNext(InstantReadBean instantReadBean) {
                    getView().onRequestEnd(instantReadBean);
                }

                @Override
                public void onError(Throwable e) {
                    getView().onRequestError();
                }

                @Override
                public void onComplete() {

                }
            }));
}
 
Example #12
Source File: TopicPresenter.java    From JReadHub with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void getDiffResult(List<TopicBean> oldData, List<TopicBean> newData) {
    addSubscribe(Observable.just(DiffUtil.calculateDiff(new DiffCallback(oldData, newData), false))
            .subscribeWith(new DisposableObserver<DiffUtil.DiffResult>() {
                @Override
                public void onNext(DiffUtil.DiffResult diffResult) {
                    getView().onDiffResult(diffResult, newData);
                }

                @Override
                public void onError(Throwable e) {

                }

                @Override
                public void onComplete() {

                }
            }));
}
 
Example #13
Source File: RelevantTopicPresenter.java    From JReadHub with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void getRelateTopic(String topicId, int eventType, long order, long timeStamp) {
    addSubscribe(mDataManager.getRelateTopic(topicId, eventType, order, timeStamp)
            .compose(RxSchedulers.observableIo2Main())
            .doOnSubscribe(disposable -> getView().onRequestStart())
            .subscribeWith(new DisposableObserver<List<RelevantTopicBean>>() {
                @Override
                public void onNext(List<RelevantTopicBean> list) {
                    getView().onRequestTopicEnd(list);
                }

                @Override
                public void onError(Throwable e) {
                    getView().onRequestError();
                }

                @Override
                public void onComplete() {

                }
            }));
}
 
Example #14
Source File: TopicDetailPresenter.java    From JReadHub with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void getTopicDetail(String topicId, boolean isPullToRefresh) {
    addSubscribe(mDataManager.getTopicDetail(topicId)
            .compose(RxSchedulers.observableIo2Main())
            .doOnSubscribe(disposable -> getView().showLoading(isPullToRefresh))
            .subscribeWith(new DisposableObserver<TopicDetailBean>() {
                @Override
                public void onNext(TopicDetailBean bean) {
                    getView().bindData(bean, true);
                }

                @Override
                public void onError(Throwable e) {
                    getView().showError();
                    e.printStackTrace();
                }

                @Override
                public void onComplete() {
                    getView().showContent();
                }
            }));
}
 
Example #15
Source File: TrustWalletTickerService.java    From trust-wallet-android-source with GNU General Public License v3.0 6 votes vote down vote up
@Override
public Observer<? super Response<T>> apply(Observer<? super T> observer) throws Exception {
    return new DisposableObserver<Response<T>>() {
        @Override
        public void onNext(Response<T> response) {
            observer.onNext(response.body());
            observer.onComplete();
        }

        @Override
        public void onError(Throwable e) {
            observer.onError(e);
        }

        @Override
        public void onComplete() {
            observer.onComplete();
        }
    };
}
 
Example #16
Source File: CoinmarketcapTickerService.java    From trust-wallet-android-source with GNU General Public License v3.0 6 votes vote down vote up
@Override
public Observer<? super Response<T>> apply(Observer<? super T> observer) throws Exception {
    return new DisposableObserver<Response<T>>() {
        @Override
        public void onNext(Response<T> response) {
            observer.onNext(response.body());
            observer.onComplete();
        }

        @Override
        public void onError(Throwable e) {
            observer.onError(e);
        }

        @Override
        public void onComplete() {
            observer.onComplete();
        }
    };
}
 
Example #17
Source File: DisposableUtil.java    From RxAndroidBle with Apache License 2.0 6 votes vote down vote up
public static <T> DisposableObserver<T> disposableObserverFromEmitter(final ObservableEmitter<T> emitter) {
    return new DisposableObserver<T>() {

        @Override
        public void onNext(T t) {
            emitter.onNext(t);
        }

        @Override
        public void onError(Throwable e) {
            emitter.tryOnError(e);
        }

        @Override
        public void onComplete() {
            emitter.onComplete();
        }
    };
}
 
Example #18
Source File: WorkflowDetailPresenter.java    From incubator-taverna-mobile with Apache License 2.0 6 votes vote down vote up
public void loadWorkflowDetail(String id) {
    checkViewAttached();
    getMvpView().showProgressbar(true);
    compositeDisposable.add(mDataManager.getDetailWorkflow(id, getDetailQueryOptions())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribeOn(Schedulers.io())
            .subscribeWith(new DisposableObserver<Workflow>() {
                @Override
                public void onNext(Workflow workflow) {
                    getMvpView().showWorkflowDetail(workflow);
                    loadUserDetail(workflow.getUploader().getId());
                    getFavourite(workflow.getId());
                }

                @Override
                public void onError(Throwable e) {
                    getMvpView().showProgressbar(false);
                }

                @Override
                public void onComplete() {
                    getMvpView().showProgressbar(false);
                }
            }));
}
 
Example #19
Source File: HomePresenter.java    From JD-Test with Apache License 2.0 6 votes vote down vote up
@Override
public void getRecommendedWares() {
    addDisposabe(mDataManager.getData(new DisposableObserver<HomeIndex>() {
        @Override
        public void onNext(HomeIndex homeIndex) {
            mHomeView.setRecommendedWares(homeIndex);
        }

        @Override
        public void onError(Throwable e) {

        }

        @Override
        public void onComplete() {

        }
    },HomeIndex.class, "recommend.txt"));
}
 
Example #20
Source File: HomePresenter.java    From JD-Test with Apache License 2.0 6 votes vote down vote up
@Override
public void getMoreRecommendedWares() {
    addDisposabe(mDataManager.getData(new DisposableObserver<HomeIndex>() {
        @Override
        public void onNext(HomeIndex homeIndex) {
            mHomeView.setMoreRecommendedWares(homeIndex);
        }

        @Override
        public void onError(Throwable e) {

        }

        @Override
        public void onComplete() {

        }
    },HomeIndex.class, "recommended.txt"));
}
 
Example #21
Source File: FindPresenter.java    From JD-Test with Apache License 2.0 6 votes vote down vote up
@Override
public void getMoreFindData() {
    addDisposabe(mDataManager.getData(new DisposableObserver<FindsBean>() {
        @Override
        public void onNext(FindsBean findsBean) {
            mFindView.setMoreData(findsBean);
        }

        @Override
        public void onError(Throwable e) {

        }

        @Override
        public void onComplete() {

        }
    },FindsBean.class, "find.txt"));
}
 
Example #22
Source File: FavouriteWorkflowDetailPresenter.java    From incubator-taverna-mobile with Apache License 2.0 6 votes vote down vote up
public void loadWorkflowDetail(String id) {
    checkViewAttached();
    getMvpView().showProgressbar(true);
    compositeDisposable.add(mDataManager.getFavoriteDetailWorkflow(id)
            .observeOn(AndroidSchedulers.mainThread())
            .subscribeOn(Schedulers.io())
            .subscribeWith(new DisposableObserver<Workflow>() {
                @Override
                public void onNext(Workflow workflow) {
                    getMvpView().showWorkflowDetail(workflow);
                    loadUserDetail(workflow.getUploader().getId());
                    getFavourite(workflow.getId());
                }

                @Override
                public void onError(Throwable e) {
                    getMvpView().showProgressbar(false);
                }

                @Override
                public void onComplete() {
                    getMvpView().showProgressbar(false);
                }
            }));
}
 
Example #23
Source File: SearchActivity.java    From Rey-MusicPlayer with Apache License 2.0 6 votes vote down vote up
private DisposableObserver<TextViewTextChangeEvent> getSearchObserver() {
    return new DisposableObserver<TextViewTextChangeEvent>() {
        @Override
        public void onComplete() {
        }

        @Override
        public void onError(Throwable e) {
        }

        @Override
        public void onNext(TextViewTextChangeEvent onTextChangeEvent) {
            String query = onTextChangeEvent.text().toString().trim();
            if (query.toString().length() == 0) {
                mImageButtonClear.setVisibility(View.INVISIBLE);
            } else {
                mImageButtonClear.setVisibility(View.VISIBLE);
            }
            onQueryTextChange(query);
        }
    };
}
 
Example #24
Source File: FragmentArtist.java    From Rey-MusicPlayer with Apache License 2.0 6 votes vote down vote up
@Override
public void onResume() {
    super.onResume();
    mCompositeDisposable.add(Observable.fromCallable(() -> mApp.getDBAccessHelper().getAllArtist())
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread()).subscribeWith(new DisposableObserver<ArrayList<Artist>>() {
                @Override
                public void onNext(ArrayList<Artist> hashMaps) {
                    mArtistList = hashMaps;
                    mAdapter.updateData(mArtistList);
                    mAdapter.notifyDataSetChanged();
                }

                @Override
                public void onError(Throwable e) {
                    Logger.log("" + e.getCause());
                }

                @Override
                public void onComplete() {

                }
            })
    );
}
 
Example #25
Source File: FragmentGenres.java    From Rey-MusicPlayer with Apache License 2.0 6 votes vote down vote up
@Override
public void onResume() {
    super.onResume();
    mCompositeDisposable
            .add(Observable.fromCallable(() -> mApp.getDBAccessHelper().getAllGenres())
                    .subscribeOn(Schedulers.io())
                    .observeOn(AndroidSchedulers.mainThread())
                    .subscribeWith(new DisposableObserver<ArrayList<Genre>>() {
                        @Override
                        public void onNext(ArrayList<Genre> hashMaps) {
                            mGenres = hashMaps;
                            mAdapter.updateData(hashMaps);
                            mAdapter.notifyDataSetChanged();
                        }

                        @Override
                        public void onError(Throwable e) {

                        }

                        @Override
                        public void onComplete() {

                        }
                    }));
}
 
Example #26
Source File: SongsFragment.java    From Rey-MusicPlayer with Apache License 2.0 6 votes vote down vote up
private void loadData() {
    mCompositeDisposable.add(Observable.fromCallable(() -> CursorHelper.getTracksForSelection("SONGS", ""))
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribeWith(new DisposableObserver<ArrayList<Song>>() {
                @Override
                public void onComplete() {

                }

                @Override
                public void onError(Throwable e) {

                }

                @Override
                public void onNext(ArrayList<Song> data) {
                    mSongList.clear();
                    mSongList.addAll(data);
                    mAdapter.update(mSongList);
                }
            }));
}
 
Example #27
Source File: AlbumFragment.java    From Rey-MusicPlayer with Apache License 2.0 6 votes vote down vote up
private void loadAlbums() {
    mCompositeDisposable.add(Observable.fromCallable(() -> CursorHelper.getAlbumsList())
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribeWith(new DisposableObserver<ArrayList<Album>>() {
                @Override
                public void onNext(ArrayList<Album> data) {
                    mAlbums = data;
                    mAdapter.updateData(data);
                    mAdapter.notifyDataSetChanged();
                }

                @Override
                public void onError(Throwable e) {
                    Log.d("FAILED", "" + e.getMessage());
                }

                @Override
                public void onComplete() {

                }
            }));
}
 
Example #28
Source File: MovieDetailsViewModel.java    From android-mvvm-sample with MIT License 6 votes vote down vote up
public void getMovieDetails(long movieId) {
    isMovieLoading.set(true);
    errorViewShowing.set(false);
    mMoviesRepository.getMovieDetails(movieId)
            .observeOn(AndroidSchedulers.mainThread())
            .subscribeOn(Schedulers.io())
            .subscribeWith(new DisposableObserver<Movie>() {
                @Override
                public void onNext(Movie value) {
                    setMovie(value);
                }

                @Override
                public void onError(Throwable e) {
                    errorViewShowing.set(true);
                    isMovieLoading.set(false);
                }

                @Override
                public void onComplete() {
                    isMovieLoading.set(false);
                    errorViewShowing.set(false);
                }
            });
}
 
Example #29
Source File: FavouriteWorkflowDetailPresenter.java    From incubator-taverna-mobile with Apache License 2.0 6 votes vote down vote up
public void getFavourite(String id) {
    checkViewAttached();
    compositeDisposable.add(mDataManager.getFavoriteWorkflow(id)
            .observeOn(AndroidSchedulers.mainThread())
            .subscribeOn(Schedulers.io())
            .subscribeWith(new DisposableObserver<Boolean>() {
                @Override
                public void onNext(Boolean b) {
                    getMvpView().getFavouriteIcon(b);
                }

                @Override
                public void onError(Throwable e) {
                    getMvpView().showErrorSnackBar("Something went wrong please try after " +
                            "sometime");
                }

                @Override
                public void onComplete() {

                }
            }));
}
 
Example #30
Source File: DebounceSearchEmitterFragment.java    From RxJava-Android-Samples with Apache License 2.0 6 votes vote down vote up
private DisposableObserver<TextViewTextChangeEvent> _getSearchObserver() {
  return new DisposableObserver<TextViewTextChangeEvent>() {
    @Override
    public void onComplete() {
      Timber.d("--------- onComplete");
    }

    @Override
    public void onError(Throwable e) {
      Timber.e(e, "--------- Woops on error!");
      _log("Dang error. check your logs");
    }

    @Override
    public void onNext(TextViewTextChangeEvent onTextChangeEvent) {
      _log(format("Searching for %s", onTextChangeEvent.text().toString()));
    }
  };
}