diff --git a/res/layout/feedinfo.xml b/res/layout/feedinfo.xml
index b018eabbe..c146e5c25 100644
--- a/res/layout/feedinfo.xml
+++ b/res/layout/feedinfo.xml
@@ -93,6 +93,18 @@
android:layout_below="@id/txtvAuthor"
android:layout_margin="8dp"
android:layout_toRightOf="@id/center_divider" />
+
+
+
Image of:\u0020
Save username and password
Close
+ Include in auto downloads
diff --git a/src/de/danoeh/antennapod/activity/FeedInfoActivity.java b/src/de/danoeh/antennapod/activity/FeedInfoActivity.java
index 3cb46a4f8..a0f4dc36f 100644
--- a/src/de/danoeh/antennapod/activity/FeedInfoActivity.java
+++ b/src/de/danoeh/antennapod/activity/FeedInfoActivity.java
@@ -7,6 +7,8 @@ import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
+import android.widget.CheckBox;
+import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.TextView;
import de.danoeh.antennapod.AppConfig;
@@ -35,6 +37,7 @@ public class FeedInfoActivity extends ActionBarActivity {
private TextView txtvDescription;
private TextView txtvLanguage;
private TextView txtvAuthor;
+ private CheckBox cbxAutoDownload;
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -44,6 +47,13 @@ public class FeedInfoActivity extends ActionBarActivity {
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
long feedId = getIntent().getLongExtra(EXTRA_FEED_ID, -1);
+ imgvCover = (ImageView) findViewById(R.id.imgvCover);
+ txtvTitle = (TextView) findViewById(R.id.txtvTitle);
+ txtvDescription = (TextView) findViewById(R.id.txtvDescription);
+ txtvLanguage = (TextView) findViewById(R.id.txtvLanguage);
+ txtvAuthor = (TextView) findViewById(R.id.txtvAuthor);
+ cbxAutoDownload = (CheckBox) findViewById(R.id.cbxAutoDownload);
+
AsyncTask loadTask = new AsyncTask() {
@Override
@@ -53,18 +63,12 @@ public class FeedInfoActivity extends ActionBarActivity {
@Override
protected void onPostExecute(Feed result) {
- super.onPostExecute(result);
if (result != null) {
feed = result;
if (AppConfig.DEBUG)
Log.d(TAG, "Language is " + feed.getLanguage());
if (AppConfig.DEBUG)
Log.d(TAG, "Author is " + feed.getAuthor());
- imgvCover = (ImageView) findViewById(R.id.imgvCover);
- txtvTitle = (TextView) findViewById(R.id.txtvTitle);
- txtvDescription = (TextView) findViewById(R.id.txtvDescription);
- txtvLanguage = (TextView) findViewById(R.id.txtvLanguage);
- txtvAuthor = (TextView) findViewById(R.id.txtvAuthor);
imgvCover.post(new Runnable() {
@Override
@@ -83,6 +87,17 @@ public class FeedInfoActivity extends ActionBarActivity {
txtvLanguage.setText(LangUtils
.getLanguageString(feed.getLanguage()));
}
+
+ cbxAutoDownload.setEnabled(UserPreferences.isEnableAutodownload());
+ cbxAutoDownload.setChecked(feed.getPreferences().getAutoDownload());
+ cbxAutoDownload.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
+ @Override
+ public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
+ feed.getPreferences().setAutoDownload(checked);
+ feed.savePreferences(FeedInfoActivity.this);
+ }
+ });
+
supportInvalidateOptionsMenu();
} else {
diff --git a/src/de/danoeh/antennapod/feed/Feed.java b/src/de/danoeh/antennapod/feed/Feed.java
index 032930f83..a99213dc7 100644
--- a/src/de/danoeh/antennapod/feed/Feed.java
+++ b/src/de/danoeh/antennapod/feed/Feed.java
@@ -1,11 +1,14 @@
package de.danoeh.antennapod.feed;
+import android.content.Context;
+
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import de.danoeh.antennapod.preferences.UserPreferences;
+import de.danoeh.antennapod.storage.DBWriter;
import de.danoeh.antennapod.util.EpisodeFilter;
/**
@@ -46,6 +49,11 @@ public class Feed extends FeedFile {
*/
private String type;
+ /**
+ * Feed preferences
+ */
+ private FeedPreferences preferences;
+
/**
* This constructor is used for restoring a feed from the database.
*/
@@ -366,4 +374,15 @@ public class Feed extends FeedFile {
this.type = type;
}
+ public void setPreferences(FeedPreferences preferences) {
+ this.preferences = preferences;
+ }
+
+ public FeedPreferences getPreferences() {
+ return preferences;
+ }
+
+ public void savePreferences(Context context) {
+ DBWriter.setFeedPreferences(context, preferences);
+ }
}
diff --git a/src/de/danoeh/antennapod/feed/FeedPreferences.java b/src/de/danoeh/antennapod/feed/FeedPreferences.java
index 084aa5691..a63c1d52b 100644
--- a/src/de/danoeh/antennapod/feed/FeedPreferences.java
+++ b/src/de/danoeh/antennapod/feed/FeedPreferences.java
@@ -1,14 +1,20 @@
package de.danoeh.antennapod.feed;
+import android.content.Context;
+
+import de.danoeh.antennapod.storage.DBWriter;
+
/**
* Contains preferences for a single feed.
*/
public class FeedPreferences {
private long feedID;
+ private boolean autoDownload;
- public FeedPreferences(long feedID) {
+ public FeedPreferences(long feedID, boolean autoDownload) {
this.feedID = feedID;
+ this.autoDownload = autoDownload;
}
public long getFeedID() {
@@ -18,4 +24,16 @@ public class FeedPreferences {
public void setFeedID(long feedID) {
this.feedID = feedID;
}
+
+ public boolean getAutoDownload() {
+ return autoDownload;
+ }
+
+ public void setAutoDownload(boolean autoDownload) {
+ this.autoDownload = autoDownload;
+ }
+
+ public void save(Context context) {
+ DBWriter.setFeedPreferences(context, this);
+ }
}
diff --git a/src/de/danoeh/antennapod/storage/DBReader.java b/src/de/danoeh/antennapod/storage/DBReader.java
index feebd2c34..83ad1b676 100644
--- a/src/de/danoeh/antennapod/storage/DBReader.java
+++ b/src/de/danoeh/antennapod/storage/DBReader.java
@@ -333,6 +333,11 @@ public final class DBReader {
if (image != null) {
image.setFeed(feed);
}
+
+ FeedPreferences preferences = new FeedPreferences(cursor.getLong(PodDBAdapter.IDX_FEED_SEL_STD_ID),
+ cursor.getInt(PodDBAdapter.IDX_FEED_SEL_PREFERENCES_AUTO_DOWNLOAD) > 0);
+
+ feed.setPreferences(preferences);
return feed;
}
@@ -768,29 +773,4 @@ public final class DBReader {
return media;
}
-
- private static FeedPreferences extractFeedPreferencesFromCursorRow(final Cursor cursor) {
- return new FeedPreferences(cursor.getLong(PodDBAdapter.IDX_FEED_SEL_PREFERENCES_ID));
- }
-
- /**
- * Loads the FeedPreferences-object of a specific Feed from the database.
- *
- * @param context A context that is used for opening a database connection.
- * @param feedID ID of the Feed.
- * @return The FeedPreferences of the Feed with the given ID or null if the no Feed could be found.
- */
- public static FeedPreferences getFeedPreferencesOfFeed(final Context context, final long feedID) {
- PodDBAdapter adapter = new PodDBAdapter(context);
- adapter.open();
-
- Cursor prefCursor = adapter.getFeedPreferenceCursor(feedID);
- if (prefCursor.moveToFirst()) {
- FeedPreferences result = extractFeedPreferencesFromCursorRow(prefCursor);
- prefCursor.close();
- return result;
- } else {
- return null;
- }
- }
}
diff --git a/src/de/danoeh/antennapod/storage/DBTasks.java b/src/de/danoeh/antennapod/storage/DBTasks.java
index b9a1fd002..35bcbd8cb 100644
--- a/src/de/danoeh/antennapod/storage/DBTasks.java
+++ b/src/de/danoeh/antennapod/storage/DBTasks.java
@@ -324,12 +324,14 @@ public final class DBTasks {
int counter = 0;
for (FeedItem item : queue) {
if (item.hasMedia() && !item.getMedia().isDownloaded()
- && !item.getMedia().isPlaying()) {
+ && !item.getMedia().isPlaying()
+ && item.getFeed().getPreferences().getAutoDownload()) {
counter++;
}
}
for (FeedItem item : unreadItems) {
- if (item.hasMedia() && !item.getMedia().isDownloaded()) {
+ if (item.hasMedia() && !item.getMedia().isDownloaded()
+ && item.getFeed().getPreferences().getAutoDownload()) {
counter++;
}
}
@@ -375,7 +377,8 @@ public final class DBTasks {
for (int i = 0; i < queue.size(); i++) { // ignore playing item
FeedItem item = queue.get(i);
if (item.hasMedia() && !item.getMedia().isDownloaded()
- && !item.getMedia().isPlaying()) {
+ && !item.getMedia().isPlaying()
+ && item.getFeed().getPreferences().getAutoDownload()) {
itemsToDownload.add(item);
episodeSpaceLeft--;
undownloadedEpisodes--;
@@ -387,7 +390,8 @@ public final class DBTasks {
}
if (episodeSpaceLeft > 0 && undownloadedEpisodes > 0) {
for (FeedItem item : unreadItems) {
- if (item.hasMedia() && !item.getMedia().isDownloaded()) {
+ if (item.hasMedia() && !item.getMedia().isDownloaded()
+ && item.getFeed().getPreferences().getAutoDownload()) {
itemsToDownload.add(item);
episodeSpaceLeft--;
undownloadedEpisodes--;
diff --git a/src/de/danoeh/antennapod/storage/PodDBAdapter.java b/src/de/danoeh/antennapod/storage/PodDBAdapter.java
index bebbc7ff6..48dfeb937 100644
--- a/src/de/danoeh/antennapod/storage/PodDBAdapter.java
+++ b/src/de/danoeh/antennapod/storage/PodDBAdapter.java
@@ -24,7 +24,7 @@ import de.danoeh.antennapod.service.download.DownloadStatus;
*/
public class PodDBAdapter {
private static final String TAG = "PodDBAdapter";
- private static final int DATABASE_VERSION = 9;
+ private static final int DATABASE_VERSION = 10;
public static final String DATABASE_NAME = "Antennapod.db";
/**
@@ -124,6 +124,7 @@ public class PodDBAdapter {
public static final String KEY_DOWNLOADSTATUS_TITLE = "title";
public static final String KEY_CHAPTER_TYPE = "type";
public static final String KEY_PLAYBACK_COMPLETION_DATE = "playback_completion_date";
+ public static final String KEY_AUTO_DOWNLOAD = "auto_download";
// Table names
public static final String TABLE_NAME_FEEDS = "Feeds";
@@ -145,8 +146,7 @@ public class PodDBAdapter {
+ KEY_DESCRIPTION + " TEXT," + KEY_PAYMENT_LINK + " TEXT,"
+ KEY_LASTUPDATE + " TEXT," + KEY_LANGUAGE + " TEXT," + KEY_AUTHOR
+ " TEXT," + KEY_IMAGE + " INTEGER," + KEY_TYPE + " TEXT,"
- + KEY_FEED_IDENTIFIER + " TEXT)";
- ;
+ + KEY_FEED_IDENTIFIER + " TEXT," + KEY_AUTO_DOWNLOAD + " INTEGER DEFAULT 1)";
private static final String CREATE_TABLE_FEED_ITEMS = "CREATE TABLE "
+ TABLE_NAME_FEED_ITEMS + " (" + TABLE_PRIMARY_KEY + KEY_TITLE
@@ -206,7 +206,8 @@ public class PodDBAdapter {
TABLE_NAME_FEEDS + "." + KEY_AUTHOR,
TABLE_NAME_FEEDS + "." + KEY_IMAGE,
TABLE_NAME_FEEDS + "." + KEY_TYPE,
- TABLE_NAME_FEEDS + "." + KEY_FEED_IDENTIFIER
+ TABLE_NAME_FEEDS + "." + KEY_FEED_IDENTIFIER,
+ TABLE_NAME_FEEDS + "." + KEY_AUTO_DOWNLOAD,
};
// column indices for FEED_SEL_STD
@@ -224,17 +225,8 @@ public class PodDBAdapter {
public static final int IDX_FEED_SEL_STD_IMAGE = 11;
public static final int IDX_FEED_SEL_STD_TYPE = 12;
public static final int IDX_FEED_SEL_STD_FEED_IDENTIFIER = 13;
+ public static final int IDX_FEED_SEL_PREFERENCES_AUTO_DOWNLOAD = 14;
- /**
- * Select all preference-columns from the feed table
- */
- private static final String[] FEED_SEL_PREFERENCES = {
- TABLE_NAME_FEEDS + "." + KEY_ID,
- // enter preferences here
- };
-
- // column indices for FEED_SEL_PREFERENCES
- public static final int IDX_FEED_SEL_PREFERENCES_ID = 0;
/**
* Select all columns from the feeditems-table except description and
@@ -373,6 +365,7 @@ public class PodDBAdapter {
throw new IllegalArgumentException("Feed ID of preference must not be null");
}
ContentValues values = new ContentValues();
+ values.put(KEY_AUTO_DOWNLOAD, prefs.getAutoDownload());
db.update(TABLE_NAME_FEEDS, values, KEY_ID + "=?", new String[]{String.valueOf(prefs.getFeedID())});
}
@@ -930,10 +923,6 @@ public class PodDBAdapter {
return c;
}
- public final Cursor getFeedPreferenceCursor(final long feedID) {
- return db.query(TABLE_NAME_FEEDS, FEED_SEL_PREFERENCES, KEY_ID + "=" + feedID, null, null, null, null);
- }
-
public final Cursor getFeedItemCursor(final String... ids) {
if (ids.length > IN_OPERATOR_MAXIMUM) {
throw new IllegalArgumentException(
@@ -1173,6 +1162,11 @@ public class PodDBAdapter {
}
feeditemCursor.close();
}
+ if (oldVersion <= 9) {
+ db.execSQL("ALTER TABLE " + TABLE_NAME_FEEDS
+ + " ADD COLUMN " + KEY_AUTO_DOWNLOAD
+ + " INTEGER DEFAULT 1");
+ }
}
}
}