diff options
author | Scott Jackson <daneren2005@gmail.com> | 2014-09-05 15:08:57 -0700 |
---|---|---|
committer | Scott Jackson <daneren2005@gmail.com> | 2014-09-05 15:08:57 -0700 |
commit | 8c6955e69f6b982b3da8e83419e389b490ee5b01 (patch) | |
tree | cd6b950b20c23eda165db930b7cf411a4c083195 | |
parent | ea5a5bb81ab61713e7f00b4224c4f53bed437c42 (diff) | |
download | dsub-8c6955e69f6b982b3da8e83419e389b490ee5b01.tar.gz dsub-8c6955e69f6b982b3da8e83419e389b490ee5b01.tar.bz2 dsub-8c6955e69f6b982b3da8e83419e389b490ee5b01.zip |
Added EntryInstanceUpdater which checks for matches in existing display and in downloadService
-rw-r--r-- | src/github/daneren2005/dsub/fragments/SubsonicFragment.java | 77 |
1 files changed, 53 insertions, 24 deletions
diff --git a/src/github/daneren2005/dsub/fragments/SubsonicFragment.java b/src/github/daneren2005/dsub/fragments/SubsonicFragment.java index 62484761..30369bd4 100644 --- a/src/github/daneren2005/dsub/fragments/SubsonicFragment.java +++ b/src/github/daneren2005/dsub/fragments/SubsonicFragment.java @@ -688,7 +688,12 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR musicService.setStarred(Arrays.asList(entry), null, null, starred, null, context);
}
- setEntryStarred(entry, starred);
+ new EntryInstanceUpdater(entry) {
+ @Override
+ public void update(Entry found) {
+ found.setStarred(starred);
+ }
+ }.execute();
return null;
}
@@ -715,25 +720,6 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR }
}.execute();
}
- protected void setEntryStarred(Entry entry, boolean starred) {
- DownloadService downloadService = DownloadService.getInstance();
- if(downloadService != null && !entry.isDirectory()) {
- List<DownloadFile> files = downloadService.getDownloads();
- for(DownloadFile file: files) {
- Entry check = file.getSong();
- if(entry.getId().equals(check.getId())) {
- check.setStarred(starred);
- downloadService.serializeQueue();
- break;
- }
- }
- }
-
- Entry find = UpdateView.findEntry(entry);
- if(find != null) {
- find.setStarred(starred);
- }
- }
public void toggleStarred(final Artist entry) {
final boolean starred = !entry.isStarred();
@@ -1492,6 +1478,13 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR protected Void doInBackground() throws Throwable {
MusicService musicService = MusicServiceFactory.getMusicService(context);
musicService.deleteBookmark(entry, context, null);
+
+ new EntryInstanceUpdater(entry) {
+ @Override
+ public void update(Entry found) {
+ found.setBookmark(null);
+ }
+ }.execute();
return null;
}
@@ -1554,10 +1547,12 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR MusicService musicService = MusicServiceFactory.getMusicService(context);
musicService.setRating(entry, rating, context, null);
- Entry findEntry = UpdateView.findEntry(entry);
- if(findEntry != null) {
- findEntry.setRating(rating);
- }
+ new EntryInstanceUpdater(entry) {
+ @Override
+ public void update(Entry found) {
+ found.setRating(rating);
+ }
+ }.execute();
return null;
}
@@ -1581,4 +1576,38 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR }
}.execute();
}
+
+ protected abstract class EntryInstanceUpdater {
+ private Entry entry;
+
+ public EntryInstanceUpdater(Entry entry) {
+ this.entry = entry;
+ }
+
+ public abstract void update(Entry found);
+
+ public void execute() {
+ DownloadService downloadService = getDownloadService();
+ if(downloadService != null && !entry.isDirectory()) {
+ private boolean serializeChanges = false;
+ List<DownloadFile> downloadFiles = downloadService.getDownloads();
+ for(DownloadFile file: downloadFiles) {
+ Entry check = file.getSong();
+ if(entry.getId().equals(check.getId())) {
+ update(entry);
+ serializeChanges = true;
+ }
+ }
+
+ if(serializeChanges) {
+ downloadService.serializeQueue();
+ }
+ }
+
+ Entry find = UpdateView.findEntry(entry);
+ if(find != null) {
+ update(find);
+ }
+ }
+ }
}
|