From 647f3ecc39b315260099ede2065085fe5e1ff43e Mon Sep 17 00:00:00 2001 From: daniel oeh Date: Wed, 24 Oct 2012 20:56:43 +0200 Subject: Added methods for getting cursors with different feeditem column selections --- src/de/danoeh/antennapod/feed/FeedManager.java | 22 +++----- src/de/danoeh/antennapod/storage/PodDBAdapter.java | 65 ++++++++++++---------- 2 files changed, 44 insertions(+), 43 deletions(-) (limited to 'src/de') diff --git a/src/de/danoeh/antennapod/feed/FeedManager.java b/src/de/danoeh/antennapod/feed/FeedManager.java index d9b4e6c56..955422ee5 100644 --- a/src/de/danoeh/antennapod/feed/FeedManager.java +++ b/src/de/danoeh/antennapod/feed/FeedManager.java @@ -1129,37 +1129,33 @@ public class FeedManager { do { FeedItem item = new FeedItem(); - item.id = itemlistCursor.getLong(PodDBAdapter.KEY_ID_INDEX); + item.id = itemlistCursor.getLong(PodDBAdapter.IDX_FI_SMALL_ID); item.setFeed(feed); item.setTitle(itemlistCursor - .getString(PodDBAdapter.KEY_TITLE_INDEX)); + .getString(PodDBAdapter.IDX_FI_SMALL_TITLE)); item.setLink(itemlistCursor - .getString(PodDBAdapter.KEY_LINK_INDEX)); - item.setDescription(itemlistCursor - .getString(PodDBAdapter.KEY_DESCRIPTION_INDEX)); - item.setContentEncoded(itemlistCursor - .getString(PodDBAdapter.KEY_CONTENT_ENCODED_INDEX)); + .getString(PodDBAdapter.IDX_FI_SMALL_LINK)); item.setPubDate(new Date(itemlistCursor - .getLong(PodDBAdapter.KEY_PUBDATE_INDEX))); + .getLong(PodDBAdapter.IDX_FI_SMALL_PUBDATE))); item.setPaymentLink(itemlistCursor - .getString(PodDBAdapter.KEY_PAYMENT_LINK_INDEX)); + .getString(PodDBAdapter.IDX_FI_SMALL_PAYMENT_LINK)); long mediaId = itemlistCursor - .getLong(PodDBAdapter.KEY_MEDIA_INDEX); + .getLong(PodDBAdapter.IDX_FI_SMALL_MEDIA); if (mediaId != 0) { mediaIds.add(String.valueOf(mediaId)); item.setMedia(new FeedMedia(mediaId, item)); } - item.read = (itemlistCursor.getInt(PodDBAdapter.KEY_READ_INDEX) > 0) ? true + item.read = (itemlistCursor.getInt(PodDBAdapter.IDX_FI_SMALL_READ) > 0) ? true : false; item.setItemIdentifier(itemlistCursor - .getString(PodDBAdapter.KEY_ITEM_IDENTIFIER_INDEX)); + .getString(PodDBAdapter.IDX_FI_SMALL_ITEM_IDENTIFIER)); if (!item.read) { unreadItems.add(item); } // extract chapters boolean hasSimpleChapters = itemlistCursor - .getInt(PodDBAdapter.KEY_HAS_SIMPLECHAPTERS_INDEX) > 0; + .getInt(PodDBAdapter.IDX_FI_SMALL_HAS_CHAPTERS) > 0; if (hasSimpleChapters) { Cursor chapterCursor = adapter .getSimpleChaptersOfFeedItemCursor(item); diff --git a/src/de/danoeh/antennapod/storage/PodDBAdapter.java b/src/de/danoeh/antennapod/storage/PodDBAdapter.java index 7b7b1b1e3..efe1704b7 100644 --- a/src/de/danoeh/antennapod/storage/PodDBAdapter.java +++ b/src/de/danoeh/antennapod/storage/PodDBAdapter.java @@ -180,22 +180,16 @@ public class PodDBAdapter { private final Context context; private PodDBHelper helper; - /** Select all columns from the feeditems-table except description and content-encoded. */ - private static final String[] SEL_FI_SMALL = { - KEY_ID, - KEY_TITLE, - KEY_PUBDATE, - KEY_READ, - KEY_LINK, - KEY_PAYMENT_LINK, - KEY_MEDIA, - KEY_FEED, - KEY_HAS_CHAPTERS, - KEY_ITEM_IDENTIFIER - }; - + /** + * Select all columns from the feeditems-table except description and + * content-encoded. + */ + private static final String[] SEL_FI_SMALL = { KEY_ID, KEY_TITLE, + KEY_PUBDATE, KEY_READ, KEY_LINK, KEY_PAYMENT_LINK, KEY_MEDIA, + KEY_FEED, KEY_HAS_CHAPTERS, KEY_ITEM_IDENTIFIER }; + // column indices for SEL_FI_SMALL - + public static final int IDX_FI_SMALL_ID = 0; public static final int IDX_FI_SMALL_TITLE = 1; public static final int IDX_FI_SMALL_PUBDATE = 2; @@ -208,18 +202,15 @@ public class PodDBAdapter { public static final int IDX_FI_SMALL_ITEM_IDENTIFIER = 9; /** Select id, description and content-encoded column from feeditems. */ - public static final String[] SEL_FI_EXTRA = { - KEY_ID, - KEY_DESCRIPTION, - KEY_CONTENT_ENCODED - }; - - //column indices for SEL_FI_EXTRA - + public static final String[] SEL_FI_EXTRA = { KEY_ID, KEY_DESCRIPTION, + KEY_CONTENT_ENCODED }; + + // column indices for SEL_FI_EXTRA + public static final int IDX_FI_EXTRA_ID = 0; public static final int IDX_FI_EXTRA_DESCRIPTION = 1; public static final int IDX_FI_EXTRA_CONTENT_ENCODED = 2; - + public PodDBAdapter(Context c) { this.context = c; helper = new PodDBHelper(context, DATABASE_NAME, null, DATABASE_VERSION); @@ -320,7 +311,8 @@ public class PodDBAdapter { values.put(KEY_DOWNLOADED, media.isDownloaded()); values.put(KEY_FILE_URL, media.getFile_url()); if (media.getPlaybackCompletionDate() != null) { - values.put(KEY_PLAYBACK_COMPLETION_DATE, media.getPlaybackCompletionDate().getTime()); + values.put(KEY_PLAYBACK_COMPLETION_DATE, media + .getPlaybackCompletionDate().getTime()); } else { values.put(KEY_PLAYBACK_COMPLETION_DATE, 0); } @@ -364,8 +356,12 @@ public class PodDBAdapter { ContentValues values = new ContentValues(); values.put(KEY_TITLE, item.getTitle()); values.put(KEY_LINK, item.getLink()); - values.put(KEY_DESCRIPTION, item.getDescription()); - values.put(KEY_CONTENT_ENCODED, item.getContentEncoded()); + if (item.getDescription() != null) { + values.put(KEY_DESCRIPTION, item.getDescription()); + } + if (item.getContentEncoded() != null) { + values.put(KEY_CONTENT_ENCODED, item.getContentEncoded()); + } values.put(KEY_PUBDATE, item.getPubDate().getTime()); values.put(KEY_PAYMENT_LINK, item.getPaymentLink()); if (item.getMedia() != null) { @@ -511,17 +507,26 @@ public class PodDBAdapter { } /** - * Returns a cursor with all FeedItems of a Feed. + * Returns a cursor with all FeedItems of a Feed. Uses SEL_FI_SMALL * * @param feed * The feed you want to get the FeedItems from. * @return The cursor of the query * */ public final Cursor getAllItemsOfFeedCursor(final Feed feed) { + open(); + Cursor c = db.query(TABLE_NAME_FEED_ITEMS, SEL_FI_SMALL, KEY_FEED + + "=?", new String[] { String.valueOf(feed.getId()) }, null, + null, null); + return c; + } + + /** Return a cursor with the SEL_FI_EXTRA selection of a single feeditem. */ + public final Cursor getExtraInformationOfItem(final FeedItem item) { open(); Cursor c = db - .query(TABLE_NAME_FEED_ITEMS, null, KEY_FEED + "=?", - new String[] { String.valueOf(feed.getId()) }, null, + .query(TABLE_NAME_FEED_ITEMS, SEL_FI_EXTRA, KEY_ID + "=?", + new String[] { String.valueOf(item.getId()) }, null, null, null); return c; } -- cgit v1.2.3