Skip to content

Commit

Permalink
#405 Move shuffle to by media controls, toggle to actionbar
Browse files Browse the repository at this point in the history
  • Loading branch information
daneren2005 committed Oct 23, 2014
1 parent fd6ef4c commit dfcd04a
Show file tree
Hide file tree
Showing 11 changed files with 71 additions and 55 deletions.
Binary file added res/drawable-hdpi/ic_menu_shuffle_selected.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/drawable-mdpi/ic_menu_shuffle_selected.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/drawable-xhdpi/ic_menu_shuffle_selected.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/drawable-xxhdpi/ic_menu_shuffle_selected.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions res/layout/download_media_buttons.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@

<ImageButton
style="@style/PlaybackControl.Small"
android:id="@+id/download_toggle_list"
android:src="?attr/toggle_list"
android:id="@+id/download_shuffle"
android:src="?attr/shuffle"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
/>
Expand Down
12 changes: 6 additions & 6 deletions res/menu/nowplaying.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@
xmlns:compat="http://schemas.android.com/apk/res-auto"
android:checkableBehavior="all">

<item
android:id="@+id/menu_shuffle"
android:icon="?attr/shuffle"
android:title="@string/download.menu_shuffle"
compat:showAsAction="ifRoom|withText"/>

<item
android:id="@+id/menu_mediaroute"
compat:actionProviderClass="android.support.v7.app.MediaRouteActionProvider"
compat:actionViewClass="android.support.v7.app.MediaRouteButton"
compat:showAsAction="always"
android:title="@string/menu.cast"/>

<item
android:id="@+id/menu_toggle_list"
android:icon="?attr/toggle_list"
android:title="@string/download.menu_toggle"
compat:showAsAction="ifRoom|withText"/>

<item
android:id="@+id/menu_remove_all"
Expand Down
12 changes: 6 additions & 6 deletions res/menu/nowplaying_offline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:compat="http://schemas.android.com/apk/res-auto">

<item
android:id="@+id/menu_shuffle"
android:icon="?attr/shuffle"
android:title="@string/download.menu_shuffle"
compat:showAsAction="always|withText"/>

<item
android:id="@+id/menu_mediaroute"
compat:actionProviderClass="android.support.v7.app.MediaRouteActionProvider"
compat:actionViewClass="android.support.v7.app.MediaRouteButton"
compat:showAsAction="always"
android:title="@string/menu.cast"/>

<item
android:id="@+id/menu_toggle_list"
android:icon="?attr/toggle_list"
android:title="@string/download.menu_toggle"
compat:showAsAction="always|withText"/>

<item
android:id="@+id/menu_remove_all"
Expand Down
2 changes: 2 additions & 0 deletions res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,8 @@
<string name="download.downloading_summary_expanded">Current: %1$s
\nEstimated Size: %2$s</string>
<string name="download.failed_to_load">Failed to load</string>
<string name="download.shuffle_on">Shuffle on</string>
<string name="download.shuffle_off">Shuffle off</string>

<string name="sync.new_podcasts">New podcasts available</string>
<string name="sync.new_playlists">New songs in playlists</string>
Expand Down
90 changes: 51 additions & 39 deletions src/github/daneren2005/dsub/fragments/NowPlayingFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -187,7 +187,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle bu
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)) {
Expand Down Expand Up @@ -350,7 +350,7 @@ protected void done(Void result) {
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);
Expand Down Expand Up @@ -453,11 +453,18 @@ public void onClick(View view) {
}
});

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);
}
}
});

Expand Down Expand Up @@ -544,7 +551,7 @@ public void remove(int which) {
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")) {
Expand Down Expand Up @@ -734,7 +741,7 @@ public void onClick(DialogInterface dialog, int which) {
new SilentBackgroundTask<Void>(context) {
@Override
protected Void doInBackground() throws Throwable {
getDownloadService().setShufflePlayEnabled(false);
getDownloadService().setShuffleRemote(false);
getDownloadService().clear();
return null;
}
Expand Down Expand Up @@ -765,19 +772,9 @@ protected void done(Void result) {
}
context.supportInvalidateOptionsMenu();
return true;
case R.id.menu_shuffle:
new SilentBackgroundTask<Void>(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<Entry> entries = new LinkedList<Entry>();
Expand Down Expand Up @@ -949,6 +946,39 @@ private void updateButtons() {
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.
Expand Down Expand Up @@ -1113,7 +1143,7 @@ protected void done(Void result) {
List<DownloadFile> list;
list = downloadService.getSongs();

if(downloadService.isShufflePlayEnabled()) {
if(downloadService.isShuffleRemote()) {
emptyTextView.setText(R.string.download_shuffle_loading);
}
else {
Expand All @@ -1132,24 +1162,6 @@ protected void done(Void result) {

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();
Expand Down
4 changes: 3 additions & 1 deletion src/github/daneren2005/dsub/service/DownloadService.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Random;
import java.util.Timer;
import java.util.TimerTask;

Expand Down Expand Up @@ -231,6 +232,7 @@ public boolean onError(MediaPlayer mediaPlayer, int what, int more) {
instance = this;
lifecycleSupport.onCreate();
shufflePlayBuffer = new ShufflePlayBuffer(this);
shuffleMode = prefs.getBoolean(Constants.PREFERENCES_KEY_SHUFFLE_MODE, false);
}

@Override
Expand Down Expand Up @@ -742,7 +744,7 @@ private int getNextPlayingIndex() {
// Add size condition to prevent infinite loop
do {
newIndex = random.nextInt(size());
} while(index == newIndex && size() > 1)
} while(index == newIndex && size() > 1);
}

return newIndex;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ public void run() {
}
editor.commit();

downloadService.setShufflePlayEnabled(true);
downloadService.setShuffleRemote(true);
} else {
downloadService.start();
}
Expand Down

0 comments on commit dfcd04a

Please sign in to comment.