diff options
author | Tom Hennen <TomHennen@users.noreply.github.com> | 2015-08-01 12:20:50 -0400 |
---|---|---|
committer | Tom Hennen <TomHennen@users.noreply.github.com> | 2015-08-01 12:20:50 -0400 |
commit | 2fdcccf9fb2fca3563e193d19b5b712c7a9394ae (patch) | |
tree | ff82fdf3668eadaba1c04dfe09c40bedef9d0d55 /core | |
parent | 12093f862731c1dd702c235007d510201d6d10be (diff) | |
parent | a3ea16b90c7a9183e1fc856e44f9e5970ab4d196 (diff) | |
download | AntennaPod-2fdcccf9fb2fca3563e193d19b5b712c7a9394ae.zip |
Merge pull request #1045 from mfietz/issue/1044
Apply podcast's auto download preference to its episodes
Diffstat (limited to 'core')
4 files changed, 55 insertions, 7 deletions
diff --git a/core/src/main/java/de/danoeh/antennapod/core/dialog/ConfirmationDialog.java b/core/src/main/java/de/danoeh/antennapod/core/dialog/ConfirmationDialog.java index ba1add895..fea2bbb2b 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/dialog/ConfirmationDialog.java +++ b/core/src/main/java/de/danoeh/antennapod/core/dialog/ConfirmationDialog.java @@ -4,7 +4,7 @@ import android.app.AlertDialog; import android.content.Context; import android.content.DialogInterface; import android.util.Log; -import de.danoeh.antennapod.core.BuildConfig; + import de.danoeh.antennapod.core.R; /** @@ -12,12 +12,16 @@ import de.danoeh.antennapod.core.R; * classes can handle events like confirmation or cancellation. */ public abstract class ConfirmationDialog { - private static final String TAG = "ConfirmationDialog"; - Context context; + private static final String TAG = ConfirmationDialog.class.getSimpleName(); + + protected Context context; int titleId; int messageId; + int positiveText; + int negativeText; + public ConfirmationDialog(Context context, int titleId, int messageId) { this.context = context; this.titleId = titleId; @@ -25,18 +29,26 @@ public abstract class ConfirmationDialog { } public void onCancelButtonPressed(DialogInterface dialog) { - if (BuildConfig.DEBUG) - Log.d(TAG, "Dialog was cancelled"); + Log.d(TAG, "Dialog was cancelled"); dialog.dismiss(); } + public void setPositiveText(int id) { + this.positiveText = id; + } + + public void setNegativeText(int id) { + this.negativeText = id; + } + + public abstract void onConfirmButtonPressed(DialogInterface dialog); public final AlertDialog createNewDialog() { AlertDialog.Builder builder = new AlertDialog.Builder(context); builder.setTitle(titleId); builder.setMessage(messageId); - builder.setPositiveButton(R.string.confirm_label, + builder.setPositiveButton(positiveText != 0 ? positiveText : R.string.confirm_label, new DialogInterface.OnClickListener() { @Override @@ -44,7 +56,7 @@ public abstract class ConfirmationDialog { onConfirmButtonPressed(dialog); } }); - builder.setNegativeButton(R.string.cancel_label, + builder.setNegativeButton(negativeText != 0 ? negativeText : R.string.cancel_label, new DialogInterface.OnClickListener() { @Override diff --git a/core/src/main/java/de/danoeh/antennapod/core/storage/DBWriter.java b/core/src/main/java/de/danoeh/antennapod/core/storage/DBWriter.java index acdcf5f85..12bc208a6 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/storage/DBWriter.java +++ b/core/src/main/java/de/danoeh/antennapod/core/storage/DBWriter.java @@ -1110,9 +1110,34 @@ public class DBWriter { EventDistributor.getInstance().sendUnreadItemsUpdateBroadcast(); } }); + } + + /** + * Sets the 'auto_download'-attribute of specific FeedItem. + * + * @param context A context that is used for opening a database connection. + * @param feed This feed's episodes will be processed. + * @param autoDownload If true, auto download will be enabled for the feed's episodes. Else, + * it will be disabled. + */ + public static Future<?> setFeedsItemsAutoDownload(final Context context, final Feed feed, + final boolean autoDownload) { + Log.d(TAG, (autoDownload ? "Enabling" : "Disabling") + " auto download for items of feed " + feed.getId()); + return dbExec.submit(new Runnable() { + @Override + public void run() { + final PodDBAdapter adapter = new PodDBAdapter(context); + adapter.open(); + adapter.setFeedsItemsAutoDownload(feed, autoDownload); + adapter.close(); + + EventDistributor.getInstance().sendUnreadItemsUpdateBroadcast(); + } + }); } + /** * Set filter of the feed * diff --git a/core/src/main/java/de/danoeh/antennapod/core/storage/PodDBAdapter.java b/core/src/main/java/de/danoeh/antennapod/core/storage/PodDBAdapter.java index c7eadcbb6..f9ac39349 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/storage/PodDBAdapter.java +++ b/core/src/main/java/de/danoeh/antennapod/core/storage/PodDBAdapter.java @@ -861,6 +861,13 @@ public class PodDBAdapter { new String[]{String.valueOf(feedItem.getId())}); } + public void setFeedsItemsAutoDownload(Feed feed, boolean autoDownload) { + final String sql = "UPDATE " + TABLE_NAME_FEED_ITEMS + + " SET " + KEY_AUTO_DOWNLOAD + "="+ (autoDownload ? "1" : "0") + + " WHERE " + KEY_FEED + "=" + feed.getId(); + db.execSQL(sql); + } + public long getDownloadLogSize() { final String query = String.format("SELECT COUNT(%s) FROM %s", KEY_ID, TABLE_NAME_DOWNLOAD_LOG); Cursor result = db.rawQuery(query, null); diff --git a/core/src/main/res/values/strings.xml b/core/src/main/res/values/strings.xml index 5079950fa..a692dbc73 100644 --- a/core/src/main/res/values/strings.xml +++ b/core/src/main/res/values/strings.xml @@ -53,6 +53,8 @@ <!-- Other --> <string name="confirm_label">Confirm</string> <string name="cancel_label">Cancel</string> + <string name="yes">Yes</string> + <string name="no">No</string> <string name="author_label">Author</string> <string name="language_label">Language</string> <string name="url_label">URL</string> @@ -75,6 +77,8 @@ <string name="close_label">Close</string> <string name="retry_label">Retry</string> <string name="auto_download_label">Include in auto downloads</string> + <string name="auto_download_apply_to_items_title">Apply to Previous Episodes</string> + <string name="auto_download_apply_to_items_message">The new <i>Auto Download</i> setting will automatically be applied to new episodes.\nDo you also want to apply it to previous episodes?</string> <string name="auto_delete_label">Auto Delete Episode\n(override global default)</string> <string name="parallel_downloads_suffix">\u0020parallel downloads</string> <string name="feed_auto_download_global">Global</string> |