Search in sources :

Example 1 with ItemsWrapper

use of butter.droid.provider.base.paging.ItemsWrapper in project butter-android by butterproject.

the class VodoProvider method items.

@NonNull
@Override
public Single<ItemsWrapper> items(@Nullable final Filter filter, @Nullable Pager pager) {
    String query = null;
    String genre = null;
    String sorter = null;
    if (filter != null) {
        if (filter.getGenre() != null) {
            genre = filter.getGenre().getKey();
        }
        if (filter.getSorter() != null) {
            sorter = filter.getSorter().getKey();
        }
        query = filter.getQuery();
    }
    final int page;
    if (pager != null && pager.getEndCursor() != null) {
        page = Integer.parseInt(pager.getEndCursor());
    } else {
        page = 0;
    }
    return vodoService.fetchMovies(query, genre, sorter, null, null, ITEMS_PER_PAGE, page).map(VodoResponse::getDownloads).flatMapObservable(Observable::fromArray).map(this::mapVodoMovie).cast(Media.class).toList().map(m -> new ItemsWrapper(m, new Paging(String.valueOf(page + 1), m.size() == ITEMS_PER_PAGE)));
}
Also used : Paging(butter.droid.provider.base.paging.Paging) ItemsWrapper(butter.droid.provider.base.paging.ItemsWrapper) Observable(io.reactivex.Observable) NonNull(android.support.annotation.NonNull)

Example 2 with ItemsWrapper

use of butter.droid.provider.base.paging.ItemsWrapper 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

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