aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--res/drawable-hdpi/ic_menu_shuffle_selected.pngbin1138 -> 0 bytes
-rw-r--r--res/drawable-mdpi/ic_menu_shuffle_selected.pngbin733 -> 0 bytes
-rw-r--r--res/drawable-xhdpi/ic_menu_shuffle_selected.pngbin1670 -> 0 bytes
-rw-r--r--res/drawable-xxhdpi/ic_menu_shuffle_selected.pngbin2573 -> 0 bytes
-rw-r--r--res/layout/download_media_buttons.xml4
-rw-r--r--res/menu/nowplaying.xml12
-rw-r--r--res/menu/nowplaying_offline.xml12
-rw-r--r--res/menu/select_album_context.xml5
-rw-r--r--res/menu/select_album_context_offline.xml6
-rw-r--r--res/menu/select_playlist_context.xml5
-rw-r--r--res/menu/select_playlist_context_offline.xml5
-rw-r--r--res/menu/select_song.xml6
-rw-r--r--res/menu/select_song_offline.xml6
-rw-r--r--res/values/strings.xml2
-rw-r--r--res/xml/changelog.xml1
-rw-r--r--src/github/daneren2005/dsub/fragments/NowPlayingFragment.java90
-rw-r--r--src/github/daneren2005/dsub/fragments/SearchFragment.java3
-rw-r--r--src/github/daneren2005/dsub/fragments/SelectBookmarkFragment.java10
-rw-r--r--src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java10
-rw-r--r--src/github/daneren2005/dsub/fragments/SelectPlaylistFragment.java11
-rw-r--r--src/github/daneren2005/dsub/fragments/SubsonicFragment.java12
-rw-r--r--src/github/daneren2005/dsub/service/DownloadService.java86
-rw-r--r--src/github/daneren2005/dsub/service/DownloadServiceLifecycleSupport.java2
-rw-r--r--src/github/daneren2005/dsub/util/Constants.java3
-rw-r--r--test/github/daneren2005/dsub/service/DownloadServiceTest.java10
25 files changed, 168 insertions, 133 deletions
diff --git a/res/drawable-hdpi/ic_menu_shuffle_selected.png b/res/drawable-hdpi/ic_menu_shuffle_selected.png
deleted file mode 100644
index e2ace634..00000000
--- a/res/drawable-hdpi/ic_menu_shuffle_selected.png
+++ /dev/null
Binary files differ
diff --git a/res/drawable-mdpi/ic_menu_shuffle_selected.png b/res/drawable-mdpi/ic_menu_shuffle_selected.png
deleted file mode 100644
index c8c01fff..00000000
--- a/res/drawable-mdpi/ic_menu_shuffle_selected.png
+++ /dev/null
Binary files differ
diff --git a/res/drawable-xhdpi/ic_menu_shuffle_selected.png b/res/drawable-xhdpi/ic_menu_shuffle_selected.png
deleted file mode 100644
index 03719061..00000000
--- a/res/drawable-xhdpi/ic_menu_shuffle_selected.png
+++ /dev/null
Binary files differ
diff --git a/res/drawable-xxhdpi/ic_menu_shuffle_selected.png b/res/drawable-xxhdpi/ic_menu_shuffle_selected.png
deleted file mode 100644
index 16cfea54..00000000
--- a/res/drawable-xxhdpi/ic_menu_shuffle_selected.png
+++ /dev/null
Binary files differ
diff --git a/res/layout/download_media_buttons.xml b/res/layout/download_media_buttons.xml
index 1e694662..1affb164 100644
--- a/res/layout/download_media_buttons.xml
+++ b/res/layout/download_media_buttons.xml
@@ -55,8 +55,8 @@
<ImageButton
style="@style/PlaybackControl.Small"
- android:id="@+id/download_shuffle"
- android:src="?attr/shuffle"
+ android:id="@+id/download_toggle_list"
+ android:src="?attr/toggle_list"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
/>
diff --git a/res/menu/nowplaying.xml b/res/menu/nowplaying.xml
index 3f49ae19..60255692 100644
--- a/res/menu/nowplaying.xml
+++ b/res/menu/nowplaying.xml
@@ -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"
diff --git a/res/menu/nowplaying_offline.xml b/res/menu/nowplaying_offline.xml
index 105b375c..bba5ba00 100644
--- a/res/menu/nowplaying_offline.xml
+++ b/res/menu/nowplaying_offline.xml
@@ -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"
diff --git a/res/menu/select_album_context.xml b/res/menu/select_album_context.xml
index c08c6da7..5b2529e7 100644
--- a/res/menu/select_album_context.xml
+++ b/res/menu/select_album_context.xml
@@ -11,6 +11,11 @@
android:id="@+id/album_menu_play_now"
android:title="@string/common.play_now"
/>
+
+ <item
+ android:id="@+id/album_menu_play_shuffled"
+ android:title="@string/common.play_shuffled"
+ />
<group android:id="@+id/hide_play_next">
<item
diff --git a/res/menu/select_album_context_offline.xml b/res/menu/select_album_context_offline.xml
index 14dbda3a..a1805f5b 100644
--- a/res/menu/select_album_context_offline.xml
+++ b/res/menu/select_album_context_offline.xml
@@ -5,6 +5,12 @@
android:id="@+id/album_menu_play_now"
android:title="@string/common.play_now"
/>
+
+ <item
+ android:id="@+id/album_menu_play_shuffled"
+ android:title="@string/common.play_shuffled"
+ />
+
<group android:id="@+id/hide_play_next">
<item
android:id="@+id/album_menu_play_next"
diff --git a/res/menu/select_playlist_context.xml b/res/menu/select_playlist_context.xml
index 7e12c89f..47033d9c 100644
--- a/res/menu/select_playlist_context.xml
+++ b/res/menu/select_playlist_context.xml
@@ -13,6 +13,11 @@
/>
<item
+ android:id="@+id/playlist_menu_play_shuffled"
+ android:title="@string/common.play_shuffled"
+ />
+
+ <item
android:id="@+id/playlist_menu_download"
android:title="@string/common.download"
/>
diff --git a/res/menu/select_playlist_context_offline.xml b/res/menu/select_playlist_context_offline.xml
index 830d6d0c..d63aec17 100644
--- a/res/menu/select_playlist_context_offline.xml
+++ b/res/menu/select_playlist_context_offline.xml
@@ -5,4 +5,9 @@
android:id="@+id/playlist_menu_play_now"
android:title="@string/common.play_now"
/>
+
+ <item
+ android:id="@+id/playlist_menu_play_shuffled"
+ android:title="@string/common.play_shuffled"
+ />
</menu> \ No newline at end of file
diff --git a/res/menu/select_song.xml b/res/menu/select_song.xml
index c1628d2e..07fd57a7 100644
--- a/res/menu/select_song.xml
+++ b/res/menu/select_song.xml
@@ -8,6 +8,12 @@
compat:showAsAction="always|withText"/>
<item
+ android:id="@+id/menu_shuffle"
+ android:icon="?attr/shuffle"
+ android:title="@string/menu.shuffle"
+ compat:showAsAction="ifRoom|withText"/>
+
+ <item
android:id="@+id/menu_download"
android:title="@string/common.download"/>
diff --git a/res/menu/select_song_offline.xml b/res/menu/select_song_offline.xml
index 5ff42d12..c45405fb 100644
--- a/res/menu/select_song_offline.xml
+++ b/res/menu/select_song_offline.xml
@@ -8,6 +8,12 @@
compat:showAsAction="always|withText"/>
<item
+ android:id="@+id/menu_shuffle"
+ android:icon="?attr/shuffle"
+ android:title="@string/menu.shuffle"
+ compat:showAsAction="ifRoom|withText"/>
+
+ <item
android:id="@+id/menu_delete"
android:title="@string/menu.delete_cache"/>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 71b6e08e..33a40981 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -212,8 +212,6 @@
<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>
diff --git a/res/xml/changelog.xml b/res/xml/changelog.xml
index 46fef498..5c8bb024 100644
--- a/res/xml/changelog.xml
+++ b/res/xml/changelog.xml
@@ -1,7 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<changelog>
<release version="4.8.2" versioncode="129" releasedate="10/30/2014">
- <change>Changed from shuffle option to persistent shuffle toggle</change>
<change>Improve automatic bookmark logic</change>
<change>Tasker: Toggle online/offline</change>
<change>Tasker: Set start/end year + genre for shuffle</change>
diff --git a/src/github/daneren2005/dsub/fragments/NowPlayingFragment.java b/src/github/daneren2005/dsub/fragments/NowPlayingFragment.java
index 8fef07a8..b6daea98 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 ImageButton shuffleButton;
+ private View toggleListButton;
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);
- shuffleButton = (ImageButton) rootView.findViewById(R.id.download_shuffle);
+ toggleListButton =rootView.findViewById(R.id.download_toggle_list);
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);
- updateButtons();
+ onDownloadListChanged();
switch (repeatMode) {
case OFF:
Util.toast(context, R.string.download_repeat_off);
@@ -453,18 +453,11 @@ public class NowPlayingFragment extends SubsonicFragment implements OnGestureLis
}
});
- shuffleButton.setOnClickListener(new View.OnClickListener() {
+ toggleListButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
- DownloadService downloadService = getDownloadService();
- downloadService.setShuffleMode(!downloadService.isShuffleMode());
- updateButtons();
+ toggleFullscreenAlbumArt();
setControlsVisible(true);
- if(downloadService.isShuffleMode()) {
- Util.toast(context, R.string.download_shuffle_on);
- } else {
- Util.toast(context, R.string.download_shuffle_off);
- }
}
});
@@ -551,7 +544,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.setShuffleRemote(true);
+ downloadService.setShufflePlayEnabled(true);
}
if(Build.MODEL.equals("Nexus 4") || Build.MODEL.equals("GT-I9100")) {
@@ -741,7 +734,7 @@ public class NowPlayingFragment extends SubsonicFragment implements OnGestureLis
new SilentBackgroundTask<Void>(context) {
@Override
protected Void doInBackground() throws Throwable {
- getDownloadService().setShuffleRemote(false);
+ getDownloadService().setShufflePlayEnabled(false);
getDownloadService().clear();
return null;
}
@@ -772,9 +765,19 @@ public class NowPlayingFragment extends SubsonicFragment implements OnGestureLis
}
context.supportInvalidateOptionsMenu();
return true;
- case R.id.menu_toggle_list:
- toggleFullscreenAlbumArt();
- setControlsVisible(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();
return true;
case R.id.menu_save_playlist:
List<Entry> entries = new LinkedList<Entry>();
@@ -946,39 +949,6 @@ 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.
@@ -1143,7 +1113,7 @@ public class NowPlayingFragment extends SubsonicFragment implements OnGestureLis
List<DownloadFile> list;
list = downloadService.getSongs();
- if(downloadService.isShuffleRemote()) {
+ if(downloadService.isShufflePlayEnabled()) {
emptyTextView.setText(R.string.download_shuffle_loading);
}
else {
@@ -1162,6 +1132,24 @@ 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/fragments/SearchFragment.java b/src/github/daneren2005/dsub/fragments/SearchFragment.java
index b7ef204f..f73989fb 100644
--- a/src/github/daneren2005/dsub/fragments/SearchFragment.java
+++ b/src/github/daneren2005/dsub/fragments/SearchFragment.java
@@ -13,6 +13,7 @@ import android.view.Menu;
import android.view.MenuInflater;
import android.view.View;
import android.view.MenuItem;
+import android.widget.AbsListView;
import android.widget.AdapterView;
import android.widget.ListAdapter;
import android.widget.ListView;
@@ -324,7 +325,7 @@ public class SearchFragment extends SubsonicFragment {
if (!append) {
downloadService.clear();
}
- downloadService.download(Arrays.asList(song), save, false, playNext);
+ downloadService.download(Arrays.asList(song), save, false, playNext, false);
if (autoplay) {
downloadService.play(downloadService.size() - 1);
}
diff --git a/src/github/daneren2005/dsub/fragments/SelectBookmarkFragment.java b/src/github/daneren2005/dsub/fragments/SelectBookmarkFragment.java
index 46251073..c26429ce 100644
--- a/src/github/daneren2005/dsub/fragments/SelectBookmarkFragment.java
+++ b/src/github/daneren2005/dsub/fragments/SelectBookmarkFragment.java
@@ -18,6 +18,8 @@
*/
package github.daneren2005.dsub.fragments;
+import android.content.DialogInterface;
+import android.util.Log;
import android.view.ContextMenu;
import android.view.MenuInflater;
import android.view.MenuItem;
@@ -28,12 +30,18 @@ import github.daneren2005.dsub.R;
import github.daneren2005.dsub.activity.DownloadActivity;
import github.daneren2005.dsub.domain.Bookmark;
import github.daneren2005.dsub.domain.MusicDirectory;
+import github.daneren2005.dsub.service.DownloadFile;
import github.daneren2005.dsub.service.DownloadService;
import github.daneren2005.dsub.service.MusicService;
+import github.daneren2005.dsub.service.MusicServiceFactory;
+import github.daneren2005.dsub.service.OfflineException;
+import github.daneren2005.dsub.service.ServerTooOldException;
+import github.daneren2005.dsub.util.LoadingTask;
import github.daneren2005.dsub.util.ProgressListener;
import github.daneren2005.dsub.util.SilentBackgroundTask;
import github.daneren2005.dsub.util.Util;
import github.daneren2005.dsub.view.BookmarkAdapter;
+import github.daneren2005.dsub.view.SongView;
import java.text.Format;
import java.text.SimpleDateFormat;
@@ -106,7 +114,7 @@ public class SelectBookmarkFragment extends SelectListFragment<MusicDirectory.En
@Override
protected Void doInBackground() throws Throwable {
downloadService.clear();
- downloadService.download(Arrays.asList(bookmark), false, true, false, 0, bookmark.getBookmark().getPosition());
+ downloadService.download(Arrays.asList(bookmark), false, true, false, false, 0, bookmark.getBookmark().getPosition());
return null;
}
diff --git a/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java b/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java
index 677664b5..a8b4ab38 100644
--- a/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java
+++ b/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java
@@ -780,7 +780,7 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Adapter
}
private void playNow(final boolean shuffle, final boolean append, final boolean playNext) {
if(getSelectedSongs().size() > 0) {
- download(append, false, !append, playNext);
+ download(append, false, !append, playNext, shuffle);
selectAll(false, false);
}
else {
@@ -804,7 +804,7 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Adapter
downloadRecursively(id, false, append, !append, shuffle, false);
} else {
selectAll(true, false);
- download(append, false, !append, false);
+ download(append, false, !append, false, shuffle);
selectAll(false, false);
}
}
@@ -857,7 +857,7 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Adapter
return indexes;
}
- private void download(final boolean append, final boolean save, final boolean autoplay, final boolean playNext) {
+ private void download(final boolean append, final boolean save, final boolean autoplay, final boolean playNext, final boolean shuffle) {
if (getDownloadService() == null) {
return;
}
@@ -866,7 +866,7 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Adapter
warnIfNetworkOrStorageUnavailable();
// Conditions for using play now button
- if(!append && !save && autoplay && !playNext) {
+ if(!append && !save && autoplay && !playNext && !shuffle) {
// Call playNow which goes through and tries to use bookmark information
playNow(songs, playlistName, playlistId);
return;
@@ -879,7 +879,7 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Adapter
getDownloadService().clear();
}
- getDownloadService().download(songs, save, autoplay, playNext);
+ getDownloadService().download(songs, save, autoplay, playNext, shuffle);
if (playlistName != null) {
getDownloadService().setSuggestedPlaylistName(playlistName, playlistId);
} else {
diff --git a/src/github/daneren2005/dsub/fragments/SelectPlaylistFragment.java b/src/github/daneren2005/dsub/fragments/SelectPlaylistFragment.java
index 741ed8a5..caf9079f 100644
--- a/src/github/daneren2005/dsub/fragments/SelectPlaylistFragment.java
+++ b/src/github/daneren2005/dsub/fragments/SelectPlaylistFragment.java
@@ -98,6 +98,17 @@ public class SelectPlaylistFragment extends SelectListFragment<Playlist> {
replaceFragment(fragment);
break;
+ case R.id.playlist_menu_play_shuffled:
+ fragment = new SelectDirectoryFragment();
+ args = new Bundle();
+ args.putString(Constants.INTENT_EXTRA_NAME_PLAYLIST_ID, playlist.getId());
+ args.putString(Constants.INTENT_EXTRA_NAME_PLAYLIST_NAME, playlist.getName());
+ args.putBoolean(Constants.INTENT_EXTRA_NAME_SHUFFLE, true);
+ args.putBoolean(Constants.INTENT_EXTRA_NAME_AUTOPLAY, true);
+ fragment.setArguments(args);
+
+ replaceFragment(fragment);
+ break;
case R.id.playlist_menu_delete:
deletePlaylist(playlist);
break;
diff --git a/src/github/daneren2005/dsub/fragments/SubsonicFragment.java b/src/github/daneren2005/dsub/fragments/SubsonicFragment.java
index 1a5cd5a7..5cab2497 100644
--- a/src/github/daneren2005/dsub/fragments/SubsonicFragment.java
+++ b/src/github/daneren2005/dsub/fragments/SubsonicFragment.java
@@ -376,6 +376,10 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR
artistOverride = true;
downloadRecursively(entry.getId(), false, false, true, false, false);
break;
+ case R.id.album_menu_play_shuffled:
+ artistOverride = true;
+ downloadRecursively(entry.getId(), false, false, true, true, false);
+ break;
case R.id.album_menu_play_next:
artistOverride = true;
downloadRecursively(entry.getId(), false, true, false, false, false, true);
@@ -411,10 +415,10 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR
playNow(songs);
break;
case R.id.song_menu_play_next:
- getDownloadService().download(songs, false, false, true);
+ getDownloadService().download(songs, false, false, true, false);
break;
case R.id.song_menu_play_last:
- getDownloadService().download(songs, false, false, false);
+ getDownloadService().download(songs, false, false, false, false);
break;
case R.id.song_menu_download:
getDownloadService().downloadBackground(songs, false);
@@ -889,7 +893,7 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR
downloadService.clear();
}
if(!background) {
- downloadService.download(songs, save, autoplay, playNext);
+ downloadService.download(songs, save, autoplay, playNext, false);
if(!append) {
transition = true;
}
@@ -1553,7 +1557,7 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR
}
downloadService.clear();
- downloadService.download(entries, false, true, true, entries.indexOf(song), position);
+ downloadService.download(entries, false, true, true, false, entries.indexOf(song), position);
downloadService.setSuggestedPlaylistName(playlistName, playlistId);
return null;
diff --git a/src/github/daneren2005/dsub/service/DownloadService.java b/src/github/daneren2005/dsub/service/DownloadService.java
index c7298169..50a2d34e 100644
--- a/src/github/daneren2005/dsub/service/DownloadService.java
+++ b/src/github/daneren2005/dsub/service/DownloadService.java
@@ -53,11 +53,12 @@ import github.daneren2005.dsub.view.UpdateView;
import github.daneren2005.serverproxy.BufferProxy;
import java.io.File;
+import java.io.IOError;
import java.io.IOException;
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;
@@ -69,6 +70,7 @@ import android.content.SharedPreferences;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.media.audiofx.AudioEffect;
+import android.media.audiofx.Equalizer;
import android.os.Build;
import android.os.Handler;
import android.os.IBinder;
@@ -114,7 +116,6 @@ public class DownloadService extends Service {
private Handler mediaPlayerHandler;
private final DownloadServiceLifecycleSupport lifecycleSupport = new DownloadServiceLifecycleSupport(this);
private ShufflePlayBuffer shufflePlayBuffer;
- private Random random = new Random();
private final LruCache<MusicDirectory.Entry, DownloadFile> downloadFileCache = new LruCache<MusicDirectory.Entry, DownloadFile>(100);
private final List<DownloadFile> cleanupCandidates = new ArrayList<DownloadFile>();
@@ -129,8 +130,7 @@ public class DownloadService extends Service {
private PlayerState playerState = IDLE;
private PlayerState nextPlayerState = IDLE;
private boolean removePlayed;
- private boolean shuffleRemote;
- private boolean shuffleMode;
+ private boolean shufflePlay;
private long revision;
private static DownloadService instance;
private String suggestedPlaylistName;
@@ -229,7 +229,6 @@ public class DownloadService extends Service {
instance = this;
lifecycleSupport.onCreate();
shufflePlayBuffer = new ShufflePlayBuffer(this);
- shuffleMode = prefs.getBoolean(Constants.PREFERENCES_KEY_SHUFFLE_MODE, false);
}
@Override
@@ -302,11 +301,11 @@ public class DownloadService extends Service {
return binder;
}
- public synchronized void download(List<MusicDirectory.Entry> songs, boolean save, boolean autoplay, boolean playNext) {
- download(songs, save, autoplay, playNext, 0, 0);
+ public synchronized void download(List<MusicDirectory.Entry> songs, boolean save, boolean autoplay, boolean playNext, boolean shuffle) {
+ download(songs, save, autoplay, playNext, shuffle, 0, 0);
}
- public synchronized void download(List<MusicDirectory.Entry> songs, boolean save, boolean autoplay, boolean playNext, int start, int position) {
- setShuffleRemote(false);
+ public synchronized void download(List<MusicDirectory.Entry> songs, boolean save, boolean autoplay, boolean playNext, boolean shuffle, int start, int position) {
+ setShufflePlayEnabled(false);
int offset = 1;
if (songs.isEmpty()) {
@@ -339,6 +338,10 @@ public class DownloadService extends Service {
}
updateJukeboxPlaylist();
+ if(shuffle) {
+ shuffle();
+ }
+
if (autoplay) {
play(start, true, position);
} else {
@@ -393,12 +396,12 @@ public class DownloadService extends Service {
if(prefs.getBoolean(Constants.PREFERENCES_KEY_REMOVE_PLAYED, false)) {
removePlayed = true;
}
- boolean startShufflePlay = prefs.getBoolean(Constants.PREFERENCES_KEY_SHUFFLE_REMOTE, false);
- download(songs, false, false, false);
+ boolean startShufflePlay = prefs.getBoolean(Constants.PREFERENCES_KEY_SHUFFLE_MODE, false);
+ download(songs, false, false, false, false);
if(startShufflePlay) {
- shuffleRemote = true;
+ shufflePlay = true;
SharedPreferences.Editor editor = prefs.edit();
- editor.putBoolean(Constants.PREFERENCES_KEY_SHUFFLE_REMOTE, true);
+ editor.putBoolean(Constants.PREFERENCES_KEY_SHUFFLE_MODE, true);
editor.commit();
}
if (currentPlayingIndex != -1) {
@@ -434,29 +437,33 @@ public class DownloadService extends Service {
return removePlayed;
}
- public synchronized void setShuffleRemote(boolean enabled) {
- shuffleRemote = enabled;
- if (shuffleRemote) {
+ public synchronized void setShufflePlayEnabled(boolean enabled) {
+ shufflePlay = enabled;
+ if (shufflePlay) {
clear();
checkDownloads();
}
SharedPreferences.Editor editor = Util.getPreferences(this).edit();
- editor.putBoolean(Constants.PREFERENCES_KEY_SHUFFLE_REMOTE, enabled);
+ editor.putBoolean(Constants.PREFERENCES_KEY_SHUFFLE_MODE, enabled);
editor.commit();
}
- public boolean isShuffleRemote() {
- return shuffleRemote;
+ public boolean isShufflePlayEnabled() {
+ return shufflePlay;
}
-
- public synchronized void setShuffleMode(boolean shuffleMode) {
- this.shuffleMode = shuffleMode;
- SharedPreferences.Editor editor = Util.getPreferences(this).edit();
- editor.putBoolean(Constants.PREFERENCES_KEY_SHUFFLE_MODE, shuffleMode);
- editor.commit();
- }
- public boolean isShuffleMode() {
- return shuffleMode;
+
+ public synchronized void shuffle() {
+ Collections.shuffle(downloadList);
+ currentPlayingIndex = downloadList.indexOf(currentPlaying);
+ if (currentPlaying != null) {
+ downloadList.remove(getCurrentPlayingIndex());
+ downloadList.add(0, currentPlaying);
+ currentPlayingIndex = 0;
+ }
+ revision++;
+ lifecycleSupport.serializeDownloadQueue();
+ updateJukeboxPlaylist();
+ setNextPlaying();
}
public RepeatMode getRepeatMode() {
@@ -717,16 +724,13 @@ public class DownloadService extends Service {
}
private int getNextPlayingIndex() {
int index = getCurrentPlayingIndex();
- int newIndex = index;
-
- // Increment based off of repeat mode
if (index != -1) {
switch (getRepeatMode()) {
case OFF:
- newIndex = index + 1;
+ index = index + 1;
break;
case ALL:
- newIndex = (index + 1) % size();
+ index = (index + 1) % size();
break;
case SINGLE:
break;
@@ -734,17 +738,7 @@ public class DownloadService extends Service {
break;
}
}
-
- // If we are in shuffle mode and index changed, get random index
- if(shuffleMode && index != newIndex) {
- // Retry if next random is same as current
- // Add size condition to prevent infinite loop
- do {
- newIndex = random.nextInt(size());
- } while(index == newIndex && size() > 1);
- }
-
- return newIndex;
+ return index;
}
public DownloadFile getCurrentPlaying() {
@@ -1731,7 +1725,7 @@ public class DownloadService extends Service {
if(removePlayed) {
checkRemovePlayed();
}
- if (shuffleRemote) {
+ if (shufflePlay) {
checkShufflePlay();
}
@@ -1913,7 +1907,7 @@ public class DownloadService extends Service {
// Is an audio book
// Next playing exists and is not a wrap around or a shuffle
// Next playing is from same context as current playing, so not at end of list
- if(entry.isAudioBook() && nextPlaying != null && downloadList.indexOf(nextPlaying) != 0 && !shuffleMode && !shuffleRemote
+ if(entry.isAudioBook() && nextPlaying != null && downloadList.indexOf(nextPlaying) != 0 && !shufflePlay
&& entry.getParent() != null && entry.getParent().equals(nextPlaying.getSong().getParent())) {
isPastCutoff = false;
}
diff --git a/src/github/daneren2005/dsub/service/DownloadServiceLifecycleSupport.java b/src/github/daneren2005/dsub/service/DownloadServiceLifecycleSupport.java
index 9cd2896b..0a1e2cdd 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.setShuffleRemote(true);
+ downloadService.setShufflePlayEnabled(true);
} else {
downloadService.start();
}
diff --git a/src/github/daneren2005/dsub/util/Constants.java b/src/github/daneren2005/dsub/util/Constants.java
index e5707cca..50651a80 100644
--- a/src/github/daneren2005/dsub/util/Constants.java
+++ b/src/github/daneren2005/dsub/util/Constants.java
@@ -113,8 +113,7 @@ public final class Constants {
public static final String PREFERENCES_KEY_PERSISTENT_NOTIFICATION = "persistentNotification";
public static final String PREFERENCES_KEY_GAPLESS_PLAYBACK = "gaplessPlayback";
public static final String PREFERENCES_KEY_REMOVE_PLAYED = "removePlayed";
- public static final String PREFERENCES_KEY_SHUFFLE_REMOTE = "shuffleMode";
- public static final String PREFERENCES_KEY_SHUFFLE_MODE = "shuffleCurrentMode";
+ public static final String PREFERENCES_KEY_SHUFFLE_MODE = "shuffleMode";
public static final String PREFERENCES_KEY_CHAT_REFRESH = "chatRefreshRate";
public static final String PREFERENCES_KEY_CHAT_ENABLED = "chatEnabled";
public static final String PREFERENCES_KEY_VIDEO_PLAYER = "videoPlayer";
diff --git a/test/github/daneren2005/dsub/service/DownloadServiceTest.java b/test/github/daneren2005/dsub/service/DownloadServiceTest.java
index 7814b4ec..44b77b84 100644
--- a/test/github/daneren2005/dsub/service/DownloadServiceTest.java
+++ b/test/github/daneren2005/dsub/service/DownloadServiceTest.java
@@ -82,7 +82,7 @@ public class DownloadServiceTest extends
// Download two songs
downloadService.getDownloads().clear();
downloadService.download(this.createMusicSongs(2), false, false, false,
- 0, 0);
+ false, 0, 0);
Log.w("testPreviousWithPlayList", "Start waiting to downloads");
Thread.sleep(5000);
@@ -106,7 +106,7 @@ public class DownloadServiceTest extends
// Download two songs
downloadService.getDownloads().clear();
downloadService.download(this.createMusicSongs(2), false, false, false,
- 0, 0);
+ false, 0, 0);
Log.w("testPreviousWithPlayList", "Start waiting downloads");
Thread.sleep(5000);
@@ -185,7 +185,7 @@ public class DownloadServiceTest extends
// Download two songs
downloadService.getDownloads().clear();
downloadService.download(this.createMusicSongs(2), false, false, false,
- 0, 0);
+ false, 0, 0);
Log.w("testPreviousWithPlayList", "Start waiting downloads");
Thread.sleep(5000);
@@ -209,7 +209,7 @@ public class DownloadServiceTest extends
// Download one songs
downloadService.getDownloads().clear();
downloadService.download(this.createMusicSongs(1), false, true, false,
- 0, 0);
+ false, 0, 0);
Log.w("testPreviousWithPlayList", "Start waiting downloads");
Thread.sleep(5000);
@@ -242,7 +242,7 @@ public class DownloadServiceTest extends
// Launch download
downloadService.download(this.createMusicSongs(1), false, false, false,
- 0, 0);
+ false, 0, 0);
// Check number of download after
int afterDownloadAction = 0;