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