Implemented auto-enqueue feature
This commit is contained in:
parent
977c3f3674
commit
0b62b06cdf
|
@ -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>
|
||||
|
||||
|
||||
|
|
|
@ -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);
|
||||
}});
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
@ -182,7 +184,7 @@ public class FeedManager {
|
|||
}
|
||||
context.sendBroadcast(update);
|
||||
}
|
||||
|
||||
|
||||
private void sendFeedUpdateBroadcast(Context context) {
|
||||
context.sendBroadcast(new Intent(ACITON_FEED_LIST_UPDATE));
|
||||
}
|
||||
|
@ -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,11 +208,13 @@ 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) {
|
||||
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);
|
||||
queue.add(item);
|
||||
adapter.open();
|
||||
adapter.setQueue(queue);
|
||||
adapter.close();
|
||||
sendQueueUpdateBroadcast(context, item);
|
||||
}
|
||||
|
||||
/** Removes all items in queue */
|
||||
|
@ -447,8 +459,11 @@ 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)) {
|
||||
|
|
|
@ -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";
|
||||
|
@ -398,7 +400,7 @@ public class DownloadService extends Service {
|
|||
|
||||
private Feed feed;
|
||||
private DownloadService service;
|
||||
|
||||
|
||||
private int reason;
|
||||
private boolean successful;
|
||||
|
||||
|
@ -469,14 +471,15 @@ public class DownloadService extends Service {
|
|||
sendDownloadHandledIntent(downloadId, statusId, hasImage, imageId);
|
||||
queryDownloads();
|
||||
}
|
||||
|
||||
|
||||
/** Checks if the feed was parsed correctly. */
|
||||
private boolean checkFeedData(Feed feed) {
|
||||
if (feed.getTitle() == null) {
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue