Migrated player status event to EventBus
This commit is contained in:
parent
405fbd45a5
commit
b5ab7d6d3c
|
@ -25,6 +25,7 @@ import android.widget.Toast;
|
|||
import com.yqritc.recyclerviewflexibledivider.HorizontalDividerItemDecoration;
|
||||
|
||||
import de.danoeh.antennapod.core.event.PlaybackPositionEvent;
|
||||
import de.danoeh.antennapod.core.event.PlayerStatusEvent;
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
import org.greenrobot.eventbus.Subscribe;
|
||||
import org.greenrobot.eventbus.ThreadMode;
|
||||
|
@ -66,8 +67,7 @@ public abstract class EpisodesListFragment extends Fragment {
|
|||
public static final String TAG = "EpisodesListFragment";
|
||||
|
||||
private static final int EVENTS = EventDistributor.FEED_LIST_UPDATE |
|
||||
EventDistributor.UNREAD_ITEMS_UPDATE |
|
||||
EventDistributor.PLAYER_STATUS_UPDATE;
|
||||
EventDistributor.UNREAD_ITEMS_UPDATE;
|
||||
|
||||
private static final String DEFAULT_PREF_NAME = "PrefAllEpisodesFragment";
|
||||
private static final String PREF_SCROLL_POSITION = "scroll_position";
|
||||
|
@ -414,6 +414,14 @@ public abstract class EpisodesListFragment extends Fragment {
|
|||
}
|
||||
}
|
||||
|
||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||
public void onPlayerStatusChanged(PlayerStatusEvent event) {
|
||||
loadItems();
|
||||
if (isUpdatingFeeds != updateRefreshMenuItemChecker.isRefreshing()) {
|
||||
requireActivity().invalidateOptionsMenu();
|
||||
}
|
||||
}
|
||||
|
||||
private final EventDistributor.EventListener contentUpdate = new EventDistributor.EventListener() {
|
||||
@Override
|
||||
public void update(EventDistributor eventDistributor, Integer arg) {
|
||||
|
|
|
@ -29,6 +29,7 @@ import com.joanzapata.iconify.Iconify;
|
|||
import com.joanzapata.iconify.widget.IconTextView;
|
||||
|
||||
import de.danoeh.antennapod.core.event.PlaybackPositionEvent;
|
||||
import de.danoeh.antennapod.core.event.PlayerStatusEvent;
|
||||
import org.apache.commons.lang3.Validate;
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
import org.greenrobot.eventbus.Subscribe;
|
||||
|
@ -81,10 +82,8 @@ public class FeedItemlistFragment extends ListFragment {
|
|||
private static final String TAG = "ItemlistFragment";
|
||||
|
||||
private static final int EVENTS = EventDistributor.UNREAD_ITEMS_UPDATE
|
||||
| EventDistributor.FEED_LIST_UPDATE
|
||||
| EventDistributor.PLAYER_STATUS_UPDATE;
|
||||
| EventDistributor.FEED_LIST_UPDATE;
|
||||
|
||||
public static final String EXTRA_SELECTED_FEEDITEM = "extra.de.danoeh.antennapod.activity.selected_feeditem";
|
||||
private static final String ARGUMENT_FEED_ID = "argument.de.danoeh.antennapod.feed_id";
|
||||
|
||||
private FeedItemlistAdapter adapter;
|
||||
|
@ -392,6 +391,13 @@ public class FeedItemlistFragment extends ListFragment {
|
|||
}
|
||||
}
|
||||
|
||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||
public void onPlayerStatusChanged(PlayerStatusEvent event) {
|
||||
refreshHeaderView();
|
||||
loadItems();
|
||||
updateProgressBarVisibility();
|
||||
}
|
||||
|
||||
private final EventDistributor.EventListener contentUpdate = new EventDistributor.EventListener() {
|
||||
|
||||
@Override
|
||||
|
|
|
@ -13,6 +13,7 @@ import android.view.View;
|
|||
import android.widget.ListView;
|
||||
|
||||
import de.danoeh.antennapod.core.event.PlaybackHistoryEvent;
|
||||
import de.danoeh.antennapod.core.event.PlayerStatusEvent;
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
import org.greenrobot.eventbus.Subscribe;
|
||||
import org.greenrobot.eventbus.ThreadMode;
|
||||
|
@ -40,11 +41,8 @@ import io.reactivex.disposables.Disposable;
|
|||
import io.reactivex.schedulers.Schedulers;
|
||||
|
||||
public class PlaybackHistoryFragment extends ListFragment {
|
||||
|
||||
public static final String TAG = "PlaybackHistoryFragment";
|
||||
|
||||
private static final int EVENTS = EventDistributor.PLAYER_STATUS_UPDATE;
|
||||
|
||||
private List<FeedItem> playbackHistory;
|
||||
private FeedItemlistAdapter adapter;
|
||||
private List<Downloader> downloaderList;
|
||||
|
@ -83,7 +81,6 @@ public class PlaybackHistoryFragment extends ListFragment {
|
|||
@Override
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
EventDistributor.getInstance().register(contentUpdate);
|
||||
EventBus.getDefault().register(this);
|
||||
loadItems();
|
||||
}
|
||||
|
@ -92,7 +89,6 @@ public class PlaybackHistoryFragment extends ListFragment {
|
|||
public void onStop() {
|
||||
super.onStop();
|
||||
EventBus.getDefault().unregister(this);
|
||||
EventDistributor.getInstance().unregister(contentUpdate);
|
||||
if (disposable != null) {
|
||||
disposable.dispose();
|
||||
}
|
||||
|
@ -172,16 +168,11 @@ public class PlaybackHistoryFragment extends ListFragment {
|
|||
getActivity().supportInvalidateOptionsMenu();
|
||||
}
|
||||
|
||||
private final EventDistributor.EventListener contentUpdate = new EventDistributor.EventListener() {
|
||||
|
||||
@Override
|
||||
public void update(EventDistributor eventDistributor, Integer arg) {
|
||||
if ((arg & EVENTS) != 0) {
|
||||
loadItems();
|
||||
getActivity().supportInvalidateOptionsMenu();
|
||||
}
|
||||
}
|
||||
};
|
||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||
public void onPlayerStatusChanged(PlayerStatusEvent event) {
|
||||
loadItems();
|
||||
getActivity().supportInvalidateOptionsMenu();
|
||||
}
|
||||
|
||||
private void onFragmentLoaded() {
|
||||
adapter.notifyDataSetChanged();
|
||||
|
|
|
@ -27,6 +27,7 @@ import android.widget.TextView;
|
|||
import com.yqritc.recyclerviewflexibledivider.HorizontalDividerItemDecoration;
|
||||
|
||||
import de.danoeh.antennapod.core.event.PlaybackPositionEvent;
|
||||
import de.danoeh.antennapod.core.event.PlayerStatusEvent;
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
import org.greenrobot.eventbus.Subscribe;
|
||||
import org.greenrobot.eventbus.ThreadMode;
|
||||
|
@ -76,8 +77,7 @@ public class QueueFragment extends Fragment {
|
|||
|
||||
public static final String TAG = "QueueFragment";
|
||||
|
||||
private static final int EVENTS = EventDistributor.UNREAD_ITEMS_UPDATE // sent when playback position is reset
|
||||
| EventDistributor.PLAYER_STATUS_UPDATE;
|
||||
private static final int EVENTS = EventDistributor.UNREAD_ITEMS_UPDATE; // sent when playback position is reset
|
||||
|
||||
private TextView infoBar;
|
||||
private RecyclerView recyclerView;
|
||||
|
@ -221,6 +221,14 @@ public class QueueFragment extends Fragment {
|
|||
}
|
||||
}
|
||||
|
||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||
public void onPlayerStatusChanged(PlayerStatusEvent event) {
|
||||
loadItems(false);
|
||||
if (isUpdatingFeeds != updateRefreshMenuItemChecker.isRefreshing()) {
|
||||
getActivity().supportInvalidateOptionsMenu();
|
||||
}
|
||||
}
|
||||
|
||||
private void saveScrollPosition() {
|
||||
int firstItem = layoutManager.findFirstVisibleItemPosition();
|
||||
View firstItemView = layoutManager.findViewByPosition(firstItem);
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
package de.danoeh.antennapod.core.event;
|
||||
|
||||
public class PlayerStatusEvent {
|
||||
public PlayerStatusEvent() {
|
||||
}
|
||||
}
|
|
@ -22,7 +22,6 @@ public class EventDistributor extends Observable {
|
|||
|
||||
public static final int FEED_LIST_UPDATE = 1;
|
||||
public static final int UNREAD_ITEMS_UPDATE = 2;
|
||||
public static final int PLAYER_STATUS_UPDATE = 128;
|
||||
|
||||
private final Handler handler;
|
||||
private final AbstractQueue<Integer> events;
|
||||
|
@ -83,8 +82,6 @@ public class EventDistributor extends Observable {
|
|||
addEvent(FEED_LIST_UPDATE);
|
||||
}
|
||||
|
||||
public void sendPlayerStatusUpdateBroadcast() { addEvent(PLAYER_STATUS_UPDATE); }
|
||||
|
||||
public abstract static class EventListener implements Observer {
|
||||
|
||||
@Override
|
||||
|
|
|
@ -5,11 +5,13 @@ import android.content.SharedPreferences;
|
|||
import android.preference.PreferenceManager;
|
||||
|
||||
import android.util.Log;
|
||||
import de.danoeh.antennapod.core.event.PlayerStatusEvent;
|
||||
import de.danoeh.antennapod.core.feed.EventDistributor;
|
||||
import de.danoeh.antennapod.core.feed.FeedMedia;
|
||||
import de.danoeh.antennapod.core.feed.MediaType;
|
||||
import de.danoeh.antennapod.core.service.playback.PlayerStatus;
|
||||
import de.danoeh.antennapod.core.util.playback.Playable;
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
|
||||
import static de.danoeh.antennapod.core.feed.FeedPreferences.SPEED_USE_GLOBAL;
|
||||
|
||||
|
@ -97,7 +99,7 @@ public class PlaybackPreferences implements SharedPreferences.OnSharedPreference
|
|||
|
||||
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
|
||||
if (key.equals(PREF_CURRENT_PLAYER_STATUS)) {
|
||||
EventDistributor.getInstance().sendPlayerStatusUpdateBroadcast();
|
||||
EventBus.getDefault().post(new PlayerStatusEvent());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue