diff options
author | Martin Fietz <Martin.Fietz@gmail.com> | 2016-06-05 12:28:11 +0200 |
---|---|---|
committer | Martin Fietz <Martin.Fietz@gmail.com> | 2016-06-06 16:29:51 +0200 |
commit | f469350497184c9558e338d9dad25c953b6cbba3 (patch) | |
tree | 0ca062c28478cba59e3e1165407901ce162f9ade /app/src | |
parent | 6cebc0c2769f54be68a3bbd0aa1928695bf1ae62 (diff) | |
download | AntennaPod-f469350497184c9558e338d9dad25c953b6cbba3.zip |
Prevent possible hang-bugs
Diffstat (limited to 'app/src')
11 files changed, 62 insertions, 9 deletions
diff --git a/app/src/free/java/de/danoeh/antennapod/fragment/ItemFragment.java b/app/src/free/java/de/danoeh/antennapod/fragment/ItemFragment.java index 2b2808adc..0e11a5a17 100644 --- a/app/src/free/java/de/danoeh/antennapod/fragment/ItemFragment.java +++ b/app/src/free/java/de/danoeh/antennapod/fragment/ItemFragment.java @@ -58,6 +58,7 @@ import de.danoeh.antennapod.core.storage.DownloadRequester; import de.danoeh.antennapod.core.util.Converter; import de.danoeh.antennapod.core.util.DateUtils; import de.danoeh.antennapod.core.util.IntentUtils; +import de.danoeh.antennapod.core.util.LongList; import de.danoeh.antennapod.core.util.ShareUtils; import de.danoeh.antennapod.core.util.playback.Timeline; import de.danoeh.antennapod.menuhandler.FeedItemMenuHandler; @@ -219,7 +220,8 @@ public class ItemFragment extends Fragment implements OnSwipeGesture { return; } DefaultActionButtonCallback actionButtonCallback = new DefaultActionButtonCallback(getActivity()); - actionButtonCallback.onActionButtonPressed(item); + actionButtonCallback.onActionButtonPressed(item, item.isTagged(FeedItem.TAG_QUEUE) ? + LongList.of(item.getId()) : new LongList(0)); FeedMedia media = item.getMedia(); if (media != null && media.isDownloaded()) { // playback was started, dialog should close itself diff --git a/app/src/main/java/de/danoeh/antennapod/adapter/ActionButtonCallback.java b/app/src/main/java/de/danoeh/antennapod/adapter/ActionButtonCallback.java index 66e6f9a00..c18564351 100644 --- a/app/src/main/java/de/danoeh/antennapod/adapter/ActionButtonCallback.java +++ b/app/src/main/java/de/danoeh/antennapod/adapter/ActionButtonCallback.java @@ -1,8 +1,9 @@ package de.danoeh.antennapod.adapter; import de.danoeh.antennapod.core.feed.FeedItem; +import de.danoeh.antennapod.core.util.LongList; public interface ActionButtonCallback { /** Is called when the action button of a list item has been pressed. */ - void onActionButtonPressed(FeedItem item); + void onActionButtonPressed(FeedItem item, LongList queueIds); } diff --git a/app/src/main/java/de/danoeh/antennapod/adapter/AllEpisodesRecycleAdapter.java b/app/src/main/java/de/danoeh/antennapod/adapter/AllEpisodesRecycleAdapter.java index d961b548f..3e8bbc488 100644 --- a/app/src/main/java/de/danoeh/antennapod/adapter/AllEpisodesRecycleAdapter.java +++ b/app/src/main/java/de/danoeh/antennapod/adapter/AllEpisodesRecycleAdapter.java @@ -232,7 +232,7 @@ public class AllEpisodesRecycleAdapter extends RecyclerView.Adapter<AllEpisodesR @Override public void onClick(View v) { FeedItem item = (FeedItem) v.getTag(); - actionButtonCallback.onActionButtonPressed(item); + actionButtonCallback.onActionButtonPressed(item, itemAccess.getQueueIds()); } }; @@ -319,6 +319,8 @@ public class AllEpisodesRecycleAdapter extends RecyclerView.Adapter<AllEpisodesR boolean isInQueue(FeedItem item); + LongList getQueueIds(); + } /** diff --git a/app/src/main/java/de/danoeh/antennapod/adapter/DefaultActionButtonCallback.java b/app/src/main/java/de/danoeh/antennapod/adapter/DefaultActionButtonCallback.java index 00ab96f6c..4a53be9dc 100644 --- a/app/src/main/java/de/danoeh/antennapod/adapter/DefaultActionButtonCallback.java +++ b/app/src/main/java/de/danoeh/antennapod/adapter/DefaultActionButtonCallback.java @@ -51,13 +51,12 @@ public class DefaultActionButtonCallback implements ActionButtonCallback { } @Override - public void onActionButtonPressed(final FeedItem item) { + public void onActionButtonPressed(final FeedItem item, final LongList queueIds) { if (item.hasMedia()) { final FeedMedia media = item.getMedia(); boolean isDownloading = DownloadRequester.getInstance().isDownloadingFile(media); if (!isDownloading && !media.isDownloaded()) { - LongList queueIds = DBReader.getQueueIDList(); if (NetworkUtils.isDownloadAllowed() || userAllowedMobileDownloads()) { try { DBTasks.downloadFeedItems(context, item); diff --git a/app/src/main/java/de/danoeh/antennapod/adapter/FeedItemlistAdapter.java b/app/src/main/java/de/danoeh/antennapod/adapter/FeedItemlistAdapter.java index 4e9c5d71b..07847d0d1 100644 --- a/app/src/main/java/de/danoeh/antennapod/adapter/FeedItemlistAdapter.java +++ b/app/src/main/java/de/danoeh/antennapod/adapter/FeedItemlistAdapter.java @@ -26,6 +26,7 @@ import de.danoeh.antennapod.core.feed.MediaType; import de.danoeh.antennapod.core.preferences.UserPreferences; import de.danoeh.antennapod.core.storage.DownloadRequester; import de.danoeh.antennapod.core.util.DateUtils; +import de.danoeh.antennapod.core.util.LongList; import de.danoeh.antennapod.core.util.ThemeUtils; /** @@ -219,7 +220,7 @@ public class FeedItemlistAdapter extends BaseAdapter { @Override public void onClick(View v) { FeedItem item = (FeedItem) v.getTag(); - callback.onActionButtonPressed(item); + callback.onActionButtonPressed(item, itemAccess.getQueueIds()); } }; @@ -243,6 +244,8 @@ public class FeedItemlistAdapter extends BaseAdapter { FeedItem getItem(int position); + LongList getQueueIds(); + } } diff --git a/app/src/main/java/de/danoeh/antennapod/adapter/QueueRecyclerAdapter.java b/app/src/main/java/de/danoeh/antennapod/adapter/QueueRecyclerAdapter.java index bbd1e0959..c6ddc6c86 100644 --- a/app/src/main/java/de/danoeh/antennapod/adapter/QueueRecyclerAdapter.java +++ b/app/src/main/java/de/danoeh/antennapod/adapter/QueueRecyclerAdapter.java @@ -309,7 +309,7 @@ public class QueueRecyclerAdapter extends RecyclerView.Adapter<QueueRecyclerAdap @Override public void onClick(View v) { FeedItem item = (FeedItem) v.getTag(); - actionButtonCallback.onActionButtonPressed(item); + actionButtonCallback.onActionButtonPressed(item, itemAccess.getQueueIds()); } }; diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/AllEpisodesFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/AllEpisodesFragment.java index 8ae7f1cf9..c27e64807 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/AllEpisodesFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/AllEpisodesFragment.java @@ -378,6 +378,20 @@ public class AllEpisodesFragment extends Fragment { return item != null && item.isTagged(FeedItem.TAG_QUEUE); } + @Override + public LongList getQueueIds() { + LongList queueIds = new LongList(); + if(episodes == null) { + return queueIds; + } + for(FeedItem item : episodes) { + if(item.isTagged(FeedItem.TAG_QUEUE)) { + queueIds.add(item.getId()); + } + } + return queueIds; + } + }; public void onEventMainThread(FeedItemEvent event) { diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/ItemlistFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/ItemlistFragment.java index dd6212b74..509f8b6de 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/ItemlistFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/ItemlistFragment.java @@ -64,6 +64,7 @@ import de.danoeh.antennapod.core.storage.DBTasks; import de.danoeh.antennapod.core.storage.DownloadRequestException; import de.danoeh.antennapod.core.storage.DownloadRequester; import de.danoeh.antennapod.core.util.FeedItemUtil; +import de.danoeh.antennapod.core.util.LongList; import de.danoeh.antennapod.core.util.gui.MoreContentListFooterUtil; import de.danoeh.antennapod.dialog.EpisodesApplyActionFragment; import de.danoeh.antennapod.menuhandler.FeedItemMenuHandler; @@ -578,6 +579,20 @@ public class ItemlistFragment extends ListFragment { } @Override + public LongList getQueueIds() { + LongList queueIds = new LongList(); + if(feed == null) { + return queueIds; + } + for(FeedItem item : feed.getItems()) { + if(item.isTagged(FeedItem.TAG_QUEUE)) { + queueIds.add(item.getId()); + } + } + return queueIds; + } + + @Override public int getCount() { return (feed != null) ? feed.getNumOfItems() : 0; } diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/PlaybackHistoryFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/PlaybackHistoryFragment.java index 49c68c732..8d40b23d6 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/PlaybackHistoryFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/PlaybackHistoryFragment.java @@ -28,6 +28,7 @@ import de.danoeh.antennapod.core.service.download.Downloader; import de.danoeh.antennapod.core.storage.DBReader; import de.danoeh.antennapod.core.storage.DBWriter; import de.danoeh.antennapod.core.util.FeedItemUtil; +import de.danoeh.antennapod.core.util.LongList; import de.greenrobot.event.EventBus; import rx.Observable; import rx.Subscription; @@ -251,6 +252,20 @@ public class PlaybackHistoryFragment extends ListFragment { return null; } } + + @Override + public LongList getQueueIds() { + LongList queueIds = new LongList(); + if(playbackHistory == null) { + return queueIds; + } + for (FeedItem item : playbackHistory) { + if (item.isTagged(FeedItem.TAG_QUEUE)) { + queueIds.add(item.getId()); + } + } + return queueIds; + } }; private void loadItems() { diff --git a/app/src/play/java/de/danoeh/antennapod/activity/MainActivity.java b/app/src/play/java/de/danoeh/antennapod/activity/MainActivity.java index b7c7d86c7..17965ca8e 100644 --- a/app/src/play/java/de/danoeh/antennapod/activity/MainActivity.java +++ b/app/src/play/java/de/danoeh/antennapod/activity/MainActivity.java @@ -209,7 +209,7 @@ public class MainActivity extends CastEnabledActivity implements NavDrawerActivi } else { edit.remove(PREF_LAST_FRAGMENT_TAG); } - edit.commit(); + edit.apply(); } private String getLastNavFragment() { diff --git a/app/src/play/java/de/danoeh/antennapod/fragment/ItemFragment.java b/app/src/play/java/de/danoeh/antennapod/fragment/ItemFragment.java index 798e6c198..524b78ed2 100644 --- a/app/src/play/java/de/danoeh/antennapod/fragment/ItemFragment.java +++ b/app/src/play/java/de/danoeh/antennapod/fragment/ItemFragment.java @@ -59,6 +59,7 @@ import de.danoeh.antennapod.core.storage.DownloadRequester; import de.danoeh.antennapod.core.util.Converter; import de.danoeh.antennapod.core.util.DateUtils; import de.danoeh.antennapod.core.util.IntentUtils; +import de.danoeh.antennapod.core.util.LongList; import de.danoeh.antennapod.core.util.ShareUtils; import de.danoeh.antennapod.core.util.playback.Timeline; import de.danoeh.antennapod.menuhandler.FeedItemMenuHandler; @@ -220,7 +221,8 @@ public class ItemFragment extends Fragment implements OnSwipeGesture { return; } DefaultActionButtonCallback actionButtonCallback = new DefaultActionButtonCallback(getActivity()); - actionButtonCallback.onActionButtonPressed(item); + actionButtonCallback.onActionButtonPressed(item, item.isTagged(FeedItem.TAG_QUEUE) ? + LongList.of(item.getId()) : new LongList(0)); FeedMedia media = item.getMedia(); if (media != null && media.isDownloaded()) { // playback was started, dialog should close itself |