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="add_feed_label">Add feed</string>
|
||||||
<string name="miro_feed_added">Feed is being added</string>
|
<string name="miro_feed_added">Feed is being added</string>
|
||||||
<string name="player_buffering_msg">Buffering</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>
|
<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);
|
context.startService(launchIntent);
|
||||||
if (showPlayer) {
|
if (showPlayer) {
|
||||||
// Launch Mediaplayer
|
// Launch Mediaplayer
|
||||||
context.startActivity(PlaybackService.getPlayerActivityIntent(context, media));
|
context.startActivity(PlaybackService.getPlayerActivityIntent(
|
||||||
|
context, media));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -161,7 +162,8 @@ public class FeedManager {
|
||||||
public void run() {
|
public void run() {
|
||||||
feeds.remove(feed);
|
feeds.remove(feed);
|
||||||
sendFeedUpdateBroadcast(context);
|
sendFeedUpdateBroadcast(context);
|
||||||
}});
|
}
|
||||||
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -191,7 +193,8 @@ public class FeedManager {
|
||||||
* Sets the 'read'-attribute of a FeedItem. Should be used by all Classes
|
* Sets the 'read'-attribute of a FeedItem. Should be used by all Classes
|
||||||
* instead of the setters of FeedItem.
|
* 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)
|
if (AppConfig.DEBUG)
|
||||||
Log.d(TAG, "Setting item with title " + item.getTitle()
|
Log.d(TAG, "Setting item with title " + item.getTitle()
|
||||||
+ " as read/unread");
|
+ " as read/unread");
|
||||||
|
@ -205,10 +208,12 @@ public class FeedManager {
|
||||||
unreadItems.remove(item);
|
unreadItems.remove(item);
|
||||||
} else {
|
} else {
|
||||||
unreadItems.add(item);
|
unreadItems.add(item);
|
||||||
Collections.sort(unreadItems, new FeedItemPubdateComparator());
|
Collections.sort(unreadItems,
|
||||||
|
new FeedItemPubdateComparator());
|
||||||
}
|
}
|
||||||
sendUnreadItemsUpdateBroadcast(context, item);
|
sendUnreadItemsUpdateBroadcast(context, item);
|
||||||
}});
|
}
|
||||||
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -303,13 +308,20 @@ public class FeedManager {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addQueueItem(Context context, FeedItem item) {
|
public void addQueueItem(final Context context, final FeedItem item) {
|
||||||
PodDBAdapter adapter = new PodDBAdapter(context);
|
contentChanger.post(new Runnable() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
queue.add(item);
|
queue.add(item);
|
||||||
|
sendQueueUpdateBroadcast(context, item);
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
PodDBAdapter adapter = new PodDBAdapter(context);
|
||||||
adapter.open();
|
adapter.open();
|
||||||
adapter.setQueue(queue);
|
adapter.setQueue(queue);
|
||||||
adapter.close();
|
adapter.close();
|
||||||
sendQueueUpdateBroadcast(context, item);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Removes all items in queue */
|
/** Removes all items in queue */
|
||||||
|
@ -448,7 +460,10 @@ public class FeedManager {
|
||||||
return null;
|
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) {
|
public boolean feedExists(String downloadUrl) {
|
||||||
for (Feed feed : feeds) {
|
for (Feed feed : feeds) {
|
||||||
if (feed.getDownload_url().equals(downloadUrl)) {
|
if (feed.getDownload_url().equals(downloadUrl)) {
|
||||||
|
|
|
@ -18,6 +18,7 @@ import javax.xml.parsers.ParserConfigurationException;
|
||||||
import org.xml.sax.SAXException;
|
import org.xml.sax.SAXException;
|
||||||
|
|
||||||
import de.danoeh.antennapod.AppConfig;
|
import de.danoeh.antennapod.AppConfig;
|
||||||
|
import de.danoeh.antennapod.PodcastApp;
|
||||||
import de.danoeh.antennapod.activity.DownloadActivity;
|
import de.danoeh.antennapod.activity.DownloadActivity;
|
||||||
import de.danoeh.antennapod.activity.AudioplayerActivity;
|
import de.danoeh.antennapod.activity.AudioplayerActivity;
|
||||||
import de.danoeh.antennapod.activity.MainActivity;
|
import de.danoeh.antennapod.activity.MainActivity;
|
||||||
|
@ -53,6 +54,7 @@ import android.os.Debug;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.Message;
|
import android.os.Message;
|
||||||
import android.os.Messenger;
|
import android.os.Messenger;
|
||||||
|
import android.preference.PreferenceManager;
|
||||||
|
|
||||||
public class DownloadService extends Service {
|
public class DownloadService extends Service {
|
||||||
private static final String TAG = "DownloadService";
|
private static final String TAG = "DownloadService";
|
||||||
|
@ -476,7 +478,8 @@ public class DownloadService extends Service {
|
||||||
Log.e(TAG, "Feed has no title.");
|
Log.e(TAG, "Feed has no title.");
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} 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;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -553,6 +556,24 @@ public class DownloadService extends Service {
|
||||||
sendDownloadHandledIntent(media.getDownloadId(), statusId, false, 0);
|
sendDownloadHandledIntent(media.getDownloadId(), statusId, false, 0);
|
||||||
media.setDownloadId(0);
|
media.setDownloadId(0);
|
||||||
manager.setFeedMedia(service, media);
|
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();
|
queryDownloads();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue