Search in sources :

Example 1 with TVContactRequestViewModel

use of cx.ring.tv.model.TVContactRequestViewModel 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)

Example 2 with TVContactRequestViewModel

use of cx.ring.tv.model.TVContactRequestViewModel in project ring-client-android by savoirfairelinux.

the class MainFragment method showContactRequests.

@Override
public void showContactRequests(final ArrayList<TVContactRequestViewModel> contactRequests) {
    contactRequestRowAdapter.clear();
    for (TVContactRequestViewModel contact : contactRequests) {
        contactRequestRowAdapter.add(new ContactRequestCard(contact));
    }
    contactRequestRowAdapter.notifyArrayItemRangeChanged(0, contactRequests.size());
    mRowsAdapter.notifyItemRangeChanged(2, 3);
}
Also used : TVContactRequestViewModel(cx.ring.tv.model.TVContactRequestViewModel) ContactRequestCard(cx.ring.tv.cards.contactrequests.ContactRequestCard)

Example 3 with TVContactRequestViewModel

use of cx.ring.tv.model.TVContactRequestViewModel in project ring-client-android by savoirfairelinux.

the class ContactRequestCardPresenter method onBindViewHolder.

@Override
public void onBindViewHolder(Card card, ImageCardView cardView) {
    ContactRequestCard contact = (ContactRequestCard) card;
    TVContactRequestViewModel model = contact.getModel();
    if (model.getUserName().isEmpty() || model.getDisplayName().equals(model.getUserName())) {
        cardView.setTitleText(model.getDisplayName());
        cardView.setContentText("");
    } else {
        cardView.setTitleText(model.getUserName());
        cardView.setContentText(model.getDisplayName());
    }
    cardView.setBackgroundColor(cardView.getResources().getColor(R.color.color_primary_dark));
    cardView.setMainImage(getCardImage(contact));
}
Also used : TVContactRequestViewModel(cx.ring.tv.model.TVContactRequestViewModel)

Example 4 with TVContactRequestViewModel

use of cx.ring.tv.model.TVContactRequestViewModel in project ring-client-android by savoirfairelinux.

the class TVContactRequestDetailPresenter method onBindDescription.

@Override
protected void onBindDescription(ViewHolder viewHolder, Object item) {
    TVContactRequestViewModel contactRequestViewModel = (TVContactRequestViewModel) item;
    if (contactRequestViewModel != null) {
        viewHolder.getTitle().setText(contactRequestViewModel.getUserName());
        viewHolder.getSubtitle().setText(contactRequestViewModel.getDisplayName());
        viewHolder.getBody().setText(contactRequestViewModel.getMessage());
    }
}
Also used : TVContactRequestViewModel(cx.ring.tv.model.TVContactRequestViewModel)

Aggregations

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