Search in sources :

Example 81 with Subscribe

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()));
    }
}
Also used : TimeSpeedConverter(de.danoeh.antennapod.core.util.TimeSpeedConverter) Subscribe(org.greenrobot.eventbus.Subscribe)

Example 82 with Subscribe

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());
}
Also used : DecimalFormat(java.text.DecimalFormat) Subscribe(org.greenrobot.eventbus.Subscribe)

Example 83 with Subscribe

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)));
}
Also used : DividerItemDecoration(androidx.recyclerview.widget.DividerItemDecoration) PlaybackController(de.danoeh.antennapod.core.util.playback.PlaybackController) Bundle(android.os.Bundle) AlertDialog(androidx.appcompat.app.AlertDialog) ProgressBar(android.widget.ProgressBar) NonNull(androidx.annotation.NonNull) Maybe(io.reactivex.Maybe) Dialog(android.app.Dialog) AndroidSchedulers(io.reactivex.android.schedulers.AndroidSchedulers) AppCompatDialogFragment(androidx.appcompat.app.AppCompatDialogFragment) EventBus(org.greenrobot.eventbus.EventBus) PlaybackPositionEvent(de.danoeh.antennapod.event.playback.PlaybackPositionEvent) View(android.view.View) Schedulers(io.reactivex.schedulers.Schedulers) RecyclerView(androidx.recyclerview.widget.RecyclerView) ChaptersListAdapter(de.danoeh.antennapod.adapter.ChaptersListAdapter) Chapter(de.danoeh.antennapod.model.feed.Chapter) Log(android.util.Log) LayoutInflater(android.view.LayoutInflater) R(de.danoeh.antennapod.R) Playable(de.danoeh.antennapod.model.playback.Playable) ThreadMode(org.greenrobot.eventbus.ThreadMode) ViewGroup(android.view.ViewGroup) PlayerStatus(de.danoeh.antennapod.playback.base.PlayerStatus) Disposable(io.reactivex.disposables.Disposable) Nullable(androidx.annotation.Nullable) Subscribe(org.greenrobot.eventbus.Subscribe) ChapterUtils(de.danoeh.antennapod.core.util.ChapterUtils) RelativeLayout(android.widget.RelativeLayout) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) Playable(de.danoeh.antennapod.model.playback.Playable)

Example 84 with Subscribe

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);
            }
        }
    }
}
Also used : DownloaderUpdate(de.danoeh.antennapod.core.event.DownloaderUpdate) Subscribe(org.greenrobot.eventbus.Subscribe)

Example 85 with Subscribe

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);
            }
        }
    }
}
Also used : FeedItem(de.danoeh.antennapod.model.feed.FeedItem) Subscribe(org.greenrobot.eventbus.Subscribe)

Aggregations

Subscribe (org.greenrobot.eventbus.Subscribe)164 Intent (android.content.Intent)20 Bundle (android.os.Bundle)11 EventBus (org.greenrobot.eventbus.EventBus)10 ThreadMode (org.greenrobot.eventbus.ThreadMode)10 View (android.view.View)9 Poi (io.jawg.osmcontributor.model.entities.Poi)9 PoiType (io.jawg.osmcontributor.model.entities.PoiType)9 ArrayList (java.util.ArrayList)9 Context (android.content.Context)8 Handler (android.os.Handler)8 ViewGroup (android.view.ViewGroup)8 FeedItem (de.danoeh.antennapod.model.feed.FeedItem)8 SuppressLint (android.annotation.SuppressLint)6 LayoutInflater (android.view.LayoutInflater)6 MenuItem (android.view.MenuItem)6 DownloaderUpdate (de.danoeh.antennapod.core.event.DownloaderUpdate)6 AndroidSchedulers (io.reactivex.android.schedulers.AndroidSchedulers)6 Disposable (io.reactivex.disposables.Disposable)6 Schedulers (io.reactivex.schedulers.Schedulers)6