Search in sources :

Example 1 with DisposableObserver

use of io.reactivex.observers.DisposableObserver in project RandomWebm by alkocher.

the class WebmListFragment method fetchWebmList.

private void fetchWebmList() {
    errorCheckConnection.setVisibility(View.GONE);
    errorNoResults.setVisibility(View.GONE);
    bottomLayout.setVisibility(View.VISIBLE);
    ApolloCall<WebmListQuery.Data> webmListQuery = WebmApolloClient.getWebmApolloClient().query(new WebmListQuery(PAGE_SIZE, Order.valueOf(order), ++currentPage, tagName, likedWebms));
    disposables.add(Rx2Apollo.from(webmListQuery).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribeWith(new DisposableObserver<Response<WebmListQuery.Data>>() {

        @Override
        public void onNext(Response<WebmListQuery.Data> dataResponse) {
            setWebmData(dataResponse.data());
        }

        @Override
        public void onError(Throwable e) {
            swipeContainer.setRefreshing(false);
            errorCheckConnection.setVisibility(View.VISIBLE);
            Log.e(TAG, e.getMessage(), e);
        }

        @Override
        public void onComplete() {
            swipeContainer.setRefreshing(false);
            bottomLayout.setVisibility(View.GONE);
        }
    }));
}
Also used : Response(com.apollographql.apollo.api.Response) DisposableObserver(io.reactivex.observers.DisposableObserver) WebmListQuery(com.example.aleksejkocergin.myapplication.WebmListQuery)

Example 2 with DisposableObserver

use of io.reactivex.observers.DisposableObserver in project RandomWebm by alkocher.

the class ToggleVotesUtil method toggleLike.

public void toggleLike(String webmId, boolean hasLike, boolean hasDislike) {
    ApolloMutationCall<ToggleLikeMutation.Data> likeMutationCall = WebmApolloClient.getWebmApolloClient().mutate(new ToggleLikeMutation(webmId, hasLike, hasDislike));
    mDisposable.add(Rx2Apollo.from(likeMutationCall).observeOn(AndroidSchedulers.mainThread()).subscribeOn(Schedulers.io()).subscribeWith(new DisposableObserver<Response<ToggleLikeMutation.Data>>() {

        @Override
        public void onNext(Response<ToggleLikeMutation.Data> dataResponse) {
        }

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

        @Override
        public void onComplete() {
            webmData.showSuccessSnackbar();
        }
    }));
}
Also used : Response(com.apollographql.apollo.api.Response) DisposableObserver(io.reactivex.observers.DisposableObserver) WebmData(com.example.aleksejkocergin.randomwebm.interfaces.WebmData) ToggleLikeMutation(com.example.aleksejkocergin.myapplication.ToggleLikeMutation)

Example 3 with DisposableObserver

use of io.reactivex.observers.DisposableObserver in project RandomWebm by alkocher.

the class WebmDetailsFetcher method fetchWebmDetails.

public void fetchWebmDetails() {
    ApolloCall<WebmQuery.Data> webmQuery = WebmApolloClient.getWebmApolloClient().query(new WebmQuery(webmId));
    disposable.add(Rx2Apollo.from(webmQuery).observeOn(AndroidSchedulers.mainThread()).subscribeOn(Schedulers.io()).subscribeWith(new DisposableObserver<Response<WebmQuery.Data>>() {

        @Override
        public void onNext(Response<WebmQuery.Data> dataResponse) {
            webmData.render(dataResponse.data());
        }

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

        @Override
        public void onComplete() {
        }
    }));
}
Also used : Response(com.apollographql.apollo.api.Response) DisposableObserver(io.reactivex.observers.DisposableObserver) WebmQuery(com.example.aleksejkocergin.myapplication.WebmQuery) WebmData(com.example.aleksejkocergin.randomwebm.interfaces.WebmData)

Example 4 with DisposableObserver

use of io.reactivex.observers.DisposableObserver in project RxJava-Android-Samples by kaushikgopal.

the class RetrofitFragment method onListContributorsClicked.

@OnClick(R.id.btn_demo_retrofit_contributors)
public void onListContributorsClicked() {
    _adapter.clear();
    // 
    _disposables.add(_githubService.contributors(_username.getText().toString(), _repo.getText().toString()).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribeWith(new DisposableObserver<List<Contributor>>() {

        @Override
        public void onComplete() {
            Timber.d("Retrofit call 1 completed");
        }

        @Override
        public void onError(Throwable e) {
            Timber.e(e, "woops we got an error while getting the list of contributors");
        }

        @Override
        public void onNext(List<Contributor> contributors) {
            for (Contributor c : contributors) {
                _adapter.add(format("%s has made %d contributions to %s", c.login, c.contributions, _repo.getText().toString()));
                Timber.d("%s has made %d contributions to %s", c.login, c.contributions, _repo.getText().toString());
            }
        }
    }));
}
Also used : DisposableObserver(io.reactivex.observers.DisposableObserver) Contributor(com.morihacky.android.rxjava.retrofit.Contributor) ArrayList(java.util.ArrayList) List(java.util.List) OnClick(butterknife.OnClick)

Example 5 with DisposableObserver

use of io.reactivex.observers.DisposableObserver in project quran_android by quran.

the class QuranPagePresenter method downloadImages.

public void downloadImages() {
    screen.hidePageDownloadError();
    compositeDisposable.add(quranPageWorker.loadPages(pages).observeOn(AndroidSchedulers.mainThread()).subscribeWith(new DisposableObserver<Response>() {

        @Override
        public void onNext(Response response) {
            if (screen != null) {
                Bitmap bitmap = response.getBitmap();
                if (bitmap != null) {
                    didDownloadImages = true;
                    screen.setPageBitmap(response.getPageNumber(), bitmap);
                } else {
                    didDownloadImages = false;
                    final int errorCode = response.getErrorCode();
                    final int errorRes;
                    switch(errorCode) {
                        case Response.ERROR_SD_CARD_NOT_FOUND:
                            errorRes = R.string.sdcard_error;
                            break;
                        case Response.ERROR_DOWNLOADING_ERROR:
                            errorRes = R.string.download_error_network;
                            break;
                        default:
                            errorRes = R.string.download_error_general;
                    }
                    screen.setPageDownloadError(errorRes);
                }
            }
        }

        @Override
        public void onError(Throwable e) {
        }

        @Override
        public void onComplete() {
        }
    }));
}
Also used : Response(com.quran.labs.androidquran.common.Response) Bitmap(android.graphics.Bitmap) DisposableObserver(io.reactivex.observers.DisposableObserver)

Aggregations

DisposableObserver (io.reactivex.observers.DisposableObserver)8 Response (com.apollographql.apollo.api.Response)4 WebmData (com.example.aleksejkocergin.randomwebm.interfaces.WebmData)3 OnClick (butterknife.OnClick)2 Contributor (com.morihacky.android.rxjava.retrofit.Contributor)2 List (java.util.List)2 Bitmap (android.graphics.Bitmap)1 Pair (android.util.Pair)1 ApplicationContext (com.b2international.snowowl.core.ApplicationContext)1 ApplicationContext.getServiceForClass (com.b2international.snowowl.core.ApplicationContext.getServiceForClass)1 SnowowlRuntimeException (com.b2international.snowowl.core.api.SnowowlRuntimeException)1 Notifications (com.b2international.snowowl.core.events.Notifications)1 IDs (com.b2international.snowowl.core.id.IDs)1 DatastoreLockContextDescriptions (com.b2international.snowowl.core.internal.locks.DatastoreLockContextDescriptions)1 JobRequests (com.b2international.snowowl.core.jobs.JobRequests)1 RemoteJobEntry (com.b2international.snowowl.core.jobs.RemoteJobEntry)1 RemoteJobNotification (com.b2international.snowowl.core.jobs.RemoteJobNotification)1 RemoteJobs (com.b2international.snowowl.core.jobs.RemoteJobs)1 Environment (com.b2international.snowowl.core.setup.Environment)1 IEventBus (com.b2international.snowowl.eventbus.IEventBus)1