Implemented auto-enqueue feature

This commit is contained in:
daniel oeh 2012-08-06 11:07:49 +02:00
parent 977c3f3674
commit 0b62b06cdf
3 changed files with 52 additions and 16 deletions

View File

@ -169,7 +169,7 @@
<string name="add_feed_label">Add feed</string>
<string name="miro_feed_added">Feed is being added</string>
<string name="player_buffering_msg">Buffering</string>
<string name="pref_autoQueue_title">Auto-queue</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>

View File

@ -106,7 +106,8 @@ public class FeedManager {
context.startService(launchIntent);
if (showPlayer) {
// Launch Mediaplayer
context.startActivity(PlaybackService.getPlayerActivityIntent(context, media));
context.startActivity(PlaybackService.getPlayerActivityIntent(
context, media));
}
}
@ -161,7 +162,8 @@ public class FeedManager {
public void run() {
feeds.remove(feed);
sendFeedUpdateBroadcast(context);
}});
}
});
}
@ -191,7 +193,8 @@ public class FeedManager {
* Sets the 'read'-attribute of a FeedItem. Should be used by all Classes
* instead of the setters of FeedItem.
*/
public void markItemRead(final Context context, final FeedItem item, final boolean read) {
public void markItemRead(final Context context, final FeedItem item,
final boolean read) {
if (AppConfig.DEBUG)
Log.d(TAG, "Setting item with title " + item.getTitle()
+ " as read/unread");
@ -205,10 +208,12 @@ public class FeedManager {
unreadItems.remove(item);
} else {
unreadItems.add(item);
Collections.sort(unreadItems, new FeedItemPubdateComparator());
Collections.sort(unreadItems,
new FeedItemPubdateComparator());
}
sendUnreadItemsUpdateBroadcast(context, item);
}});
}
});
}
@ -303,13 +308,20 @@ public class FeedManager {
return result;
}
public void addQueueItem(Context context, FeedItem item) {
PodDBAdapter adapter = new PodDBAdapter(context);
public void addQueueItem(final Context context, final FeedItem item) {
contentChanger.post(new Runnable() {
@Override
public void run() {
queue.add(item);
sendQueueUpdateBroadcast(context, item);
}
});
PodDBAdapter adapter = new PodDBAdapter(context);
adapter.open();
adapter.setQueue(queue);
adapter.close();
sendQueueUpdateBroadcast(context, item);
}
/** Removes all items in queue */
@ -448,7 +460,10 @@ public class FeedManager {
return null;
}
/** Returns true if a feed with the given download link is already in the feedlist. */
/**
* Returns true if a feed with the given download link is already in the
* feedlist.
*/
public boolean feedExists(String downloadUrl) {
for (Feed feed : feeds) {
if (feed.getDownload_url().equals(downloadUrl)) {

View File

@ -18,6 +18,7 @@ import javax.xml.parsers.ParserConfigurationException;
import org.xml.sax.SAXException;
import de.danoeh.antennapod.AppConfig;
import de.danoeh.antennapod.PodcastApp;
import de.danoeh.antennapod.activity.DownloadActivity;
import de.danoeh.antennapod.activity.AudioplayerActivity;
import de.danoeh.antennapod.activity.MainActivity;
@ -53,6 +54,7 @@ import android.os.Debug;
import android.os.Handler;
import android.os.Message;
import android.os.Messenger;
import android.preference.PreferenceManager;
public class DownloadService extends Service {
private static final String TAG = "DownloadService";
@ -476,7 +478,8 @@ public class DownloadService extends Service {
Log.e(TAG, "Feed has no title.");
return false;
} else {
if (AppConfig.DEBUG) Log.d(TAG, "Feed appears to be valid.");
if (AppConfig.DEBUG)
Log.d(TAG, "Feed appears to be valid.");
return true;
}
}
@ -553,6 +556,24 @@ public class DownloadService extends Service {
sendDownloadHandledIntent(media.getDownloadId(), statusId, false, 0);
media.setDownloadId(0);
manager.setFeedMedia(service, 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");
}
queryDownloads();
}
}