diff --git a/src/ch/blinkenlights/android/vanilla/PlaybackService.java b/src/ch/blinkenlights/android/vanilla/PlaybackService.java index 03cab5ab..c10e0def 100644 --- a/src/ch/blinkenlights/android/vanilla/PlaybackService.java +++ b/src/ch/blinkenlights/android/vanilla/PlaybackService.java @@ -264,7 +264,14 @@ public final class PlaybackService extends Service * The appplication-wide instance of the PlaybackService. */ public static PlaybackService sInstance; + /** + * Static referenced-array to PlaybackActivities, used for callbacks + */ private static final ArrayList sActivities = new ArrayList(5); + /** + * Static reference to the ShowQueueActivity + */ + private static ShowQueueActivity sShowQueueActivity = null; /** * Cached app-wide SharedPreferences instance. */ @@ -1652,6 +1659,10 @@ public final class PlaybackService extends Service // to processSong(); mHandler.removeMessages(GAPLESS_UPDATE); mHandler.sendEmptyMessageDelayed(GAPLESS_UPDATE, 350); + + if (sShowQueueActivity != null) + sShowQueueActivity.refreshSongQueueList(false); + } @Override @@ -1720,6 +1731,14 @@ public final class PlaybackService extends Service sActivities.remove(activity); } + public static void addActivity(ShowQueueActivity activity) { + sShowQueueActivity = activity; + } + + public static void removeActivity(ShowQueueActivity activity) { + sShowQueueActivity = null; + } + /** * Initializes the service state, loading songs saved from the disk into the * song timeline. diff --git a/src/ch/blinkenlights/android/vanilla/ShowQueueActivity.java b/src/ch/blinkenlights/android/vanilla/ShowQueueActivity.java index 6e811525..5b35b0d4 100644 --- a/src/ch/blinkenlights/android/vanilla/ShowQueueActivity.java +++ b/src/ch/blinkenlights/android/vanilla/ShowQueueActivity.java @@ -50,6 +50,8 @@ public class ShowQueueActivity mListView.setFastScrollAlwaysVisible(true); mListView.setEditable(true); + PlaybackService.addActivity(this); + mListView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView parent, View view, int position, long id) { @@ -60,10 +62,6 @@ public class ShowQueueActivity @Override public boolean onItemLongClick(AdapterView parent, View view, int position, long id) { mService.jumpToQueuePosition(position); - /* This activity will stay open on longpress, so we have - * to update the playmerker ourselfs */ - listAdapter.highlightRow(position); - listAdapter.notifyDataSetChanged(); return true; }}); @@ -89,6 +87,12 @@ public class ShowQueueActivity refreshSongQueueList(true); } + @Override + public void onDestroy() { + PlaybackService.removeActivity(this); + super.onDestroy(); + } + /** * Fired from adapter list if user moved an item * @param from the item index that was dragged @@ -96,23 +100,30 @@ public class ShowQueueActivity */ public void onItemMoved(int from, int to) { mService.moveSong(from, to); - refreshSongQueueList(false); } - private void refreshSongQueueList(boolean scroll) { - int i, stotal, spos; + /** + * Triggers a refresh of the queueview + * @param scroll enable or disable jumping to the currently playing item + */ + public void refreshSongQueueList(final boolean scroll) { + runOnUiThread(new Runnable(){ + public void run() { + int i, stotal, spos; + stotal = mService.getTimelineLength(); /* Total number of songs in queue */ + spos = mService.getTimelinePosition(); /* Current position in queue */ - stotal = mService.getTimelineLength(); /* Total number of songs in queue */ - spos = mService.getTimelinePosition(); /* Current position in queue */ + listAdapter.clear(); /* Flush all existing entries... */ + listAdapter.highlightRow(spos); /* and highlight current position */ - listAdapter.clear(); /* Flush all existing entries... */ - listAdapter.highlightRow(spos); /* and highlight current position */ + for(i=0 ; i