From dfcd04a8d983627f33ff46cfb572cba1f13176ac Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Wed, 22 Oct 2014 19:24:47 -0700 Subject: #405 Move shuffle to by media controls, toggle to actionbar --- .../dsub/fragments/NowPlayingFragment.java | 90 ++++++++++++---------- .../daneren2005/dsub/service/DownloadService.java | 4 +- .../service/DownloadServiceLifecycleSupport.java | 2 +- 3 files changed, 55 insertions(+), 41 deletions(-) (limited to 'src') diff --git a/src/github/daneren2005/dsub/fragments/NowPlayingFragment.java b/src/github/daneren2005/dsub/fragments/NowPlayingFragment.java index eb4ce5ab..f3a1cd4c 100644 --- a/src/github/daneren2005/dsub/fragments/NowPlayingFragment.java +++ b/src/github/daneren2005/dsub/fragments/NowPlayingFragment.java @@ -111,7 +111,7 @@ public class NowPlayingFragment extends SubsonicFragment implements OnGestureLis private View stopButton; private View startButton; private ImageButton repeatButton; - private View toggleListButton; + private ImageButton shuffleButton; private ImageButton starButton; private ImageButton bookmarkButton; private ImageButton rateBadButton; @@ -187,7 +187,7 @@ public class NowPlayingFragment extends SubsonicFragment implements OnGestureLis bookmarkButton = (ImageButton) rootView.findViewById(R.id.download_bookmark); rateBadButton = (ImageButton) rootView.findViewById(R.id.download_rating_bad); rateGoodButton = (ImageButton) rootView.findViewById(R.id.download_rating_good); - toggleListButton =rootView.findViewById(R.id.download_toggle_list); + shuffleButton = (ImageButton) rootView.findViewById(R.id.download_shuffle); starButton = (ImageButton)rootView.findViewById(R.id.download_star); if(Util.getPreferences(context).getBoolean(Constants.PREFERENCES_KEY_MENU_STAR, true)) { @@ -350,7 +350,7 @@ public class NowPlayingFragment extends SubsonicFragment implements OnGestureLis public void onClick(View view) { RepeatMode repeatMode = getDownloadService().getRepeatMode().next(); getDownloadService().setRepeatMode(repeatMode); - onDownloadListChanged(); + updateButtons(); switch (repeatMode) { case OFF: Util.toast(context, R.string.download_repeat_off); @@ -453,11 +453,18 @@ public class NowPlayingFragment extends SubsonicFragment implements OnGestureLis } }); - toggleListButton.setOnClickListener(new View.OnClickListener() { + shuffleButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { - toggleFullscreenAlbumArt(); + DownloadService downloadService = getDownloadService(); + downloadService.setShuffleMode(!downloadService.isShuffleMode()); + updateButtons(); setControlsVisible(true); + if(downloadService.isShuffleMode()) { + Util.toast(context, R.string.download_shuffle_on); + } else { + Util.toast(context, R.string.download_shuffle_off); + } } }); @@ -544,7 +551,7 @@ public class NowPlayingFragment extends SubsonicFragment implements OnGestureLis if (downloadService != null && context.getIntent().getBooleanExtra(Constants.INTENT_EXTRA_NAME_SHUFFLE, false)) { context.getIntent().removeExtra(Constants.INTENT_EXTRA_NAME_SHUFFLE); warnIfNetworkOrStorageUnavailable(); - downloadService.setShufflePlayEnabled(true); + downloadService.setShuffleRemote(true); } if(Build.MODEL.equals("Nexus 4") || Build.MODEL.equals("GT-I9100")) { @@ -734,7 +741,7 @@ public class NowPlayingFragment extends SubsonicFragment implements OnGestureLis new SilentBackgroundTask(context) { @Override protected Void doInBackground() throws Throwable { - getDownloadService().setShufflePlayEnabled(false); + getDownloadService().setShuffleRemote(false); getDownloadService().clear(); return null; } @@ -765,19 +772,9 @@ public class NowPlayingFragment extends SubsonicFragment implements OnGestureLis } context.supportInvalidateOptionsMenu(); return true; - case R.id.menu_shuffle: - new SilentBackgroundTask(context) { - @Override - protected Void doInBackground() throws Throwable { - getDownloadService().shuffle(); - return null; - } - - @Override - protected void done(Void result) { - Util.toast(context, R.string.download_menu_shuffle_notification); - } - }.execute(); + case R.id.menu_toggle_list: + toggleFullscreenAlbumArt(); + setControlsVisible(true); return true; case R.id.menu_save_playlist: List entries = new LinkedList(); @@ -949,6 +946,39 @@ public class NowPlayingFragment extends SubsonicFragment implements OnGestureLis rateBadButton.setVisibility(View.VISIBLE); rateGoodButton.setVisibility(View.VISIBLE); } + + DownloadService downloadService = getDownloadService(); + if(downloadService == null) { + return; + } + + switch (downloadService.getRepeatMode()) { + case OFF: + if("light".equals(SubsonicActivity.getThemeName()) | "light_fullscreen".equals(SubsonicActivity.getThemeName())) { + repeatButton.setImageResource(R.drawable.media_repeat_off_light); + } else { + repeatButton.setImageResource(R.drawable.media_repeat_off); + } + break; + case ALL: + repeatButton.setImageResource(R.drawable.media_repeat_all); + break; + case SINGLE: + repeatButton.setImageResource(R.drawable.media_repeat_single); + break; + default: + break; + } + + if(downloadService.isShuffleMode()) { + shuffleButton.setImageResource(R.drawable.ic_menu_shuffle_selected); + } else { + if("light".equals(SubsonicActivity.getThemeName())) { + shuffleButton.setImageResource(R.drawable.ic_menu_shuffle_light); + } else { + shuffleButton.setImageResource(R.drawable.ic_menu_shuffle_dark); + } + } } // Scroll to current playing/downloading. @@ -1113,7 +1143,7 @@ public class NowPlayingFragment extends SubsonicFragment implements OnGestureLis List list; list = downloadService.getSongs(); - if(downloadService.isShufflePlayEnabled()) { + if(downloadService.isShuffleRemote()) { emptyTextView.setText(R.string.download_shuffle_loading); } else { @@ -1132,24 +1162,6 @@ public class NowPlayingFragment extends SubsonicFragment implements OnGestureLis emptyTextView.setVisibility(list.isEmpty() ? View.VISIBLE : View.GONE); currentRevision = downloadService.getDownloadListUpdateRevision(); - - switch (downloadService.getRepeatMode()) { - case OFF: - if("light".equals(SubsonicActivity.getThemeName()) | "light_fullscreen".equals(SubsonicActivity.getThemeName())) { - repeatButton.setImageResource(R.drawable.media_repeat_off_light); - } else { - repeatButton.setImageResource(R.drawable.media_repeat_off); - } - break; - case ALL: - repeatButton.setImageResource(R.drawable.media_repeat_all); - break; - case SINGLE: - repeatButton.setImageResource(R.drawable.media_repeat_single); - break; - default: - break; - } if(scrollWhenLoaded) { scrollToCurrent(); diff --git a/src/github/daneren2005/dsub/service/DownloadService.java b/src/github/daneren2005/dsub/service/DownloadService.java index 81289f86..2b727dfb 100644 --- a/src/github/daneren2005/dsub/service/DownloadService.java +++ b/src/github/daneren2005/dsub/service/DownloadService.java @@ -59,6 +59,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.Iterator; import java.util.List; +import java.util.Random; import java.util.Timer; import java.util.TimerTask; @@ -231,6 +232,7 @@ public class DownloadService extends Service { instance = this; lifecycleSupport.onCreate(); shufflePlayBuffer = new ShufflePlayBuffer(this); + shuffleMode = prefs.getBoolean(Constants.PREFERENCES_KEY_SHUFFLE_MODE, false); } @Override @@ -742,7 +744,7 @@ public class DownloadService extends Service { // Add size condition to prevent infinite loop do { newIndex = random.nextInt(size()); - } while(index == newIndex && size() > 1) + } while(index == newIndex && size() > 1); } return newIndex; diff --git a/src/github/daneren2005/dsub/service/DownloadServiceLifecycleSupport.java b/src/github/daneren2005/dsub/service/DownloadServiceLifecycleSupport.java index 0a1e2cdd..9cd2896b 100644 --- a/src/github/daneren2005/dsub/service/DownloadServiceLifecycleSupport.java +++ b/src/github/daneren2005/dsub/service/DownloadServiceLifecycleSupport.java @@ -198,7 +198,7 @@ public class DownloadServiceLifecycleSupport { } editor.commit(); - downloadService.setShufflePlayEnabled(true); + downloadService.setShuffleRemote(true); } else { downloadService.start(); } -- cgit v1.2.3