use of butter.droid.ui.media.detail.model.UiSubItem 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);
}
}
use of butter.droid.ui.media.detail.model.UiSubItem in project butter-android by butterproject.
the class EpisodeDialogFragment method playClick.
@OnClick(R.id.play_button)
public void playClick() {
smoothDismiss();
// TODO parent
UiSubItem selectedSub = this.selectedSub;
final SubtitleWrapper subtitleWrapper;
if (selectedSub != null) {
subtitleWrapper = new SubtitleWrapper(selectedSub.getSubtitle());
} else {
subtitleWrapper = null;
}
// TODO use pare presenter
StreamInfo streamInfo = new StreamInfo(selectedTorrent, new MediaWrapper(episode, mediaMeta), null, subtitleWrapper);
((FragmentListener) getActivity()).playStream(streamInfo);
}
use of butter.droid.ui.media.detail.model.UiSubItem in project butter-android by butterproject.
the class StreamableDetailPresenterImpl method subtitleSelected.
@Override
public void subtitleSelected(UiSubItem item) {
UiSubItem selectedSub = this.selectedSub;
if (selectedSub != null) {
selectedSub.setSelected(false);
}
this.selectedSub = item;
item.setSelected(true);
String language = item.getLanguage();
parentPresenter.selectSubtitle(new SubtitleWrapper(item.getSubtitle()));
if (language == null) {
view.setSubtitleText(R.string.no_subs);
} else {
view.setSubtitleText(item.getName());
}
view.hideDialog();
}
use of butter.droid.ui.media.detail.model.UiSubItem in project butter-android by butterproject.
the class EpisodeDialogFragment method onSubsItemSelected.
@Override
public void onSubsItemSelected(final int position, final UiSubItem item) {
UiSubItem selectedSub = this.selectedSub;
if (selectedSub != null) {
selectedSub.setSelected(false);
}
this.selectedSub = item;
item.setSelected(true);
String language = item.getLanguage();
if (language == null) {
subtitlesPreview.setText(R.string.no_subs);
} else {
subtitlesPreview.setText(item.getName());
}
subsDialog.dismiss();
subsDialog = null;
}
use of butter.droid.ui.media.detail.model.UiSubItem in project butter-android by butterproject.
the class SubsPickerDialog method onViewCreated.
@Override
public void onViewCreated(@NonNull final View view, @Nullable final Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
ButterKnife.bind(this, view);
SubsPickerCallback callback;
Fragment parentFragment = getParentFragment();
FragmentActivity activity = getActivity();
if (parentFragment != null && parentFragment instanceof SubsPickerCallback) {
callback = (SubsPickerCallback) parentFragment;
} else if (activity != null && activity instanceof SubsPickerCallback) {
callback = (SubsPickerCallback) activity;
} else {
throw new IllegalStateException("Parent has to implement SubsPickerCallback");
}
SubsPickerAdapter subsPickerAdapter = new SubsPickerAdapter(itemsLayout, callback);
ArrayList<UiSubItem> items = getArguments().getParcelableArrayList(ARG_ITEMS);
subsPickerAdapter.setData(items);
}
Aggregations