diff options
author | Martin Fietz <marf@hadiko-99-4.hadiko.uni-karlsruhe.de> | 2015-05-03 21:19:20 +0200 |
---|---|---|
committer | Martin Fietz <marf@hadiko-99-4.hadiko.uni-karlsruhe.de> | 2015-05-03 21:19:20 +0200 |
commit | a766977e6dcb60a537922118185f723ef3e873c6 (patch) | |
tree | 6e50aa9ce1e429dfa38cfa3b1ec299f50890770a /app/src/main/java/de/danoeh/antennapod/adapter | |
parent | fd7cdd3c715565b621cb7ba2f485dd1bad696044 (diff) | |
download | AntennaPod-a766977e6dcb60a537922118185f723ef3e873c6.zip |
Check if items are already in the queue
Diffstat (limited to 'app/src/main/java/de/danoeh/antennapod/adapter')
-rw-r--r-- | app/src/main/java/de/danoeh/antennapod/adapter/ActionButtonUtils.java | 40 | ||||
-rw-r--r-- | app/src/main/java/de/danoeh/antennapod/adapter/DefaultActionButtonCallback.java | 55 |
2 files changed, 65 insertions, 30 deletions
diff --git a/app/src/main/java/de/danoeh/antennapod/adapter/ActionButtonUtils.java b/app/src/main/java/de/danoeh/antennapod/adapter/ActionButtonUtils.java index 8d3e73429..8e347a819 100644 --- a/app/src/main/java/de/danoeh/antennapod/adapter/ActionButtonUtils.java +++ b/app/src/main/java/de/danoeh/antennapod/adapter/ActionButtonUtils.java @@ -10,7 +10,9 @@ import org.apache.commons.lang3.Validate; import de.danoeh.antennapod.R; import de.danoeh.antennapod.core.feed.FeedItem; import de.danoeh.antennapod.core.feed.FeedMedia; +import de.danoeh.antennapod.core.storage.DBReader; import de.danoeh.antennapod.core.storage.DownloadRequester; +import de.danoeh.antennapod.core.util.LongList; /** * Utility methods for the action button that is displayed on the right hand side @@ -26,9 +28,21 @@ public class ActionButtonUtils { Validate.notNull(context); this.context = context; - drawables = context.obtainStyledAttributes(new int[]{ - R.attr.av_play, R.attr.navigation_cancel, R.attr.av_download, R.attr.av_pause, R.attr.navigation_accept}); - labels = new int[]{R.string.play_label, R.string.cancel_download_label, R.string.download_label, R.string.mark_read_label}; + drawables = context.obtainStyledAttributes(new int[] { + R.attr.av_play, + R.attr.navigation_cancel, + R.attr.av_download, + R.attr.av_pause, + R.attr.navigation_accept, + R.attr.content_new + }); + labels = new int[] { + R.string.play_label, + R.string.cancel_download_label, + R.string.download_label, + R.string.mark_read_label, + R.string.add_to_queue_label + }; } /** @@ -50,18 +64,26 @@ public class ActionButtonUtils { butSecondary.setContentDescription(context.getString(labels[1])); } else { // item is not downloaded and not being downloaded - butSecondary.setVisibility(View.VISIBLE); - butSecondary.setImageDrawable(drawables.getDrawable(2)); - butSecondary.setContentDescription(context.getString(labels[2])); + LongList queueIds = DBReader.getQueueIDList(context); + if(DefaultActionButtonCallback.userAllowedMobileDownloads() || + !DefaultActionButtonCallback.userChoseAddToQueue() || queueIds.contains(item.getId())) { + butSecondary.setVisibility(View.VISIBLE); + butSecondary.setImageDrawable(drawables.getDrawable(2)); + butSecondary.setContentDescription(context.getString(labels[2])); + } else { + // mobile download not allowed yet, item is not in queue and user chose add to queue + butSecondary.setVisibility(View.VISIBLE); + butSecondary.setImageDrawable(drawables.getDrawable(5)); + butSecondary.setContentDescription(context.getString(labels[4])); + } } } else { - // item is not being downloaded + // item is downloaded butSecondary.setVisibility(View.VISIBLE); if (media.isCurrentlyPlaying()) { butSecondary.setImageDrawable(drawables.getDrawable(3)); } else { - butSecondary - .setImageDrawable(drawables.getDrawable(0)); + butSecondary.setImageDrawable(drawables.getDrawable(0)); } butSecondary.setContentDescription(context.getString(labels[0])); } 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 20f07f71c..6df18e759 100644 --- a/app/src/main/java/de/danoeh/antennapod/adapter/DefaultActionButtonCallback.java +++ b/app/src/main/java/de/danoeh/antennapod/adapter/DefaultActionButtonCallback.java @@ -14,12 +14,13 @@ import de.danoeh.antennapod.core.feed.FeedItem; import de.danoeh.antennapod.core.feed.FeedMedia; import de.danoeh.antennapod.core.gpoddernet.model.GpodnetEpisodeAction; import de.danoeh.antennapod.core.preferences.GpodnetPreferences; -import de.danoeh.antennapod.core.preferences.UserPreferences; import de.danoeh.antennapod.core.service.playback.PlaybackService; +import de.danoeh.antennapod.core.storage.DBReader; import de.danoeh.antennapod.core.storage.DBTasks; import de.danoeh.antennapod.core.storage.DBWriter; import de.danoeh.antennapod.core.storage.DownloadRequestException; import de.danoeh.antennapod.core.storage.DownloadRequester; +import de.danoeh.antennapod.core.util.LongList; import de.danoeh.antennapod.core.util.NetworkUtils; /** @@ -31,7 +32,7 @@ public class DefaultActionButtonCallback implements ActionButtonCallback { private final Context context; - private final int TEN_MINUTES_IN_MILLIS = 60 * 1000 * 10; + private static final int TEN_MINUTES_IN_MILLIS = 60 * 1000 * 10; // remember timestamp when user allowed downloading via mobile connection private static long allowMobileDownloadsTimestamp; @@ -42,6 +43,14 @@ public class DefaultActionButtonCallback implements ActionButtonCallback { this.context = context; } + public static boolean userAllowedMobileDownloads() { + return System.currentTimeMillis() - allowMobileDownloadsTimestamp < TEN_MINUTES_IN_MILLIS; + } + + public static boolean userChoseAddToQueue() { + return System.currentTimeMillis() - onlyAddToQueueTimeStamp < TEN_MINUTES_IN_MILLIS; + } + @Override public void onActionButtonPressed(final FeedItem item) { @@ -49,8 +58,8 @@ public class DefaultActionButtonCallback implements ActionButtonCallback { final FeedMedia media = item.getMedia(); boolean isDownloading = DownloadRequester.getInstance().isDownloadingFile(media); if (!isDownloading && !media.isDownloaded()) { - if (UserPreferences.isAllowMobileUpdate() || NetworkUtils.connectedToWifi(context) || - (System.currentTimeMillis()-allowMobileDownloadsTimestamp) < TEN_MINUTES_IN_MILLIS) { + LongList queueIds = DBReader.getQueueIDList(context); + if (NetworkUtils.isDownloadAllowed(context) || userAllowedMobileDownloads()) { try { DBTasks.downloadFeedItems(context, item); Toast.makeText(context, R.string.status_downloading_label, Toast.LENGTH_SHORT).show(); @@ -58,13 +67,11 @@ public class DefaultActionButtonCallback implements ActionButtonCallback { e.printStackTrace(); DownloadRequestErrorDialogCreator.newRequestErrorDialog(context, e.getMessage()); } + } else if(userChoseAddToQueue() && !queueIds.contains(item.getId())) { + DBWriter.addQueueItem(context, item.getId()); + Toast.makeText(context, R.string.added_to_queue_label, Toast.LENGTH_SHORT).show(); } else { - if(System.currentTimeMillis() - onlyAddToQueueTimeStamp < TEN_MINUTES_IN_MILLIS) { - DBWriter.addQueueItem(context, item.getId()); - Toast.makeText(context, R.string.added_to_queue_label, Toast.LENGTH_SHORT).show(); - } else { - confirmMobileDownload(context, item); - } + confirmMobileDownload(context, item); } } else if (isDownloading) { DownloadRequester.getInstance().cancelDownload(context, media); @@ -118,17 +125,23 @@ public class DefaultActionButtonCallback implements ActionButtonCallback { DownloadRequestErrorDialogCreator.newRequestErrorDialog(context, e.getMessage()); } } - }) - .setNeutralButton(R.string.confirm_mobile_download_dialog_only_add_to_queue, - new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - onlyAddToQueueTimeStamp = System.currentTimeMillis(); - DBWriter.addQueueItem(context, item.getId()); - Toast.makeText(context, R.string.added_to_queue_label, Toast.LENGTH_SHORT).show(); - } - }) - .setNegativeButton(R.string.cancel_label, null) + }); + LongList queueIds = DBReader.getQueueIDList(context); + if(!queueIds.contains(item.getId())) { + builder.setNeutralButton(R.string.confirm_mobile_download_dialog_only_add_to_queue, + new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + onlyAddToQueueTimeStamp = System.currentTimeMillis(); + DBWriter.addQueueItem(context, item.getId()); + Toast.makeText(context, R.string.added_to_queue_label, Toast.LENGTH_SHORT).show(); + } + }) + .setMessage(context.getText(R.string.confirm_mobile_download_dialog_message_not_in_queue)); + } else { + builder.setMessage(context.getText(R.string.confirm_mobile_download_dialog_message)); + } + builder.setNegativeButton(R.string.cancel_label, null) .create() .show(); } |