From df87756cd3330be032671ff8cb694395cebe1457 Mon Sep 17 00:00:00 2001 From: owner Date: Wed, 21 Nov 2012 23:13:43 -0800 Subject: Added special context menu for videos --- subsonic-android/res/menu/select_video_context.xml | 25 ++++++++++++++++++++++ .../res/menu/select_video_context_offline.xml | 25 ++++++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 subsonic-android/res/menu/select_video_context.xml create mode 100644 subsonic-android/res/menu/select_video_context_offline.xml (limited to 'subsonic-android/res/menu') diff --git a/subsonic-android/res/menu/select_video_context.xml b/subsonic-android/res/menu/select_video_context.xml new file mode 100644 index 00000000..2edcb10a --- /dev/null +++ b/subsonic-android/res/menu/select_video_context.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + + diff --git a/subsonic-android/res/menu/select_video_context_offline.xml b/subsonic-android/res/menu/select_video_context_offline.xml new file mode 100644 index 00000000..2edcb10a --- /dev/null +++ b/subsonic-android/res/menu/select_video_context_offline.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + + -- cgit v1.2.3 From 385b399420ee3321bf7624a76276229efc986688 Mon Sep 17 00:00:00 2001 From: owner Date: Fri, 23 Nov 2012 09:18:39 -0800 Subject: Added option to play videos with external player --- subsonic-android/res/menu/select_video_context.xml | 4 ++++ .../res/menu/select_video_context_offline.xml | 23 ++-------------------- subsonic-android/res/values/strings.xml | 1 + .../dsub/activity/SelectAlbumActivity.java | 14 ++++++++++--- 4 files changed, 18 insertions(+), 24 deletions(-) (limited to 'subsonic-android/res/menu') diff --git a/subsonic-android/res/menu/select_video_context.xml b/subsonic-android/res/menu/select_video_context.xml index 2edcb10a..ed04b6ff 100644 --- a/subsonic-android/res/menu/select_video_context.xml +++ b/subsonic-android/res/menu/select_video_context.xml @@ -1,5 +1,9 @@ + + - - - - - - - - + android:id="@+id/song_menu_play_external" + android:title="@string/common.play_external"/> diff --git a/subsonic-android/res/values/strings.xml b/subsonic-android/res/values/strings.xml index 26301b17..531c84eb 100644 --- a/subsonic-android/res/values/strings.xml +++ b/subsonic-android/res/values/strings.xml @@ -18,6 +18,7 @@ Name Comment Play Web View (Flash) + Play External Player Home Library diff --git a/subsonic-android/src/github/daneren2005/dsub/activity/SelectAlbumActivity.java b/subsonic-android/src/github/daneren2005/dsub/activity/SelectAlbumActivity.java index 2d87c263..cd71db36 100644 --- a/subsonic-android/src/github/daneren2005/dsub/activity/SelectAlbumActivity.java +++ b/subsonic-android/src/github/daneren2005/dsub/activity/SelectAlbumActivity.java @@ -78,7 +78,7 @@ public class SelectAlbumActivity extends SubsonicTabActivity { intent.putExtra(Constants.INTENT_EXTRA_NAME_NAME, entry.getTitle()); Util.startActivityWithoutTransition(SelectAlbumActivity.this, intent); } else if (entry.isVideo()) { - playVideo(entry); + playExternalPlayer(entry); } } } @@ -291,7 +291,10 @@ public class SelectAlbumActivity extends SubsonicTabActivity { toggleStarred(entry); break; case R.id.song_menu_webview: - playVideo(entry); + playWebView(entry); + break; + case R.id.song_menu_play_external: + playExternalPlayer(entry); break; default: return super.onContextItemSelected(menuItem); @@ -492,12 +495,17 @@ public class SelectAlbumActivity extends SubsonicTabActivity { } } - private void playVideo(MusicDirectory.Entry entry) { + private void playWebView(MusicDirectory.Entry entry) { Intent intent = new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse(MusicServiceFactory.getMusicService(this).getVideoUrl(this, entry.getId()))); startActivity(intent); } + private void playExternalPlayer(MusicDirectory.Entry entry) { + Intent intent = new Intent(Intent.ACTION_VIEW); + intent.setDataAndType(Uri.parse(entry.getPath()), "video/*"); + startActivity(intent); + } private void checkLicenseAndTrialPeriod(Runnable onValid) { if (licenseValid) { -- cgit v1.2.3 From 2e3820f52ddf5720053db60b2d9fa251e0089149 Mon Sep 17 00:00:00 2001 From: owner Date: Fri, 23 Nov 2012 13:24:37 -0800 Subject: Added options to remove songs from playlists --- subsonic-android/res/menu/select_song.xml | 4 ++ subsonic-android/res/menu/select_song_context.xml | 4 ++ subsonic-android/res/values/strings.xml | 2 + .../dsub/activity/SelectAlbumActivity.java | 82 +++++++++++++++++++--- .../dsub/service/CachedMusicService.java | 5 ++ .../daneren2005/dsub/service/MusicService.java | 2 + .../dsub/service/OfflineMusicService.java | 5 ++ .../daneren2005/dsub/service/RESTMusicService.java | 19 +++++ 8 files changed, 112 insertions(+), 11 deletions(-) (limited to 'subsonic-android/res/menu') diff --git a/subsonic-android/res/menu/select_song.xml b/subsonic-android/res/menu/select_song.xml index cd49e44f..3a55fee0 100644 --- a/subsonic-android/res/menu/select_song.xml +++ b/subsonic-android/res/menu/select_song.xml @@ -46,6 +46,10 @@ android:id="@+id/menu_add_playlist" android:title="@string/menu.add_playlist"/> + + + + diff --git a/subsonic-android/res/values/strings.xml b/subsonic-android/res/values/strings.xml index 12e93949..dc02569a 100644 --- a/subsonic-android/res/values/strings.xml +++ b/subsonic-android/res/values/strings.xml @@ -52,6 +52,7 @@ Settings Help Add To Playlist + Remove From Playlist Deleted playlist %s Failed to delete playlist %s @@ -145,6 +146,7 @@ Failed to grab list of playlists Added %1$s songs to \"%2$s\" Failed to update \"%s\", please try later. + Removed %1$s songs from \"%2$s\" %1$s %2$s %d kbps diff --git a/subsonic-android/src/github/daneren2005/dsub/activity/SelectAlbumActivity.java b/subsonic-android/src/github/daneren2005/dsub/activity/SelectAlbumActivity.java index fea1cfd0..891c2edd 100644 --- a/subsonic-android/src/github/daneren2005/dsub/activity/SelectAlbumActivity.java +++ b/subsonic-android/src/github/daneren2005/dsub/activity/SelectAlbumActivity.java @@ -34,16 +34,11 @@ import android.widget.*; import com.actionbarsherlock.view.Menu; import github.daneren2005.dsub.R; import github.daneren2005.dsub.domain.MusicDirectory; -import github.daneren2005.dsub.service.DownloadFile; -import github.daneren2005.dsub.service.MusicService; -import github.daneren2005.dsub.service.MusicServiceFactory; +import github.daneren2005.dsub.service.*; import github.daneren2005.dsub.util.*; import java.io.File; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; +import java.util.*; public class SelectAlbumActivity extends SubsonicTabActivity { @@ -115,10 +110,17 @@ public class SelectAlbumActivity extends SubsonicTabActivity { inflater.inflate(R.menu.select_album, menu); hideButtons = false; } else { - if(Util.isOffline(this)) + if(Util.isOffline(this)) { inflater.inflate(R.menu.select_song_offline, menu); - else + } + else { inflater.inflate(R.menu.select_song, menu); + + String playlistId = getIntent().getStringExtra(Constants.INTENT_EXTRA_NAME_PLAYLIST_ID); + if(playlistId == null) { + menu.removeItem(R.id.menu_remove_playlist); + } + } } return true; } @@ -157,6 +159,11 @@ public class SelectAlbumActivity extends SubsonicTabActivity { case R.id.menu_add_playlist: addToPlaylist(getSelectedSongs()); return true; + case R.id.menu_remove_playlist: + String playlistId = getIntent().getStringExtra(Constants.INTENT_EXTRA_NAME_PLAYLIST_ID); + String playlistName = getIntent().getStringExtra(Constants.INTENT_EXTRA_NAME_PLAYLIST_NAME); + removeFromPlaylist(playlistId, playlistName, getSelectedIndexes()); + return true; case R.id.menu_exit: intent = new Intent(this, MainActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); @@ -226,10 +233,16 @@ public class SelectAlbumActivity extends SubsonicTabActivity { inflater.inflate(R.menu.select_album_context, menu); } else if(!entry.isVideo()) { MenuInflater inflater = getMenuInflater(); - if(Util.isOffline(this)) + if(Util.isOffline(this)) { inflater.inflate(R.menu.select_song_context_offline, menu); - else + } + else { inflater.inflate(R.menu.select_song_context, menu); + String playlistId = getIntent().getStringExtra(Constants.INTENT_EXTRA_NAME_PLAYLIST_ID); + if(playlistId == null) { + menu.removeItem(R.id.song_menu_remove_playlist); + } + } } else { MenuInflater inflater = getMenuInflater(); if(Util.isOffline(this)) @@ -298,6 +311,11 @@ public class SelectAlbumActivity extends SubsonicTabActivity { case R.id.song_menu_play_external: playExternalPlayer(entry); break; + case R.id.song_menu_remove_playlist: + String playlistId = getIntent().getStringExtra(Constants.INTENT_EXTRA_NAME_PLAYLIST_ID); + String playlistName = getIntent().getStringExtra(Constants.INTENT_EXTRA_NAME_PLAYLIST_NAME); + removeFromPlaylist(playlistId, playlistName, Arrays.asList(info.position - 1)); + break; default: return super.onContextItemSelected(menuItem); } @@ -425,6 +443,19 @@ public class SelectAlbumActivity extends SubsonicTabActivity { } return songs; } + + private List getSelectedIndexes() { + List indexes = new ArrayList(); + + int count = entryList.getCount(); + for (int i = 0; i < count; i++) { + if (entryList.isItemChecked(i)) { + indexes.add(i - 1); + } + } + + return indexes; + } private void download(final boolean append, final boolean save, final boolean autoplay, final boolean playNext, final boolean shuffle) { if (getDownloadService() == null) { @@ -651,4 +682,33 @@ public class SelectAlbumActivity extends SubsonicTabActivity { return header; } + + public void removeFromPlaylist(final String id, final String name, final List indexes) { + new LoadingTask(this, true) { + @Override + protected Void doInBackground() throws Throwable { + MusicService musicService = MusicServiceFactory.getMusicService(SelectAlbumActivity.this); + musicService.removeFromPlaylist(id, indexes, SelectAlbumActivity.this, null); + return null; + } + + @Override + protected void done(Void result) { + refresh(); + Util.toast(SelectAlbumActivity.this, getResources().getString(R.string.removed_playlist, indexes.size(), name)); + } + + @Override + protected void error(Throwable error) { + String msg; + if (error instanceof OfflineException || error instanceof ServerTooOldException) { + msg = getErrorMessage(error); + } else { + msg = getResources().getString(R.string.updated_playlist_error, name) + " " + getErrorMessage(error); + } + + Util.toast(SelectAlbumActivity.this, msg, false); + } + }.execute(); + } } diff --git a/subsonic-android/src/github/daneren2005/dsub/service/CachedMusicService.java b/subsonic-android/src/github/daneren2005/dsub/service/CachedMusicService.java index 42fd8e57..c9233d01 100644 --- a/subsonic-android/src/github/daneren2005/dsub/service/CachedMusicService.java +++ b/subsonic-android/src/github/daneren2005/dsub/service/CachedMusicService.java @@ -160,6 +160,11 @@ public class CachedMusicService implements MusicService { musicService.addToPlaylist(id, toAdd, context, progressListener); } + @Override + public void removeFromPlaylist(String id, List toRemove, Context context, ProgressListener progressListener) throws Exception { + musicService.removeFromPlaylist(id, toRemove, context, progressListener); + } + @Override public void updatePlaylist(String id, String name, String comment, Context context, ProgressListener progressListener) throws Exception { musicService.updatePlaylist(id, name, comment, context, progressListener); diff --git a/subsonic-android/src/github/daneren2005/dsub/service/MusicService.java b/subsonic-android/src/github/daneren2005/dsub/service/MusicService.java index ebcfe9aa..67e4bed5 100644 --- a/subsonic-android/src/github/daneren2005/dsub/service/MusicService.java +++ b/subsonic-android/src/github/daneren2005/dsub/service/MusicService.java @@ -65,6 +65,8 @@ public interface MusicService { void addToPlaylist(String id, List toAdd, Context context, ProgressListener progressListener) throws Exception; + void removeFromPlaylist(String id, List toRemove, Context context, ProgressListener progressListener) throws Exception; + void updatePlaylist(String id, String name, String comment, Context context, ProgressListener progressListener) throws Exception; Lyrics getLyrics(String artist, String title, Context context, ProgressListener progressListener) throws Exception; diff --git a/subsonic-android/src/github/daneren2005/dsub/service/OfflineMusicService.java b/subsonic-android/src/github/daneren2005/dsub/service/OfflineMusicService.java index 135a1e12..ce353740 100644 --- a/subsonic-android/src/github/daneren2005/dsub/service/OfflineMusicService.java +++ b/subsonic-android/src/github/daneren2005/dsub/service/OfflineMusicService.java @@ -294,6 +294,11 @@ public class OfflineMusicService extends RESTMusicService { throw new OfflineException("Updating playlist not available in offline mode"); } + @Override + public void removeFromPlaylist(String id, List toRemove, Context context, ProgressListener progressListener) throws Exception { + throw new OfflineException("Removing from playlist not available in offline mode"); + } + @Override public void updatePlaylist(String id, String name, String comment, Context context, ProgressListener progressListener) throws Exception { throw new OfflineException("Updating playlist not available in offline mode"); diff --git a/subsonic-android/src/github/daneren2005/dsub/service/RESTMusicService.java b/subsonic-android/src/github/daneren2005/dsub/service/RESTMusicService.java index 25bacb61..00e9f2b1 100644 --- a/subsonic-android/src/github/daneren2005/dsub/service/RESTMusicService.java +++ b/subsonic-android/src/github/daneren2005/dsub/service/RESTMusicService.java @@ -422,6 +422,25 @@ public class RESTMusicService implements MusicService { } } + @Override + public void removeFromPlaylist(String id, List toRemove, Context context, ProgressListener progressListener) throws Exception { + checkServerVersion(context, "1.8", "Updating playlists is not supported."); + List names = new ArrayList(); + List values = new ArrayList(); + names.add("playlistId"); + values.add(id); + for(Integer song: toRemove) { + names.add("songIndexToRemove"); + values.add(song); + } + Reader reader = getReader(context, progressListener, "updatePlaylist", null, names, values); + try { + new ErrorParser(context).parse(reader); + } finally { + Util.close(reader); + } + } + @Override public void updatePlaylist(String id, String name, String comment, Context context, ProgressListener progressListener) throws Exception { checkServerVersion(context, "1.8", "Updating playlists is not supported."); -- cgit v1.2.3