Search in sources :

Example 1 with Pager

use of butter.droid.provider.filter.Pager 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 2 with Pager

use of butter.droid.provider.filter.Pager in project butter-android by butterproject.

the class TVSearchPresenterImpl method getProviderRequests.

private List<Single<SearchResult>> getProviderRequests(String query) {
    List<Single<SearchResult>> requests = new ArrayList<>();
    ProviderWrapper[] providers = providerManager.getProviders();
    for (int i = 0; i < providers.length; i++) {
        MediaProvider provider = providers[i].getMediaProvider();
        final int providerId = i;
        // TODO: 6/17/17 Define title of search row
        requests.add(provider.items(new Filter(null, null, query), new Pager(null)).flatMapObservable(w -> Observable.fromIterable(w.getMedia())).map(m -> new MediaWrapper(m, providerId)).toList().map(l -> new SearchResult(R.string.movie_results, l)));
    }
    return requests;
}
Also used : MediaCardPresenter(butter.droid.tv.presenters.MediaCardPresenter) MediaCardItem(butter.droid.tv.presenters.MediaCardPresenter.MediaCardItem) BehaviorSubject(io.reactivex.subjects.BehaviorSubject) Filter(butter.droid.provider.base.filter.Filter) StringRes(android.support.annotation.StringRes) Single(io.reactivex.Single) AndroidSchedulers(io.reactivex.android.schedulers.AndroidSchedulers) Timber(timber.log.Timber) ArrayList(java.util.ArrayList) TimeUnit(java.util.concurrent.TimeUnit) CompositeDisposable(io.reactivex.disposables.CompositeDisposable) Disposable(io.reactivex.disposables.Disposable) List(java.util.List) ProviderWrapper(butter.droid.base.manager.internal.provider.model.ProviderWrapper) PublishSubject(io.reactivex.subjects.PublishSubject) ProviderManager(butter.droid.base.manager.internal.provider.ProviderManager) Observer(io.reactivex.Observer) 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) MediaProvider(butter.droid.provider.MediaProvider) MediaWrapper(butter.droid.base.providers.media.model.MediaWrapper) Single(io.reactivex.Single) MediaProvider(butter.droid.provider.MediaProvider) Filter(butter.droid.provider.base.filter.Filter) Pager(butter.droid.provider.filter.Pager) ArrayList(java.util.ArrayList) ProviderWrapper(butter.droid.base.manager.internal.provider.model.ProviderWrapper)

Example 3 with Pager

use of butter.droid.provider.filter.Pager 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)

Example 4 with Pager

use of butter.droid.provider.filter.Pager in project butter-android by butterproject.

the class BaseMediaListPresenterImpl method loadNextPage.

@Override
public void loadNextPage(@Nullable String endCursor) {
    cancelListCall();
    if (items.isEmpty()) {
        updateLoadingMessage(getLoadingMessage());
        showLoading();
    }
    providerManager.getMediaProvider(providerId).items(filter, new Pager(endCursor)).flatMap(w -> Single.zip(Single.just(w.getPaging()), Observable.fromIterable(w.getMedia()).map(i -> new MediaWrapper(i, providerId)).toList(), Pair::create)).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new SingleObserver<Pair<Paging, List<MediaWrapper>>>() {

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

        @Override
        public void onSuccess(final Pair<Paging, List<MediaWrapper>> value) {
            Paging paging = value.first;
            view.addItems(value.second, !paging.hasNextPage(), paging.getEndCursor());
            items.addAll(value.second);
            showLoaded();
        }

        @Override
        public void onError(final Throwable e) {
            // TODO: 6/24/17 Most of this is not relevant any more
            if (e.getMessage().equals("Canceled")) {
                showLoaded();
            } else if (e.getMessage() != null && e.getMessage().equals(ButterApplication.getAppContext().getString(R.string.movies_error))) {
                view.addItems(null, false, null);
                showLoaded();
            } else {
                Timber.e(e.getMessage());
                view.showErrorMessage(R.string.unknown_error);
                showLoaded();
            }
        }
    });
}
Also used : R(butter.droid.R) Pair(android.util.Pair) Filter(butter.droid.provider.base.filter.Filter) StringRes(android.support.annotation.StringRes) PreferencesHandler(butter.droid.base.content.preferences.PreferencesHandler) Single(io.reactivex.Single) AndroidSchedulers(io.reactivex.android.schedulers.AndroidSchedulers) Timber(timber.log.Timber) ArrayList(java.util.ArrayList) Disposable(io.reactivex.disposables.Disposable) List(java.util.List) ButterApplication(butter.droid.base.ButterApplication) 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) Pager(butter.droid.provider.filter.Pager) Paging(butter.droid.provider.base.paging.Paging) ArrayList(java.util.ArrayList) List(java.util.List) Pair(android.util.Pair)

Aggregations

ProviderManager (butter.droid.base.manager.internal.provider.ProviderManager)4 MediaWrapper (butter.droid.base.providers.media.model.MediaWrapper)4 Filter (butter.droid.provider.base.filter.Filter)4 Pager (butter.droid.provider.filter.Pager)4 Observable (io.reactivex.Observable)4 Single (io.reactivex.Single)4 AndroidSchedulers (io.reactivex.android.schedulers.AndroidSchedulers)4 Disposable (io.reactivex.disposables.Disposable)4 Schedulers (io.reactivex.schedulers.Schedulers)4 List (java.util.List)4 Nullable (android.support.annotation.Nullable)3 Pair (android.util.Pair)3 Paging (butter.droid.provider.base.paging.Paging)3 MediaCardItem (butter.droid.tv.presenters.MediaCardPresenter.MediaCardItem)3 SingleObserver (io.reactivex.SingleObserver)3 ArrayList (java.util.ArrayList)3 StringRes (android.support.annotation.StringRes)2 R (butter.droid.tv.R)2 Timber (timber.log.Timber)2 NonNull (android.support.annotation.NonNull)1