Search in sources :

Example 1 with ResourceSingleObserver

use of io.reactivex.observers.ResourceSingleObserver 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

TrustRequest (cx.ring.model.TrustRequest)1 TVContactRequestViewModel (cx.ring.tv.model.TVContactRequestViewModel)1 NonNull (io.reactivex.annotations.NonNull)1 ResourceSingleObserver (io.reactivex.observers.ResourceSingleObserver)1 ArrayList (java.util.ArrayList)1