From a3057042bde71874de8e4a59f802e6127da6cb40 Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Fri, 3 Oct 2014 15:17:59 -0700 Subject: Conditionally remove delete from album/artist menus as well, only do in online mode --- .../dsub/fragments/SubsonicFragment.java | 62 +++++++++++++++------- 1 file changed, 43 insertions(+), 19 deletions(-) diff --git a/src/github/daneren2005/dsub/fragments/SubsonicFragment.java b/src/github/daneren2005/dsub/fragments/SubsonicFragment.java index 914aa36c..e6443aeb 100644 --- a/src/github/daneren2005/dsub/fragments/SubsonicFragment.java +++ b/src/github/daneren2005/dsub/fragments/SubsonicFragment.java @@ -261,28 +261,52 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR menu.setGroupVisible(R.id.hide_rating, false); } - // 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; - DownloadFile downloadFile = songView.getDownloadFile(); - - try { - if(downloadFile != null) { - if(downloadFile.isWorkDone()) { - // Remove permanent cache menu if already perma cached - if(downloadFile.isSaved()) { - menu.removeItem(R.id.song_menu_pin); + 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; + DownloadFile downloadFile = songView.getDownloadFile(); + + try { + if(downloadFile != null) { + if(downloadFile.isWorkDone()) { + // Remove permanent cache menu if already perma cached + if(downloadFile.isSaved()) { + menu.removeItem(R.id.song_menu_pin); + } + + // Remove cache option no matter what if already downloaded + menu.removeItem(R.id.song_menu_download); + } else { + // Remove delete option if nothing to delete + menu.removeItem(R.id.song_menu_delete); } - - // Remove cache option no matter what if already downloaded - menu.removeItem(R.id.song_menu_download); - } else { - // Remove delete option if nothing to delete - menu.removeItem(R.id.song_menu_delete); } + } catch(Exception e) { + Log.w(TAG, "Failed to lookup downloadFile info", e); + } + } + // Apply similar logic to album views + else if(info.targetView instanceof AlbumCell || info.targetView instanceof AlbumView + || info.targetView instanceof ArtistView || info.targetView instanceof ArtistEntryView) { + File folder; + if(info.targetView instanceof AlbumCell) { + folder = ((AlbumCell) info.targetView).getFile(); + } else if(info.targetView instanceof AlbumView) { + folder = ((AlbumView) info.targetView).getFile(); + } else if(info.targetView instanceof ArtistView) { + folder = ((ArtistView) info.targetView).getFile(); + } else if(info.targetView instanceof ArtistEntryView) { + folder = ((ArtistEntryView) info.targetView).getFile(); + } + + try { + if(!folder.exists()) { + menu.removeItem(R.id.album_menu_delete); + } + } catch(Exception e) { + Log.w(TAG, "Failed to lookup album directory info", e); } - } catch(Exception e) { - Log.w(TAG, "Failed to lookup downloadFile info", e); } } } -- cgit v1.2.3