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());
}
}));
}
Aggregations