From a9ed7c936d0e4c065b116d49c3abaff20f900a19 Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Mon, 29 Apr 2013 21:29:49 -0700 Subject: Combine context menu builder --- .../daneren2005/dsub/fragments/SearchFragment.java | 13 +------ .../dsub/fragments/SelectArtistFragment.java | 11 ++---- .../dsub/fragments/SelectDirectoryFragment.java | 33 ++--------------- .../dsub/fragments/SubsonicFragment.java | 43 ++++++++++++++++++++++ 4 files changed, 50 insertions(+), 50 deletions(-) (limited to 'subsonic-android/src/github') diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/SearchFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/SearchFragment.java index ea09328d..b38beab4 100644 --- a/subsonic-android/src/github/daneren2005/dsub/fragments/SearchFragment.java +++ b/subsonic-android/src/github/daneren2005/dsub/fragments/SearchFragment.java @@ -142,18 +142,7 @@ public class SearchFragment extends SubsonicFragment { AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo; Object selectedItem = list.getItemAtPosition(info.position); - - boolean isArtist = selectedItem instanceof Artist; - boolean isAlbum = selectedItem instanceof MusicDirectory.Entry && ((MusicDirectory.Entry) selectedItem).isDirectory(); - boolean isSong = selectedItem instanceof MusicDirectory.Entry && (!((MusicDirectory.Entry) selectedItem).isDirectory()) - && (!((MusicDirectory.Entry) selectedItem).isVideo()); - - MenuInflater inflater = context.getMenuInflater(); - if (isArtist || isAlbum) { - inflater.inflate(R.menu.select_album_context, menu); - } else if (isSong) { - inflater.inflate(R.menu.select_song_context, menu); - } + onCreateContextMenu(menu, view, menuInfo, selectedItem); } @Override diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/SelectArtistFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/SelectArtistFragment.java index bac9c71d..dba70ce8 100644 --- a/subsonic-android/src/github/daneren2005/dsub/fragments/SelectArtistFragment.java +++ b/subsonic-android/src/github/daneren2005/dsub/fragments/SelectArtistFragment.java @@ -83,15 +83,10 @@ public class SelectArtistFragment extends SubsonicTabFragment implements Adapter super.onCreateContextMenu(menu, view, menuInfo); AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo; + Object entry = artistList.getItemAtPosition(info.position); - if (artistList.getItemAtPosition(info.position) instanceof Artist) { - MenuInflater inflater = context.getMenuInflater(); - if(Util.isOffline(context)) { - inflater.inflate(R.menu.select_artist_context_offline, menu); - } - else { - inflater.inflate(R.menu.select_artist_context, menu); - } + if (entry instanceof Artist) { + onCreateContextMenu(menu, view, menuInfo, entry); } 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); diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java index c518f73e..c4d28995 100644 --- a/subsonic-android/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java +++ b/subsonic-android/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java @@ -184,36 +184,9 @@ public class SelectDirectoryFragment extends SubsonicTabFragment implements Adap 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); + onCreateContextMenu(menu, view, menuInfo, entry); + if(!entry.isVideo() && !Util.isOffline(context) && playlistId == null) { + menu.removeItem(R.id.song_menu_remove_playlist); } } diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicFragment.java index 4b52196f..e9da1827 100644 --- a/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicFragment.java +++ b/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicFragment.java @@ -30,6 +30,8 @@ import android.media.MediaMetadataRetriever; import android.net.Uri; import android.os.Bundle; import android.util.Log; +import android.view.ContextMenu; +import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; import android.widget.AdapterView; @@ -117,6 +119,47 @@ public class SubsonicFragment extends SherlockFragment { return false; } + + 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 (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); + } + } 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); + } + } else if(selected instanceof Artist) { + if(Util.isOffline(context)) { + inflater.inflate(R.menu.select_artist_context_offline, menu); + } + else { + inflater.inflate(R.menu.select_artist_context, menu); + } + } + } public boolean onContextItemSelected(MenuItem menuItem, Object selectedItem) { Artist artist = selectedItem instanceof Artist ? (Artist) selectedItem : null; -- cgit v1.2.3