Search in sources :

Example 1 with MediaCardItem

use of butter.droid.tv.presenters.MediaCardPresenter.MediaCardItem in project butter-android by butterproject.

the class TVOverviewFragment method onItemSelected.

@Override
public void onItemSelected(Presenter.ViewHolder itemViewHolder, Object item, RowPresenter.ViewHolder rowViewHolder, Row row) {
    int index = rowsAdapter.indexOf(row);
    MediaWrapper mediaItem = null;
    if (item instanceof MediaCardPresenter.MediaCardItem) {
        mediaItem = ((MediaCardItem) item).getMediaWrapper();
    }
    presenter.rowSelected(index, mediaItem);
}
Also used : MediaWrapper(butter.droid.base.providers.media.model.MediaWrapper) MediaCardItem(butter.droid.tv.presenters.MediaCardPresenter.MediaCardItem)

Example 2 with MediaCardItem

use of butter.droid.tv.presenters.MediaCardPresenter.MediaCardItem in project butter-android by butterproject.

the class TVOverviewPresenterImpl method loadProviderMedia.

private void loadProviderMedia(final int providerId) {
    cancelMovieCall(providerId);
    final butter.droid.provider.MediaProvider provider = providerManager.getMediaProvider(providerId);
    provider.getDefaultSorter().flatMap(sorter -> {
        Filter f;
        if (sorter.isPresent()) {
            f = new Filter(null, sorter.get());
        } else {
            f = new Filter(null, null);
        }
        return provider.items(f, new Pager(null));
    }).flatMap(w -> Single.zip(Single.just(w.getPaging()), Observable.fromIterable(w.getMedia()).map(m -> new MediaWrapper(m, providerId)).toList(), Pair::create)).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new SingleObserver<Pair<Paging, List<MediaWrapper>>>() {

        @Override
        public void onSubscribe(final Disposable d) {
            listRequests.add(providerId, d);
        }

        @Override
        public void onSuccess(final Pair<Paging, List<MediaWrapper>> items) {
            List<MediaWrapper> mediaItems = items.second;
            List<MediaCardItem> cardItems = convertMediaToOverview(mediaItems);
            view.displayProviderData(providerId, cardItems);
            if (selectedRow == 0) {
                view.updateBackgroundImage(mediaItems.get(0).getMedia().getBackdrop());
            }
        }

        @Override
        public void onError(final Throwable e) {
            view.showErrorMessage(R.string.movies_error);
        }
    });
}
Also used : MediaCardItem(butter.droid.tv.presenters.MediaCardPresenter.MediaCardItem) MaybeObserver(io.reactivex.MaybeObserver) Pair(android.util.Pair) NavItem(butter.droid.provider.base.nav.NavItem) Filter(butter.droid.provider.base.filter.Filter) NonNull(android.support.annotation.NonNull) Single(io.reactivex.Single) AndroidSchedulers(io.reactivex.android.schedulers.AndroidSchedulers) ArrayList(java.util.ArrayList) Disposable(io.reactivex.disposables.Disposable) List(java.util.List) SingleObserver(io.reactivex.SingleObserver) ProviderManager(butter.droid.base.manager.internal.provider.ProviderManager) KeyDisposable(butter.droid.base.utils.rx.KeyDisposable) R(butter.droid.tv.R) Pager(butter.droid.provider.filter.Pager) Observable(io.reactivex.Observable) Schedulers(io.reactivex.schedulers.Schedulers) MediaWrapper(butter.droid.base.providers.media.model.MediaWrapper) Nullable(android.support.annotation.Nullable) MoreItem(butter.droid.tv.presenters.MorePresenter.MoreItem) Paging(butter.droid.provider.base.paging.Paging) MediaWrapper(butter.droid.base.providers.media.model.MediaWrapper) Disposable(io.reactivex.disposables.Disposable) KeyDisposable(butter.droid.base.utils.rx.KeyDisposable) Paging(butter.droid.provider.base.paging.Paging) Filter(butter.droid.provider.base.filter.Filter) Pager(butter.droid.provider.filter.Pager) ArrayList(java.util.ArrayList) List(java.util.List) Pair(android.util.Pair)

Example 3 with MediaCardItem

use of butter.droid.tv.presenters.MediaCardPresenter.MediaCardItem in project butter-android by butterproject.

the class TVMediaGridPresenterImpl method loadItems.

private void loadItems(@Nullable String endCursor) {
    cancelCurrentCall();
    providerManager.getMediaProvider(providerId).items(filter, new Pager(endCursor)).flatMap(i -> Single.zip(Single.just(i).map(ItemsWrapper::getMedia).flatMapObservable(Observable::fromIterable).map(media -> new MediaWrapper(media, providerId)).map(MediaCardItem::new).toList(), Single.just(i).map(ItemsWrapper::getPaging), Pair::create)).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new SingleObserver<Pair<List<MediaCardItem>, Paging>>() {

        @Override
        public void onSubscribe(final Disposable d) {
            currentCall = d;
        }

        @Override
        public void onSuccess(final Pair<List<MediaCardItem>, Paging> value) {
            view.appendItems(value.first, !value.second.hasNextPage(), value.second.getEndCursor());
        }

        @Override
        public void onError(final Throwable e) {
            view.displayError("Error getting show list");
        }
    });
}
Also used : MediaCardItem(butter.droid.tv.presenters.MediaCardPresenter.MediaCardItem) ItemsWrapper(butter.droid.provider.base.paging.ItemsWrapper) Pair(android.util.Pair) Filter(butter.droid.provider.base.filter.Filter) Single(io.reactivex.Single) AndroidSchedulers(io.reactivex.android.schedulers.AndroidSchedulers) Disposable(io.reactivex.disposables.Disposable) List(java.util.List) SingleObserver(io.reactivex.SingleObserver) ProviderManager(butter.droid.base.manager.internal.provider.ProviderManager) Pager(butter.droid.provider.filter.Pager) Observable(io.reactivex.Observable) Schedulers(io.reactivex.schedulers.Schedulers) MediaWrapper(butter.droid.base.providers.media.model.MediaWrapper) Nullable(android.support.annotation.Nullable) Paging(butter.droid.provider.base.paging.Paging) MediaWrapper(butter.droid.base.providers.media.model.MediaWrapper) Disposable(io.reactivex.disposables.Disposable) Paging(butter.droid.provider.base.paging.Paging) Observable(io.reactivex.Observable) Pager(butter.droid.provider.filter.Pager) List(java.util.List) MediaCardItem(butter.droid.tv.presenters.MediaCardPresenter.MediaCardItem) Pair(android.util.Pair)

Aggregations

MediaWrapper (butter.droid.base.providers.media.model.MediaWrapper)3 MediaCardItem (butter.droid.tv.presenters.MediaCardPresenter.MediaCardItem)3 Nullable (android.support.annotation.Nullable)2 Pair (android.util.Pair)2 ProviderManager (butter.droid.base.manager.internal.provider.ProviderManager)2 Filter (butter.droid.provider.base.filter.Filter)2 Paging (butter.droid.provider.base.paging.Paging)2 Pager (butter.droid.provider.filter.Pager)2 Observable (io.reactivex.Observable)2 Single (io.reactivex.Single)2 SingleObserver (io.reactivex.SingleObserver)2 AndroidSchedulers (io.reactivex.android.schedulers.AndroidSchedulers)2 Disposable (io.reactivex.disposables.Disposable)2 Schedulers (io.reactivex.schedulers.Schedulers)2 List (java.util.List)2 NonNull (android.support.annotation.NonNull)1 KeyDisposable (butter.droid.base.utils.rx.KeyDisposable)1 NavItem (butter.droid.provider.base.nav.NavItem)1 ItemsWrapper (butter.droid.provider.base.paging.ItemsWrapper)1 R (butter.droid.tv.R)1