diff options
Diffstat (limited to 'storage/database')
2 files changed, 40 insertions, 2 deletions
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 46c731205..bcb57f3bb 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; @@ -1095,9 +1097,11 @@ public class PodDBAdapter { return db.rawQuery(query, null); } - public Cursor getDownloadedItemsCursor() { + public Cursor getDownloadedItemsCursor(SortOrder sortOrder) { + String sortQuery = FeedItemSortQuery.generateFrom(sortOrder); final String query = SELECT_FEED_ITEMS_AND_MEDIA - + "WHERE " + TABLE_NAME_FEED_MEDIA + "." + KEY_DOWNLOADED + " > 0"; + + " WHERE " + TABLE_NAME_FEED_MEDIA + "." + KEY_DOWNLOADED + " > 0" + + " ORDER BY " + sortQuery; return db.rawQuery(query, null); } 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 |