Search in sources :

Example 1 with Episode

use of butter.droid.provider.base.model.Episode in project butter-android by butterproject.

the class TVShowDetailsFragment method pickTorrent.

@Override
public void pickTorrent(final Episode episode, final Torrent[] torrents) {
    ArrayList<String> choices = new ArrayList<>(torrents.length);
    for (final Torrent torrent : torrents) {
        choices.add(mediaDisplayManager.getFormatDisplayName(torrent.getFormat()));
    }
    new AlertDialog.Builder(getActivity()).setTitle(getString(R.string.choose_quality)).setSingleChoiceItems(choices.toArray(new CharSequence[choices.size()]), 0, (dialog, which) -> {
        presenter.torrentSelected(episode, torrents[which]);
        dialog.dismiss();
    }).show();
}
Also used : AlertDialog(android.app.AlertDialog) MediaDisplayManager(butter.droid.base.manager.internal.media.MediaDisplayManager) Context(android.content.Context) ListRow(android.support.v17.leanback.widget.ListRow) Bundle(android.os.Bundle) HeaderItem(android.support.v17.leanback.widget.HeaderItem) ClassPresenterSelector(android.support.v17.leanback.widget.ClassPresenterSelector) AndroidSupportInjection(dagger.android.support.AndroidSupportInjection) Fragment(android.support.v4.app.Fragment) ArrayObjectAdapter(android.support.v17.leanback.widget.ArrayObjectAdapter) StreamInfo(butter.droid.base.providers.media.model.StreamInfo) Torrent(butter.droid.provider.base.model.Torrent) Season(butter.droid.provider.base.model.Season) TVBaseDetailsFragment(butter.droid.tv.ui.detail.base.TVBaseDetailsFragment) ArrayList(java.util.ArrayList) AlertDialog(android.app.AlertDialog) Inject(javax.inject.Inject) EpisodeCardPresenter(butter.droid.tv.ui.detail.show.presenter.EpisodeCardPresenter) Episode(butter.droid.provider.base.model.Episode) TVStreamLoadingActivity(butter.droid.tv.ui.loading.TVStreamLoadingActivity) DetailsOverviewRow(android.support.v17.leanback.widget.DetailsOverviewRow) R(butter.droid.tv.R) MediaWrapper(butter.droid.base.providers.media.model.MediaWrapper) Torrent(butter.droid.provider.base.model.Torrent) ArrayList(java.util.ArrayList)

Example 2 with Episode

use of butter.droid.provider.base.model.Episode in project butter-android by butterproject.

the class EpisodeDialogFragment method onActivityCreated.

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    if (!TextUtils.isEmpty(episode.getTitle())) {
        title.setText(episode.getTitle());
        headerImage.setContentDescription(episode.getTitle());
    } else {
        title.setText(R.string.no_title_available);
        headerImage.setContentDescription(getString(R.string.no_title_available));
    }
    // TODO: 6/17/17 meta provider
    // aired.setVisibility(episode.aired > 0 ? View.VISIBLE : View.GONE);
    // Date airedDate = new Date((long) episode.aired * 1000);
    // aired.setText(String.format(getString(R.string.aired), new SimpleDateFormat("MMMM dd, yyyy", LocaleUtils.getCurrent())
    // .format(airedDate)));
    // if (!TextUtils.isEmpty(episode.getOverview())) {
    // synopsis.setText(episode.getOverview());
    // } else {
    // synopsis.setText(R.string.no_synopsis_available);
    // }
    // info.setText(String.format(Locale.US, "S%02dE%02d", episode.getSeasion(), episode.getEpisode()));
    // subtitlesPreview.setFragmentManager(getFragmentManager());
    subtitlesPreview.setOnClickListener(v -> showSubsPickerDialog());
    quality.setFragmentManager(getFragmentManager());
    final Format[] formats = mediaDisplayManager.getSortedTorrentFormats(episode.getTorrents());
    String[] formatDisplay = new String[formats.length];
    for (int i = 0; i < formats.length; i++) {
        formatDisplay[i] = mediaDisplayManager.getFormatDisplayName(formats[i]);
    }
    quality.setData(formatDisplay);
    int defaultFormatIndex = mediaDisplayManager.getDefaultFormatIndex(formats);
    // // TODO: 7/30/17 Handle sorting
    selectedTorrent = episode.getTorrents()[defaultFormatIndex];
    this.quality.setText(formatDisplay[defaultFormatIndex]);
    this.quality.setDefault(defaultFormatIndex);
    updateMagnet();
    this.quality.setListener((position, value) -> {
        selectedTorrent = episode.getTorrents()[position];
        updateMagnet();
    });
    if (providerManager.hasSubsProvider(mediaMeta.getProviderId())) {
        subtitlesPreview.setText(R.string.loading_subs);
        subtitlesPreview.setClickable(false);
        providerManager.getSubsProvider(mediaMeta.getProviderId()).list(episode).flatMap(subs -> {
            if (subs.isEmpty()) {
                return Single.<List<UiSubItem>>just(Collections.EMPTY_LIST);
            } else {
                final String defaultSubtitle = preferencesHandler.getSubtitleDefaultLanguage();
                return Observable.fromIterable(subs).map(sub -> new UiSubItem(sub, sub.equals(defaultSubtitle))).startWith(new UiSubItem(null, defaultSubtitle == null)).toList();
            }
        }).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new SingleObserver<List<UiSubItem>>() {

            @Override
            public void onSubscribe(final Disposable d) {
            // TODO dispose
            }

            @Override
            public void onSuccess(final List<UiSubItem> subs) {
                if (subs.isEmpty()) {
                    subtitlesPreview.setText(R.string.no_subs_available);
                    subtitleList = null;
                } else {
                    subtitlesPreview.setClickable(true);
                    subtitleList = subs;
                    UiSubItem selectedItem = null;
                    for (final UiSubItem sub : subs) {
                        if (sub.isSelected()) {
                            selectedItem = sub;
                            String name = sub.getName();
                            if (TextUtils.isEmpty(name)) {
                                subtitlesPreview.setText(R.string.no_subs);
                            } else {
                                subtitlesPreview.setText(name);
                            }
                            break;
                        }
                    }
                    if (selectedItem == null) {
                        selectedItem = subs.get(0);
                    }
                    selectedSub = selectedItem;
                }
            }

            @Override
            public void onError(final Throwable e) {
                // subtitleList = null;
                subtitlesPreview.setText(R.string.no_subs_available);
                subtitlesPreview.setClickable(false);
            }
        });
    } else {
        subtitlesPreview.setText(R.string.no_subs_available);
        subtitlesPreview.setClickable(false);
    }
    scrollView.setListener(new BottomSheetScrollView.Listener() {

        @Override
        public void onScroll(int scrollY, BottomSheetScrollView.Direction direction) {
        }

        @Override
        public void onTouch(boolean touching) {
            EpisodeDialogFragment.this.touching = touching;
            int scrollY = scrollView.getScrollY();
            if (!EpisodeDialogFragment.this.touching && opened && scrollY <= threshold) {
                smoothDismiss();
            }
        }

        @Override
        public void onScrollStart() {
        }

        @Override
        public void onScrollEnd() {
            if (!touching && opened && scrollView.getScrollY() <= threshold) {
                smoothDismiss();
            }
        }
    });
    if (metaProvider != null) {
    // TODO: 6/17/17 meta
    // metaProvider.getEpisodeMeta(episode.imdbId, episode.getSeasion(), episode.getEpisode(),
    // (Callback) (metaData, ex) -> {
    // String imageUrl = episode.getBackdrop();
    // if (ex == null) {
    // imageUrl = metaData.images.poster;
    // }
    // Picasso.with(headerImage.getContext()).load(imageUrl).into(headerImage);
    // });
    } else {
        Picasso.with(headerImage.getContext()).load(episode.getBackdrop()).into(headerImage);
    }
}
Also used : ImageButton(android.widget.ImageButton) LinearLayout(android.widget.LinearLayout) Bundle(android.os.Bundle) ImageView(android.widget.ImageView) AndroidSchedulers(io.reactivex.android.schedulers.AndroidSchedulers) OnClick(butterknife.OnClick) BindView(butterknife.BindView) Picasso(com.squareup.picasso.Picasso) ProviderManager(butter.droid.base.manager.internal.provider.ProviderManager) ContextThemeWrapper(android.view.ContextThemeWrapper) View(android.view.View) Schedulers(io.reactivex.schedulers.Schedulers) SubtitleWrapper(butter.droid.base.providers.subs.model.SubtitleWrapper) PreferencesHandler(butter.droid.base.content.preferences.PreferencesHandler) ViewGroup(android.view.ViewGroup) OptionPreview(butter.droid.widget.OptionPreview) SubsPickerCallback(butter.droid.ui.media.detail.dialog.subs.SubsPickerDialog.SubsPickerCallback) Disposable(io.reactivex.disposables.Disposable) List(java.util.List) TextView(android.widget.TextView) Nullable(android.support.annotation.Nullable) SubsPickerDialog(butter.droid.ui.media.detail.dialog.subs.SubsPickerDialog) KeyEvent(android.view.KeyEvent) DaggerAppCompatDialogFragment(dagger.android.support.DaggerAppCompatDialogFragment) ButterKnife(butterknife.ButterKnife) Dialog(android.app.Dialog) NonNull(android.support.annotation.NonNull) StreamInfo(butter.droid.base.providers.media.model.StreamInfo) Single(io.reactivex.Single) Format(butter.droid.provider.base.model.Format) SynopsisDialogFragment(butter.droid.ui.media.detail.streamable.dialog.SynopsisDialogFragment) Inject(javax.inject.Inject) Episode(butter.droid.provider.base.model.Episode) Observable(io.reactivex.Observable) MediaWrapper(butter.droid.base.providers.media.model.MediaWrapper) OptionSelector(butter.droid.widget.OptionSelector) DialogInterface(android.content.DialogInterface) MediaDisplayManager(butter.droid.base.manager.internal.media.MediaDisplayManager) R(butter.droid.R) LayoutInflater(android.view.LayoutInflater) TextUtils(android.text.TextUtils) MediaMeta(butter.droid.base.providers.media.model.MediaMeta) Torrent(butter.droid.provider.base.model.Torrent) BottomSheetScrollView(butter.droid.widget.BottomSheetScrollView) Magnet(butter.droid.base.torrent.Magnet) SingleObserver(io.reactivex.SingleObserver) MetaProvider(butter.droid.base.providers.meta.MetaProvider) UiSubItem(butter.droid.ui.media.detail.model.UiSubItem) PixelUtils(butter.droid.base.utils.PixelUtils) Activity(android.app.Activity) Collections(java.util.Collections) Disposable(io.reactivex.disposables.Disposable) Format(butter.droid.provider.base.model.Format) UiSubItem(butter.droid.ui.media.detail.model.UiSubItem) List(java.util.List) BottomSheetScrollView(butter.droid.widget.BottomSheetScrollView)

Example 3 with Episode

use of butter.droid.provider.base.model.Episode in project butter-android by butterproject.

the class EpisodeListAdapter method getView.

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    ViewHolder holder;
    if (convertView == null) {
        convertView = inflater.inflate(R.layout.episode_list_item, parent, false);
        holder = new ViewHolder(convertView);
        convertView.setTag(holder);
    } else {
        holder = (ViewHolder) convertView.getTag();
    }
    Episode episode = getItem(position);
    holder.bind(episode);
    return convertView;
}
Also used : Episode(butter.droid.provider.base.model.Episode)

Example 4 with Episode

use of butter.droid.provider.base.model.Episode in project butter-android by butterproject.

the class RecommendationService method buildShowRecommendations.

private void buildShowRecommendations(@NonNull RecommendationBuilder builder) {
    Timber.d("building show recommendations");
    try {
        int count = 0;
        for (Media media : shows) {
            Show show = (Show) media;
            Timber.d("Recommendation - " + show.getTitle());
            Episode latestEpisode = findLatestEpisode(show);
            priority--;
            totalCount--;
            builder.setBackgroundContentUri(RecommendationContentProvider.CONTENT_URI + URLEncoder.encode(show.getBackdrop(), "UTF-8")).setId(totalCount).setPriority(priority).setTitle(show.getTitle()).setDescription(latestEpisode == null ? "" : getString(R.string.episode_number_format, latestEpisode.getEpisode())).setImage(show.getPoster()).build();
            if (++count >= MAX_SHOW_RECOMMENDATIONS) {
                break;
            }
        }
    } catch (IOException e) {
        Timber.e("Unable to update recommendation", e);
    }
}
Also used : Episode(butter.droid.provider.base.model.Episode) Media(butter.droid.provider.base.model.Media) Show(butter.droid.provider.base.model.Show) IOException(java.io.IOException)

Example 5 with Episode

use of butter.droid.provider.base.model.Episode in project butter-android by butterproject.

the class TVShowDetailsFragment method showSeasons.

@Override
public void showSeasons(final Season[] seasons) {
    ArrayObjectAdapter objectAdapter = getObjectArrayAdapter();
    for (int i = 0; i < seasons.length; i++) {
        Season season = seasons[i];
        HeaderItem header = new HeaderItem(i, season.getTitle());
        EpisodeCardPresenter presenter = new EpisodeCardPresenter(getActivity());
        presenter.setOnClickListener(this);
        ArrayObjectAdapter episodes = new ArrayObjectAdapter(presenter);
        for (final Episode episode : season.getEpisodes()) {
            episodes.add(episode);
        }
        objectAdapter.add(new ListRow(header, episodes));
    }
    objectAdapter.notifyArrayItemRangeChanged(1, objectAdapter.size());
}
Also used : Episode(butter.droid.provider.base.model.Episode) ArrayObjectAdapter(android.support.v17.leanback.widget.ArrayObjectAdapter) HeaderItem(android.support.v17.leanback.widget.HeaderItem) Season(butter.droid.provider.base.model.Season) ListRow(android.support.v17.leanback.widget.ListRow) EpisodeCardPresenter(butter.droid.tv.ui.detail.show.presenter.EpisodeCardPresenter)

Aggregations

Episode (butter.droid.provider.base.model.Episode)7 Torrent (butter.droid.provider.base.model.Torrent)3 Bundle (android.os.Bundle)2 ArrayObjectAdapter (android.support.v17.leanback.widget.ArrayObjectAdapter)2 HeaderItem (android.support.v17.leanback.widget.HeaderItem)2 ListRow (android.support.v17.leanback.widget.ListRow)2 MediaDisplayManager (butter.droid.base.manager.internal.media.MediaDisplayManager)2 MediaWrapper (butter.droid.base.providers.media.model.MediaWrapper)2 StreamInfo (butter.droid.base.providers.media.model.StreamInfo)2 Format (butter.droid.provider.base.model.Format)2 Season (butter.droid.provider.base.model.Season)2 Inject (javax.inject.Inject)2 Activity (android.app.Activity)1 AlertDialog (android.app.AlertDialog)1 Dialog (android.app.Dialog)1 Context (android.content.Context)1 DialogInterface (android.content.DialogInterface)1 NonNull (android.support.annotation.NonNull)1 Nullable (android.support.annotation.Nullable)1 ClassPresenterSelector (android.support.v17.leanback.widget.ClassPresenterSelector)1