diff options
author | Scott Jackson <daneren2005@gmail.com> | 2013-04-14 20:22:42 -0700 |
---|---|---|
committer | Scott Jackson <daneren2005@gmail.com> | 2013-04-14 20:22:42 -0700 |
commit | 85ab2efdd0a692c97bc9afce4851466585dec2d4 (patch) | |
tree | 4f9dc27ab864cb6931fa26b0958859d5c9fe78e1 | |
parent | 634536648d7847fe648c18d7572d7717d6348e43 (diff) | |
download | dsub-85ab2efdd0a692c97bc9afce4851466585dec2d4.tar.gz dsub-85ab2efdd0a692c97bc9afce4851466585dec2d4.tar.bz2 dsub-85ab2efdd0a692c97bc9afce4851466585dec2d4.zip |
Fix the remainder of the missing context menus
-rw-r--r-- | subsonic-android/src/github/daneren2005/dsub/fragments/SelectArtistFragment.java | 32 | ||||
-rw-r--r-- | subsonic-android/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java | 122 |
2 files changed, 144 insertions, 10 deletions
diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/SelectArtistFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/SelectArtistFragment.java index bd5f7921..4f3a820f 100644 --- a/subsonic-android/src/github/daneren2005/dsub/fragments/SelectArtistFragment.java +++ b/subsonic-android/src/github/daneren2005/dsub/fragments/SelectArtistFragment.java @@ -22,9 +22,11 @@ import github.daneren2005.dsub.service.MusicService; import github.daneren2005.dsub.service.MusicServiceFactory;
import github.daneren2005.dsub.util.BackgroundTask;
import github.daneren2005.dsub.util.Constants;
+import github.daneren2005.dsub.util.FileUtil;
import github.daneren2005.dsub.util.TabBackgroundTask;
import github.daneren2005.dsub.util.Util;
import github.daneren2005.dsub.view.ArtistAdapter;
+import java.io.File;
import java.util.ArrayList;
import java.util.List;
@@ -84,10 +86,12 @@ public class SelectArtistFragment extends LibraryFunctionsFragment implements Ad if (artistList.getItemAtPosition(info.position) instanceof Artist) {
MenuInflater inflater = context.getMenuInflater();
- if(Util.isOffline(context))
+ if(Util.isOffline(context)) {
inflater.inflate(R.menu.select_artist_context_offline, menu);
- else
+ }
+ else {
inflater.inflate(R.menu.select_artist_context, menu);
+ }
} else if (info.position == 0) {
String musicFolderId = Util.getSelectedMusicFolderId(context);
MenuItem menuItem = menu.add(MENU_GROUP_MUSIC_FOLDER, -1, 0, R.string.select_artist_all_folders);
@@ -112,7 +116,7 @@ public class SelectArtistFragment extends LibraryFunctionsFragment implements Ad if(!primaryFragment) {
return false;
}
-
+
AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuItem.getMenuInfo();
Artist artist = (Artist) artistList.getItemAtPosition(info.position);
@@ -120,25 +124,25 @@ public class SelectArtistFragment extends LibraryFunctionsFragment implements Ad if (artist != null) {
switch (menuItem.getItemId()) {
case R.id.artist_menu_play_now:
- // downloadRecursively(artist.getId(), false, false, true, false, false);
+ downloadRecursively(artist.getId(), false, false, true, false, false);
break;
case R.id.artist_menu_play_shuffled:
- // downloadRecursively(artist.getId(), false, false, true, true, false);
+ downloadRecursively(artist.getId(), false, false, true, true, false);
break;
case R.id.artist_menu_play_last:
- // downloadRecursively(artist.getId(), false, true, false, false, false);
+ downloadRecursively(artist.getId(), false, true, false, false, false);
break;
case R.id.artist_menu_download:
- // downloadRecursively(artist.getId(), false, true, false, false, true);
+ downloadRecursively(artist.getId(), false, true, false, false, true);
break;
case R.id.artist_menu_pin:
- // downloadRecursively(artist.getId(), true, true, false, false, true);
+ downloadRecursively(artist.getId(), true, true, false, false, true);
break;
case R.id.artist_menu_delete:
- // deleteRecursively(artist);
+ deleteRecursively(artist);
break;
default:
- // return super.onContextItemSelected(menuItem);
+ return super.onContextItemSelected(menuItem);
}
} else if (info.position == 0) {
MusicFolder selectedFolder = menuItem.getItemId() == -1 ? null : musicFolders.get(menuItem.getItemId());
@@ -218,4 +222,12 @@ public class SelectArtistFragment extends LibraryFunctionsFragment implements Ad private void selectFolder() {
folderButton.showContextMenu();
}
+
+ public void deleteRecursively(Artist artist) {
+ File dir = FileUtil.getArtistDirectory(context, artist);
+ Util.recursiveDelete(dir);
+ if(Util.isOffline(context)) {
+ refresh();
+ }
+ }
}
diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java index 9e8d42e9..11e500b6 100644 --- a/subsonic-android/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java +++ b/subsonic-android/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java @@ -9,7 +9,10 @@ import android.net.Uri; import android.os.Bundle;
import android.support.v4.app.FragmentTransaction;
import android.util.Log;
+import android.view.ContextMenu;
import android.view.LayoutInflater;
+import android.view.MenuInflater;
+import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
@@ -35,6 +38,7 @@ import github.daneren2005.dsub.util.TabBackgroundTask; import github.daneren2005.dsub.util.Util;
import java.io.File;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
@@ -175,6 +179,124 @@ public class SelectDirectoryFragment extends LibraryFunctionsFragment implements }
@Override
+ public void onCreateContextMenu(ContextMenu menu, View view, ContextMenu.ContextMenuInfo menuInfo) {
+ super.onCreateContextMenu(menu, view, menuInfo);
+ AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;
+
+ MusicDirectory.Entry entry = (MusicDirectory.Entry) entryList.getItemAtPosition(info.position);
+
+ MenuInflater inflater = context.getMenuInflater();
+ if (entry.isDirectory()) {
+ if(Util.isOffline(context)) {
+ inflater.inflate(R.menu.select_album_context_offline, menu);
+ }
+ else {
+ inflater.inflate(R.menu.select_album_context, menu);
+ }
+ } else if(!entry.isVideo()) {
+ if(Util.isOffline(context)) {
+ inflater.inflate(R.menu.select_song_context_offline, menu);
+ }
+ else {
+ inflater.inflate(R.menu.select_song_context, menu);
+ if(playlistId == null) {
+ menu.removeItem(R.id.song_menu_remove_playlist);
+ }
+ }
+ } else {
+ if(Util.isOffline(context)) {
+ inflater.inflate(R.menu.select_video_context_offline, menu);
+ }
+ else {
+ inflater.inflate(R.menu.select_video_context, menu);
+ }
+ }
+
+ if (!Util.isOffline(context) && !entry.isVideo()) {
+ menu.findItem(entry.isDirectory() ? R.id.album_menu_star : R.id.song_menu_star).setTitle(entry.isStarred() ? R.string.common_unstar : R.string.common_star);
+ }
+ }
+
+ @Override
+ public boolean onContextItemSelected(MenuItem menuItem) {
+ if(!primaryFragment) {
+ return false;
+ }
+
+ AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuItem.getMenuInfo();
+ MusicDirectory.Entry entry = (MusicDirectory.Entry) entryList.getItemAtPosition(info.position);
+ List<MusicDirectory.Entry> songs = new ArrayList<MusicDirectory.Entry>(10);
+ songs.add((MusicDirectory.Entry) entryList.getItemAtPosition(info.position));
+ switch (menuItem.getItemId()) {
+ case R.id.album_menu_play_now:
+ downloadRecursively(entry.getId(), false, false, true, false, false);
+ break;
+ case R.id.album_menu_play_shuffled:
+ downloadRecursively(entry.getId(), false, false, true, true, false);
+ break;
+ case R.id.album_menu_play_last:
+ downloadRecursively(entry.getId(), false, true, false, false, false);
+ break;
+ case R.id.album_menu_download:
+ downloadRecursively(entry.getId(), false, true, false, false, true);
+ break;
+ case R.id.album_menu_pin:
+ downloadRecursively(entry.getId(), true, true, false, false, true);
+ break;
+ case R.id.album_menu_star:
+ toggleStarred(entry);
+ break;
+ case R.id.album_menu_delete:
+ deleteRecursively(entry);
+ break;
+ case R.id.song_menu_play_now:
+ 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);
+ break;
+ case R.id.song_menu_play_last:
+ getDownloadService().download(songs, false, false, false, false);
+ break;
+ case R.id.song_menu_download:
+ getDownloadService().downloadBackground(songs, false);
+ break;
+ case R.id.song_menu_pin:
+ getDownloadService().downloadBackground(songs, true);
+ break;
+ case R.id.song_menu_delete:
+ getDownloadService().delete(songs);
+ break;
+ case R.id.song_menu_add_playlist:
+ addToPlaylist(songs);
+ break;
+ case R.id.song_menu_star:
+ toggleStarred(entry);
+ break;
+ case R.id.song_menu_webview:
+ playWebView(entry);
+ break;
+ case R.id.song_menu_play_external:
+ playExternalPlayer(entry);
+ break;
+ case R.id.song_menu_info:
+ displaySongInfo(entry);
+ break;
+ case R.id.song_menu_stream_external:
+ streamExternalPlayer(entry);
+ break;
+ case R.id.song_menu_remove_playlist:
+ removeFromPlaylist(playlistId, playlistName, Arrays.<Integer>asList(info.position - 1));
+ break;
+ default:
+ return super.onContextItemSelected(menuItem);
+ }
+ return true;
+ }
+
+ @Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
if (position >= 0) {
MusicDirectory.Entry entry = (MusicDirectory.Entry) parent.getItemAtPosition(position);
|