Prevent possible hang-bugs

This commit is contained in:
Martin Fietz 2016-06-05 12:28:11 +02:00
parent 6cebc0c276
commit f469350497
11 changed files with 62 additions and 9 deletions

View File

@ -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

View File

@ -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);
}

View File

@ -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();
}
/**

View File

@ -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);

View File

@ -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();
}
}

View File

@ -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());
}
};

View File

@ -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) {

View File

@ -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;
@ -577,6 +578,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;

View File

@ -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() {

View File

@ -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() {

View File

@ -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