Search in sources :

Example 11 with NonNull

use of io.reactivex.annotations.NonNull in project Varis-Android by dkhmelenko.

the class RepositoriesPresenter method reloadRepos.

/**
 * Starts loading repositories
 */
public void reloadRepos() {
    String accessToken = mAppSettings.getAccessToken();
    if (StringUtils.isEmpty(accessToken)) {
        Disposable subscription = mTravisRestClient.getApiService().getRepos("").subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(reposHandler());
        mSubscriptions.add(subscription);
    } else {
        Disposable subscription = mTravisRestClient.getApiService().getUser().doOnSuccess(this::cacheUserData).flatMap(new Function<User, SingleSource<List<Repo>>>() {

            @Override
            public SingleSource<List<Repo>> apply(@NonNull User user) throws Exception {
                String loginName = mUser.getLogin();
                return mTravisRestClient.getApiService().getUserRepos(loginName);
            }
        }).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(reposHandler());
        mSubscriptions.add(subscription);
    }
}
Also used : CompositeDisposable(io.reactivex.disposables.CompositeDisposable) Disposable(io.reactivex.disposables.Disposable) Function(io.reactivex.functions.Function) User(com.khmelenko.lab.varis.network.response.User) NonNull(io.reactivex.annotations.NonNull) List(java.util.List)

Example 12 with NonNull

use of io.reactivex.annotations.NonNull in project Varis-Android by dkhmelenko.

the class BuildsDetailsPresenter method cancelBuild.

/**
 * Cancels build process
 */
public void cancelBuild() {
    RequestBody emptyBody = RequestBody.create(MediaType.parse("application/json"), "");
    Disposable subscription = mTravisRestClient.getApiService().cancelBuild(mBuildId, emptyBody).onErrorReturn(throwable -> new Object()).flatMap(new Function<Object, SingleSource<BuildDetails>>() {

        @Override
        public SingleSource<BuildDetails> apply(@NonNull Object o) throws Exception {
            return mTravisRestClient.getApiService().getBuild(mRepoSlug, mBuildId);
        }
    }).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe((buildDetails, throwable) -> {
        if (throwable == null) {
            handleBuildDetails(buildDetails);
        } else {
            handleLoadingFailed(throwable);
        }
    });
    mSubscriptions.add(subscription);
}
Also used : CompositeDisposable(io.reactivex.disposables.CompositeDisposable) Disposable(io.reactivex.disposables.Disposable) Function(io.reactivex.functions.Function) BuildDetails(com.khmelenko.lab.varis.network.response.BuildDetails) NonNull(io.reactivex.annotations.NonNull) RequestBody(okhttp3.RequestBody)

Example 13 with NonNull

use of io.reactivex.annotations.NonNull in project Varis-Android by dkhmelenko.

the class BuildsDetailsPresenter method restartBuild.

/**
 * Restarts build process
 */
public void restartBuild() {
    RequestBody emptyBody = RequestBody.create(MediaType.parse("application/json"), "");
    Disposable subscription = mTravisRestClient.getApiService().restartBuild(mBuildId, emptyBody).onErrorReturn(throwable -> new Object()).flatMap(new Function<Object, SingleSource<BuildDetails>>() {

        @Override
        public SingleSource<BuildDetails> apply(@NonNull Object o) throws Exception {
            return mTravisRestClient.getApiService().getBuild(mRepoSlug, mBuildId);
        }
    }).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe((buildDetails, throwable) -> {
        if (throwable == null) {
            handleBuildDetails(buildDetails);
        } else {
            handleLoadingFailed(throwable);
        }
    });
    mSubscriptions.add(subscription);
}
Also used : CompositeDisposable(io.reactivex.disposables.CompositeDisposable) Disposable(io.reactivex.disposables.Disposable) Function(io.reactivex.functions.Function) BuildDetails(com.khmelenko.lab.varis.network.response.BuildDetails) NonNull(io.reactivex.annotations.NonNull) RequestBody(okhttp3.RequestBody)

Example 14 with NonNull

use of io.reactivex.annotations.NonNull in project Varis-Android by dkhmelenko.

the class BuildsDetailsPresenter method startLoadingLog.

/**
 * Starts loading log file
 *
 * @param jobId Job ID
 */
public void startLoadingLog(long jobId) {
    mJobId = jobId;
    String accessToken = mAppSettings.getAccessToken();
    Single<String> responseSingle;
    if (StringUtils.isEmpty(accessToken)) {
        responseSingle = mRawClient.getApiService().getLog(String.valueOf(mJobId));
    } else {
        String auth = String.format("token %1$s", mAppSettings.getAccessToken());
        responseSingle = mRawClient.getApiService().getLog(auth, String.valueOf(mJobId));
    }
    Disposable subscription = responseSingle.subscribeOn(Schedulers.io()).map(s -> mRawClient.getLogUrl(mJobId)).onErrorResumeNext(new Function<Throwable, SingleSource<String>>() {

        @Override
        public SingleSource<String> apply(@NonNull Throwable throwable) throws Exception {
            String redirectUrl = "";
            if (throwable instanceof HttpException) {
                HttpException httpException = (HttpException) throwable;
                Headers headers = httpException.response().headers();
                for (String header : headers.names()) {
                    if (header.equals("Location")) {
                        redirectUrl = headers.get(header);
                        break;
                    }
                }
                return Single.just(redirectUrl);
            } else {
                return Single.error(throwable);
            }
        }
    }).retry(LOAD_LOG_MAX_ATTEMPT).map(mRawClient::singleStringRequest).map(response -> mLogsParser.parseLog(response.blockingGet())).observeOn(AndroidSchedulers.mainThread()).subscribe((log, throwable) -> {
        if (throwable == null) {
            getView().setLog(log);
        } else {
            getView().showLogError();
            getView().showLoadingError(throwable.getMessage());
        }
    });
    mSubscriptions.add(subscription);
}
Also used : CompositeDisposable(io.reactivex.disposables.CompositeDisposable) Disposable(io.reactivex.disposables.Disposable) Function(io.reactivex.functions.Function) Headers(okhttp3.Headers) NonNull(io.reactivex.annotations.NonNull) HttpException(retrofit2.HttpException)

Example 15 with NonNull

use of io.reactivex.annotations.NonNull in project ring-client-android by savoirfairelinux.

the class MainPresenter method loadContactRequest.

public void loadContactRequest() {
    mCompositeDisposable.add(Single.fromCallable(() -> {
        List<TrustRequest> requests = mAccountService.getCurrentAccount().getRequests();
        ArrayList<TVContactRequestViewModel> contactRequestViewModels = new ArrayList<>();
        for (TrustRequest request : requests) {
            byte[] photo;
            if (request.getVCard().getPhotos().isEmpty()) {
                photo = null;
            } else {
                photo = request.getVCard().getPhotos().get(0).getData();
            }
            TVContactRequestViewModel tvContactRequestVM = new TVContactRequestViewModel(request.getContactId(), request.getDisplayname(), request.getFullname(), photo, request.getMessage());
            contactRequestViewModels.add(tvContactRequestVM);
        }
        return contactRequestViewModels;
    }).subscribeOn(Schedulers.computation()).observeOn(mMainScheduler).subscribeWith(new ResourceSingleObserver<ArrayList<TVContactRequestViewModel>>() {

        @Override
        public void onSuccess(@NonNull ArrayList<TVContactRequestViewModel> contactRequestViewModels) {
            mContactRequestViewModels = contactRequestViewModels;
            if (mContactRequestViewModels.isEmpty()) {
                getView().showContactRequestsRow(false);
            } else {
                getView().showContactRequestsRow(true);
                getView().showContactRequests(mContactRequestViewModels);
            }
        }

        @Override
        public void onError(@NonNull Throwable e) {
            Log.e(TAG, e.toString());
        }
    }));
}
Also used : TVContactRequestViewModel(cx.ring.tv.model.TVContactRequestViewModel) ResourceSingleObserver(io.reactivex.observers.ResourceSingleObserver) TrustRequest(cx.ring.model.TrustRequest) NonNull(io.reactivex.annotations.NonNull) ArrayList(java.util.ArrayList)

Aggregations

NonNull (io.reactivex.annotations.NonNull)39 Disposable (io.reactivex.disposables.Disposable)17 CompositeDisposable (io.reactivex.disposables.CompositeDisposable)15 Consumer (io.reactivex.functions.Consumer)14 Function (io.reactivex.functions.Function)13 BuildDetails (com.khmelenko.lab.varis.network.response.BuildDetails)6 OnClick (butterknife.OnClick)5 List (java.util.List)5 RequestBody (okhttp3.RequestBody)5 ObservableEmitter (io.reactivex.ObservableEmitter)4 ObservableOnSubscribe (io.reactivex.ObservableOnSubscribe)4 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 Headers (okhttp3.Headers)3 View (android.view.View)2 ANError (com.androidnetworking.error.ANError)2 User (com.khmelenko.lab.varis.network.response.User)2 LzyResponse (com.lzy.demo.model.LzyResponse)2 ServerModel (com.lzy.demo.model.ServerModel)2 Action (io.reactivex.functions.Action)2