diff options
author | Scott Jackson <daneren2005@gmail.com> | 2014-09-04 16:28:58 -0700 |
---|---|---|
committer | Scott Jackson <daneren2005@gmail.com> | 2014-09-04 16:28:58 -0700 |
commit | f56982435e236235f4230c2ddc679b06790cb7eb (patch) | |
tree | f462ecd310deab36dfda6526166a7144898d60be | |
parent | 8b82a10e774db88fb49a55b24f788d9ae871eaf2 (diff) | |
download | dsub-f56982435e236235f4230c2ddc679b06790cb7eb.tar.gz dsub-f56982435e236235f4230c2ddc679b06790cb7eb.tar.bz2 dsub-f56982435e236235f4230c2ddc679b06790cb7eb.zip |
Make GenericEntryUpdater able to update any sort of schema, accept multiple inputs
-rw-r--r-- | src/github/daneren2005/dsub/service/CachedMusicService.java | 132 |
1 files changed, 89 insertions, 43 deletions
diff --git a/src/github/daneren2005/dsub/service/CachedMusicService.java b/src/github/daneren2005/dsub/service/CachedMusicService.java index 8521d1d5..58de141f 100644 --- a/src/github/daneren2005/dsub/service/CachedMusicService.java +++ b/src/github/daneren2005/dsub/service/CachedMusicService.java @@ -795,7 +795,7 @@ public class CachedMusicService implements MusicService { public void setRating(final Entry entry, final int rating, Context context, ProgressListener progressListener) throws Exception { musicService.setRating(entry, rating, context, progressListener); - new GenericSongUpdater(context, entry) { + new GenericEntryUpdater(context, entry) { @Override public void updateResult(Entry result) { result.setRating(rating); @@ -1229,74 +1229,120 @@ public class CachedMusicService implements MusicService { } } } - private abstract class GenericSongUpdater { + private abstract class GenericEntryUpdater { Context context; - Entry entry; + List<Entry> entries; - public GenericSongUpdater(Context context, Entry entry) { + public GenericEntryUpdater(Context context, Entry entry) { this.context = context; - this.entry = entry; + this.entries = Arrays.asList(entry); + } + public GenericEntryUpdater(Context context, List<Entry> entries) { + this.context = context; + this.entries = entries; } - public boolean checkResult(Entry check) { + public boolean checkResult(Entry entry, Entry check) { return entry.getId().equals(check.getId()); } public abstract void updateResult(Entry result); public void execute() { String cacheName, parent; - if(Util.isTagBrowsing(context, musicService.getInstance(context))) { - // If starring album, needs to reference artist instead - if(entry.isDirectory()) { - cacheName = "artist"; - parent = entry.getArtistId(); + boolean isTagBrowsing = Util.isTagBrowsing(context, musicService.getInstance(context)); + + // Run through each entry, trying to update the directory it is in + List<Entry> songs; + for(final Entry entry: entries) { + if(isTagBrowsing) { + // If starring album, needs to reference artist instead + if(entry.isDirectory()) { + if(entry.isAlbum()) { + cacheName = "artist"; + parent = entry.getArtistId(); + } else { + cacheName = "artists"; + parent = null; + } + } else { + cacheName = "album"; + parent = entry.getAlbumId(); + } } else { - cacheName = "album"; - parent = entry.getAlbumId(); + if(entry.isDirectory() && !entry.isAlbum()) { + cacheName = "indexes"; + parent = null; + } else { + cacheName = "directory"; + parent = entry.getParent(); + } } - } else { - cacheName = "directory"; - parent = entry.getParent(); - } - new MusicDirectoryUpdater(context, cacheName, parent) { - @Override - public boolean checkResult(Entry check) { - return GenericSongUpdater.this.checkResult(check); + // Parent is only null when it is an artist + if(parent == null) { + new IndexesUpdater(context, cacheName) { + @Override + public boolean checkResult(Artist check) { + return checkResult(entry, new Entry(check)); + } + + @Override + public void updateResult(List<Artist> objects, Artist result) { + updateResult(new Entry(result)); + } + }.execute(); + } else { + new MusicDirectoryUpdater(context, cacheName, parent) { + @Override + public boolean checkResult(Entry check) { + return checkResult(entry, check); + } + + @Override + public void updateResult(List<Entry> objects, Entry result) { + updateResult(result); + } + }.execute(); } - @Override - public void updateResult(List<Entry> objects, Entry result) { - GenericSongUpdater.this.updateResult(result); + if(entry instanceof PodcastEpisode) { + PodcastEpisode episode = (PodcastEpisode) entry; + new MusicDirectoryUpdater(context, cacheName, "p-" + entry.getId()) { + @Override + public boolean checkResult(Entry check) { + return checkResult(entry, check); + } + + @Override + public void updateResult(List<Entry> objects, Entry result) { + updateResult(result); + } + }.execute(); + } else if(!entry.isDirectory()) { + songs.add(entry); } - }.execute(); + } - if(entry instanceof PodcastEpisode) { - PodcastEpisode episode = (PodcastEpisode) entry; - new MusicDirectoryUpdater(context, cacheName, "p-" + entry.getId()) { + // Only run through playlists once and check each song against it + if(songs.size() > 0) { + new PlaylistDirectoryUpdater(context) { @Override public boolean checkResult(Entry check) { - return GenericSongUpdater.this.checkResult(check); + for(Entry entry: songs) { + if(checkResult(entry, check)) { + return true; + } + } + + return false; } @Override - public void updateResult(List<Entry> objects, Entry result) { - GenericSongUpdater.this.updateResult(result); + public void updateResult(Entry result) { + GenericEntryUpdater.this.updateResult(result); } }.execute(); } - - new PlaylistDirectoryUpdater(context) { - @Override - public boolean checkResult(Entry check) { - return GenericSongUpdater.this.checkResult(check); - } - - @Override - public void updateResult(Entry result) { - GenericSongUpdater.this.updateResult(result); - } - }.execute(); } } private abstract class IndexesUpdater extends SerializeUpdater<Artist> { |