summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordaniel oeh <daniel.oeh@gmail.com>2013-10-08 23:43:13 +0200
committerdaniel oeh <daniel.oeh@gmail.com>2013-10-08 23:43:13 +0200
commite58922fad08bedf4bfe86025d836abdeae49a806 (patch)
tree1bd8699fdf274fec52700affaeeb4a32382d2ae0
parenta482899eef4a0a7ada979ba0c87b19e91c2f49f1 (diff)
parentcdd9a0dfdeef8d319063f844fce1e1722f7d9529 (diff)
downloadAntennaPod-e58922fad08bedf4bfe86025d836abdeae49a806.zip
Merge branch 'feed_preferences' into develop
Conflicts: res/values/strings.xml src/de/danoeh/antennapod/storage/DBTasks.java src/de/danoeh/antennapod/storage/PodDBAdapter.java
-rw-r--r--res/layout/feedinfo.xml64
-rw-r--r--res/values/strings.xml4
-rw-r--r--src/de/danoeh/antennapod/activity/FeedInfoActivity.java27
-rw-r--r--src/de/danoeh/antennapod/feed/Feed.java19
-rw-r--r--src/de/danoeh/antennapod/feed/FeedPreferences.java39
-rw-r--r--src/de/danoeh/antennapod/storage/DBReader.java48
-rw-r--r--src/de/danoeh/antennapod/storage/DBTasks.java14
-rw-r--r--src/de/danoeh/antennapod/storage/DBWriter.java20
-rw-r--r--src/de/danoeh/antennapod/storage/PodDBAdapter.java110
9 files changed, 261 insertions, 84 deletions
diff --git a/res/layout/feedinfo.xml b/res/layout/feedinfo.xml
index b018eabbe..e1c1c10a3 100644
--- a/res/layout/feedinfo.xml
+++ b/res/layout/feedinfo.xml
@@ -1,14 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:orientation="vertical" >
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:orientation="vertical">
<RelativeLayout
android:id="@+id/header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
- android:gravity="center_vertical" >
+ android:gravity="center_vertical">
<ImageView
android:id="@+id/imgvCover"
@@ -16,7 +16,7 @@
android:layout_height="70dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
- android:layout_margin="4dp" />
+ android:layout_margin="4dp"/>
<TextView
android:id="@+id/txtvTitle"
@@ -26,37 +26,38 @@
android:layout_margin="4dp"
android:layout_toRightOf="@id/imgvCover"
android:textSize="@dimen/text_size_large"
- android:textStyle="bold" />
+ android:textStyle="bold"
+ android:textColor="?android:attr/textColorPrimary"/>
<View
android:id="@+id/divider"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_below="@id/imgvCover"
- android:background="@color/bright_blue" />
+ android:background="@color/bright_blue"/>
</RelativeLayout>
<ScrollView
android:id="@+id/scrollView"
android:layout_width="match_parent"
android:layout_height="0dp"
- android:layout_weight="1" >
+ android:layout_weight="1">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
- android:orientation="vertical" >
+ android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
- android:layout_marginBottom="16dp" >
+ android:layout_marginBottom="16dp">
<View
android:id="@+id/center_divider"
android:layout_width="0dp"
android:layout_height="0dp"
- android:layout_centerHorizontal="true" />
+ android:layout_centerHorizontal="true"/>
<TextView
android:id="@+id/lblAuthor"
@@ -65,7 +66,7 @@
android:layout_alignParentLeft="true"
android:layout_margin="8dp"
android:text="@string/author_label"
- android:textStyle="bold" />
+ android:textColor="?android:attr/textColorPrimary"/>
<TextView
android:id="@+id/txtvAuthor"
@@ -73,7 +74,7 @@
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_margin="8dp"
- android:layout_toRightOf="@id/center_divider" />
+ android:layout_toRightOf="@id/center_divider"/>
<TextView
android:id="@+id/lblLanguage"
@@ -83,7 +84,7 @@
android:layout_below="@id/txtvAuthor"
android:layout_margin="8dp"
android:text="@string/language_label"
- android:textStyle="bold" />
+ android:textColor="?android:attr/textColorPrimary"/>
<TextView
android:id="@+id/txtvLanguage"
@@ -92,14 +93,45 @@
android:layout_alignParentRight="true"
android:layout_below="@id/txtvAuthor"
android:layout_margin="8dp"
- android:layout_toRightOf="@id/center_divider" />
+ android:layout_toRightOf="@id/center_divider"/>
</RelativeLayout>
<TextView
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_marginLeft="8dp"
+ android:layout_marginBottom="8dp"
+ android:layout_marginTop="24dp"
+ android:textSize="@dimen/text_size_medium"
+ android:textColor="?android:attr/textColorPrimary"
+ android:text="@string/description_label"/>
+
+ <TextView
android:id="@+id/txtvDescription"
android:layout_width="match_parent"
android:layout_height="wrap_content"
- android:layout_margin="8dp" />
+ android:layout_margin="8dp"/>
+
+ <TextView
+ android:id="@+id/txtvSettings"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_margin="8dp"
+ android:text="@string/podcast_settings_label"
+ android:textSize="@dimen/text_size_medium"
+ android:textColor="?android:attr/textColorPrimary"
+ android:layout_marginLeft="8dp"
+ android:layout_marginBottom="8dp"
+ android:layout_marginTop="24dp"/>
+
+ <CheckBox
+ android:id="@+id/cbxAutoDownload"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_margin="8dp"
+ android:text="@string/auto_download_label"
+ android:enabled="false"
+ android:textColor="?android:attr/textColorPrimary"/>
</LinearLayout>
</ScrollView>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index c0aa27776..350318fcb 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -34,6 +34,7 @@
<string name="cancel_label">Cancel</string>
<string name="author_label">Author</string>
<string name="language_label">Language</string>
+ <string name="podcast_settings_label">Settings</string>
<string name="cover_label">Cover</string>
<string name="error_label">Error</string>
<string name="error_msg_prefix">An error occurred:</string>
@@ -41,6 +42,7 @@
<string name="external_storage_error_msg">No external storage is available. Please make sure that external storage is mounted so that the app can work properly.</string>
<string name="chapters_label">Chapters</string>
<string name="shownotes_label">Shownotes</string>
+ <string name="description_label">Description</string>
<string name="most_recent_prefix">Most Recent Episode:\u0020</string>
<string name="episodes_suffix">\u0020episodes</string>
<string name="published_prefix">Published:\u0020</string>
@@ -52,7 +54,7 @@
<string name="save_username_password_label">Save username and password</string>
<string name="close_label">Close</string>
<string name="retry_label">Retry</string>
-
+ <string name="auto_download_label">Include in auto downloads</string>
<!-- 'Add Feed' Activity labels -->
<string name="feedurl_label">Feed URL</string>
diff --git a/src/de/danoeh/antennapod/activity/FeedInfoActivity.java b/src/de/danoeh/antennapod/activity/FeedInfoActivity.java
index 349793c66..78c466ae8 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<Long, Void, Feed> loadTask = new AsyncTask<Long, Void, Feed>() {
@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;
/**
@@ -47,6 +50,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.
*/
public Feed(long id, Date lastUpdate, String title, String link, String description, String paymentLink,
@@ -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
new file mode 100644
index 000000000..a63c1d52b
--- /dev/null
+++ b/src/de/danoeh/antennapod/feed/FeedPreferences.java
@@ -0,0 +1,39 @@
+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, boolean autoDownload) {
+ this.feedID = feedID;
+ this.autoDownload = autoDownload;
+ }
+
+ public long getFeedID() {
+ return feedID;
+ }
+
+ 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 ce6d4b894..8aa93d7ed 100644
--- a/src/de/danoeh/antennapod/storage/DBReader.java
+++ b/src/de/danoeh/antennapod/storage/DBReader.java
@@ -10,14 +10,7 @@ import android.database.Cursor;
import android.database.SQLException;
import android.util.Log;
import de.danoeh.antennapod.AppConfig;
-import de.danoeh.antennapod.feed.Chapter;
-import de.danoeh.antennapod.feed.Feed;
-import de.danoeh.antennapod.feed.FeedImage;
-import de.danoeh.antennapod.feed.FeedItem;
-import de.danoeh.antennapod.feed.FeedMedia;
-import de.danoeh.antennapod.feed.ID3Chapter;
-import de.danoeh.antennapod.feed.SimpleChapter;
-import de.danoeh.antennapod.feed.VorbisCommentChapter;
+import de.danoeh.antennapod.feed.*;
import de.danoeh.antennapod.service.download.*;
import de.danoeh.antennapod.util.DownloadError;
import de.danoeh.antennapod.util.comparator.DownloadStatusComparator;
@@ -28,7 +21,6 @@ import de.danoeh.antennapod.util.comparator.FeedItemPubdateComparator;
* In general, all database calls in DBReader-methods are executed on the caller's thread.
* This means that the caller should make sure that DBReader-methods are not executed on the GUI-thread.
* This class will use the {@link de.danoeh.antennapod.feed.EventDistributor} to notify listeners about changes in the database.
-
*/
public final class DBReader {
private static final String TAG = "DBReader";
@@ -77,9 +69,10 @@ public final class DBReader {
/**
* Returns a list with the download URLs of all feeds.
+ *
* @param context A context that is used for opening the database connection.
* @return A list of Strings with the download URLs of all feeds.
- * */
+ */
public static List<String> getFeedListDownloadUrls(final Context context) {
PodDBAdapter adapter = new PodDBAdapter(context);
List<String> result = new ArrayList<String>();
@@ -314,33 +307,38 @@ public final class DBReader {
private static Feed extractFeedFromCursorRow(PodDBAdapter adapter,
Cursor cursor) {
Date lastUpdate = new Date(
- cursor.getLong(PodDBAdapter.KEY_LAST_UPDATE_INDEX));
+ cursor.getLong(PodDBAdapter.IDX_FEED_SEL_STD_LASTUPDATE));
final FeedImage image;
- long imageIndex = cursor.getLong(PodDBAdapter.KEY_IMAGE_INDEX);
+ long imageIndex = cursor.getLong(PodDBAdapter.IDX_FEED_SEL_STD_IMAGE);
if (imageIndex != 0) {
image = getFeedImage(adapter, imageIndex);
} else {
image = null;
}
- Feed feed = new Feed(cursor.getLong(PodDBAdapter.KEY_ID_INDEX),
+ Feed feed = new Feed(cursor.getLong(PodDBAdapter.IDX_FEED_SEL_STD_ID),
lastUpdate,
- cursor.getString(PodDBAdapter.KEY_TITLE_INDEX),
- cursor.getString(PodDBAdapter.KEY_LINK_INDEX),
- cursor.getString(PodDBAdapter.KEY_DESCRIPTION_INDEX),
- cursor.getString(PodDBAdapter.KEY_PAYMENT_LINK_INDEX),
- cursor.getString(PodDBAdapter.KEY_AUTHOR_INDEX),
- cursor.getString(PodDBAdapter.KEY_LANGUAGE_INDEX),
- cursor.getString(PodDBAdapter.KEY_TYPE_INDEX),
- cursor.getString(PodDBAdapter.KEY_FEED_IDENTIFIER_INDEX),
+ cursor.getString(PodDBAdapter.IDX_FEED_SEL_STD_TITLE),
+ cursor.getString(PodDBAdapter.IDX_FEED_SEL_STD_LINK),
+ cursor.getString(PodDBAdapter.IDX_FEED_SEL_STD_DESCRIPTION),
+ cursor.getString(PodDBAdapter.IDX_FEED_SEL_STD_PAYMENT_LINK),
+ cursor.getString(PodDBAdapter.IDX_FEED_SEL_STD_AUTHOR),
+ cursor.getString(PodDBAdapter.IDX_FEED_SEL_STD_LANGUAGE),
+ cursor.getString(PodDBAdapter.IDX_FEED_SEL_STD_TYPE),
+ cursor.getString(PodDBAdapter.IDX_FEED_SEL_STD_FEED_IDENTIFIER),
image,
- cursor.getString(PodDBAdapter.KEY_FILE_URL_INDEX),
- cursor.getString(PodDBAdapter.KEY_DOWNLOAD_URL_INDEX),
- cursor.getInt(PodDBAdapter.KEY_DOWNLOADED_INDEX) > 0);
+ cursor.getString(PodDBAdapter.IDX_FEED_SEL_STD_FILE_URL),
+ cursor.getString(PodDBAdapter.IDX_FEED_SEL_STD_DOWNLOAD_URL),
+ cursor.getInt(PodDBAdapter.IDX_FEED_SEL_STD_DOWNLOADED) > 0);
- if (image != null) {
+ 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;
}
diff --git a/src/de/danoeh/antennapod/storage/DBTasks.java b/src/de/danoeh/antennapod/storage/DBTasks.java
index 7813a6f6d..6b611bbbf 100644
--- a/src/de/danoeh/antennapod/storage/DBTasks.java
+++ b/src/de/danoeh/antennapod/storage/DBTasks.java
@@ -343,12 +343,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++;
}
}
@@ -398,7 +400,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--;
@@ -410,7 +413,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--;
@@ -435,7 +439,7 @@ public final class DBTasks {
}
}
});
-
+
}
private static int getPerformAutoCleanupArgs(Context context,
diff --git a/src/de/danoeh/antennapod/storage/DBWriter.java b/src/de/danoeh/antennapod/storage/DBWriter.java
index 26c09c68a..6be1a5327 100644
--- a/src/de/danoeh/antennapod/storage/DBWriter.java
+++ b/src/de/danoeh/antennapod/storage/DBWriter.java
@@ -780,7 +780,7 @@ public class DBWriter {
/**
* Updates download URLs of feeds from a given Map. The key of the Map is the original URL of the feed
* and the value is the updated URL
- * */
+ */
public static Future<?> updateFeedDownloadURLs(final Context context, final Map<String, String> urls) {
return dbExec.submit(new Runnable() {
@Override
@@ -797,6 +797,24 @@ public class DBWriter {
});
}
+ /**
+ * Saves a FeedPreferences object in the database. The Feed ID of the FeedPreferences-object MUST NOT be 0.
+ *
+ * @param context Used for opening a database connection.
+ * @param preferences The FeedPreferences object.
+ */
+ public static Future<?> setFeedPreferences(final Context context, final FeedPreferences preferences) {
+ return dbExec.submit(new Runnable() {
+ @Override
+ public void run() {
+ PodDBAdapter adapter = new PodDBAdapter(context);
+ adapter.open();
+ adapter.setFeedPreferences(preferences);
+ adapter.close();
+ }
+ });
+ }
+
private static boolean itemListContains(List<FeedItem> items, long itemId) {
for (FeedItem item : items) {
if (item.getId() == itemId) {
diff --git a/src/de/danoeh/antennapod/storage/PodDBAdapter.java b/src/de/danoeh/antennapod/storage/PodDBAdapter.java
index 53eb9858c..068f80ded 100644
--- a/src/de/danoeh/antennapod/storage/PodDBAdapter.java
+++ b/src/de/danoeh/antennapod/storage/PodDBAdapter.java
@@ -14,11 +14,7 @@ import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;
import de.danoeh.antennapod.AppConfig;
-import de.danoeh.antennapod.feed.Chapter;
-import de.danoeh.antennapod.feed.Feed;
-import de.danoeh.antennapod.feed.FeedImage;
-import de.danoeh.antennapod.feed.FeedItem;
-import de.danoeh.antennapod.feed.FeedMedia;
+import de.danoeh.antennapod.feed.*;
import de.danoeh.antennapod.service.download.DownloadStatus;
// TODO Remove media column from feeditem table
@@ -28,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";
/**
@@ -128,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";
@@ -149,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
@@ -194,10 +190,49 @@ public class PodDBAdapter {
private PodDBHelper helper;
/**
+ * Select all columns from the feed-table
+ */
+ private static final String[] FEED_SEL_STD = {
+ TABLE_NAME_FEEDS + "." + KEY_ID,
+ TABLE_NAME_FEEDS + "." + KEY_TITLE,
+ TABLE_NAME_FEEDS + "." + KEY_FILE_URL,
+ TABLE_NAME_FEEDS + "." + KEY_DOWNLOAD_URL,
+ TABLE_NAME_FEEDS + "." + KEY_DOWNLOADED,
+ TABLE_NAME_FEEDS + "." + KEY_LINK,
+ TABLE_NAME_FEEDS + "." + KEY_DESCRIPTION,
+ TABLE_NAME_FEEDS + "." + KEY_PAYMENT_LINK,
+ TABLE_NAME_FEEDS + "." + KEY_LASTUPDATE,
+ TABLE_NAME_FEEDS + "." + KEY_LANGUAGE,
+ 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_AUTO_DOWNLOAD,
+ };
+
+ // column indices for FEED_SEL_STD
+ public static final int IDX_FEED_SEL_STD_ID = 0;
+ public static final int IDX_FEED_SEL_STD_TITLE = 1;
+ public static final int IDX_FEED_SEL_STD_FILE_URL = 2;
+ public static final int IDX_FEED_SEL_STD_DOWNLOAD_URL = 3;
+ public static final int IDX_FEED_SEL_STD_DOWNLOADED = 4;
+ public static final int IDX_FEED_SEL_STD_LINK = 5;
+ public static final int IDX_FEED_SEL_STD_DESCRIPTION = 6;
+ public static final int IDX_FEED_SEL_STD_PAYMENT_LINK = 7;
+ public static final int IDX_FEED_SEL_STD_LASTUPDATE = 8;
+ public static final int IDX_FEED_SEL_STD_LANGUAGE = 9;
+ public static final int IDX_FEED_SEL_STD_AUTHOR = 10;
+ 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 columns from the feeditems-table except description and
* content-encoded.
*/
- private static final String[] SEL_FI_SMALL = {
+ private static final String[] FEEDITEM_SEL_FI_SMALL = {
TABLE_NAME_FEED_ITEMS + "." + KEY_ID,
TABLE_NAME_FEED_ITEMS + "." + KEY_TITLE,
TABLE_NAME_FEED_ITEMS + "." + KEY_PUBDATE,
@@ -209,16 +244,16 @@ public class PodDBAdapter {
TABLE_NAME_FEED_ITEMS + "." + KEY_ITEM_IDENTIFIER};
/**
- * Contains SEL_FI_SMALL as comma-separated list. Useful for raw queries.
+ * Contains FEEDITEM_SEL_FI_SMALL as comma-separated list. Useful for raw queries.
*/
private static final String SEL_FI_SMALL_STR;
static {
- String selFiSmall = Arrays.toString(SEL_FI_SMALL);
+ String selFiSmall = Arrays.toString(FEEDITEM_SEL_FI_SMALL);
SEL_FI_SMALL_STR = selFiSmall.substring(1, selFiSmall.length() - 1);
}
- // column indices for SEL_FI_SMALL
+ // column indices for FEEDITEM_SEL_FI_SMALL
public static final int IDX_FI_SMALL_ID = 0;
public static final int IDX_FI_SMALL_TITLE = 1;
@@ -325,6 +360,15 @@ public class PodDBAdapter {
return feed.getId();
}
+ public void setFeedPreferences(FeedPreferences prefs) {
+ if (prefs.getFeedID() == 0) {
+ 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())});
+ }
+
/**
* Inserts or updates an image entry
*
@@ -453,7 +497,8 @@ public class PodDBAdapter {
/**
* Inserts or updates a feeditem entry
- * @param item The FeedItem
+ *
+ * @param item The FeedItem
* @param saveFeed true if the Feed of the item should also be saved. This should be set to
* false if the method is executed on a list of FeedItems of the same Feed.
* @return the id of the entry
@@ -484,7 +529,7 @@ public class PodDBAdapter {
new String[]{String.valueOf(item.getId())});
}
if (item.getMedia() != null) {
- setMedia(item.getMedia());
+ setMedia(item.getMedia());
}
if (item.getChapters() != null) {
setChapters(item);
@@ -665,7 +710,7 @@ public class PodDBAdapter {
* @return The cursor of the query
*/
public final Cursor getAllFeedsCursor() {
- Cursor c = db.query(TABLE_NAME_FEEDS, null, null, null, null, null,
+ Cursor c = db.query(TABLE_NAME_FEEDS, FEED_SEL_STD, null, null, null, null,
KEY_TITLE + " ASC");
return c;
}
@@ -675,14 +720,14 @@ public class PodDBAdapter {
}
public final Cursor getExpiredFeedsCursor(long expirationTime) {
- Cursor c = db.query(TABLE_NAME_FEEDS, null, KEY_LASTUPDATE + " < " + String.valueOf(System.currentTimeMillis() - expirationTime),
+ Cursor c = db.query(TABLE_NAME_FEEDS, FEED_SEL_STD, KEY_LASTUPDATE + " < " + String.valueOf(System.currentTimeMillis() - expirationTime),
null, null, null,
null);
return c;
}
/**
- * Returns a cursor with all FeedItems of a Feed. Uses SEL_FI_SMALL
+ * Returns a cursor with all FeedItems of a Feed. Uses FEEDITEM_SEL_FI_SMALL
*
* @param feed The feed you want to get the FeedItems from.
* @return The cursor of the query
@@ -692,7 +737,7 @@ public class PodDBAdapter {
}
public final Cursor getAllItemsOfFeedCursor(final long feedId) {
- Cursor c = db.query(TABLE_NAME_FEED_ITEMS, SEL_FI_SMALL, KEY_FEED
+ Cursor c = db.query(TABLE_NAME_FEED_ITEMS, FEEDITEM_SEL_FI_SMALL, KEY_FEED
+ "=?", new String[]{String.valueOf(feedId)}, null, null,
null);
return c;
@@ -749,7 +794,7 @@ public class PodDBAdapter {
/**
* Returns a cursor which contains all feed items in the queue. The returned
- * cursor uses the SEL_FI_SMALL selection.
+ * cursor uses the FEEDITEM_SEL_FI_SMALL selection.
*/
public final Cursor getQueueCursor() {
Object[] args = (Object[]) new String[]{
@@ -762,7 +807,7 @@ public class PodDBAdapter {
"SELECT %s FROM %s INNER JOIN %s ON %s=%s ORDER BY %s", args);
Cursor c = db.rawQuery(query, null);
/*
- * Cursor c = db.query(TABLE_NAME_FEED_ITEMS, SEL_FI_SMALL,
+ * Cursor c = db.query(TABLE_NAME_FEED_ITEMS, FEEDITEM_SEL_FI_SMALL,
* "INNER JOIN ? ON ?=?", new String[] { TABLE_NAME_QUEUE,
* TABLE_NAME_FEED_ITEMS + "." + KEY_ID, TABLE_NAME_QUEUE + "." +
* KEY_FEEDITEM }, null, null, TABLE_NAME_QUEUE + "." + KEY_FEEDITEM);
@@ -777,10 +822,10 @@ public class PodDBAdapter {
/**
* Returns a cursor which contains all feed items in the unread items list.
- * The returned cursor uses the SEL_FI_SMALL selection.
+ * The returned cursor uses the FEEDITEM_SEL_FI_SMALL selection.
*/
public final Cursor getUnreadItemsCursor() {
- Cursor c = db.query(TABLE_NAME_FEED_ITEMS, SEL_FI_SMALL, KEY_READ
+ Cursor c = db.query(TABLE_NAME_FEED_ITEMS, FEEDITEM_SEL_FI_SMALL, KEY_READ
+ "=0", null, null, null, KEY_PUBDATE + " DESC");
return c;
}
@@ -875,7 +920,7 @@ public class PodDBAdapter {
}
public final Cursor getFeedCursor(final long id) {
- Cursor c = db.query(TABLE_NAME_FEEDS, null, KEY_ID + "=" + id, null,
+ Cursor c = db.query(TABLE_NAME_FEEDS, FEED_SEL_STD, KEY_ID + "=" + id, null,
null, null, null);
return c;
}
@@ -887,7 +932,7 @@ public class PodDBAdapter {
+ IN_OPERATOR_MAXIMUM);
}
- return db.query(TABLE_NAME_FEED_ITEMS, SEL_FI_SMALL, KEY_ID + " IN "
+ return db.query(TABLE_NAME_FEED_ITEMS, FEEDITEM_SEL_FI_SMALL, KEY_ID + " IN "
+ buildInOperator(ids.length), ids, null, null, null);
}
@@ -938,14 +983,14 @@ public class PodDBAdapter {
public Cursor searchItemDescriptions(long feedID, String query) {
if (feedID != 0) {
// search items in specific feed
- return db.query(TABLE_NAME_FEED_ITEMS, SEL_FI_SMALL, KEY_FEED
+ return db.query(TABLE_NAME_FEED_ITEMS, FEEDITEM_SEL_FI_SMALL, KEY_FEED
+ "=? AND " + KEY_DESCRIPTION + " LIKE '%"
+ prepareSearchQuery(query) + "%'",
new String[]{String.valueOf(feedID)}, null, null,
null);
} else {
// search through all items
- return db.query(TABLE_NAME_FEED_ITEMS, SEL_FI_SMALL,
+ return db.query(TABLE_NAME_FEED_ITEMS, FEEDITEM_SEL_FI_SMALL,
KEY_DESCRIPTION + " LIKE '%" + prepareSearchQuery(query)
+ "%'", null, null, null, null);
}
@@ -960,14 +1005,14 @@ public class PodDBAdapter {
public Cursor searchItemContentEncoded(long feedID, String query) {
if (feedID != 0) {
// search items in specific feed
- return db.query(TABLE_NAME_FEED_ITEMS, SEL_FI_SMALL, KEY_FEED
+ return db.query(TABLE_NAME_FEED_ITEMS, FEEDITEM_SEL_FI_SMALL, KEY_FEED
+ "=? AND " + KEY_CONTENT_ENCODED + " LIKE '%"
+ prepareSearchQuery(query) + "%'",
new String[]{String.valueOf(feedID)}, null, null,
null);
} else {
// search through all items
- return db.query(TABLE_NAME_FEED_ITEMS, SEL_FI_SMALL,
+ return db.query(TABLE_NAME_FEED_ITEMS, FEEDITEM_SEL_FI_SMALL,
KEY_CONTENT_ENCODED + " LIKE '%"
+ prepareSearchQuery(query) + "%'", null, null,
null, null);
@@ -977,14 +1022,14 @@ public class PodDBAdapter {
public Cursor searchItemTitles(long feedID, String query) {
if (feedID != 0) {
// search items in specific feed
- return db.query(TABLE_NAME_FEED_ITEMS, SEL_FI_SMALL, KEY_FEED
+ return db.query(TABLE_NAME_FEED_ITEMS, FEEDITEM_SEL_FI_SMALL, KEY_FEED
+ "=? AND " + KEY_TITLE + " LIKE '%"
+ prepareSearchQuery(query) + "%'",
new String[]{String.valueOf(feedID)}, null, null,
null);
} else {
// search through all items
- return db.query(TABLE_NAME_FEED_ITEMS, SEL_FI_SMALL,
+ return db.query(TABLE_NAME_FEED_ITEMS, FEEDITEM_SEL_FI_SMALL,
KEY_TITLE + " LIKE '%"
+ prepareSearchQuery(query) + "%'", null, null,
null, null);
@@ -1120,6 +1165,11 @@ public class PodDBAdapter {
}
feeditemCursor.close();
}
+ if (oldVersion <= 9) {
+ db.execSQL("ALTER TABLE " + TABLE_NAME_FEEDS
+ + " ADD COLUMN " + KEY_AUTO_DOWNLOAD
+ + " INTEGER DEFAULT 1");
+ }
}
}
}