From 5926ba234c562c1731de1a6f080b4c383260fc19 Mon Sep 17 00:00:00 2001 From: Adrian Ulrich Date: Sun, 12 Oct 2014 21:11:37 +0200 Subject: [PATCH] bugfix: avoid returning stale songs in any case --- .../android/vanilla/SongTimeline.java | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/ch/blinkenlights/android/vanilla/SongTimeline.java b/src/ch/blinkenlights/android/vanilla/SongTimeline.java index 55a326ef..07191d28 100644 --- a/src/ch/blinkenlights/android/vanilla/SongTimeline.java +++ b/src/ch/blinkenlights/android/vanilla/SongTimeline.java @@ -341,14 +341,22 @@ public final class SongTimeline { cursor.moveToNext(); if (cursor.getLong(0) == e.id) e.populate(cursor); - else - // We weren't able to query this song. - it.remove(); } } cursor.close(); + // The query may have returned zero results or we might + // have failed to populate some songs: Get rid of all + // uninitialized items (where path == null) + Iterator it = songs.iterator(); + while (it.hasNext()) { + Song e = it.next(); + if (e.path == null) { + it.remove(); + } + } + // Revert to the order the songs were saved in. Collections.sort(songs, new FlagComparator());