diff options
author | Scott Jackson <daneren2005@gmail.com> | 2014-08-18 20:54:15 -0700 |
---|---|---|
committer | Scott Jackson <daneren2005@gmail.com> | 2014-08-18 20:54:15 -0700 |
commit | ed19c9a381481c84059cef15fdd0bc3987b65796 (patch) | |
tree | 38666a1f9e55cea8a0434a6c361f379e4a527991 | |
parent | bb6d5c3ef4bd46f2a9006615ad201a756033da5a (diff) | |
download | dsub-ed19c9a381481c84059cef15fdd0bc3987b65796.tar.gz dsub-ed19c9a381481c84059cef15fdd0bc3987b65796.tar.bz2 dsub-ed19c9a381481c84059cef15fdd0bc3987b65796.zip |
Add Resume Playing? dialog when doing context -> Play Now for song with a bookmark on it
6 files changed, 113 insertions, 47 deletions
diff --git a/res/values/strings.xml b/res/values/strings.xml index 71a74db6..ffd6ba7f 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -237,6 +237,10 @@ \nCreated: %3$s
\nLast Updated: %4$s
\nComment: %5$s</string>
+ <string name="bookmark.resume_title">Resume playing?</string>
+ <string name="bookmark.resume">Resume playing \'%1$s\' from %2$s</string>
+ <string name="bookmark.action_resume">Resume</string>
+ <string name="bookmark.action_start_over">Start Over</string>
<string name="song_details.error">Error</string>
<string name="song_details.skipped">Skipped</string>
diff --git a/src/github/daneren2005/dsub/domain/Bookmark.java b/src/github/daneren2005/dsub/domain/Bookmark.java index c114d329..4a86b1bd 100644 --- a/src/github/daneren2005/dsub/domain/Bookmark.java +++ b/src/github/daneren2005/dsub/domain/Bookmark.java @@ -34,6 +34,13 @@ public class Bookmark implements Serializable { private Date created;
private Date changed;
+ public Bookmark() {
+
+ }
+ public Bookmark(int position) {
+ this.position = position;
+ }
+
public int getPosition() {
return position;
}
diff --git a/src/github/daneren2005/dsub/fragments/SelectBookmarkFragment.java b/src/github/daneren2005/dsub/fragments/SelectBookmarkFragment.java index 20d52423..16350f69 100644 --- a/src/github/daneren2005/dsub/fragments/SelectBookmarkFragment.java +++ b/src/github/daneren2005/dsub/fragments/SelectBookmarkFragment.java @@ -41,6 +41,7 @@ import github.daneren2005.dsub.util.Util; import github.daneren2005.dsub.view.BookmarkAdapter; import java.text.Format; import java.text.SimpleDateFormat; +import java.util.Arrays; import java.util.List; public class SelectBookmarkFragment extends SelectListFragment<MusicDirectory.Entry> { @@ -106,7 +107,7 @@ public class SelectBookmarkFragment extends SelectListFragment<MusicDirectory.En new SilentBackgroundTask<Void>(context) { @Override protected Void doInBackground() throws Throwable { - downloadService.download(bookmark); + downloadService.download(Arrays.asList(bookmark), false, true, false, false, bookmark.getBookmark().getPosition()); return null; } diff --git a/src/github/daneren2005/dsub/fragments/SubsonicFragment.java b/src/github/daneren2005/dsub/fragments/SubsonicFragment.java index 580016bb..e1c0d95d 100644 --- a/src/github/daneren2005/dsub/fragments/SubsonicFragment.java +++ b/src/github/daneren2005/dsub/fragments/SubsonicFragment.java @@ -83,6 +83,8 @@ import java.util.LinkedList; import java.util.List;
import java.util.Random;
+import static github.daneren2005.dsub.domain.MusicDirectory.Entry;
+
public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnRefreshListener {
private static final String TAG = SubsonicFragment.class.getSimpleName();
private static int TAG_INC = 10;
@@ -162,8 +164,8 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR public void onCreateContextMenu(ContextMenu menu, View view, ContextMenu.ContextMenuInfo menuInfo, Object selected) {
MenuInflater inflater = context.getMenuInflater();
- if(selected instanceof MusicDirectory.Entry) {
- MusicDirectory.Entry entry = (MusicDirectory.Entry) selected;
+ if(selected instanceof Entry) {
+ Entry entry = (Entry) selected;
if(entry instanceof PodcastEpisode && !entry.isVideo()) {
if(Util.isOffline(context)) {
inflater.inflate(R.menu.select_podcast_episode_context_offline, menu);
@@ -252,8 +254,8 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR public boolean onContextItemSelected(MenuItem menuItem, Object selectedItem) {
Artist artist = selectedItem instanceof Artist ? (Artist) selectedItem : null;
- MusicDirectory.Entry entry = selectedItem instanceof MusicDirectory.Entry ? (MusicDirectory.Entry) selectedItem : null;
- List<MusicDirectory.Entry> songs = new ArrayList<MusicDirectory.Entry>(1);
+ Entry entry = selectedItem instanceof Entry ? (Entry) selectedItem : null;
+ List<Entry> songs = new ArrayList<Entry>(1);
songs.add(entry);
switch (menuItem.getItemId()) {
@@ -315,15 +317,19 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR displaySongInfo(entry);
break;
case R.id.album_menu_show_artist:
- showArtist((MusicDirectory.Entry) selectedItem);
+ showArtist((Entry) selectedItem);
break;
case R.id.album_menu_share:
createShare(songs);
break;
case R.id.song_menu_play_now:
- getDownloadService().clear();
- getDownloadService().download(songs, false, true, true, false);
- Util.startActivityWithoutTransition(context, DownloadActivity.class);
+ if(entry.getBookmark() != null) {
+ playBookmark(songs);
+ } else {
+ getDownloadService().clear();
+ getDownloadService().download(songs, false, true, true, false);
+ Util.startActivityWithoutTransition(context, DownloadActivity.class);
+ }
break;
case R.id.song_menu_play_next:
getDownloadService().download(songs, false, false, true, false);
@@ -636,7 +642,7 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR dialog.show();
}
- public void toggleStarred(final MusicDirectory.Entry entry) {
+ public void toggleStarred(final Entry entry) {
final boolean starred = !entry.isStarred();
entry.setStarred(starred);
@@ -692,12 +698,12 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR }
}.execute();
}
- protected void setEntryStarred(MusicDirectory.Entry entry, boolean starred) {
+ protected void setEntryStarred(Entry entry, boolean starred) {
DownloadService downloadService = DownloadService.getInstance();
if(downloadService != null && !entry.isDirectory()) {
List<DownloadFile> files = downloadService.getDownloads();
for(DownloadFile file: files) {
- MusicDirectory.Entry check = file.getSong();
+ Entry check = file.getSong();
if(entry.getId().equals(check.getId())) {
check.setStarred(starred);
downloadService.serializeQueue();
@@ -706,7 +712,7 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR }
}
- MusicDirectory.Entry find = UpdateView.findEntry(entry);
+ Entry find = UpdateView.findEntry(entry);
if(find != null) {
find.setStarred(starred);
}
@@ -789,7 +795,7 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR Collections.shuffle(root.getChildren());
}
- List<MusicDirectory.Entry> songs = new LinkedList<MusicDirectory.Entry>();
+ List<Entry> songs = new LinkedList<Entry>();
getSongsRecursively(root, songs);
DownloadService downloadService = getDownloadService();
@@ -813,17 +819,17 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR return transition;
}
- private void getSongsRecursively(MusicDirectory parent, List<MusicDirectory.Entry> songs) throws Exception {
+ private void getSongsRecursively(MusicDirectory parent, List<Entry> songs) throws Exception {
if (songs.size() > MAX_SONGS) {
return;
}
- for (MusicDirectory.Entry song : parent.getChildren(false, true)) {
+ for (Entry song : parent.getChildren(false, true)) {
if (!song.isVideo()) {
songs.add(song);
}
}
- for (MusicDirectory.Entry dir : parent.getChildren(true, false)) {
+ for (Entry dir : parent.getChildren(true, false)) {
MusicService musicService = MusicServiceFactory.getMusicService(context);
MusicDirectory musicDirectory;
@@ -861,7 +867,7 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR }
}
- protected void addToPlaylist(final List<MusicDirectory.Entry> songs) {
+ protected void addToPlaylist(final List<Entry> songs) {
if(songs.isEmpty()) {
Util.toast(context, "No songs selected");
return;
@@ -925,7 +931,7 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR }.execute();
}
- private void addToPlaylist(final Playlist playlist, final List<MusicDirectory.Entry> songs) {
+ private void addToPlaylist(final Playlist playlist, final List<Entry> songs) {
new SilentBackgroundTask<Void>(context) {
@Override
protected Void doInBackground() throws Throwable {
@@ -953,7 +959,7 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR }.execute();
}
- protected void createNewPlaylist(final List<MusicDirectory.Entry> songs, final boolean getSuggestion) {
+ protected void createNewPlaylist(final List<Entry> songs, final boolean getSuggestion) {
View layout = context.getLayoutInflater().inflate(R.layout.save_playlist, null);
final EditText playlistNameView = (EditText) layout.findViewById(R.id.save_playlist_name);
final CheckBox overwriteCheckBox = (CheckBox) layout.findViewById(R.id.save_playlist_overwrite);
@@ -1011,7 +1017,7 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR AlertDialog dialog = builder.create();
dialog.show();
}
- private void createNewPlaylist(final List<MusicDirectory.Entry> songs, final String name) {
+ private void createNewPlaylist(final List<Entry> songs, final String name) {
new SilentBackgroundTask<Void>(context) {
@Override
protected Void doInBackground() throws Throwable {
@@ -1032,13 +1038,13 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR }
}.execute();
}
- private void overwritePlaylist(final List<MusicDirectory.Entry> songs, final String name, final String id) {
+ private void overwritePlaylist(final List<Entry> songs, final String name, final String id) {
new SilentBackgroundTask<Void>(context) {
@Override
protected Void doInBackground() throws Throwable {
MusicService musicService = MusicServiceFactory.getMusicService(context);
MusicDirectory playlist = musicService.getPlaylist(true, id, name, context, null);
- List<MusicDirectory.Entry> toDelete = playlist.getChildren();
+ List<Entry> toDelete = playlist.getChildren();
musicService.overwritePlaylist(id, name, toDelete.size(), songs, context, null);
return null;
}
@@ -1062,7 +1068,7 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR }.execute();
}
- public void displaySongInfo(final MusicDirectory.Entry song) {
+ public void displaySongInfo(final Entry song) {
Integer bitrate = null;
String format = null;
long size = 0;
@@ -1134,7 +1140,7 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR Util.info(context, song.getTitle(), msg);
}
- protected void playVideo(MusicDirectory.Entry entry) {
+ protected void playVideo(Entry entry) {
if(entryExists(entry)) {
playExternalPlayer(entry);
} else {
@@ -1142,7 +1148,7 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR }
}
- protected void playWebView(MusicDirectory.Entry entry) {
+ protected void playWebView(Entry entry) {
int maxBitrate = Util.getMaxVideoBitrate(context);
Intent intent = new Intent(Intent.ACTION_VIEW);
@@ -1150,7 +1156,7 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR startActivity(intent);
}
- protected void playExternalPlayer(MusicDirectory.Entry entry) {
+ protected void playExternalPlayer(Entry entry) {
if(!entryExists(entry)) {
Util.toast(context, R.string.download_need_download);
} else {
@@ -1166,7 +1172,7 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR }
}
}
- protected void streamExternalPlayer(MusicDirectory.Entry entry) {
+ protected void streamExternalPlayer(Entry entry) {
String videoPlayerType = Util.getVideoPlayerType(context);
if("flash".equals(videoPlayerType)) {
playWebView(entry);
@@ -1178,7 +1184,7 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR streamExternalPlayer(entry, entry.getTranscodedSuffix());
}
}
- protected void streamExternalPlayer(MusicDirectory.Entry entry, String format) {
+ protected void streamExternalPlayer(Entry entry, String format) {
try {
int maxBitrate = Util.getMaxVideoBitrate(context);
@@ -1208,7 +1214,7 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR }
}
- protected boolean entryExists(MusicDirectory.Entry entry) {
+ protected boolean entryExists(Entry entry) {
DownloadFile check = new DownloadFile(context, entry, false);
return check.isCompleteFileAvailable();
}
@@ -1224,7 +1230,7 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR }
}
- public void deleteRecursively(MusicDirectory.Entry album) {
+ public void deleteRecursively(Entry album) {
File dir = FileUtil.getAlbumDirectory(context, album);
if(dir == null) return;
@@ -1235,7 +1241,7 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR }
}
- public void showArtist(MusicDirectory.Entry entry) {
+ public void showArtist(Entry entry) {
SubsonicFragment fragment = new SelectDirectoryFragment();
Bundle args = new Bundle();
if(Util.isTagBrowsing(context)) {
@@ -1250,12 +1256,12 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR replaceFragment(fragment, true);
}
- public void createShare(final List<MusicDirectory.Entry> entries) {
+ public void createShare(final List<Entry> entries) {
new LoadingTask<List<Share>>(context, true) {
@Override
protected List<Share> doInBackground() throws Throwable {
List<String> ids = new ArrayList<String>(entries.size());
- for(MusicDirectory.Entry entry: entries) {
+ for(Entry entry: entries) {
ids.add(entry.getId());
}
@@ -1296,4 +1302,54 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR public GestureDetector getGestureDetector() {
return gestureScanner;
}
+
+ protected void playBookmark(final List<Entry> songs) {
+ if(songs.size() == 1) {
+ final Entry song = songs.get(0);
+ final Integer position = song.getBookmark().getPosition();
+
+ AlertDialog.Builder builder = new AlertDialog.Builder(context);
+ builder.setTitle(R.string.bookmark_resume_title)
+ .setMessage(getResources().getString(R.string.bookmark_resume, song.getTitle(), Util.formatDuration(position / 1000)))
+ .setPositiveButton(R.string.bookmark_action_resume, new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int id) {
+ getDownloadService().clear();
+ getDownloadService().download(songs, false, true, true, false, position);
+ Util.startActivityWithoutTransition(context, DownloadActivity.class);
+ }
+ })
+ .setNegativeButton(R.string.bookmark_action_start_over, new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int id) {
+ new SilentBackgroundTask<Void>(context) {
+ @Override
+ protected Void doInBackground() throws Throwable {
+ MusicService musicService = MusicServiceFactory.getMusicService(context);
+ musicService.deleteBookmark(song.getId(), context, null);
+ return null;
+ }
+
+ @Override
+ protected void error(Throwable error) {
+ String msg;
+ if (error instanceof OfflineException || error instanceof ServerTooOldException) {
+ msg = getErrorMessage(error);
+ } else {
+ msg = context.getResources().getString(R.string.bookmark_deleted_error, song.getTitle()) + " " + getErrorMessage(error);
+ }
+
+ Util.toast(context, msg, false);
+ }
+ }.execute();
+
+ getDownloadService().clear();
+ getDownloadService().download(songs, false, true, true, false);
+ Util.startActivityWithoutTransition(context, DownloadActivity.class);
+ }
+ });
+ AlertDialog dialog = builder.create();
+ dialog.show();
+ }
+ }
}
diff --git a/src/github/daneren2005/dsub/service/DownloadService.java b/src/github/daneren2005/dsub/service/DownloadService.java index 4b8f9018..81249660 100644 --- a/src/github/daneren2005/dsub/service/DownloadService.java +++ b/src/github/daneren2005/dsub/service/DownloadService.java @@ -294,19 +294,10 @@ public class DownloadService extends Service { return binder; } - public synchronized void download(MusicDirectory.Entry entry) { - Bookmark bookmark = entry.getBookmark(); - - clear(); - DownloadFile downloadFile = new DownloadFile(this, entry, false); - downloadList.add(downloadFile); - revision++; - updateJukeboxPlaylist(); - play(0, true, bookmark.getPosition()); - lifecycleSupport.serializeDownloadQueue(); - } - public synchronized void download(List<MusicDirectory.Entry> songs, boolean save, boolean autoplay, boolean playNext, boolean shuffle) { + download(songs, save, autoplay, playNext, shuffle, 0); + } + public synchronized void download(List<MusicDirectory.Entry> songs, boolean save, boolean autoplay, boolean playNext, boolean shuffle, int position) { setShufflePlayEnabled(false); int offset = 1; @@ -345,7 +336,7 @@ public class DownloadService extends Service { } if (autoplay) { - play(0); + play(0, true, position); } else { if (currentPlaying == null) { currentPlaying = downloadList.get(0); diff --git a/src/github/daneren2005/dsub/service/parser/MusicDirectoryEntryParser.java b/src/github/daneren2005/dsub/service/parser/MusicDirectoryEntryParser.java index a9bafd12..67effc24 100644 --- a/src/github/daneren2005/dsub/service/parser/MusicDirectoryEntryParser.java +++ b/src/github/daneren2005/dsub/service/parser/MusicDirectoryEntryParser.java @@ -19,6 +19,8 @@ package github.daneren2005.dsub.service.parser; import android.content.Context; + +import github.daneren2005.dsub.domain.Bookmark; import github.daneren2005.dsub.domain.MusicDirectory; /** @@ -59,6 +61,11 @@ public class MusicDirectoryEntryParser extends AbstractParser { entry.setPath(get("path")); entry.setVideo(getBoolean("isVideo")); entry.setDiscNumber(getInteger("discNumber")); + + Integer bookmark = getInteger("bookmarkPosition"); + if(bookmark != null) { + entry.setBookmark(new Bookmark(bookmark)); + } } else if(!"".equals(artist)) { entry.setPath(artist + "/" + entry.getTitle()); } |