Migrated feed list update event to EventBus
This commit is contained in:
parent
d4b9d0fd59
commit
728ed23077
|
@ -4,6 +4,7 @@ import android.content.Context;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
|
import de.danoeh.antennapod.core.event.FeedListUpdateEvent;
|
||||||
import org.apache.commons.io.FileUtils;
|
import org.apache.commons.io.FileUtils;
|
||||||
import org.apache.commons.io.IOUtils;
|
import org.apache.commons.io.IOUtils;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
@ -201,7 +202,7 @@ public class UITestUtils {
|
||||||
adapter.setCompleteFeed(hostedFeeds.toArray(new Feed[hostedFeeds.size()]));
|
adapter.setCompleteFeed(hostedFeeds.toArray(new Feed[hostedFeeds.size()]));
|
||||||
adapter.setQueue(queue);
|
adapter.setQueue(queue);
|
||||||
adapter.close();
|
adapter.close();
|
||||||
EventDistributor.getInstance().sendFeedUpdateBroadcast();
|
EventBus.getDefault().post(new FeedListUpdateEvent());
|
||||||
EventBus.getDefault().post(QueueEvent.setQueue(queue));
|
EventBus.getDefault().post(QueueEvent.setQueue(queue));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -34,6 +34,7 @@ import android.widget.Toast;
|
||||||
|
|
||||||
import com.bumptech.glide.Glide;
|
import com.bumptech.glide.Glide;
|
||||||
|
|
||||||
|
import de.danoeh.antennapod.core.event.FeedListUpdateEvent;
|
||||||
import de.danoeh.antennapod.core.event.UnreadItemsUpdateEvent;
|
import de.danoeh.antennapod.core.event.UnreadItemsUpdateEvent;
|
||||||
import org.apache.commons.lang3.ArrayUtils;
|
import org.apache.commons.lang3.ArrayUtils;
|
||||||
import org.apache.commons.lang3.Validate;
|
import org.apache.commons.lang3.Validate;
|
||||||
|
@ -85,8 +86,6 @@ public class MainActivity extends CastEnabledActivity implements NavDrawerActivi
|
||||||
|
|
||||||
private static final String TAG = "MainActivity";
|
private static final String TAG = "MainActivity";
|
||||||
|
|
||||||
private static final int EVENTS = EventDistributor.FEED_LIST_UPDATE;
|
|
||||||
|
|
||||||
public static final String PREF_NAME = "MainActivityPrefs";
|
public static final String PREF_NAME = "MainActivityPrefs";
|
||||||
public static final String PREF_IS_FIRST_LAUNCH = "prefMainActivityIsFirstLaunch";
|
public static final String PREF_IS_FIRST_LAUNCH = "prefMainActivityIsFirstLaunch";
|
||||||
public static final String PREF_LAST_FRAGMENT_TAG = "prefMainActivityLastFragmentTag";
|
public static final String PREF_LAST_FRAGMENT_TAG = "prefMainActivityLastFragmentTag";
|
||||||
|
@ -490,7 +489,6 @@ public class MainActivity extends CastEnabledActivity implements NavDrawerActivi
|
||||||
@Override
|
@Override
|
||||||
public void onStart() {
|
public void onStart() {
|
||||||
super.onStart();
|
super.onStart();
|
||||||
EventDistributor.getInstance().register(contentUpdate);
|
|
||||||
EventBus.getDefault().register(this);
|
EventBus.getDefault().register(this);
|
||||||
RatingDialog.init(this);
|
RatingDialog.init(this);
|
||||||
}
|
}
|
||||||
|
@ -518,7 +516,6 @@ public class MainActivity extends CastEnabledActivity implements NavDrawerActivi
|
||||||
@Override
|
@Override
|
||||||
protected void onStop() {
|
protected void onStop() {
|
||||||
super.onStop();
|
super.onStop();
|
||||||
EventDistributor.getInstance().unregister(contentUpdate);
|
|
||||||
EventBus.getDefault().unregister(this);
|
EventBus.getDefault().unregister(this);
|
||||||
if (disposable != null) {
|
if (disposable != null) {
|
||||||
disposable.dispose();
|
disposable.dispose();
|
||||||
|
@ -822,16 +819,11 @@ public class MainActivity extends CastEnabledActivity implements NavDrawerActivi
|
||||||
loadData();
|
loadData();
|
||||||
}
|
}
|
||||||
|
|
||||||
private final EventDistributor.EventListener contentUpdate = new EventDistributor.EventListener() {
|
|
||||||
|
|
||||||
@Override
|
@Subscribe
|
||||||
public void update(EventDistributor eventDistributor, Integer arg) {
|
public void onFeedListChanged(FeedListUpdateEvent event) {
|
||||||
if ((EVENTS & arg) != 0) {
|
|
||||||
Log.d(TAG, "Received contentUpdate Intent.");
|
|
||||||
loadData();
|
loadData();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
private void handleNavIntent() {
|
private void handleNavIntent() {
|
||||||
Log.d(TAG, "handleNavIntent()");
|
Log.d(TAG, "handleNavIntent()");
|
||||||
|
|
|
@ -36,6 +36,7 @@ import de.danoeh.antennapod.R;
|
||||||
import de.danoeh.antennapod.adapter.NavListAdapter;
|
import de.danoeh.antennapod.adapter.NavListAdapter;
|
||||||
import de.danoeh.antennapod.core.asynctask.FeedRemover;
|
import de.danoeh.antennapod.core.asynctask.FeedRemover;
|
||||||
import de.danoeh.antennapod.core.dialog.ConfirmationDialog;
|
import de.danoeh.antennapod.core.dialog.ConfirmationDialog;
|
||||||
|
import de.danoeh.antennapod.core.event.FeedListUpdateEvent;
|
||||||
import de.danoeh.antennapod.core.event.MessageEvent;
|
import de.danoeh.antennapod.core.event.MessageEvent;
|
||||||
import de.danoeh.antennapod.core.feed.EventDistributor;
|
import de.danoeh.antennapod.core.feed.EventDistributor;
|
||||||
import de.danoeh.antennapod.core.feed.Feed;
|
import de.danoeh.antennapod.core.feed.Feed;
|
||||||
|
@ -119,7 +120,6 @@ public abstract class MediaplayerInfoActivity extends MediaplayerActivity implem
|
||||||
if (disposable != null) {
|
if (disposable != null) {
|
||||||
disposable.dispose();
|
disposable.dispose();
|
||||||
}
|
}
|
||||||
EventDistributor.getInstance().unregister(contentUpdate);
|
|
||||||
saveCurrentFragment();
|
saveCurrentFragment();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -171,7 +171,6 @@ public abstract class MediaplayerInfoActivity extends MediaplayerActivity implem
|
||||||
@Override
|
@Override
|
||||||
protected void onStart() {
|
protected void onStart() {
|
||||||
super.onStart();
|
super.onStart();
|
||||||
EventDistributor.getInstance().register(contentUpdate);
|
|
||||||
loadData();
|
loadData();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -445,16 +444,10 @@ public abstract class MediaplayerInfoActivity extends MediaplayerActivity implem
|
||||||
snackbar.show();
|
snackbar.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
private final EventDistributor.EventListener contentUpdate = new EventDistributor.EventListener() {
|
@Subscribe
|
||||||
|
public void onFeedListChanged(FeedListUpdateEvent event) {
|
||||||
@Override
|
|
||||||
public void update(EventDistributor eventDistributor, Integer arg) {
|
|
||||||
if ((EventDistributor.FEED_LIST_UPDATE & arg) != 0) {
|
|
||||||
Log.d(TAG, "Received contentUpdate Intent.");
|
|
||||||
loadData();
|
loadData();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
private final NavListAdapter.ItemAccess itemAccess = new NavListAdapter.ItemAccess() {
|
private final NavListAdapter.ItemAccess itemAccess = new NavListAdapter.ItemAccess() {
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -32,6 +32,7 @@ import android.widget.TextView;
|
||||||
import com.bumptech.glide.Glide;
|
import com.bumptech.glide.Glide;
|
||||||
import com.bumptech.glide.request.RequestOptions;
|
import com.bumptech.glide.request.RequestOptions;
|
||||||
|
|
||||||
|
import de.danoeh.antennapod.core.event.FeedListUpdateEvent;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.greenrobot.eventbus.EventBus;
|
import org.greenrobot.eventbus.EventBus;
|
||||||
import org.greenrobot.eventbus.Subscribe;
|
import org.greenrobot.eventbus.Subscribe;
|
||||||
|
@ -94,7 +95,6 @@ public class OnlineFeedViewActivity extends AppCompatActivity {
|
||||||
public static final String ARG_TITLE = "title";
|
public static final String ARG_TITLE = "title";
|
||||||
private static final int RESULT_ERROR = 2;
|
private static final int RESULT_ERROR = 2;
|
||||||
private static final String TAG = "OnlineFeedViewActivity";
|
private static final String TAG = "OnlineFeedViewActivity";
|
||||||
private static final int EVENTS = EventDistributor.FEED_LIST_UPDATE;
|
|
||||||
private volatile List<Feed> feeds;
|
private volatile List<Feed> feeds;
|
||||||
private Feed feed;
|
private Feed feed;
|
||||||
private String selectedDownloadUrl;
|
private String selectedDownloadUrl;
|
||||||
|
@ -109,30 +109,6 @@ public class OnlineFeedViewActivity extends AppCompatActivity {
|
||||||
private Disposable download;
|
private Disposable download;
|
||||||
private Disposable parser;
|
private Disposable parser;
|
||||||
private Disposable updater;
|
private Disposable updater;
|
||||||
private final EventDistributor.EventListener listener = new EventDistributor.EventListener() {
|
|
||||||
@Override
|
|
||||||
public void update(EventDistributor eventDistributor, Integer arg) {
|
|
||||||
if ((arg & EventDistributor.FEED_LIST_UPDATE) != 0) {
|
|
||||||
updater = Observable.fromCallable(DBReader::getFeedList)
|
|
||||||
.subscribeOn(Schedulers.io())
|
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
|
||||||
.subscribe(
|
|
||||||
feeds -> {
|
|
||||||
OnlineFeedViewActivity.this.feeds = feeds;
|
|
||||||
setSubscribeButtonState(feed);
|
|
||||||
}, error -> Log.e(TAG, Log.getStackTraceString(error))
|
|
||||||
);
|
|
||||||
} else if ((arg & EVENTS) != 0) {
|
|
||||||
setSubscribeButtonState(feed);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
|
||||||
public void onEventMainThread(DownloadEvent event) {
|
|
||||||
Log.d(TAG, "onEventMainThread() called with: " + "event = [" + event + "]");
|
|
||||||
setSubscribeButtonState(feed);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
@ -202,7 +178,6 @@ public class OnlineFeedViewActivity extends AppCompatActivity {
|
||||||
protected void onStart() {
|
protected void onStart() {
|
||||||
super.onStart();
|
super.onStart();
|
||||||
isPaused = false;
|
isPaused = false;
|
||||||
EventDistributor.getInstance().register(listener);
|
|
||||||
EventBus.getDefault().register(this);
|
EventBus.getDefault().register(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -210,7 +185,6 @@ public class OnlineFeedViewActivity extends AppCompatActivity {
|
||||||
protected void onStop() {
|
protected void onStop() {
|
||||||
super.onStop();
|
super.onStop();
|
||||||
isPaused = true;
|
isPaused = true;
|
||||||
EventDistributor.getInstance().unregister(listener);
|
|
||||||
EventBus.getDefault().unregister(this);
|
EventBus.getDefault().unregister(this);
|
||||||
if (downloader != null && !downloader.isFinished()) {
|
if (downloader != null && !downloader.isFinished()) {
|
||||||
downloader.cancel();
|
downloader.cancel();
|
||||||
|
@ -312,6 +286,25 @@ public class OnlineFeedViewActivity extends AppCompatActivity {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Subscribe
|
||||||
|
public void onFeedListChanged(FeedListUpdateEvent event) {
|
||||||
|
updater = Observable.fromCallable(DBReader::getFeedList)
|
||||||
|
.subscribeOn(Schedulers.io())
|
||||||
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
|
.subscribe(
|
||||||
|
feeds -> {
|
||||||
|
OnlineFeedViewActivity.this.feeds = feeds;
|
||||||
|
setSubscribeButtonState(feed);
|
||||||
|
}, error -> Log.e(TAG, Log.getStackTraceString(error))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||||
|
public void onEventMainThread(DownloadEvent event) {
|
||||||
|
Log.d(TAG, "onEventMainThread() called with: " + "event = [" + event + "]");
|
||||||
|
setSubscribeButtonState(feed);
|
||||||
|
}
|
||||||
|
|
||||||
private void parseFeed() {
|
private void parseFeed() {
|
||||||
if (feed == null || (feed.getFile_url() == null && feed.isDownloaded())) {
|
if (feed == null || (feed.getFile_url() == null && feed.isDownloaded())) {
|
||||||
throw new IllegalStateException("feed must be non-null and downloaded when parseFeed is called");
|
throw new IllegalStateException("feed must be non-null and downloaded when parseFeed is called");
|
||||||
|
@ -388,7 +381,6 @@ public class OnlineFeedViewActivity extends AppCompatActivity {
|
||||||
|
|
||||||
this.feed = feed;
|
this.feed = feed;
|
||||||
this.selectedDownloadUrl = feed.getDownload_url();
|
this.selectedDownloadUrl = feed.getDownload_url();
|
||||||
EventDistributor.getInstance().register(listener);
|
|
||||||
ListView listView = findViewById(R.id.listview);
|
ListView listView = findViewById(R.id.listview);
|
||||||
listView.setSelector(android.R.color.transparent);
|
listView.setSelector(android.R.color.transparent);
|
||||||
LayoutInflater inflater = LayoutInflater.from(this);
|
LayoutInflater inflater = LayoutInflater.from(this);
|
||||||
|
|
|
@ -25,6 +25,7 @@ import android.widget.Toast;
|
||||||
import com.yqritc.recyclerviewflexibledivider.HorizontalDividerItemDecoration;
|
import com.yqritc.recyclerviewflexibledivider.HorizontalDividerItemDecoration;
|
||||||
|
|
||||||
import de.danoeh.antennapod.core.event.DownloadLogEvent;
|
import de.danoeh.antennapod.core.event.DownloadLogEvent;
|
||||||
|
import de.danoeh.antennapod.core.event.FeedListUpdateEvent;
|
||||||
import de.danoeh.antennapod.core.event.PlaybackPositionEvent;
|
import de.danoeh.antennapod.core.event.PlaybackPositionEvent;
|
||||||
import de.danoeh.antennapod.core.event.PlayerStatusEvent;
|
import de.danoeh.antennapod.core.event.PlayerStatusEvent;
|
||||||
import de.danoeh.antennapod.core.event.UnreadItemsUpdateEvent;
|
import de.danoeh.antennapod.core.event.UnreadItemsUpdateEvent;
|
||||||
|
@ -67,9 +68,6 @@ import io.reactivex.schedulers.Schedulers;
|
||||||
public abstract class EpisodesListFragment extends Fragment {
|
public abstract class EpisodesListFragment extends Fragment {
|
||||||
|
|
||||||
public static final String TAG = "EpisodesListFragment";
|
public static final String TAG = "EpisodesListFragment";
|
||||||
|
|
||||||
private static final int EVENTS = EventDistributor.FEED_LIST_UPDATE;
|
|
||||||
|
|
||||||
private static final String DEFAULT_PREF_NAME = "PrefAllEpisodesFragment";
|
private static final String DEFAULT_PREF_NAME = "PrefAllEpisodesFragment";
|
||||||
private static final String PREF_SCROLL_POSITION = "scroll_position";
|
private static final String PREF_SCROLL_POSITION = "scroll_position";
|
||||||
private static final String PREF_SCROLL_OFFSET = "scroll_offset";
|
private static final String PREF_SCROLL_OFFSET = "scroll_offset";
|
||||||
|
@ -103,7 +101,6 @@ public abstract class EpisodesListFragment extends Fragment {
|
||||||
public void onStart() {
|
public void onStart() {
|
||||||
super.onStart();
|
super.onStart();
|
||||||
setHasOptionsMenu(true);
|
setHasOptionsMenu(true);
|
||||||
EventDistributor.getInstance().register(contentUpdate);
|
|
||||||
EventBus.getDefault().register(this);
|
EventBus.getDefault().register(this);
|
||||||
loadItems();
|
loadItems();
|
||||||
}
|
}
|
||||||
|
@ -125,7 +122,6 @@ public abstract class EpisodesListFragment extends Fragment {
|
||||||
public void onStop() {
|
public void onStop() {
|
||||||
super.onStop();
|
super.onStop();
|
||||||
EventBus.getDefault().unregister(this);
|
EventBus.getDefault().unregister(this);
|
||||||
EventDistributor.getInstance().unregister(contentUpdate);
|
|
||||||
if (disposable != null) {
|
if (disposable != null) {
|
||||||
disposable.dispose();
|
disposable.dispose();
|
||||||
}
|
}
|
||||||
|
@ -427,22 +423,15 @@ public abstract class EpisodesListFragment extends Fragment {
|
||||||
updateUi();
|
updateUi();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||||
public void onUnreadItemsChanged(UnreadItemsUpdateEvent event) {
|
public void onUnreadItemsChanged(UnreadItemsUpdateEvent event) {
|
||||||
updateUi();
|
updateUi();
|
||||||
}
|
}
|
||||||
|
|
||||||
private final EventDistributor.EventListener contentUpdate = new EventDistributor.EventListener() {
|
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||||
@Override
|
public void onFeedListChanged(FeedListUpdateEvent event) {
|
||||||
public void update(EventDistributor eventDistributor, Integer arg) {
|
updateUi();
|
||||||
if ((arg & EVENTS) != 0) {
|
|
||||||
loadItems();
|
|
||||||
if (isUpdatingFeeds != updateRefreshMenuItemChecker.isRefreshing()) {
|
|
||||||
requireActivity().invalidateOptionsMenu();
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
void loadItems() {
|
void loadItems() {
|
||||||
if (disposable != null) {
|
if (disposable != null) {
|
||||||
|
|
|
@ -28,6 +28,7 @@ import com.bumptech.glide.request.RequestOptions;
|
||||||
import com.joanzapata.iconify.Iconify;
|
import com.joanzapata.iconify.Iconify;
|
||||||
import com.joanzapata.iconify.widget.IconTextView;
|
import com.joanzapata.iconify.widget.IconTextView;
|
||||||
|
|
||||||
|
import de.danoeh.antennapod.core.event.FeedListUpdateEvent;
|
||||||
import de.danoeh.antennapod.core.event.PlaybackPositionEvent;
|
import de.danoeh.antennapod.core.event.PlaybackPositionEvent;
|
||||||
import de.danoeh.antennapod.core.event.PlayerStatusEvent;
|
import de.danoeh.antennapod.core.event.PlayerStatusEvent;
|
||||||
import de.danoeh.antennapod.core.event.UnreadItemsUpdateEvent;
|
import de.danoeh.antennapod.core.event.UnreadItemsUpdateEvent;
|
||||||
|
@ -81,9 +82,6 @@ import io.reactivex.schedulers.Schedulers;
|
||||||
@SuppressLint("ValidFragment")
|
@SuppressLint("ValidFragment")
|
||||||
public class FeedItemlistFragment extends ListFragment {
|
public class FeedItemlistFragment extends ListFragment {
|
||||||
private static final String TAG = "ItemlistFragment";
|
private static final String TAG = "ItemlistFragment";
|
||||||
|
|
||||||
private static final int EVENTS = EventDistributor.FEED_LIST_UPDATE;
|
|
||||||
|
|
||||||
private static final String ARGUMENT_FEED_ID = "argument.de.danoeh.antennapod.feed_id";
|
private static final String ARGUMENT_FEED_ID = "argument.de.danoeh.antennapod.feed_id";
|
||||||
|
|
||||||
private FeedItemlistAdapter adapter;
|
private FeedItemlistAdapter adapter;
|
||||||
|
@ -150,7 +148,6 @@ public class FeedItemlistFragment extends ListFragment {
|
||||||
|
|
||||||
registerForContextMenu(getListView());
|
registerForContextMenu(getListView());
|
||||||
|
|
||||||
EventDistributor.getInstance().register(contentUpdate);
|
|
||||||
EventBus.getDefault().register(this);
|
EventBus.getDefault().register(this);
|
||||||
loadItems();
|
loadItems();
|
||||||
}
|
}
|
||||||
|
@ -159,7 +156,6 @@ public class FeedItemlistFragment extends ListFragment {
|
||||||
public void onDestroyView() {
|
public void onDestroyView() {
|
||||||
super.onDestroyView();
|
super.onDestroyView();
|
||||||
|
|
||||||
EventDistributor.getInstance().unregister(contentUpdate);
|
|
||||||
EventBus.getDefault().unregister(this);
|
EventBus.getDefault().unregister(this);
|
||||||
if (disposable != null) {
|
if (disposable != null) {
|
||||||
disposable.dispose();
|
disposable.dispose();
|
||||||
|
@ -407,18 +403,10 @@ public class FeedItemlistFragment extends ListFragment {
|
||||||
updateUi();
|
updateUi();
|
||||||
}
|
}
|
||||||
|
|
||||||
private final EventDistributor.EventListener contentUpdate = new EventDistributor.EventListener() {
|
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||||
|
public void onFeedListChanged(FeedListUpdateEvent event) {
|
||||||
@Override
|
updateUi();
|
||||||
public void update(EventDistributor eventDistributor, Integer arg) {
|
|
||||||
if ((EVENTS & arg) != 0) {
|
|
||||||
Log.d(TAG, "Received contentUpdate Intent. arg " + arg);
|
|
||||||
refreshHeaderView();
|
|
||||||
loadItems();
|
|
||||||
updateProgressBarVisibility();
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
private void updateProgressBarVisibility() {
|
private void updateProgressBarVisibility() {
|
||||||
if (isUpdatingFeed != updateRefreshMenuItemChecker.isRefreshing()) {
|
if (isUpdatingFeed != updateRefreshMenuItemChecker.isRefreshing()) {
|
||||||
|
|
|
@ -28,6 +28,7 @@ import de.danoeh.antennapod.adapter.SubscriptionsAdapter;
|
||||||
import de.danoeh.antennapod.core.asynctask.FeedRemover;
|
import de.danoeh.antennapod.core.asynctask.FeedRemover;
|
||||||
import de.danoeh.antennapod.core.dialog.ConfirmationDialog;
|
import de.danoeh.antennapod.core.dialog.ConfirmationDialog;
|
||||||
import de.danoeh.antennapod.core.event.DownloadEvent;
|
import de.danoeh.antennapod.core.event.DownloadEvent;
|
||||||
|
import de.danoeh.antennapod.core.event.FeedListUpdateEvent;
|
||||||
import de.danoeh.antennapod.core.event.UnreadItemsUpdateEvent;
|
import de.danoeh.antennapod.core.event.UnreadItemsUpdateEvent;
|
||||||
import de.danoeh.antennapod.core.feed.EventDistributor;
|
import de.danoeh.antennapod.core.feed.EventDistributor;
|
||||||
import de.danoeh.antennapod.core.feed.Feed;
|
import de.danoeh.antennapod.core.feed.Feed;
|
||||||
|
@ -56,8 +57,6 @@ import org.greenrobot.eventbus.ThreadMode;
|
||||||
public class SubscriptionFragment extends Fragment {
|
public class SubscriptionFragment extends Fragment {
|
||||||
|
|
||||||
public static final String TAG = "SubscriptionFragment";
|
public static final String TAG = "SubscriptionFragment";
|
||||||
|
|
||||||
private static final int EVENTS = EventDistributor.FEED_LIST_UPDATE;
|
|
||||||
private static final String PREFS = "SubscriptionFragment";
|
private static final String PREFS = "SubscriptionFragment";
|
||||||
private static final String PREF_NUM_COLUMNS = "columns";
|
private static final String PREF_NUM_COLUMNS = "columns";
|
||||||
|
|
||||||
|
@ -159,7 +158,6 @@ public class SubscriptionFragment extends Fragment {
|
||||||
@Override
|
@Override
|
||||||
public void onStart() {
|
public void onStart() {
|
||||||
super.onStart();
|
super.onStart();
|
||||||
EventDistributor.getInstance().register(contentUpdate);
|
|
||||||
EventBus.getDefault().register(this);
|
EventBus.getDefault().register(this);
|
||||||
loadSubscriptions();
|
loadSubscriptions();
|
||||||
}
|
}
|
||||||
|
@ -167,7 +165,6 @@ public class SubscriptionFragment extends Fragment {
|
||||||
@Override
|
@Override
|
||||||
public void onStop() {
|
public void onStop() {
|
||||||
super.onStop();
|
super.onStop();
|
||||||
EventDistributor.getInstance().unregister(contentUpdate);
|
|
||||||
EventBus.getDefault().unregister(this);
|
EventBus.getDefault().unregister(this);
|
||||||
if(disposable != null) {
|
if(disposable != null) {
|
||||||
disposable.dispose();
|
disposable.dispose();
|
||||||
|
@ -294,15 +291,10 @@ public class SubscriptionFragment extends Fragment {
|
||||||
dialog.createNewDialog().show();
|
dialog.createNewDialog().show();
|
||||||
}
|
}
|
||||||
|
|
||||||
private final EventDistributor.EventListener contentUpdate = new EventDistributor.EventListener() {
|
@Subscribe
|
||||||
@Override
|
public void onFeedListChanged(FeedListUpdateEvent event) {
|
||||||
public void update(EventDistributor eventDistributor, Integer arg) {
|
|
||||||
if ((EVENTS & arg) != 0) {
|
|
||||||
Log.d(TAG, "Received contentUpdate Intent.");
|
|
||||||
loadSubscriptions();
|
loadSubscriptions();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onUnreadItemsChanged(UnreadItemsUpdateEvent event) {
|
public void onUnreadItemsChanged(UnreadItemsUpdateEvent event) {
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
package de.danoeh.antennapod.core.event;
|
||||||
|
|
||||||
|
public class FeedListUpdateEvent {
|
||||||
|
public FeedListUpdateEvent() {
|
||||||
|
}
|
||||||
|
}
|
|
@ -20,8 +20,6 @@ import java.util.concurrent.ConcurrentLinkedQueue;
|
||||||
public class EventDistributor extends Observable {
|
public class EventDistributor extends Observable {
|
||||||
private static final String TAG = "EventDistributor";
|
private static final String TAG = "EventDistributor";
|
||||||
|
|
||||||
public static final int FEED_LIST_UPDATE = 1;
|
|
||||||
|
|
||||||
private final Handler handler;
|
private final Handler handler;
|
||||||
private final AbstractQueue<Integer> events;
|
private final AbstractQueue<Integer> events;
|
||||||
|
|
||||||
|
@ -73,10 +71,6 @@ public class EventDistributor extends Observable {
|
||||||
super.addObserver(observer);
|
super.addObserver(observer);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendFeedUpdateBroadcast() {
|
|
||||||
addEvent(FEED_LIST_UPDATE);
|
|
||||||
}
|
|
||||||
|
|
||||||
public abstract static class EventListener implements Observer {
|
public abstract static class EventListener implements Observer {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -21,6 +21,7 @@ import java.util.concurrent.FutureTask;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
|
||||||
import de.danoeh.antennapod.core.ClientConfig;
|
import de.danoeh.antennapod.core.ClientConfig;
|
||||||
|
import de.danoeh.antennapod.core.event.FeedListUpdateEvent;
|
||||||
import de.danoeh.antennapod.core.feed.EventDistributor;
|
import de.danoeh.antennapod.core.feed.EventDistributor;
|
||||||
import de.danoeh.antennapod.core.feed.Feed;
|
import de.danoeh.antennapod.core.feed.Feed;
|
||||||
import de.danoeh.antennapod.core.feed.FeedItem;
|
import de.danoeh.antennapod.core.feed.FeedItem;
|
||||||
|
@ -35,6 +36,7 @@ import de.danoeh.antennapod.core.util.LongList;
|
||||||
import de.danoeh.antennapod.core.util.comparator.FeedItemPubdateComparator;
|
import de.danoeh.antennapod.core.util.comparator.FeedItemPubdateComparator;
|
||||||
import de.danoeh.antennapod.core.util.exception.MediaFileNotFoundException;
|
import de.danoeh.antennapod.core.util.exception.MediaFileNotFoundException;
|
||||||
import de.danoeh.antennapod.core.util.playback.PlaybackServiceStarter;
|
import de.danoeh.antennapod.core.util.playback.PlaybackServiceStarter;
|
||||||
|
import org.greenrobot.eventbus.EventBus;
|
||||||
|
|
||||||
import static android.content.Context.MODE_PRIVATE;
|
import static android.content.Context.MODE_PRIVATE;
|
||||||
|
|
||||||
|
@ -298,7 +300,7 @@ public final class DBTasks {
|
||||||
media.setDownloaded(false);
|
media.setDownloaded(false);
|
||||||
media.setFile_url(null);
|
media.setFile_url(null);
|
||||||
DBWriter.setFeedMedia(media);
|
DBWriter.setFeedMedia(media);
|
||||||
EventDistributor.getInstance().sendFeedUpdateBroadcast();
|
EventBus.getDefault().post(new FeedListUpdateEvent());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -563,7 +565,7 @@ public final class DBTasks {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
EventDistributor.getInstance().sendFeedUpdateBroadcast();
|
EventBus.getDefault().post(new FeedListUpdateEvent());
|
||||||
|
|
||||||
return resultFeeds;
|
return resultFeeds;
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@ import android.util.Log;
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
|
||||||
import de.danoeh.antennapod.core.event.DownloadLogEvent;
|
import de.danoeh.antennapod.core.event.DownloadLogEvent;
|
||||||
|
import de.danoeh.antennapod.core.event.FeedListUpdateEvent;
|
||||||
import de.danoeh.antennapod.core.event.PlaybackHistoryEvent;
|
import de.danoeh.antennapod.core.event.PlaybackHistoryEvent;
|
||||||
import de.danoeh.antennapod.core.event.UnreadItemsUpdateEvent;
|
import de.danoeh.antennapod.core.event.UnreadItemsUpdateEvent;
|
||||||
import org.greenrobot.eventbus.EventBus;
|
import org.greenrobot.eventbus.EventBus;
|
||||||
|
@ -174,7 +175,7 @@ public class DBWriter {
|
||||||
if (ClientConfig.gpodnetCallbacks.gpodnetEnabled()) {
|
if (ClientConfig.gpodnetCallbacks.gpodnetEnabled()) {
|
||||||
GpodnetPreferences.addRemovedFeed(feed.getDownload_url());
|
GpodnetPreferences.addRemovedFeed(feed.getDownload_url());
|
||||||
}
|
}
|
||||||
EventDistributor.getInstance().sendFeedUpdateBroadcast();
|
EventBus.getDefault().post(new FeedListUpdateEvent());
|
||||||
|
|
||||||
// we assume we also removed download log entries for the feed or its media files.
|
// we assume we also removed download log entries for the feed or its media files.
|
||||||
// especially important if download or refresh failed, as the user should not be able
|
// especially important if download or refresh failed, as the user should not be able
|
||||||
|
@ -804,7 +805,7 @@ public class DBWriter {
|
||||||
adapter.open();
|
adapter.open();
|
||||||
adapter.setFeedPreferences(preferences);
|
adapter.setFeedPreferences(preferences);
|
||||||
adapter.close();
|
adapter.close();
|
||||||
EventDistributor.getInstance().sendFeedUpdateBroadcast();
|
EventBus.getDefault().post(new FeedListUpdateEvent());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -843,7 +844,7 @@ public class DBWriter {
|
||||||
adapter.open();
|
adapter.open();
|
||||||
adapter.setFeedCustomTitle(feed.getId(), feed.getCustomTitle());
|
adapter.setFeedCustomTitle(feed.getId(), feed.getCustomTitle());
|
||||||
adapter.close();
|
adapter.close();
|
||||||
EventDistributor.getInstance().sendFeedUpdateBroadcast();
|
EventBus.getDefault().post(new FeedListUpdateEvent());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue