Auto-enqueue will now enqueue when the user starts the download

This commit is contained in:
daniel oeh 2012-09-21 13:31:54 +02:00
parent ea7b7bbb73
commit 81fbf3bcb6
4 changed files with 21 additions and 22 deletions

View File

@ -152,7 +152,7 @@
<string name="pref_revokeAccess_title">Revoke access</string>
<string name="pref_revokeAccess_sum">Revoke the access permission to your flattr account for this app.</string>
<string name="pref_autoQueue_title">Auto-enqueue</string>
<string name="pref_autoQueue_sum">Add an episode to the queue after it has been downloaded.</string>
<string name="pref_autoQueue_sum">Add an episode to the queue when you start to download it.</string>
<string name="pref_display_only_episodes_title">Display only episodes</string>
<string name="pref_display_only_episodes_sum">Display only items which also have an episode.</string>
<string name="user_interface_label">User Interface</string>

View File

@ -10,6 +10,7 @@ import java.util.concurrent.Executors;
import java.util.concurrent.ThreadFactory;
import de.danoeh.antennapod.AppConfig;
import de.danoeh.antennapod.PodcastApp;
import de.danoeh.antennapod.activity.AudioplayerActivity;
import de.danoeh.antennapod.asynctask.DownloadStatus;
import de.danoeh.antennapod.service.PlaybackService;
@ -25,6 +26,7 @@ import android.os.AsyncTask;
import android.os.Debug;
import android.os.Handler;
import android.os.Message;
import android.preference.PreferenceManager;
import android.util.Log;
/**
@ -368,14 +370,28 @@ public class FeedManager {
}
public void downloadAllItemsInQueue(final Context context) {
DownloadRequester requester = DownloadRequester.getInstance();
for (FeedItem item : queue) {
if (!queue.isEmpty()) {
downloadFeedItem(context, queue.toArray(new FeedItem[queue.size()]));
}
}
public void downloadFeedItem(final Context context, FeedItem... items) {
boolean autoQueue = PreferenceManager.getDefaultSharedPreferences(
context.getApplicationContext()).getBoolean(
PodcastApp.PREF_AUTO_QUEUE, true);
List<FeedItem> addToQueue = new ArrayList<FeedItem>();
for (FeedItem item : items) {
if (item.getMedia() != null
&& !requester.isDownloadingFile(item.getMedia())
&& !item.getMedia().isDownloaded()) {
requester.downloadMedia(context, item.getMedia());
addToQueue.add(item);
}
}
if (autoQueue) {
addQueueItem(context, addToQueue.toArray(new FeedItem[addToQueue.size()]));
}
}
public void enqueueAllNewItems(final Context context) {

View File

@ -694,24 +694,7 @@ public class DownloadService extends Service {
saveDownloadStatus(status);
sendDownloadHandledIntent(DOWNLOAD_TYPE_MEDIA);
manager.setFeedMedia(DownloadService.this, media);
boolean autoQueue = PreferenceManager.getDefaultSharedPreferences(
getApplicationContext()).getBoolean(
PodcastApp.PREF_AUTO_QUEUE, true);
if (!manager.isInQueue(media.getItem())) {
// Auto-queue
if (autoQueue) {
if (AppConfig.DEBUG)
Log.d(TAG, "Autoqueue is enabled. Adding item to queue");
manager.addQueueItem(DownloadService.this, media.getItem());
} else {
if (AppConfig.DEBUG)
Log.d(TAG, "Autoqueue is disabled");
}
} else {
if (AppConfig.DEBUG)
Log.d(TAG, "Item is already in queue");
}
downloadsBeingHandled -= 1;
queryDownloads();
}

View File

@ -69,7 +69,7 @@ public class FeedItemMenuHandler {
FeedManager manager = FeedManager.getInstance();
switch (item.getItemId()) {
case R.id.download_item:
requester.downloadMedia(context, selectedItem.getMedia());
manager.downloadFeedItem(context, selectedItem);
break;
case R.id.play_item:
manager.playMedia(context, selectedItem.getMedia(), true, true,