diff options
author | daniel oeh <daniel.oeh@gmail.com> | 2013-10-08 23:43:13 +0200 |
---|---|---|
committer | daniel oeh <daniel.oeh@gmail.com> | 2013-10-08 23:43:13 +0200 |
commit | e58922fad08bedf4bfe86025d836abdeae49a806 (patch) | |
tree | 1bd8699fdf274fec52700affaeeb4a32382d2ae0 /src/de | |
parent | a482899eef4a0a7ada979ba0c87b19e91c2f49f1 (diff) | |
parent | cdd9a0dfdeef8d319063f844fce1e1722f7d9529 (diff) | |
download | AntennaPod-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
Diffstat (limited to 'src/de')
-rw-r--r-- | src/de/danoeh/antennapod/activity/FeedInfoActivity.java | 27 | ||||
-rw-r--r-- | src/de/danoeh/antennapod/feed/Feed.java | 19 | ||||
-rw-r--r-- | src/de/danoeh/antennapod/feed/FeedPreferences.java | 39 | ||||
-rw-r--r-- | src/de/danoeh/antennapod/storage/DBReader.java | 48 | ||||
-rw-r--r-- | src/de/danoeh/antennapod/storage/DBTasks.java | 14 | ||||
-rw-r--r-- | src/de/danoeh/antennapod/storage/DBWriter.java | 20 | ||||
-rw-r--r-- | src/de/danoeh/antennapod/storage/PodDBAdapter.java | 110 |
7 files changed, 210 insertions, 67 deletions
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"); + } } } } |