diff options
Diffstat (limited to 'app')
26 files changed, 165 insertions, 270 deletions
diff --git a/app/src/main/java/github/daneren2005/dsub/adapter/SectionAdapter.java b/app/src/main/java/github/daneren2005/dsub/adapter/SectionAdapter.java index f57012b5..6f5def3e 100644 --- a/app/src/main/java/github/daneren2005/dsub/adapter/SectionAdapter.java +++ b/app/src/main/java/github/daneren2005/dsub/adapter/SectionAdapter.java @@ -16,8 +16,12 @@ package github.daneren2005.dsub.adapter; import android.content.Context; +import android.support.v7.widget.PopupMenu; import android.support.v7.widget.RecyclerView; import android.util.Log; +import android.view.Menu; +import android.view.MenuInflater; +import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; @@ -39,8 +43,6 @@ public abstract class SectionAdapter<T> extends RecyclerView.Adapter<UpdateViewH protected List<List<T>> sections; protected boolean singleSectionHeader; protected OnItemClickedListener<T> onItemClickedListener; - protected UpdateView contextView; - protected T contextItem; private List<T> selected = new ArrayList<>(); protected SectionAdapter() {} @@ -100,9 +102,19 @@ public abstract class SectionAdapter<T> extends RecyclerView.Adapter<UpdateViewH moreButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - T item = holder.getItem(); - setContextItem(updateView, item); - v.showContextMenu(); + final T item = holder.getItem(); + if(onItemClickedListener != null) { + PopupMenu popup = new PopupMenu(context, v); + onItemClickedListener.onCreateContextMenu(popup.getMenu(), popup.getMenuInflater(), updateView, item); + + popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { + @Override + public boolean onMenuItemClick(MenuItem menuItem) { + return onItemClickedListener.onContextItemSelected(menuItem, updateView, item); + } + }); + popup.show(); + } } }); @@ -261,17 +273,6 @@ public abstract class SectionAdapter<T> extends RecyclerView.Adapter<UpdateViewH return -1; } - public void setContextItem(UpdateView updateView, T item) { - contextView = updateView; - contextItem = item; - } - public UpdateView getContextView() { - return contextView; - } - public T getContextItem() { - return contextItem; - } - public void setOnItemClickedListener(OnItemClickedListener<T> onItemClickedListener) { this.onItemClickedListener = onItemClickedListener; } @@ -324,5 +325,7 @@ public abstract class SectionAdapter<T> extends RecyclerView.Adapter<UpdateViewH public interface OnItemClickedListener<T> { void onItemClicked(T item); + void onCreateContextMenu(Menu menu, MenuInflater menuInflater, UpdateView<T> updateView, T item); + boolean onContextItemSelected(MenuItem menuItem, UpdateView<T> updateView, T item); } } diff --git a/app/src/main/java/github/daneren2005/dsub/fragments/AdminFragment.java b/app/src/main/java/github/daneren2005/dsub/fragments/AdminFragment.java index f3f9eb64..69164036 100644 --- a/app/src/main/java/github/daneren2005/dsub/fragments/AdminFragment.java +++ b/app/src/main/java/github/daneren2005/dsub/fragments/AdminFragment.java @@ -17,6 +17,7 @@ package github.daneren2005.dsub.fragments; import android.os.Bundle; import android.view.ContextMenu; +import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; @@ -37,6 +38,7 @@ import github.daneren2005.dsub.util.ProgressListener; import github.daneren2005.dsub.util.UserUtil; import github.daneren2005.dsub.util.Util; import github.daneren2005.dsub.adapter.UserAdapter; +import github.daneren2005.dsub.view.UpdateView; public class AdminFragment extends SelectRecyclerFragment<User> { private static String TAG = AdminFragment.class.getSimpleName(); @@ -57,21 +59,16 @@ public class AdminFragment extends SelectRecyclerFragment<User> { } @Override - public void onCreateContextMenu(ContextMenu menu, View view, ContextMenu.ContextMenuInfo menuInfo) { - super.onCreateContextMenu(menu, view, menuInfo); - - MenuInflater inflater = context.getMenuInflater(); + public void onCreateContextMenu(Menu menu, MenuInflater menuInflater, UpdateView<User> updateView, User item) { if(UserUtil.isCurrentAdmin()) { - inflater.inflate(R.menu.admin_context, menu); + menuInflater.inflate(R.menu.admin_context, menu); } else if(UserUtil.isCurrentRole(User.SETTINGS)) { - inflater.inflate(R.menu.admin_context_user, menu); + menuInflater.inflate(R.menu.admin_context_user, menu); } } @Override - public boolean onContextItemSelected(MenuItem menuItem) { - User user = adapter.getContextItem(); - + public boolean onContextItemSelected(MenuItem menuItem, UpdateView<User> updateView, User user) { switch(menuItem.getItemId()) { case R.id.admin_change_email: UserUtil.changeEmail(context, user); diff --git a/app/src/main/java/github/daneren2005/dsub/fragments/MainFragment.java b/app/src/main/java/github/daneren2005/dsub/fragments/MainFragment.java index 96e1d326..0e67b80d 100644 --- a/app/src/main/java/github/daneren2005/dsub/fragments/MainFragment.java +++ b/app/src/main/java/github/daneren2005/dsub/fragments/MainFragment.java @@ -31,6 +31,8 @@ import github.daneren2005.dsub.service.MusicService; import github.daneren2005.dsub.service.MusicServiceFactory; import github.daneren2005.dsub.util.SilentBackgroundTask; import github.daneren2005.dsub.view.ChangeLog; +import github.daneren2005.dsub.view.UpdateView; + import java.io.File; import java.util.ArrayList; import java.util.Arrays; @@ -401,4 +403,12 @@ public class MainFragment extends SelectRecyclerFragment<Integer> { showVideos(); } } + + @Override + public void onCreateContextMenu(Menu menu, MenuInflater menuInflater, UpdateView<Integer> updateView, Integer item) {} + + @Override + public boolean onContextItemSelected(MenuItem menuItem, UpdateView<Integer> updateView, Integer item) { + return false; + } } diff --git a/app/src/main/java/github/daneren2005/dsub/fragments/NowPlayingFragment.java b/app/src/main/java/github/daneren2005/dsub/fragments/NowPlayingFragment.java index 0f9d9f68..1b652f57 100644 --- a/app/src/main/java/github/daneren2005/dsub/fragments/NowPlayingFragment.java +++ b/app/src/main/java/github/daneren2005/dsub/fragments/NowPlayingFragment.java @@ -541,7 +541,6 @@ public class NowPlayingFragment extends SubsonicFragment implements OnGestureLis } } }); - registerForContextMenu(playlistView); if(Build.MODEL.equals("Nexus 4") || Build.MODEL.equals("GT-I9100")) { View slider = rootView.findViewById(R.id.download_slider); @@ -602,42 +601,25 @@ public class NowPlayingFragment extends SubsonicFragment implements OnGestureLis } @Override - public void onCreateContextMenu(android.view.ContextMenu menu, View view, ContextMenu.ContextMenuInfo menuInfo) { - super.onCreateContextMenu(menu, view, menuInfo); - if(!primaryFragment) { - return; + public void onCreateContextMenu(Menu menu, MenuInflater menuInflater, UpdateView<DownloadFile> updateView, DownloadFile downloadFile) { + if(Util.isOffline(context)) { + menuInflater.inflate(R.menu.nowplaying_context_offline, menu); + } else { + menuInflater.inflate(R.menu.nowplaying_context, menu); + menu.findItem(R.id.menu_star).setTitle(downloadFile.getSong().isStarred() ? R.string.common_unstar : R.string.common_star); } - UpdateView targetView = songListAdapter.getContextView(); - menuInfo = new AdapterView.AdapterContextMenuInfo(targetView, 0, 0); - - if (view == playlistView) { - DownloadFile downloadFile = songListAdapter.getContextItem(); - - android.view.MenuInflater inflater = context.getMenuInflater(); - if(Util.isOffline(context)) { - inflater.inflate(R.menu.nowplaying_context_offline, menu); - } else { - inflater.inflate(R.menu.nowplaying_context, menu); - menu.findItem(R.id.menu_star).setTitle(downloadFile.getSong().isStarred() ? R.string.common_unstar : R.string.common_star); - } - if (downloadFile.getSong().getParent() == null) { - menu.findItem(R.id.menu_show_album).setVisible(false); - menu.findItem(R.id.menu_show_artist).setVisible(false); - } - - hideMenuItems(menu, (AdapterView.AdapterContextMenuInfo) menuInfo); + if (downloadFile.getSong().getParent() == null) { + menu.findItem(R.id.menu_show_album).setVisible(false); + menu.findItem(R.id.menu_show_artist).setVisible(false); } + + hideMenuItems(menu, updateView); } @Override - public boolean onContextItemSelected(android.view.MenuItem menuItem) { - if(!primaryFragment) { - return false; - } - - DownloadFile downloadFile = songListAdapter.getContextItem(); - return menuItemSelected(menuItem.getItemId(), downloadFile) || super.onContextItemSelected(menuItem); + public boolean onContextItemSelected(MenuItem menuItem, UpdateView<DownloadFile> updateView, DownloadFile downloadFile) { + return menuItemSelected(menuItem.getItemId(), downloadFile); } private boolean menuItemSelected(int menuItemId, final DownloadFile song) { @@ -705,20 +687,7 @@ public class NowPlayingFragment extends SubsonicFragment implements OnGestureLis replaceFragment(fragment); return true; - } case R.id.menu_remove: - new SilentBackgroundTask<Void>(context) { - @Override - protected Void doInBackground() throws Throwable { - getDownloadService().remove(song); - return null; - } - - @Override - protected void done(Void result) { - onDownloadListChanged(); - } - }.execute(); - return true; + } case R.id.menu_delete: List<Entry> songs = new ArrayList<Entry>(1); songs.add(song.getSong()); diff --git a/app/src/main/java/github/daneren2005/dsub/fragments/SearchFragment.java b/app/src/main/java/github/daneren2005/dsub/fragments/SearchFragment.java index 20a87e7d..96b32d8d 100644 --- a/app/src/main/java/github/daneren2005/dsub/fragments/SearchFragment.java +++ b/app/src/main/java/github/daneren2005/dsub/fragments/SearchFragment.java @@ -123,32 +123,17 @@ public class SearchFragment extends SubsonicFragment implements SectionAdapter.O } @Override - public void onCreateContextMenu(ContextMenu menu, View view, ContextMenu.ContextMenuInfo menuInfo) { - super.onCreateContextMenu(menu, view, menuInfo); - UpdateView targetView = adapter.getContextView(); - menuInfo = new AdapterView.AdapterContextMenuInfo(targetView, 0, 0); - - Serializable item = adapter.getContextItem(); - onCreateContextMenu(menu, view, menuInfo, item); + public void onCreateContextMenu(Menu menu, MenuInflater menuInflater, UpdateView<Serializable> updateView, Serializable item) { + onCreateContextMenuSupport(menu, menuInflater, updateView, item); if(item instanceof MusicDirectory.Entry && !((MusicDirectory.Entry) item).isVideo() && !Util.isOffline(context)) { menu.removeItem(R.id.song_menu_remove_playlist); } - recreateContextMenu(menu); } @Override - public boolean onContextItemSelected(MenuItem menuItem) { - if(menuItem.getGroupId() != getSupportTag()) { - return false; - } - - Serializable item = adapter.getContextItem(); - if(onContextItemSelected(menuItem, item)) { - return true; - } - - return true; + public boolean onContextItemSelected(MenuItem menuItem, UpdateView<Serializable> updateView, Serializable item) { + return onContextItemSelected(menuItem, item); } @Override diff --git a/app/src/main/java/github/daneren2005/dsub/fragments/SelectArtistFragment.java b/app/src/main/java/github/daneren2005/dsub/fragments/SelectArtistFragment.java index 8a2b7153..a9d5afd6 100644 --- a/app/src/main/java/github/daneren2005/dsub/fragments/SelectArtistFragment.java +++ b/app/src/main/java/github/daneren2005/dsub/fragments/SelectArtistFragment.java @@ -79,27 +79,14 @@ public class SelectArtistFragment extends SelectRecyclerFragment<Artist> impleme } @Override - public void onCreateContextMenu(ContextMenu menu, View view, ContextMenu.ContextMenuInfo menuInfo) { - super.onCreateContextMenu(menu, view, menuInfo); - UpdateView targetView = adapter.getContextView(); - menuInfo = new AdapterView.AdapterContextMenuInfo(targetView, 0, 0); - - Artist artist = adapter.getContextItem(); - - onCreateContextMenu(menu, view, menuInfo, artist); + public void onCreateContextMenu(Menu menu, MenuInflater menuInflater, UpdateView<Artist> updateView, Artist item) { + onCreateContextMenuSupport(menu, menuInflater, updateView, item); recreateContextMenu(menu); } @Override - public boolean onContextItemSelected(MenuItem menuItem) { - if(menuItem.getGroupId() != getSupportTag()) { - return false; - } - - AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuItem.getMenuInfo(); - Artist artist = adapter.getContextItem(); - - return onContextItemSelected(menuItem, artist); + public boolean onContextItemSelected(MenuItem menuItem, UpdateView<Artist> updateView, Artist item) { + return onContextItemSelected(menuItem, item); } @Override diff --git a/app/src/main/java/github/daneren2005/dsub/fragments/SelectBookmarkFragment.java b/app/src/main/java/github/daneren2005/dsub/fragments/SelectBookmarkFragment.java index a774a287..e326e3e2 100644 --- a/app/src/main/java/github/daneren2005/dsub/fragments/SelectBookmarkFragment.java +++ b/app/src/main/java/github/daneren2005/dsub/fragments/SelectBookmarkFragment.java @@ -19,6 +19,7 @@ package github.daneren2005.dsub.fragments; import android.view.ContextMenu; +import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; @@ -43,21 +44,13 @@ public class SelectBookmarkFragment extends SelectRecyclerFragment<MusicDirector private static final String TAG = SelectBookmarkFragment.class.getSimpleName(); @Override - public void onCreateContextMenu(ContextMenu menu, View view, ContextMenu.ContextMenuInfo menuInfo) { - super.onCreateContextMenu(menu, view, menuInfo); - UpdateView targetView = adapter.getContextView(); - menuInfo = new AdapterView.AdapterContextMenuInfo(targetView, 0, 0); - - MenuInflater inflater = context.getMenuInflater(); - inflater.inflate(R.menu.select_bookmark_context, menu); - - hideMenuItems(menu, (AdapterView.AdapterContextMenuInfo) menuInfo); + public void onCreateContextMenu(Menu menu, MenuInflater menuInflater, UpdateView<MusicDirectory.Entry> updateView, MusicDirectory.Entry item) { + menuInflater.inflate(R.menu.select_bookmark_context, menu); + hideMenuItems(menu, updateView); } @Override - public boolean onContextItemSelected(MenuItem menuItem) { - MusicDirectory.Entry bookmark = adapter.getContextItem(); - + public boolean onContextItemSelected(MenuItem menuItem, UpdateView<MusicDirectory.Entry> updateView, MusicDirectory.Entry bookmark) { switch(menuItem.getItemId()) { case R.id.bookmark_menu_info: displayBookmarkInfo(bookmark); @@ -66,12 +59,8 @@ public class SelectBookmarkFragment extends SelectRecyclerFragment<MusicDirector deleteBookmark(bookmark, adapter); return true; } - - if(onContextItemSelected(menuItem, bookmark)) { - return true; - } - return true; + return onContextItemSelected(menuItem, bookmark); } @Override @@ -115,7 +104,7 @@ public class SelectBookmarkFragment extends SelectRecyclerFragment<MusicDirector } }.execute(); } - + private void displayBookmarkInfo(final MusicDirectory.Entry entry) { Bookmark bookmark = entry.getBookmark(); String comment = bookmark.getComment(); diff --git a/app/src/main/java/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java b/app/src/main/java/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java index 08a051cf..9f66a27e 100644 --- a/app/src/main/java/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java +++ b/app/src/main/java/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java @@ -197,8 +197,6 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Section recyclerView.setLayoutManager(layoutManager); } - registerForContextMenu(recyclerView); - if(entries == null) { if(primaryFragment || secondaryFragment) { load(false); @@ -336,18 +334,8 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Section } @Override - public void onCreateContextMenu(ContextMenu menu, View view, ContextMenu.ContextMenuInfo menuInfo) { - super.onCreateContextMenu(menu, view, menuInfo); - Entry entry = entryGridAdapter.getContextItem(); - UpdateView targetView = entryGridAdapter.getContextView(); - menuInfo = new AdapterView.AdapterContextMenuInfo(targetView, 0, 0); - - // Don't try to display a context menu if error here - if(entry == null) { - return; - } - - onCreateContextMenu(menu, view, menuInfo, entry); + public void onCreateContextMenu(Menu menu, MenuInflater menuInflater, UpdateView updateView, Entry entry) { + onCreateContextMenuSupport(menu, menuInflater, updateView, entry); if(!entry.isVideo() && !Util.isOffline(context) && (playlistId == null || !playlistOwner) && (podcastId == null || Util.isOffline(context) && podcastId != null)) { menu.removeItem(R.id.song_menu_remove_playlist); } @@ -369,14 +357,8 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Section recreateContextMenu(menu); } - @Override - public boolean onContextItemSelected(MenuItem menuItem) { - if(menuItem.getGroupId() != getSupportTag()) { - return false; - } - Entry entry = entryGridAdapter.getContextItem(); - + public boolean onContextItemSelected(MenuItem menuItem, UpdateView<Entry> updateView, Entry entry) { if(Util.getPreferences(context).getBoolean(Constants.PREFERENCES_KEY_PLAY_NOW_AFTER, false) && menuItem.getItemId() == R.id.song_menu_play_now) { List<Entry> songs = new ArrayList<Entry>(); songs.add(entry); @@ -388,7 +370,7 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Section playNow(songs); return true; } - + if(onContextItemSelected(menuItem, entry)) { return true; } @@ -404,7 +386,7 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Section deletePodcastEpisode((PodcastEpisode) entry); break; } - + return true; } diff --git a/app/src/main/java/github/daneren2005/dsub/fragments/SelectGenreFragment.java b/app/src/main/java/github/daneren2005/dsub/fragments/SelectGenreFragment.java index fe012f62..cb57c280 100644 --- a/app/src/main/java/github/daneren2005/dsub/fragments/SelectGenreFragment.java +++ b/app/src/main/java/github/daneren2005/dsub/fragments/SelectGenreFragment.java @@ -16,6 +16,9 @@ package github.daneren2005.dsub.fragments; import android.os.Bundle; +import android.view.Menu; +import android.view.MenuInflater; +import android.view.MenuItem; import android.view.View; import android.widget.AdapterView; import android.widget.ArrayAdapter; @@ -26,6 +29,7 @@ import github.daneren2005.dsub.service.MusicService; import github.daneren2005.dsub.util.Constants; import github.daneren2005.dsub.util.ProgressListener; import github.daneren2005.dsub.adapter.GenreAdapter; +import github.daneren2005.dsub.view.UpdateView; import java.util.List; @@ -64,4 +68,12 @@ public class SelectGenreFragment extends SelectRecyclerFragment<Genre> { replaceFragment(fragment); } + + @Override + public void onCreateContextMenu(Menu menu, MenuInflater menuInflater, UpdateView<Genre> updateView, Genre item) {} + + @Override + public boolean onContextItemSelected(MenuItem menuItem, UpdateView<Genre> updateView, Genre item) { + return false; + } } diff --git a/app/src/main/java/github/daneren2005/dsub/fragments/SelectPlaylistFragment.java b/app/src/main/java/github/daneren2005/dsub/fragments/SelectPlaylistFragment.java index 49589971..7a4c708e 100644 --- a/app/src/main/java/github/daneren2005/dsub/fragments/SelectPlaylistFragment.java +++ b/app/src/main/java/github/daneren2005/dsub/fragments/SelectPlaylistFragment.java @@ -7,6 +7,7 @@ import android.os.Bundle; import android.support.v4.app.FragmentTransaction; import android.support.v7.widget.RecyclerView; import android.view.ContextMenu; +import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; @@ -31,6 +32,7 @@ import github.daneren2005.dsub.util.LoadingTask; import github.daneren2005.dsub.util.UserUtil; import github.daneren2005.dsub.util.Util; import github.daneren2005.dsub.adapter.PlaylistAdapter; +import github.daneren2005.dsub.view.UpdateView; import java.util.ArrayList; import java.util.Arrays; @@ -40,23 +42,19 @@ public class SelectPlaylistFragment extends SelectRecyclerFragment<Playlist> { private static final String TAG = SelectPlaylistFragment.class.getSimpleName(); @Override - public void onCreateContextMenu(ContextMenu menu, View view, ContextMenu.ContextMenuInfo menuInfo) { - super.onCreateContextMenu(menu, view, menuInfo); - - MenuInflater inflater = context.getMenuInflater(); + public void onCreateContextMenu(Menu menu, MenuInflater menuInflater, UpdateView<Playlist> updateView, Playlist playlist) { if (Util.isOffline(context)) { - inflater.inflate(R.menu.select_playlist_context_offline, menu); + menuInflater.inflate(R.menu.select_playlist_context_offline, menu); } else { - inflater.inflate(R.menu.select_playlist_context, menu); + menuInflater.inflate(R.menu.select_playlist_context, menu); - Playlist playlist = adapter.getContextItem(); if(SyncUtil.isSyncedPlaylist(context, playlist.getId())) { menu.removeItem(R.id.playlist_menu_sync); } else { menu.removeItem(R.id.playlist_menu_stop_sync); } - + if(!ServerInfo.checkServerVersion(context, "1.8")) { menu.removeItem(R.id.playlist_update_info); } else if(playlist.getPublic() != null && playlist.getPublic() == true && playlist.getId().indexOf(".m3u") == -1 && !UserUtil.getCurrentUsername(context).equals(playlist.getOwner())) { @@ -69,13 +67,7 @@ public class SelectPlaylistFragment extends SelectRecyclerFragment<Playlist> { } @Override - public boolean onContextItemSelected(MenuItem menuItem) { - if(menuItem.getGroupId() != getSupportTag()) { - return false; - } - - Playlist playlist = adapter.getContextItem(); - + public boolean onContextItemSelected(MenuItem menuItem, UpdateView<Playlist> updateView, Playlist playlist) { SubsonicFragment fragment; Bundle args; FragmentTransaction trans; @@ -119,10 +111,9 @@ public class SelectPlaylistFragment extends SelectRecyclerFragment<Playlist> { case R.id.playlist_update_info: updatePlaylistInfo(playlist); break; - default: - return false; } - return true; + + return false; } @Override diff --git a/app/src/main/java/github/daneren2005/dsub/fragments/SelectPodcastsFragment.java b/app/src/main/java/github/daneren2005/dsub/fragments/SelectPodcastsFragment.java index 520d0414..f8afce6e 100644 --- a/app/src/main/java/github/daneren2005/dsub/fragments/SelectPodcastsFragment.java +++ b/app/src/main/java/github/daneren2005/dsub/fragments/SelectPodcastsFragment.java @@ -18,6 +18,8 @@ import android.support.v7.app.AlertDialog; import android.content.DialogInterface; import android.os.Bundle; import android.view.ContextMenu; +import android.view.Menu; +import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; import android.widget.TextView; @@ -37,6 +39,7 @@ import github.daneren2005.dsub.util.SilentBackgroundTask; import github.daneren2005.dsub.util.UserUtil; import github.daneren2005.dsub.util.Util; import github.daneren2005.dsub.adapter.PodcastChannelAdapter; +import github.daneren2005.dsub.view.UpdateView; import java.util.ArrayList; import java.util.List; @@ -61,35 +64,26 @@ public class SelectPodcastsFragment extends SelectRecyclerFragment<PodcastChanne return false; } - - @Override - public void onCreateContextMenu(ContextMenu menu, View view, ContextMenu.ContextMenuInfo menuInfo) { - super.onCreateContextMenu(menu, view, menuInfo); - android.view.MenuInflater inflater = context.getMenuInflater(); + @Override + public void onCreateContextMenu(Menu menu, MenuInflater menuInflater, UpdateView<PodcastChannel> updateView, PodcastChannel podcast) { if(!Util.isOffline(context) && UserUtil.canPodcast()) { - inflater.inflate(R.menu.select_podcasts_context, menu); + menuInflater.inflate(R.menu.select_podcasts_context, menu); - PodcastChannel podcast = adapter.getContextItem(); if(SyncUtil.isSyncedPodcast(context, podcast.getId())) { menu.removeItem(R.id.podcast_menu_sync); } else { menu.removeItem(R.id.podcast_menu_stop_sync); } } else { - inflater.inflate(R.menu.select_podcasts_context_offline, menu); + menuInflater.inflate(R.menu.select_podcasts_context_offline, menu); } recreateContextMenu(menu); } @Override - public boolean onContextItemSelected(MenuItem menuItem) { - if(menuItem.getGroupId() != getSupportTag()) { - return false; - } - - PodcastChannel channel = adapter.getContextItem(); + public boolean onContextItemSelected(MenuItem menuItem, UpdateView<PodcastChannel> updateView, PodcastChannel channel) { switch (menuItem.getItemId()) { case R.id.podcast_menu_sync: syncPodcast(channel); @@ -104,7 +98,7 @@ public class SelectPodcastsFragment extends SelectRecyclerFragment<PodcastChanne deletePodcast(channel); break; } - + return true; } @@ -145,7 +139,7 @@ public class SelectPodcastsFragment extends SelectRecyclerFragment<PodcastChanne replaceFragment(fragment); } } - + public void refreshPodcasts() { new SilentBackgroundTask<Void>(context) { @Override diff --git a/app/src/main/java/github/daneren2005/dsub/fragments/SelectRecyclerFragment.java b/app/src/main/java/github/daneren2005/dsub/fragments/SelectRecyclerFragment.java index 526a4312..0c3b27f8 100644 --- a/app/src/main/java/github/daneren2005/dsub/fragments/SelectRecyclerFragment.java +++ b/app/src/main/java/github/daneren2005/dsub/fragments/SelectRecyclerFragment.java @@ -89,7 +89,6 @@ public abstract class SelectRecyclerFragment<T> extends SubsonicFragment impleme } else { recyclerView.setAdapter(adapter = getAdapter(objects)); } - registerForContextMenu(recyclerView); return rootView; } diff --git a/app/src/main/java/github/daneren2005/dsub/fragments/SelectShareFragment.java b/app/src/main/java/github/daneren2005/dsub/fragments/SelectShareFragment.java index 3d79b7b9..65723618 100644 --- a/app/src/main/java/github/daneren2005/dsub/fragments/SelectShareFragment.java +++ b/app/src/main/java/github/daneren2005/dsub/fragments/SelectShareFragment.java @@ -19,6 +19,8 @@ import android.support.v7.app.AlertDialog; import android.content.DialogInterface; import android.os.Bundle; import android.view.ContextMenu; +import android.view.Menu; +import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; import android.widget.CheckBox; @@ -41,25 +43,19 @@ import github.daneren2005.dsub.util.LoadingTask; import github.daneren2005.dsub.util.ProgressListener; import github.daneren2005.dsub.util.Util; import github.daneren2005.dsub.adapter.ShareAdapter; +import github.daneren2005.dsub.view.UpdateView; public class SelectShareFragment extends SelectRecyclerFragment<Share> { private static final String TAG = SelectShareFragment.class.getSimpleName(); @Override - public void onCreateContextMenu(ContextMenu menu, View view, ContextMenu.ContextMenuInfo menuInfo) { - super.onCreateContextMenu(menu, view, menuInfo); - android.view.MenuInflater inflater = context.getMenuInflater(); - inflater.inflate(R.menu.select_share_context, menu); + public void onCreateContextMenu(Menu menu, MenuInflater menuInflater, UpdateView<Share> updateView, Share item) { + menuInflater.inflate(R.menu.select_share_context, menu); recreateContextMenu(menu); } @Override - public boolean onContextItemSelected(MenuItem menuItem) { - if(menuItem.getGroupId() != getSupportTag()) { - return false; - } - - Share share = adapter.getContextItem(); + public boolean onContextItemSelected(MenuItem menuItem, UpdateView<Share> updateView, Share share) { switch (menuItem.getItemId()) { case R.id.share_menu_share: shareExternal(share); diff --git a/app/src/main/java/github/daneren2005/dsub/fragments/SelectVideoFragment.java b/app/src/main/java/github/daneren2005/dsub/fragments/SelectVideoFragment.java index bf25db77..0a79b3d5 100644 --- a/app/src/main/java/github/daneren2005/dsub/fragments/SelectVideoFragment.java +++ b/app/src/main/java/github/daneren2005/dsub/fragments/SelectVideoFragment.java @@ -16,6 +16,8 @@ package github.daneren2005.dsub.fragments; import android.view.ContextMenu; +import android.view.Menu; +import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; import android.widget.AdapterView; @@ -60,23 +62,13 @@ public class SelectVideoFragment extends SelectRecyclerFragment<MusicDirectory.E } @Override - public void onCreateContextMenu(ContextMenu menu, View view, ContextMenu.ContextMenuInfo menuInfo) { - super.onCreateContextMenu(menu, view, menuInfo); - UpdateView targetView = adapter.getContextView(); - menuInfo = new AdapterView.AdapterContextMenuInfo(targetView, 0, 0); - - MusicDirectory.Entry entry = adapter.getContextItem(); - onCreateContextMenu(menu, view, menuInfo, entry); + public void onCreateContextMenu(Menu menu, MenuInflater menuInflater, UpdateView<MusicDirectory.Entry> updateView, MusicDirectory.Entry item) { + onCreateContextMenuSupport(menu, menuInflater, updateView, item); recreateContextMenu(menu); } @Override - public boolean onContextItemSelected(MenuItem menuItem) { - if (menuItem.getGroupId() != getSupportTag()) { - return false; - } - - MusicDirectory.Entry entry = adapter.getContextItem(); + public boolean onContextItemSelected(MenuItem menuItem, UpdateView<MusicDirectory.Entry> updateView, MusicDirectory.Entry entry) { return onContextItemSelected(menuItem, entry); } } diff --git a/app/src/main/java/github/daneren2005/dsub/fragments/SelectYearFragment.java b/app/src/main/java/github/daneren2005/dsub/fragments/SelectYearFragment.java index a89bc280..4e1e51e5 100644 --- a/app/src/main/java/github/daneren2005/dsub/fragments/SelectYearFragment.java +++ b/app/src/main/java/github/daneren2005/dsub/fragments/SelectYearFragment.java @@ -16,6 +16,9 @@ package github.daneren2005.dsub.fragments; import android.os.Bundle; +import android.view.Menu; +import android.view.MenuInflater; +import android.view.MenuItem; import android.view.View; import android.widget.AdapterView; import android.widget.ArrayAdapter; @@ -29,6 +32,7 @@ import github.daneren2005.dsub.adapter.SectionAdapter; import github.daneren2005.dsub.service.MusicService; import github.daneren2005.dsub.util.Constants; import github.daneren2005.dsub.util.ProgressListener; +import github.daneren2005.dsub.view.UpdateView; public class SelectYearFragment extends SelectRecyclerFragment<String> { @@ -69,4 +73,12 @@ public class SelectYearFragment extends SelectRecyclerFragment<String> { replaceFragment(fragment); } + + @Override + public void onCreateContextMenu(Menu menu, MenuInflater menuInflater, UpdateView<String> updateView, String item) {} + + @Override + public boolean onContextItemSelected(MenuItem menuItem, UpdateView<String> updateView, String item) { + return false; + } } diff --git a/app/src/main/java/github/daneren2005/dsub/fragments/SimilarArtistFragment.java b/app/src/main/java/github/daneren2005/dsub/fragments/SimilarArtistFragment.java index 088b6d00..5677e445 100644 --- a/app/src/main/java/github/daneren2005/dsub/fragments/SimilarArtistFragment.java +++ b/app/src/main/java/github/daneren2005/dsub/fragments/SimilarArtistFragment.java @@ -16,12 +16,9 @@ package github.daneren2005.dsub.fragments; import android.os.Bundle; -import android.view.ContextMenu; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; -import android.view.View; -import android.widget.AdapterView; import github.daneren2005.dsub.R; import github.daneren2005.dsub.adapter.ArtistAdapter; @@ -84,24 +81,13 @@ public class SimilarArtistFragment extends SelectRecyclerFragment<Artist> { } @Override - public void onCreateContextMenu(ContextMenu menu, View view, ContextMenu.ContextMenuInfo menuInfo) { - super.onCreateContextMenu(menu, view, menuInfo); - UpdateView targetView = adapter.getContextView(); - menuInfo = new AdapterView.AdapterContextMenuInfo(targetView, 0, 0); - - Artist artist = adapter.getContextItem(); - onCreateContextMenu(menu, view, menuInfo, artist); - + public void onCreateContextMenu(Menu menu, MenuInflater menuInflater, UpdateView<Artist> updateView, Artist item) { + onCreateContextMenuSupport(menu, menuInflater, updateView, item); recreateContextMenu(menu); } @Override - public boolean onContextItemSelected(MenuItem menuItem) { - if(menuItem.getGroupId() != getSupportTag()) { - return false; - } - - Artist artist = adapter.getContextItem(); + public boolean onContextItemSelected(MenuItem menuItem, UpdateView<Artist> updateView, Artist artist) { return onContextItemSelected(menuItem, artist); } diff --git a/app/src/main/java/github/daneren2005/dsub/fragments/SubsonicFragment.java b/app/src/main/java/github/daneren2005/dsub/fragments/SubsonicFragment.java index a155e807..c5c5a132 100644 --- a/app/src/main/java/github/daneren2005/dsub/fragments/SubsonicFragment.java +++ b/app/src/main/java/github/daneren2005/dsub/fragments/SubsonicFragment.java @@ -34,21 +34,17 @@ import android.os.Bundle; import android.os.StatFs; import android.support.v4.app.Fragment; import android.support.v4.widget.SwipeRefreshLayout; -import android.support.v7.internal.view.ContextThemeWrapper; import android.support.v7.widget.GridLayoutManager; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.util.Log; -import android.view.ContextMenu; import android.view.GestureDetector; -import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; import android.widget.AbsListView; -import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.Button; import android.widget.CheckBox; @@ -195,17 +191,15 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR return false; } - public void onCreateContextMenu(ContextMenu menu, View view, ContextMenu.ContextMenuInfo menuInfo, Object selected) { - MenuInflater inflater = context.getMenuInflater(); - + public void onCreateContextMenuSupport(Menu menu, MenuInflater menuInflater, UpdateView updateView, Object 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); + menuInflater.inflate(R.menu.select_podcast_episode_context_offline, menu); } else { - inflater.inflate(R.menu.select_podcast_episode_context, menu); + menuInflater.inflate(R.menu.select_podcast_episode_context, menu); if(entry.getBookmark() == null) { menu.removeItem(R.id.bookmark_menu_delete); @@ -214,10 +208,10 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR } else if (entry.isDirectory()) { if(Util.isOffline(context)) { - inflater.inflate(R.menu.select_album_context_offline, menu); + menuInflater.inflate(R.menu.select_album_context_offline, menu); } else { - inflater.inflate(R.menu.select_album_context, menu); + menuInflater.inflate(R.menu.select_album_context, menu); if(Util.isTagBrowsing(context)) { menu.removeItem(R.id.menu_rate); @@ -226,10 +220,10 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR 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(!entry.isVideo()) { if(Util.isOffline(context)) { - inflater.inflate(R.menu.select_song_context_offline, menu); + menuInflater.inflate(R.menu.select_song_context_offline, menu); } else { - inflater.inflate(R.menu.select_song_context, menu); + menuInflater.inflate(R.menu.select_song_context, menu); if(entry.getBookmark() == null) { menu.removeItem(R.id.bookmark_menu_delete); @@ -238,28 +232,28 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR 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(Util.isOffline(context)) { - inflater.inflate(R.menu.select_video_context_offline, menu); + menuInflater.inflate(R.menu.select_video_context_offline, menu); } else { - inflater.inflate(R.menu.select_video_context, menu); + menuInflater.inflate(R.menu.select_video_context, menu); } } } else if(selected instanceof Artist) { Artist artist = (Artist) selected; if(Util.isOffline(context)) { - inflater.inflate(R.menu.select_artist_context_offline, menu); + menuInflater.inflate(R.menu.select_artist_context_offline, menu); } else { - inflater.inflate(R.menu.select_artist_context, menu); + menuInflater.inflate(R.menu.select_artist_context, menu); menu.findItem(R.id.artist_menu_star).setTitle(artist.isStarred() ? R.string.common_unstar : R.string.common_star); } } - hideMenuItems(menu, (AdapterView.AdapterContextMenuInfo) menuInfo); + hideMenuItems(menu, updateView); } - protected void hideMenuItems(ContextMenu menu, AdapterView.AdapterContextMenuInfo info) { + protected void hideMenuItems(Menu menu, UpdateView updateView) { if(!ServerInfo.checkServerVersion(context, "1.8")) { menu.setGroupVisible(R.id.server_1_8, false); menu.setGroupVisible(R.id.hide_star, false); @@ -290,8 +284,8 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR if(!Util.isOffline(context)) { // If we are looking at a standard song view, get downloadFile to cache what options to show - if(info.targetView instanceof SongView) { - SongView songView = (SongView) info.targetView; + if(updateView instanceof SongView) { + SongView songView = (SongView) updateView; DownloadFile downloadFile = songView.getDownloadFile(); try { @@ -314,17 +308,17 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR } } // Apply similar logic to album views - else if(info.targetView instanceof AlbumView || info.targetView instanceof ArtistView || info.targetView instanceof ArtistEntryView) { + else if(updateView instanceof AlbumView || updateView instanceof ArtistView || updateView instanceof ArtistEntryView) { File folder = null; int id = 0; - if(info.targetView instanceof AlbumView) { - folder = ((AlbumView) info.targetView).getFile(); + if(updateView instanceof AlbumView) { + folder = ((AlbumView) updateView).getFile(); id = R.id.album_menu_delete; - } else if(info.targetView instanceof ArtistView) { - folder = ((ArtistView) info.targetView).getFile(); + } else if(updateView instanceof ArtistView) { + folder = ((ArtistView) updateView).getFile(); id = R.id.artist_menu_delete; - } else if(info.targetView instanceof ArtistEntryView) { - folder = ((ArtistEntryView) info.targetView).getFile(); + } else if(updateView instanceof ArtistEntryView) { + folder = ((ArtistEntryView) updateView).getFile(); id = R.id.artist_menu_delete; } @@ -339,7 +333,7 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR } } - protected void recreateContextMenu(ContextMenu menu) { + protected void recreateContextMenu(Menu menu) { List<MenuItem> menuItems = new ArrayList<MenuItem>(); for(int i = 0; i < menu.size(); i++) { MenuItem item = menu.getItem(i); diff --git a/app/src/main/java/github/daneren2005/dsub/fragments/UserFragment.java b/app/src/main/java/github/daneren2005/dsub/fragments/UserFragment.java index 25196d66..bdd0472b 100644 --- a/app/src/main/java/github/daneren2005/dsub/fragments/UserFragment.java +++ b/app/src/main/java/github/daneren2005/dsub/fragments/UserFragment.java @@ -16,6 +16,8 @@ package github.daneren2005.dsub.fragments; import android.os.Bundle; +import android.view.Menu; +import android.view.MenuInflater; import android.view.MenuItem; import java.util.List; @@ -29,6 +31,7 @@ import github.daneren2005.dsub.util.Constants; import github.daneren2005.dsub.util.ProgressListener; import github.daneren2005.dsub.util.UserUtil; import github.daneren2005.dsub.adapter.SettingsAdapter; +import github.daneren2005.dsub.view.UpdateView; public class UserFragment extends SelectRecyclerFragment<User.Setting>{ private User user; @@ -93,4 +96,12 @@ public class UserFragment extends SelectRecyclerFragment<User.Setting>{ public void onItemClicked(User.Setting item) { } + + @Override + public void onCreateContextMenu(Menu menu, MenuInflater menuInflater, UpdateView<User.Setting> updateView, User.Setting item) {} + + @Override + public boolean onContextItemSelected(MenuItem menuItem, UpdateView<User.Setting> updateView, User.Setting item) { + return false; + } } diff --git a/app/src/main/res/menu/nowplaying_context.xml b/app/src/main/res/menu/nowplaying_context.xml index c9347353..845a98c8 100644 --- a/app/src/main/res/menu/nowplaying_context.xml +++ b/app/src/main/res/menu/nowplaying_context.xml @@ -19,10 +19,6 @@ android:title="@string/download.menu_lyrics"/> <item - android:id="@+id/menu_remove" - android:title="@string/download.menu_remove"/> - - <item android:id="@+id/menu_delete" android:title="@string/menu.delete_cache"/> diff --git a/app/src/main/res/menu/nowplaying_context_offline.xml b/app/src/main/res/menu/nowplaying_context_offline.xml index 24b23a8d..9ce63d79 100644 --- a/app/src/main/res/menu/nowplaying_context_offline.xml +++ b/app/src/main/res/menu/nowplaying_context_offline.xml @@ -15,10 +15,6 @@ android:title="@string/download.menu_show_album"/> <item - android:id="@+id/menu_remove" - android:title="@string/download.menu_remove"/> - - <item android:id="@+id/menu_delete" android:title="@string/menu.delete_cache"/> diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index 97ab596b..e77d0aa7 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -190,8 +190,7 @@ <string name="download.playerstate_playing_shuffle">Playing shuffle</string> <string name="download.menu_show_album">Zeige Album</string> <string name="download.menu_lyrics">Liedtext</string> - <string name="download.menu_remove">Entferne aus Warteschlange</string> - <string name="download.menu_remove_all">Alle entfernen</string> + <string name="download.menu_remove_all">Alle entfernen</string> <string name="download.menu_screen_on">Bildschirm an</string> <string name="download.menu_shuffle">Mischen</string> <string name="download.menu_toggle">Umschalten</string> diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml index cd255e13..b91bc929 100644 --- a/app/src/main/res/values-es/strings.xml +++ b/app/src/main/res/values-es/strings.xml @@ -176,8 +176,7 @@ <string name="download.playerstate_playing_shuffle">Reproduciendo en aleatorio</string> <string name="download.menu_show_album">Mostrar disco</string> <string name="download.menu_lyrics">Letras</string> - <string name="download.menu_remove">Eliminar de la cola</string> - <string name="download.menu_remove_all">Borrar todo</string> + <string name="download.menu_remove_all">Borrar todo</string> <string name="download.menu_screen_on">Pantalla encendida</string> <string name="download.menu_shuffle">Aleatorio</string> <string name="download.menu_toggle">Cambiar</string> diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index 759e3fd8..d547a261 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -175,8 +175,7 @@ <string name="download.playerstate_playing_shuffle">Lecture au hasard</string> <string name="download.menu_show_album">Afficher l\'album</string> <string name="download.menu_lyrics">Paroles</string> - <string name="download.menu_remove">Enlever de la queue</string> - <string name="download.menu_remove_all">Enlever tout</string> + <string name="download.menu_remove_all">Enlever tout</string> <string name="download.menu_screen_on">Ecran actif</string> <string name="download.menu_shuffle">Hasard</string> <string name="download.menu_toggle">Basculer</string> diff --git a/app/src/main/res/values-hu/strings.xml b/app/src/main/res/values-hu/strings.xml index 6222989a..6a28c051 100644 --- a/app/src/main/res/values-hu/strings.xml +++ b/app/src/main/res/values-hu/strings.xml @@ -186,8 +186,7 @@ <string name="download.playerstate_playing_shuffle">Sorrend keverése</string> <string name="download.menu_show_album">Ugrás az albumhoz</string> <string name="download.menu_lyrics">Dalszöveg</string> - <string name="download.menu_remove">Eltávolítás a várólistáról</string> - <string name="download.menu_remove_all">Összes eltávolítása</string> + <string name="download.menu_remove_all">Összes eltávolítása</string> <string name="download.menu_screen_on">Kijelző be</string> <string name="download.menu_shuffle">Sorrend keverése</string> <string name="download.menu_toggle">Váltás</string> diff --git a/app/src/main/res/values-ru/strings.xml b/app/src/main/res/values-ru/strings.xml index cfae3ea0..a3bb71be 100644 --- a/app/src/main/res/values-ru/strings.xml +++ b/app/src/main/res/values-ru/strings.xml @@ -108,7 +108,6 @@ <string name="download.playerstate_playing_shuffle">Воспроизводится случайно</string> <string name="download.menu_show_album">Показать альбом</string> <string name="download.menu_lyrics">Текст</string> - <string name="download.menu_remove">Убрать из очереди</string> <string name="download.menu_remove_all">Очистить</string> <string name="download.menu_screen_on">Включить подсветку</string> <string name="download.menu_shuffle">Перемешать</string> diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index bb0a997b..877b510f 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -190,8 +190,7 @@ <string name="download.playerstate_playing_shuffle">Playing shuffle</string> <string name="download.menu_show_album">Show Album</string> <string name="download.menu_lyrics">Lyrics</string> - <string name="download.menu_remove">Remove from queue</string> - <string name="download.menu_remove_all">Remove all</string> + <string name="download.menu_remove_all">Remove all</string> <string name="download.menu_screen_on">Screen on</string> <string name="download.menu_shuffle">Shuffle</string> <string name="download.menu_toggle">Toggle</string> |