From c3bcc48d3c5e12f2ea8259340e90726a3b3a962c Mon Sep 17 00:00:00 2001 From: Adrian Ulrich Date: Wed, 22 Oct 2014 18:31:36 +0200 Subject: [PATCH] Move MENU_CLEAR_QUEUE action to PlaybackActivity and make ShowQueueActivity extend it --- .../android/vanilla/FullPlaybackActivity.java | 3 -- .../android/vanilla/PlaybackActivity.java | 17 ++++++- .../android/vanilla/PlaybackService.java | 18 ++----- .../android/vanilla/ShowQueueActivity.java | 48 ++++++++++++------- 4 files changed, 49 insertions(+), 37 deletions(-) diff --git a/src/ch/blinkenlights/android/vanilla/FullPlaybackActivity.java b/src/ch/blinkenlights/android/vanilla/FullPlaybackActivity.java index e65c2667..76e8fbd5 100644 --- a/src/ch/blinkenlights/android/vanilla/FullPlaybackActivity.java +++ b/src/ch/blinkenlights/android/vanilla/FullPlaybackActivity.java @@ -381,9 +381,6 @@ public class FullPlaybackActivity extends PlaybackActivity case MENU_ENQUEUE_GENRE: PlaybackService.get(this).enqueueFromCurrent(MediaUtils.TYPE_GENRE); break; - case MENU_CLEAR_QUEUE: - PlaybackService.get(this).clearQueue(); - break; case MENU_SONG_FAVORITE: PlaybackService psvc = PlaybackService.get(this); ContentResolver resolver = getContentResolver(); diff --git a/src/ch/blinkenlights/android/vanilla/PlaybackActivity.java b/src/ch/blinkenlights/android/vanilla/PlaybackActivity.java index d69b6fff..ff6e7f9a 100644 --- a/src/ch/blinkenlights/android/vanilla/PlaybackActivity.java +++ b/src/ch/blinkenlights/android/vanilla/PlaybackActivity.java @@ -1,6 +1,7 @@ /* * Copyright (C) 2010, 2011 Christopher Eby - * + * Copyright (C) 2014 Adrian Ulrich + * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights @@ -327,6 +328,13 @@ public abstract class PlaybackActivity extends Activity { } + /** + * Called when the timeline change has changed. + */ + public void onTimelineChanged() + { + } + static final int MENU_SORT = 1; static final int MENU_PREFS = 2; static final int MENU_LIBRARY = 3; @@ -338,6 +346,7 @@ public abstract class PlaybackActivity extends Activity static final int MENU_CLEAR_QUEUE = 11; static final int MENU_SONG_FAVORITE = 12; static final int MENU_SHOW_QUEUE = 13; + static final int MENU_SAVEAS_PLAYLIST = 14; @Override public boolean onCreateOptionsMenu(Menu menu) @@ -352,10 +361,14 @@ public abstract class PlaybackActivity extends Activity switch (item.getItemId()) { case MENU_PREFS: startActivity(new Intent(this, PreferencesActivity.class)); - return true; + break; + case MENU_CLEAR_QUEUE: + PlaybackService.get(this).clearQueue(); + break; default: return false; } + return true; } @Override diff --git a/src/ch/blinkenlights/android/vanilla/PlaybackService.java b/src/ch/blinkenlights/android/vanilla/PlaybackService.java index 217f4176..1376fb17 100644 --- a/src/ch/blinkenlights/android/vanilla/PlaybackService.java +++ b/src/ch/blinkenlights/android/vanilla/PlaybackService.java @@ -268,10 +268,6 @@ public final class PlaybackService extends Service * 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. */ @@ -1660,9 +1656,9 @@ public final class PlaybackService extends Service mHandler.removeMessages(GAPLESS_UPDATE); mHandler.sendEmptyMessageDelayed(GAPLESS_UPDATE, 350); - if (sShowQueueActivity != null) - sShowQueueActivity.refreshSongQueueList(false); - + ArrayList list = sActivities; + for (int i = list.size(); --i != -1; ) + list.get(i).onTimelineChanged(); } @Override @@ -1731,14 +1727,6 @@ 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 dcbe66bc..803e6e1e 100644 --- a/src/ch/blinkenlights/android/vanilla/ShowQueueActivity.java +++ b/src/ch/blinkenlights/android/vanilla/ShowQueueActivity.java @@ -22,6 +22,7 @@ import java.util.Arrays; import android.app.Activity; import android.os.Bundle; import android.view.View; +import android.view.Menu; import android.view.MenuItem; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; @@ -29,7 +30,7 @@ import android.widget.AdapterView.OnItemLongClickListener; import android.widget.ListView; import com.mobeta.android.dslv.DragSortListView; -public class ShowQueueActivity extends Activity { +public class ShowQueueActivity extends PlaybackActivity { private DragSortListView mListView; private ShowQueueAdapter listAdapter; private PlaybackService mService; @@ -49,8 +50,6 @@ public class ShowQueueActivity extends Activity { mListView.setDropListener(onDrop); mListView.setRemoveListener(onRemove); - PlaybackService.addActivity(this); - mListView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView parent, View view, int position, long id) { @@ -65,17 +64,32 @@ public class ShowQueueActivity extends Activity { }}); } - - /* - ** Called when the user hits the ActionBar item - ** There is only one item (title) and it should quit this activity - */ + + /** + * Inflate the ActionBar menu + */ @Override - public boolean onOptionsItemSelected(MenuItem item) { - finish(); + public boolean onCreateOptionsMenu(Menu menu) { + menu.add(0, MENU_CLEAR_QUEUE, 0, R.string.clear_queue).setIcon(R.drawable.ic_menu_close_clear_cancel); + menu.add(0, MENU_SAVEAS_PLAYLIST, 0, R.string.save_as_playlist).setIcon(R.drawable.ic_menu_preferences); return true; } - + + /** + * Called after the user selected an action from the ActionBar + * + * @param item The selected menu item + */ + @Override + public boolean onOptionsItemSelected(MenuItem item) { + if (item.getItemId() == android.R.id.home) { + finish(); + return true; + } else { + return super.onOptionsItemSelected(item); + } + } + /* ** Called when we are displayed (again) ** This will always refresh the whole song list @@ -86,12 +100,6 @@ public class ShowQueueActivity extends Activity { refreshSongQueueList(true); } - @Override - public void onDestroy() { - PlaybackService.removeActivity(this); - super.onDestroy(); - } - /** * Fired from adapter listview if user moved an item * @param from the item index that was dragged @@ -119,6 +127,12 @@ public class ShowQueueActivity extends Activity { } }; + /** + * Called when the song timeline has changed + */ + public void onTimelineChanged() { + refreshSongQueueList(false); + } /** * Triggers a refresh of the queueview