Search in sources :

Example 6 with UiSubItem

use of butter.droid.ui.media.detail.model.UiSubItem in project butter-android by butterproject.

the class StreamableDetailPresenterImpl method displaySubtitles.

private void displaySubtitles() {
    if (providerManager.hasSubsProvider(mediaWrapper.getProviderId())) {
        view.setSubtitleText(R.string.loading_subs);
        view.setSubtitleEnabled(false);
        providerManager.getSubsProvider(mediaWrapper.getProviderId()).list(mediaWrapper.getMedia()).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.getLanguage().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) {
                subtitlesRequest = d;
            }

            @Override
            public void onSuccess(final List<UiSubItem> subs) {
                if (subs.isEmpty()) {
                    view.setSubtitleText(R.string.no_subs_available);
                    subtitleList = null;
                } else {
                    view.setSubtitleEnabled(true);
                    subtitleList = subs;
                    UiSubItem selectedItem = null;
                    for (final UiSubItem sub : subs) {
                        if (sub.isSelected()) {
                            selectedItem = sub;
                            String name = sub.getName();
                            if (TextUtils.isEmpty(name)) {
                                view.setSubtitleText(R.string.no_subs);
                            } else {
                                view.setSubtitleText(name);
                            }
                            break;
                        }
                    }
                    if (selectedItem == null) {
                        selectedItem = subs.get(0);
                    }
                    selectedSub = selectedItem;
                    if (selectedItem.getLanguage() == null) {
                        parentPresenter.selectSubtitle(new SubtitleWrapper());
                    } else {
                        parentPresenter.selectSubtitle(new SubtitleWrapper(selectedItem.getSubtitle()));
                    }
                }
            }

            @Override
            public void onError(final Throwable e) {
                subtitleList = null;
                view.setSubtitleText(R.string.no_subs_available);
                view.setSubtitleEnabled(false);
            }
        });
    } else {
        view.setSubtitleText(R.string.no_subs_available);
        view.setSubtitleEnabled(false);
    }
}
Also used : YouTubeManager(butter.droid.base.manager.internal.youtube.YouTubeManager) StreamInfo(butter.droid.base.providers.media.model.StreamInfo) Single(io.reactivex.Single) AndroidSchedulers(io.reactivex.android.schedulers.AndroidSchedulers) Format(butter.droid.provider.base.model.Format) PlayerManager(butter.droid.base.manager.internal.vlc.PlayerManager) ProviderManager(butter.droid.base.manager.internal.provider.ProviderManager) Observable(io.reactivex.Observable) Schedulers(io.reactivex.schedulers.Schedulers) MediaWrapper(butter.droid.base.providers.media.model.MediaWrapper) MediaDisplayManager(butter.droid.base.manager.internal.media.MediaDisplayManager) R(butter.droid.R) SubtitleWrapper(butter.droid.base.providers.subs.model.SubtitleWrapper) TextUtils(android.text.TextUtils) PreferencesHandler(butter.droid.base.content.preferences.PreferencesHandler) Torrent(butter.droid.provider.base.model.Torrent) Disposable(io.reactivex.disposables.Disposable) List(java.util.List) SingleObserver(io.reactivex.SingleObserver) MediaDetailPresenter(butter.droid.ui.media.detail.MediaDetailPresenter) UiSubItem(butter.droid.ui.media.detail.model.UiSubItem) Genre(butter.droid.provider.base.filter.Genre) Streamable(butter.droid.provider.base.model.Streamable) Movie(butter.droid.provider.base.model.Movie) Collections(java.util.Collections) Resources(android.content.res.Resources) Disposable(io.reactivex.disposables.Disposable) UiSubItem(butter.droid.ui.media.detail.model.UiSubItem) List(java.util.List) SubtitleWrapper(butter.droid.base.providers.subs.model.SubtitleWrapper)

Aggregations

UiSubItem (butter.droid.ui.media.detail.model.UiSubItem)6 SubtitleWrapper (butter.droid.base.providers.subs.model.SubtitleWrapper)4 MediaWrapper (butter.droid.base.providers.media.model.MediaWrapper)3 StreamInfo (butter.droid.base.providers.media.model.StreamInfo)3 TextUtils (android.text.TextUtils)2 R (butter.droid.R)2 PreferencesHandler (butter.droid.base.content.preferences.PreferencesHandler)2 MediaDisplayManager (butter.droid.base.manager.internal.media.MediaDisplayManager)2 ProviderManager (butter.droid.base.manager.internal.provider.ProviderManager)2 Format (butter.droid.provider.base.model.Format)2 Torrent (butter.droid.provider.base.model.Torrent)2 OnClick (butterknife.OnClick)2 Activity (android.app.Activity)1 Dialog (android.app.Dialog)1 DialogInterface (android.content.DialogInterface)1 Resources (android.content.res.Resources)1 Bundle (android.os.Bundle)1 NonNull (android.support.annotation.NonNull)1 Nullable (android.support.annotation.Nullable)1 BottomSheetDialogFragment (android.support.design.widget.BottomSheetDialogFragment)1