use of org.greenrobot.eventbus.Subscribe in project AntennaPod by AntennaPod.
the class AudioPlayerFragment method updatePosition.
@Subscribe(threadMode = ThreadMode.MAIN)
public void updatePosition(PlaybackPositionEvent event) {
if (controller == null || txtvPosition == null || txtvLength == null || sbPosition == null) {
return;
}
TimeSpeedConverter converter = new TimeSpeedConverter(controller.getCurrentPlaybackSpeedMultiplier());
int currentPosition = converter.convert(event.getPosition());
int duration = converter.convert(event.getDuration());
int remainingTime = converter.convert(Math.max(event.getDuration() - event.getPosition(), 0));
currentChapterIndex = ChapterUtils.getCurrentChapterIndex(controller.getMedia(), currentPosition);
Log.d(TAG, "currentPosition " + Converter.getDurationStringLong(currentPosition));
if (currentPosition == PlaybackService.INVALID_TIME || duration == PlaybackService.INVALID_TIME) {
Log.w(TAG, "Could not react to position observer update because of invalid time");
return;
}
txtvPosition.setText(Converter.getDurationStringLong(currentPosition));
showTimeLeft = UserPreferences.shouldShowRemainingTime();
if (showTimeLeft) {
txtvLength.setText(((remainingTime > 0) ? "-" : "") + Converter.getDurationStringLong(remainingTime));
} else {
txtvLength.setText(Converter.getDurationStringLong(duration));
}
if (!sbPosition.isPressed()) {
float progress = ((float) event.getPosition()) / event.getDuration();
sbPosition.setProgress((int) (progress * sbPosition.getMax()));
}
}
use of org.greenrobot.eventbus.Subscribe in project AntennaPod by AntennaPod.
the class AudioPlayerFragment method updatePlaybackSpeedButton.
@Subscribe(threadMode = ThreadMode.MAIN)
public void updatePlaybackSpeedButton(SpeedChangedEvent event) {
String speedStr = new DecimalFormat("0.00").format(event.getNewSpeed());
txtvPlaybackSpeed.setText(speedStr);
butPlaybackSpeed.setSpeed(event.getNewSpeed());
}
use of org.greenrobot.eventbus.Subscribe in project AntennaPod by AntennaPod.
the class ChaptersFragment method loadMediaInfo.
private void loadMediaInfo() {
if (disposable != null) {
disposable.dispose();
}
disposable = Maybe.create(emitter -> {
Playable media = controller.getMedia();
if (media != null) {
ChapterUtils.loadChapters(media, getContext());
emitter.onSuccess(media);
} else {
emitter.onComplete();
}
}).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(media -> onMediaChanged((Playable) media), error -> Log.e(TAG, Log.getStackTraceString(error)));
}
use of org.greenrobot.eventbus.Subscribe in project AntennaPod by AntennaPod.
the class EpisodesListFragment method onEventMainThread.
@Subscribe(sticky = true, threadMode = ThreadMode.MAIN)
public void onEventMainThread(DownloadEvent event) {
Log.d(TAG, "onEventMainThread() called with: " + "event = [" + event + "]");
DownloaderUpdate update = event.update;
if (event.hasChangedFeedUpdateStatus(isUpdatingFeeds)) {
((PagedToolbarFragment) getParentFragment()).invalidateOptionsMenuIfActive(this);
}
if (update.mediaIds.length > 0) {
for (long mediaId : update.mediaIds) {
int pos = FeedItemUtil.indexOfItemWithMediaId(episodes, mediaId);
if (pos >= 0) {
listAdapter.notifyItemChangedCompat(pos);
}
}
}
}
use of org.greenrobot.eventbus.Subscribe in project AntennaPod by AntennaPod.
the class EpisodesListFragment method onEventMainThread.
@Subscribe(threadMode = ThreadMode.MAIN)
public void onEventMainThread(FeedItemEvent event) {
Log.d(TAG, "onEventMainThread() called with: " + "event = [" + event + "]");
for (FeedItem item : event.items) {
int pos = FeedItemUtil.indexOfItemWithId(episodes, item.getId());
if (pos >= 0) {
episodes.remove(pos);
if (shouldUpdatedItemRemainInList(item)) {
episodes.add(pos, item);
listAdapter.notifyItemChangedCompat(pos);
} else {
listAdapter.notifyItemRemoved(pos);
}
}
}
}
Aggregations