From da0176422bf9fe48878479038ed6bdfc10972af0 Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Sat, 13 Sep 2014 08:16:55 -0700 Subject: Add static import for Entry --- .../dsub/fragments/SelectDirectoryFragment.java | 84 +++++++++++----------- 1 file changed, 43 insertions(+), 41 deletions(-) diff --git a/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java b/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java index 0d9c2025..1e09f334 100644 --- a/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java +++ b/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java @@ -51,6 +51,8 @@ import java.util.Arrays; import java.util.HashSet; import java.util.Set; +import static github.daneren2005.dsub.domain.MusicDirectory.Entry; + public class SelectDirectoryFragment extends SubsonicFragment implements AdapterView.OnItemClickListener { private static final String TAG = SelectDirectoryFragment.class.getSimpleName(); @@ -60,8 +62,8 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Adapter private Boolean licenseValid; private boolean showHeader = true; private EntryAdapter entryAdapter; - private List albums; - private List entries; + private List albums; + private List entries; private boolean albumContext = false; private boolean addAlbumHeader = false; private LoadTask currentTask; @@ -92,8 +94,8 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Adapter public void onCreate(Bundle bundle) { super.onCreate(bundle); if(bundle != null) { - entries = (List) bundle.getSerializable(Constants.FRAGMENT_LIST); - albums = (List) bundle.getSerializable(Constants.FRAGMENT_LIST2); + entries = (List) bundle.getSerializable(Constants.FRAGMENT_LIST); + albums = (List) bundle.getSerializable(Constants.FRAGMENT_LIST2); restoredInstance = true; } } @@ -132,11 +134,11 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Adapter lookupParent = true; } if(entries == null) { - entries = (List) args.getSerializable(Constants.FRAGMENT_LIST); - albums = (List) args.getSerializable(Constants.FRAGMENT_LIST2); + entries = (List) args.getSerializable(Constants.FRAGMENT_LIST); + albums = (List) args.getSerializable(Constants.FRAGMENT_LIST2); if(albums == null) { - albums = new ArrayList(); + albums = new ArrayList(); } } } @@ -298,15 +300,15 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Adapter AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo; - MusicDirectory.Entry entry; + Entry entry; if(view.getId() == R.id.select_album_entries) { if(info.position == 0) { return; } - entry = (MusicDirectory.Entry) entryList.getItemAtPosition(info.position); + entry = (Entry) entryList.getItemAtPosition(info.position); albumContext = false; } else { - entry = (MusicDirectory.Entry) albumList.getItemAtPosition(info.position); + entry = (Entry) albumList.getItemAtPosition(info.position); albumContext = true; } @@ -352,10 +354,10 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Adapter } if(Util.getPreferences(context).getBoolean(Constants.PREFERENCES_KEY_PLAY_NOW_AFTER, false) && menuItem.getItemId() == R.id.song_menu_play_now) { - List songs = new ArrayList(); + List songs = new ArrayList(); Iterator it = entries.listIterator(info.position - headers); while(it.hasNext()) { - songs.add((MusicDirectory.Entry) it.next()); + songs.add((Entry) it.next()); } playNow(songs); @@ -384,7 +386,7 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Adapter @Override public void onItemClick(AdapterView parent, View view, int position, long id) { if (position >= 0) { - MusicDirectory.Entry entry = (MusicDirectory.Entry) parent.getItemAtPosition(position); + Entry entry = (Entry) parent.getItemAtPosition(position); if (entry.isDirectory()) { SubsonicFragment fragment = new SelectDirectoryFragment(); Bundle args = new Bundle(); @@ -490,15 +492,15 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Adapter } else { root = share.getMusicDirectory(); } - List songs = new ArrayList(); + List songs = new ArrayList(); getSongsRecursively(root, songs); root.replaceChildren(songs); return root; } - private void getSongsRecursively(MusicDirectory parent, List songs) throws Exception { + private void getSongsRecursively(MusicDirectory parent, List songs) throws Exception { songs.addAll(parent.getChildren(false, true)); - for (MusicDirectory.Entry dir : parent.getChildren(true, false)) { + for (Entry dir : parent.getChildren(true, false)) { MusicService musicService = MusicServiceFactory.getMusicService(context); MusicDirectory musicDirectory; @@ -715,7 +717,7 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Adapter albumList.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView parent, View view, int position, long id) { - MusicDirectory.Entry entry = (MusicDirectory.Entry) parent.getItemAtPosition(position); + Entry entry = (Entry) parent.getItemAtPosition(position); SubsonicFragment fragment = new SelectDirectoryFragment(); Bundle args = new Bundle(); args.putString(Constants.INTENT_EXTRA_NAME_ID, entry.getId()); @@ -751,7 +753,7 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Adapter private void playAll(final boolean shuffle, final boolean append) { boolean hasSubFolders = false; for (int i = 0; i < entryList.getCount(); i++) { - MusicDirectory.Entry entry = (MusicDirectory.Entry) entryList.getItemAtPosition(i); + Entry entry = (Entry) entryList.getItemAtPosition(i); if (entry != null && entry.isDirectory()) { hasSubFolders = true; break; @@ -774,7 +776,7 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Adapter boolean someUnselected = false; int count = entryList.getCount(); for (int i = 0; i < count; i++) { - if (!entryList.isItemChecked(i) && entryList.getItemAtPosition(i) instanceof MusicDirectory.Entry) { + if (!entryList.isItemChecked(i) && entryList.getItemAtPosition(i) instanceof Entry) { someUnselected = true; break; } @@ -786,7 +788,7 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Adapter int count = entryList.getCount(); int selectedCount = 0; for (int i = 0; i < count; i++) { - MusicDirectory.Entry entry = (MusicDirectory.Entry) entryList.getItemAtPosition(i); + Entry entry = (Entry) entryList.getItemAtPosition(i); if (entry != null && !entry.isDirectory() && !entry.isVideo()) { entryList.setItemChecked(i, selected); selectedCount++; @@ -801,12 +803,12 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Adapter } } - private List getSelectedSongs() { - List songs = new ArrayList(10); + private List getSelectedSongs() { + List songs = new ArrayList(10); int count = entryList.getCount(); for (int i = 0; i < count; i++) { if (entryList.isItemChecked(i)) { - MusicDirectory.Entry entry = (MusicDirectory.Entry) entryList.getItemAtPosition(i); + Entry entry = (Entry) entryList.getItemAtPosition(i); // Don't try to add directories or 1-starred songs if(!entry.isDirectory() && entry.getRating() != 1) { songs.add(entry); @@ -835,7 +837,7 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Adapter return; } - final List songs = getSelectedSongs(); + final List songs = getSelectedSongs(); warnIfNetworkOrStorageUnavailable(); // Conditions for using play now button @@ -878,14 +880,14 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Adapter checkLicenseAndTrialPeriod(onValid); } private void downloadBackground(final boolean save) { - List songs = getSelectedSongs(); + List songs = getSelectedSongs(); if(songs.isEmpty()) { selectAll(true, false); songs = getSelectedSongs(); } downloadBackground(save, songs); } - private void downloadBackground(final boolean save, final List songs) { + private void downloadBackground(final boolean save, final List songs) { if (getDownloadService() == null) { return; } @@ -908,7 +910,7 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Adapter } private void delete() { - List songs = getSelectedSongs(); + List songs = getSelectedSongs(); if(songs.isEmpty()) { selectAll(true, false); songs = getSelectedSongs(); @@ -1009,7 +1011,7 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Adapter MusicService musicService = MusicServiceFactory.getMusicService(context); musicService.deletePodcastEpisode(episode.getEpisodeId(), episode.getParent(), null, context); if (getDownloadService() != null) { - List episodeList = new ArrayList(1); + List episodeList = new ArrayList(1); episodeList.add(episode); getDownloadService().delete(episodeList); } @@ -1033,24 +1035,24 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Adapter } public void unstarSelected() { - List selected = getSelectedSongs(); + List selected = getSelectedSongs(); if(selected.size() == 0) { selected = entries; } if(selected.size() == 0) { return; } - final List unstar = new ArrayList(); + final List unstar = new ArrayList(); unstar.addAll(selected); new LoadingTask(context, true) { @Override protected Void doInBackground() throws Throwable { MusicService musicService = MusicServiceFactory.getMusicService(context); - List entries = new ArrayList(); - List artists = new ArrayList(); - List albums = new ArrayList(); - for(MusicDirectory.Entry entry: unstar) { + List entries = new ArrayList(); + List artists = new ArrayList(); + List albums = new ArrayList(); + for(Entry entry: unstar) { if(entry.isDirectory()) { if(entry.isAlbum()) { albums.add(entry); @@ -1063,10 +1065,10 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Adapter } musicService.setStarred(entries, artists, albums, false, this, context); - for(MusicDirectory.Entry entry: unstar) { + for(Entry entry: unstar) { new EntryInstanceUpdater(entry) { @Override - public void update(MusicDirectory.Entry found) { + public void update(Entry found) { found.setStarred(false); } }.execute(); @@ -1079,7 +1081,7 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Adapter protected void done(Void result) { Util.toast(context, context.getResources().getString(R.string.starring_content_unstarred, Integer.toString(unstar.size()))); - for(MusicDirectory.Entry entry: unstar) { + for(Entry entry: unstar) { entries.remove(entry); } entryAdapter.notifyDataSetChanged(); @@ -1154,7 +1156,7 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Adapter builder.create().show(); } - private View createHeader(List entries) { + private View createHeader(List entries) { View header = entryList.findViewById(R.id.select_album_header); boolean add = false; if(header == null) { @@ -1165,12 +1167,12 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Adapter final ImageLoader imageLoader = getImageLoader(); // Try a few times to get a random cover art - MusicDirectory.Entry coverArt = null; + Entry coverArt = null; for(int i = 0; (i < 3) && (coverArt == null || coverArt.getCoverArt() == null); i++) { coverArt = entries.get(random.nextInt(entries.size())); } - final MusicDirectory.Entry albumRep = coverArt; + final Entry albumRep = coverArt; View coverArtView = header.findViewById(R.id.select_album_art); coverArtView.setOnClickListener(new View.OnClickListener() { @Override @@ -1207,7 +1209,7 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Adapter Set artists = new HashSet(); Set years = new HashSet(); Integer totalDuration = 0; - for (MusicDirectory.Entry entry : entries) { + for (Entry entry : entries) { if (!entry.isDirectory()) { songCount++; if (entry.getArtist() != null) { -- cgit v1.2.3