diff options
Diffstat (limited to 'storage/database')
5 files changed, 75 insertions, 77 deletions
diff --git a/storage/database/build.gradle b/storage/database/build.gradle index 141cdb086..0dc5cef63 100644 --- a/storage/database/build.gradle +++ b/storage/database/build.gradle @@ -4,8 +4,8 @@ plugins { apply from: "../../common.gradle" android { - lintOptions { - disable "StaticFieldLeak" + lint { + disable "StaticFieldLeak", "StringFormatCount", "StringFormatMatches", "StringFormatInvalid", "PluralsCandidate", "StringFormatTrivial" } } diff --git a/storage/database/src/main/java/de/danoeh/antennapod/storage/database/DBUpgrader.java b/storage/database/src/main/java/de/danoeh/antennapod/storage/database/DBUpgrader.java index 78eaf6964..e4a1f5a3d 100644 --- a/storage/database/src/main/java/de/danoeh/antennapod/storage/database/DBUpgrader.java +++ b/storage/database/src/main/java/de/danoeh/antennapod/storage/database/DBUpgrader.java @@ -330,6 +330,10 @@ class DBUpgrader { db.execSQL("ALTER TABLE " + PodDBAdapter.TABLE_NAME_FEED_ITEMS + " ADD COLUMN " + PodDBAdapter.KEY_PODCASTINDEX_CHAPTER_URL + " TEXT"); } + if (oldVersion < 3010000) { + db.execSQL("ALTER TABLE " + PodDBAdapter.TABLE_NAME_FEEDS + + " ADD COLUMN " + PodDBAdapter.KEY_NEW_EPISODES_ACTION + " INTEGER DEFAULT 0"); + } } } diff --git a/storage/database/src/main/java/de/danoeh/antennapod/storage/database/PodDBAdapter.java b/storage/database/src/main/java/de/danoeh/antennapod/storage/database/PodDBAdapter.java index 35064b605..40933e8d1 100644 --- a/storage/database/src/main/java/de/danoeh/antennapod/storage/database/PodDBAdapter.java +++ b/storage/database/src/main/java/de/danoeh/antennapod/storage/database/PodDBAdapter.java @@ -38,6 +38,8 @@ import de.danoeh.antennapod.model.feed.FeedPreferences; import de.danoeh.antennapod.model.download.DownloadStatus; import de.danoeh.antennapod.model.feed.SortOrder; import de.danoeh.antennapod.storage.database.mapper.FeedItemFilterQuery; +import de.danoeh.antennapod.storage.database.mapper.FeedItemSortQuery; + import org.apache.commons.io.FileUtils; import static de.danoeh.antennapod.model.feed.FeedPreferences.SPEED_USE_GLOBAL; @@ -50,7 +52,7 @@ public class PodDBAdapter { private static final String TAG = "PodDBAdapter"; public static final String DATABASE_NAME = "Antennapod.db"; - public static final int VERSION = 2060000; + public static final int VERSION = 3010000; /** * Maximum number of arguments for IN-operator. @@ -116,6 +118,7 @@ public class PodDBAdapter { public static final String KEY_FEED_SKIP_ENDING = "feed_skip_ending"; public static final String KEY_FEED_TAGS = "tags"; public static final String KEY_EPISODE_NOTIFICATION = "episode_notification"; + public static final String KEY_NEW_EPISODES_ACTION = "new_episodes_action"; public static final String KEY_PODCASTINDEX_CHAPTER_URL = "podcastindex_chapter_url"; // Table names @@ -157,7 +160,8 @@ public class PodDBAdapter { + KEY_FEED_TAGS + " TEXT," + KEY_FEED_SKIP_INTRO + " INTEGER DEFAULT 0," + KEY_FEED_SKIP_ENDING + " INTEGER DEFAULT 0," - + KEY_EPISODE_NOTIFICATION + " INTEGER DEFAULT 0)"; + + KEY_EPISODE_NOTIFICATION + " INTEGER DEFAULT 0," + + KEY_NEW_EPISODES_ACTION + " INTEGER DEFAULT 0)"; private static final String CREATE_TABLE_FEED_ITEMS = "CREATE TABLE " + TABLE_NAME_FEED_ITEMS + " (" + TABLE_PRIMARY_KEY @@ -307,7 +311,8 @@ public class PodDBAdapter { + TABLE_NAME_FEEDS + "." + KEY_FEED_TAGS + ", " + TABLE_NAME_FEEDS + "." + KEY_FEED_SKIP_INTRO + ", " + TABLE_NAME_FEEDS + "." + KEY_FEED_SKIP_ENDING + ", " - + TABLE_NAME_FEEDS + "." + KEY_EPISODE_NOTIFICATION; + + TABLE_NAME_FEEDS + "." + KEY_EPISODE_NOTIFICATION + ", " + + TABLE_NAME_FEEDS + "." + KEY_NEW_EPISODES_ACTION; private static final String JOIN_FEED_ITEM_AND_MEDIA = " LEFT JOIN " + TABLE_NAME_FEED_MEDIA + " ON " + TABLE_NAME_FEED_ITEMS + "." + KEY_ID + "=" + TABLE_NAME_FEED_MEDIA + "." + KEY_FEEDITEM + " "; @@ -444,7 +449,7 @@ public class PodDBAdapter { ContentValues values = new ContentValues(); values.put(KEY_AUTO_DOWNLOAD_ENABLED, prefs.getAutoDownload()); values.put(KEY_KEEP_UPDATED, prefs.getKeepUpdated()); - values.put(KEY_AUTO_DELETE_ACTION, prefs.getAutoDeleteAction().ordinal()); + values.put(KEY_AUTO_DELETE_ACTION, prefs.getAutoDeleteAction().code); values.put(KEY_FEED_VOLUME_ADAPTION, prefs.getVolumeAdaptionSetting().toInteger()); values.put(KEY_USERNAME, prefs.getUsername()); values.put(KEY_PASSWORD, prefs.getPassword()); @@ -456,6 +461,7 @@ public class PodDBAdapter { values.put(KEY_FEED_SKIP_INTRO, prefs.getFeedSkipIntro()); values.put(KEY_FEED_SKIP_ENDING, prefs.getFeedSkipEnding()); values.put(KEY_EPISODE_NOTIFICATION, prefs.getShowEpisodeNotification()); + values.put(KEY_NEW_EPISODES_ACTION, prefs.getNewEpisodesAction().code); db.update(TABLE_NAME_FEEDS, values, KEY_ID + "=?", new String[]{String.valueOf(prefs.getFeedID())}); } @@ -728,6 +734,13 @@ public class PodDBAdapter { } } + public void resetPagedFeedPage(Feed feed) { + final String sql = "UPDATE " + TABLE_NAME_FEEDS + + " SET " + KEY_NEXT_PAGE_LINK + "=" + KEY_DOWNLOAD_URL + + " WHERE " + KEY_ID + "=" + feed.getId(); + db.execSQL(sql); + } + public void setFeedLastUpdateFailed(long feedId, boolean failed) { final String sql = "UPDATE " + TABLE_NAME_FEEDS + " SET " + KEY_LAST_UPDATE_FAILED + "=" + (failed ? "1" : "0") @@ -1041,27 +1054,20 @@ public class PodDBAdapter { db.execSQL(sql); } - /** - * Returns a cursor which contains all feed items that are considered new. - * Excludes those feeds that do not have 'Keep Updated' enabled. - * The returned cursor uses the FEEDITEM_SEL_FI_SMALL selection. - */ - public final Cursor getNewItemsCursor(int offset, int limit) { - final String query = SELECT_FEED_ITEMS_AND_MEDIA - + " INNER JOIN " + TABLE_NAME_FEEDS - + " ON " + TABLE_NAME_FEED_ITEMS + "." + KEY_FEED + "=" + TABLE_NAME_FEEDS + "." + KEY_ID - + " WHERE " + TABLE_NAME_FEED_ITEMS + "." + KEY_READ + "=" + FeedItem.NEW - + " AND " + TABLE_NAME_FEEDS + "." + KEY_KEEP_UPDATED + " > 0" - + " ORDER BY " + TABLE_NAME_FEED_ITEMS + "." + KEY_PUBDATE + " DESC" - + " LIMIT " + offset + ", " + limit; + public final Cursor getEpisodesCursor(int offset, int limit, FeedItemFilter filter, SortOrder sortOrder) { + String orderByQuery = FeedItemSortQuery.generateFrom(sortOrder); + String filterQuery = FeedItemFilterQuery.generateFrom(filter); + String whereClause = "".equals(filterQuery) ? "" : " WHERE " + filterQuery; + final String query = SELECT_FEED_ITEMS_AND_MEDIA + whereClause + + "ORDER BY " + orderByQuery + " LIMIT " + offset + ", " + limit; return db.rawQuery(query, null); } - public final Cursor getRecentlyPublishedItemsCursor(int offset, int limit, FeedItemFilter filter) { + public final Cursor getEpisodeCountCursor(FeedItemFilter filter) { String filterQuery = FeedItemFilterQuery.generateFrom(filter); String whereClause = "".equals(filterQuery) ? "" : " WHERE " + filterQuery; - final String query = SELECT_FEED_ITEMS_AND_MEDIA + whereClause - + " ORDER BY " + KEY_PUBDATE + " DESC LIMIT " + offset + ", " + limit; + final String query = "SELECT count(" + TABLE_NAME_FEED_ITEMS + "." + KEY_ID + ") FROM " + TABLE_NAME_FEED_ITEMS + + JOIN_FEED_ITEM_AND_MEDIA + whereClause; return db.rawQuery(query, null); } @@ -1087,26 +1093,6 @@ public class PodDBAdapter { return "((" + SELECT_KEY_ITEM_ID + " * " + seed + ") % 46471)"; } - public final Cursor getTotalEpisodeCountCursor(FeedItemFilter filter) { - String filterQuery = FeedItemFilterQuery.generateFrom(filter); - String whereClause = "".equals(filterQuery) ? "" : " WHERE " + filterQuery; - final String query = "SELECT count(" + TABLE_NAME_FEED_ITEMS + "." + KEY_ID + ") FROM " + TABLE_NAME_FEED_ITEMS - + JOIN_FEED_ITEM_AND_MEDIA + whereClause; - return db.rawQuery(query, null); - } - - public Cursor getDownloadedItemsCursor() { - final String query = SELECT_FEED_ITEMS_AND_MEDIA - + "WHERE " + TABLE_NAME_FEED_MEDIA + "." + KEY_DOWNLOADED + " > 0"; - return db.rawQuery(query, null); - } - - public Cursor getPlayedItemsCursor() { - final String query = SELECT_FEED_ITEMS_AND_MEDIA - + "WHERE " + TABLE_NAME_FEED_ITEMS + "." + KEY_READ + "=" + FeedItem.PLAYED; - return db.rawQuery(query, null); - } - /** * Returns a cursor which contains feed media objects with a playback * completion date in ascending order. @@ -1214,7 +1200,7 @@ public class PodDBAdapter { + TABLE_NAME_FEED_MEDIA + "." + KEY_POSITION + "> 0"; } final String timeFilter = lastPlayedTime + ">=" + timeFilterFrom - + " AND " + lastPlayedTime + "<=" + timeFilterTo; + + " AND " + lastPlayedTime + "<" + timeFilterTo; String playedTime = TABLE_NAME_FEED_MEDIA + "." + KEY_PLAYED_DURATION; if (includeMarkedAsPlayed) { playedTime = "(CASE WHEN " + playedTime + " != 0" @@ -1255,25 +1241,6 @@ public class PodDBAdapter { return result; } - public final int getNumberOfNewItems() { - Object[] args = new String[]{ - TABLE_NAME_FEED_ITEMS + "." + KEY_ID, - TABLE_NAME_FEED_ITEMS, - TABLE_NAME_FEEDS, - TABLE_NAME_FEED_ITEMS + "." + KEY_FEED + "=" + TABLE_NAME_FEEDS + "." + KEY_ID, - TABLE_NAME_FEED_ITEMS + "." + KEY_READ + "=" + FeedItem.NEW - + " AND " + TABLE_NAME_FEEDS + "." + KEY_KEEP_UPDATED + " > 0" - }; - final String query = String.format("SELECT COUNT(%s) FROM %s INNER JOIN %s ON %s WHERE %s", args); - Cursor c = db.rawQuery(query, null); - int result = 0; - if (c.moveToFirst()) { - result = c.getInt(0); - } - c.close(); - return result; - } - public final Map<Long, Integer> getFeedCounters(FeedCounter setting, long... feedIds) { String whereRead; switch (setting) { @@ -1359,19 +1326,6 @@ public class PodDBAdapter { return result; } - public final int getNumberOfDownloadedEpisodes() { - final String query = "SELECT COUNT(DISTINCT " + KEY_ID + ") AS count FROM " + TABLE_NAME_FEED_MEDIA + - " WHERE " + KEY_DOWNLOADED + " > 0"; - - Cursor c = db.rawQuery(query, null); - int result = 0; - if (c.moveToFirst()) { - result = c.getInt(0); - } - c.close(); - return result; - } - /** * Uses DatabaseUtils to escape a search query and removes ' at the * beginning and the end of the string returned by the escape method. @@ -1530,6 +1484,9 @@ public class PodDBAdapter { public void onUpgrade(final SQLiteDatabase db, final int oldVersion, final int newVersion) { Log.w("DBAdapter", "Upgrading from version " + oldVersion + " to " + newVersion + "."); DBUpgrader.upgrade(db, oldVersion, newVersion); + + db.execSQL("DELETE FROM " + PodDBAdapter.TABLE_NAME_DOWNLOAD_LOG + " WHERE " + + PodDBAdapter.KEY_COMPLETION_DATE + "<" + (System.currentTimeMillis() - 7L * 24L * 3600L * 1000L)); } } } diff --git a/storage/database/src/main/java/de/danoeh/antennapod/storage/database/mapper/FeedItemSortQuery.java b/storage/database/src/main/java/de/danoeh/antennapod/storage/database/mapper/FeedItemSortQuery.java new file mode 100644 index 000000000..aae5154d3 --- /dev/null +++ b/storage/database/src/main/java/de/danoeh/antennapod/storage/database/mapper/FeedItemSortQuery.java @@ -0,0 +1,34 @@ +package de.danoeh.antennapod.storage.database.mapper; + +import de.danoeh.antennapod.model.feed.SortOrder; +import de.danoeh.antennapod.storage.database.PodDBAdapter; + +public class FeedItemSortQuery { + public static String generateFrom(SortOrder sortOrder) { + String sortQuery = ""; + switch (sortOrder) { + case EPISODE_TITLE_A_Z: + sortQuery = PodDBAdapter.TABLE_NAME_FEED_ITEMS + "." + PodDBAdapter.KEY_TITLE + " " + "ASC"; + break; + case EPISODE_TITLE_Z_A: + sortQuery = PodDBAdapter.TABLE_NAME_FEED_ITEMS + "." + PodDBAdapter.KEY_TITLE + " " + "DESC"; + break; + case DATE_OLD_NEW: + sortQuery = PodDBAdapter.TABLE_NAME_FEED_ITEMS + "." + PodDBAdapter.KEY_PUBDATE + " " + "ASC"; + break; + case DATE_NEW_OLD: + sortQuery = PodDBAdapter.TABLE_NAME_FEED_ITEMS + "." + PodDBAdapter.KEY_PUBDATE + " " + "DESC"; + break; + case DURATION_SHORT_LONG: + sortQuery = PodDBAdapter.TABLE_NAME_FEED_MEDIA + "." + PodDBAdapter.KEY_DURATION + " " + "ASC"; + break; + case DURATION_LONG_SHORT: + sortQuery = PodDBAdapter.TABLE_NAME_FEED_MEDIA + "." + PodDBAdapter.KEY_DURATION + " " + "DESC"; + break; + default: + sortQuery = ""; + break; + } + return sortQuery; + } +}
\ No newline at end of file diff --git a/storage/database/src/main/java/de/danoeh/antennapod/storage/database/mapper/FeedPreferencesCursorMapper.java b/storage/database/src/main/java/de/danoeh/antennapod/storage/database/mapper/FeedPreferencesCursorMapper.java index 289bcbab8..2de100dff 100644 --- a/storage/database/src/main/java/de/danoeh/antennapod/storage/database/mapper/FeedPreferencesCursorMapper.java +++ b/storage/database/src/main/java/de/danoeh/antennapod/storage/database/mapper/FeedPreferencesCursorMapper.java @@ -34,14 +34,14 @@ public abstract class FeedPreferencesCursorMapper { int indexAutoSkipIntro = cursor.getColumnIndexOrThrow(PodDBAdapter.KEY_FEED_SKIP_INTRO); int indexAutoSkipEnding = cursor.getColumnIndexOrThrow(PodDBAdapter.KEY_FEED_SKIP_ENDING); int indexEpisodeNotification = cursor.getColumnIndexOrThrow(PodDBAdapter.KEY_EPISODE_NOTIFICATION); + int indexNewEpisodesAction = cursor.getColumnIndexOrThrow(PodDBAdapter.KEY_NEW_EPISODES_ACTION); int indexTags = cursor.getColumnIndexOrThrow(PodDBAdapter.KEY_FEED_TAGS); long feedId = cursor.getLong(indexId); boolean autoDownload = cursor.getInt(indexAutoDownload) > 0; boolean autoRefresh = cursor.getInt(indexAutoRefresh) > 0; - int autoDeleteActionIndex = cursor.getInt(indexAutoDeleteAction); FeedPreferences.AutoDeleteAction autoDeleteAction = - FeedPreferences.AutoDeleteAction.values()[autoDeleteActionIndex]; + FeedPreferences.AutoDeleteAction.fromCode(cursor.getInt(indexAutoDeleteAction)); int volumeAdaptionValue = cursor.getInt(indexVolumeAdaption); VolumeAdaptionSetting volumeAdaptionSetting = VolumeAdaptionSetting.fromInteger(volumeAdaptionValue); String username = cursor.getString(indexUsername); @@ -52,6 +52,8 @@ public abstract class FeedPreferencesCursorMapper { float feedPlaybackSpeed = cursor.getFloat(indexFeedPlaybackSpeed); int feedAutoSkipIntro = cursor.getInt(indexAutoSkipIntro); int feedAutoSkipEnding = cursor.getInt(indexAutoSkipEnding); + FeedPreferences.NewEpisodesAction feedNewEpisodesAction = + FeedPreferences.NewEpisodesAction.fromCode(cursor.getInt(indexNewEpisodesAction)); boolean showNotification = cursor.getInt(indexEpisodeNotification) > 0; String tagsString = cursor.getString(indexTags); if (TextUtils.isEmpty(tagsString)) { @@ -69,6 +71,7 @@ public abstract class FeedPreferencesCursorMapper { feedAutoSkipIntro, feedAutoSkipEnding, showNotification, + feedNewEpisodesAction, new HashSet<>(Arrays.asList(tagsString.split(FeedPreferences.TAG_SEPARATOR)))); } } |