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