diff --git a/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/MainActivity.java b/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/MainActivity.java index 4c37fc3c2..c4733f9e4 100644 --- a/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/MainActivity.java +++ b/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/MainActivity.java @@ -109,14 +109,24 @@ public class MainActivity extends WebSocketActivityBase { @Override public boolean onPrepareOptionsMenu(Menu menu) { boolean connected = wss.getState() == WebSocketService.State.Connected; + boolean streaming = isStreamingSelected(); + menu.findItem(R.id.action_playlists).setEnabled(connected); menu.findItem(R.id.action_genres).setEnabled(connected); + + menu.findItem(R.id.action_remote_toggle).setIcon( + streaming ? R.mipmap.ic_toolbar_streaming : R.mipmap.ic_toolbar_remote); + return super.onPrepareOptionsMenu(menu); } @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { + case R.id.action_remote_toggle: + togglePlaybackService(); + return true; + case R.id.action_settings: startActivity(SettingsActivity.getStartIntent(this)); return true; @@ -144,6 +154,28 @@ public class MainActivity extends WebSocketActivityBase { return this.playbackEvents; } + private boolean isStreamingSelected() { + return prefs.getBoolean( + Prefs.Key.STREAMING_PLAYBACK, + Prefs.Default.STREAMING_PLAYBACK); + } + + private void togglePlaybackService() { + final boolean streaming = isStreamingSelected(); + + if (streaming) { + playback.stop(); + } + + prefs.edit().putBoolean(Prefs.Key.STREAMING_PLAYBACK, !streaming).apply(); + + reloadPlaybackService(); + this.playback = getPlaybackService(); + + supportInvalidateOptionsMenu(); + rebindUi(); + } + private void bindCheckBoxEventListeners() { this.shuffleCb.setOnCheckedChangeListener(shuffleListener); this.muteCb.setOnCheckedChangeListener(muteListener); diff --git a/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/activity/WebSocketActivityBase.java b/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/activity/WebSocketActivityBase.java index 2154ed1df..c42430d7b 100644 --- a/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/activity/WebSocketActivityBase.java +++ b/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/activity/WebSocketActivityBase.java @@ -107,6 +107,14 @@ public abstract class WebSocketActivityBase extends AppCompatActivity implements } + protected void reloadPlaybackService() { + if (!paused && this.playback != null) { + this.playback.disconnect(getPlaybackServiceEventListener()); + this.playback = PlaybackServiceFactory.instance(this); + this.playback.connect(getPlaybackServiceEventListener()); + } + } + protected final Runner runner() { return this.runnerDelegate.runner(); } diff --git a/src/musikdroid/app/src/main/res/menu/main_menu.xml b/src/musikdroid/app/src/main/res/menu/main_menu.xml index 67fa3bc5a..0d6fba36a 100644 --- a/src/musikdroid/app/src/main/res/menu/main_menu.xml +++ b/src/musikdroid/app/src/main/res/menu/main_menu.xml @@ -3,6 +3,12 @@ xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto"> + + settings genres playlists + remote playback <unknown> playback mode: streaming downsampler bitrate: