diff options
author | daniel oeh <daniel.oeh@gmail.com> | 2014-11-10 12:32:10 +0100 |
---|---|---|
committer | daniel oeh <daniel.oeh@gmail.com> | 2014-11-10 12:32:10 +0100 |
commit | d2ee409530405d0004787ca734455f6679904a56 (patch) | |
tree | 6a0182c4aac3163fe76d0c35e67e6d598a1401c6 | |
parent | c49db40ebe75329e1e94885fe2467f7588e8b6ce (diff) | |
download | AntennaPod-d2ee409530405d0004787ca734455f6679904a56.zip |
Bugfix: Playbackhistory had wrong sort order
fixes #540
3 files changed, 7 insertions, 7 deletions
diff --git a/app/src/androidTest/java/de/test/antennapod/storage/DBReaderTest.java b/app/src/androidTest/java/de/test/antennapod/storage/DBReaderTest.java index 63286d11d..33f7fb350 100644 --- a/app/src/androidTest/java/de/test/antennapod/storage/DBReaderTest.java +++ b/app/src/androidTest/java/de/test/antennapod/storage/DBReaderTest.java @@ -325,8 +325,9 @@ public class DBReaderTest extends InstrumentationTestCase { public void testGetPlaybackHistory() { final Context context = getInstrumentation().getTargetContext(); - final int numItems = 10; - final int playedItems = 5; + final int numItems = (DBReader.PLAYBACK_HISTORY_SIZE+1) * 2; + final int playedItems = DBReader.PLAYBACK_HISTORY_SIZE + 1; + final int numReturnedItems = Math.min(playedItems, DBReader.PLAYBACK_HISTORY_SIZE); final int numFeeds = 1; Feed feed = DBTestUtils.saveFeedlist(context, numFeeds, numItems, true).get(0); @@ -344,8 +345,8 @@ public class DBReaderTest extends InstrumentationTestCase { List<FeedItem> saved = DBReader.getPlaybackHistory(context); assertNotNull(saved); - assertEquals("Wrong size: ", playedItems, saved.size()); - for (int i = 0; i < playedItems; i++) { + assertEquals("Wrong size: ", numReturnedItems, saved.size()); + for (int i = 0; i < numReturnedItems; i++) { FeedItem item = saved.get(i); assertNotNull(item.getMedia().getPlaybackCompletionDate()); assertEquals("Wrong sort order: ", item.getId(), ids[i]); diff --git a/core/src/main/java/de/danoeh/antennapod/core/storage/DBReader.java b/core/src/main/java/de/danoeh/antennapod/core/storage/DBReader.java index 62edaae29..9cc87cb47 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/storage/DBReader.java +++ b/core/src/main/java/de/danoeh/antennapod/core/storage/DBReader.java @@ -549,7 +549,6 @@ public final class DBReader { public static List<FeedItem> getPlaybackHistory(final Context context) { if (BuildConfig.DEBUG) Log.d(TAG, "Loading playback history"); - final int PLAYBACK_HISTORY_SIZE = 50; PodDBAdapter adapter = new PodDBAdapter(context); adapter.open(); diff --git a/core/src/main/java/de/danoeh/antennapod/core/storage/PodDBAdapter.java b/core/src/main/java/de/danoeh/antennapod/core/storage/PodDBAdapter.java index 6b6e09369..eab92eab2 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/storage/PodDBAdapter.java +++ b/core/src/main/java/de/danoeh/antennapod/core/storage/PodDBAdapter.java @@ -1037,8 +1037,8 @@ public class PodDBAdapter { Validate.isTrue(limit >= 0, "Limit must be >= 0"); Cursor c = db.query(TABLE_NAME_FEED_MEDIA, null, - KEY_PLAYBACK_COMPLETION_DATE + " > 0 LIMIT " + limit, null, null, - null, null); + KEY_PLAYBACK_COMPLETION_DATE + " > 0", null, null, + null, String.format("%s DESC LIMIT %d", KEY_PLAYBACK_COMPLETION_DATE, limit)); return c; } |