aboutsummaryrefslogtreecommitdiff
path: root/src/github/daneren2005
diff options
context:
space:
mode:
authorScott Jackson <daneren2005@gmail.com>2014-08-19 21:45:56 -0700
committerScott Jackson <daneren2005@gmail.com>2014-08-19 21:45:56 -0700
commit9deb868578f32847402566f83667f24597633e5b (patch)
tree447eebb4f22143bb52b1087a32e6204c6b252603 /src/github/daneren2005
parente376bc4abd109cbc9c15db2a0dbaf3341ec77871 (diff)
downloaddsub-9deb868578f32847402566f83667f24597633e5b.tar.gz
dsub-9deb868578f32847402566f83667f24597633e5b.tar.bz2
dsub-9deb868578f32847402566f83667f24597633e5b.zip
More work on synchronized bookmarks
Diffstat (limited to 'src/github/daneren2005')
-rw-r--r--src/github/daneren2005/dsub/fragments/NowPlayingFragment.java13
-rw-r--r--src/github/daneren2005/dsub/fragments/SelectBookmarkFragment.java2
-rw-r--r--src/github/daneren2005/dsub/fragments/SubsonicFragment.java4
-rw-r--r--src/github/daneren2005/dsub/service/CachedMusicService.java48
-rw-r--r--src/github/daneren2005/dsub/service/MusicService.java4
-rw-r--r--src/github/daneren2005/dsub/service/OfflineMusicService.java4
-rw-r--r--src/github/daneren2005/dsub/service/RESTMusicService.java4
-rw-r--r--src/github/daneren2005/dsub/util/Util.java14
8 files changed, 61 insertions, 32 deletions
diff --git a/src/github/daneren2005/dsub/fragments/NowPlayingFragment.java b/src/github/daneren2005/dsub/fragments/NowPlayingFragment.java
index 3486f154..4565b192 100644
--- a/src/github/daneren2005/dsub/fragments/NowPlayingFragment.java
+++ b/src/github/daneren2005/dsub/fragments/NowPlayingFragment.java
@@ -30,7 +30,6 @@ import android.os.Bundle;
import android.os.Handler;
import android.support.v4.view.MenuItemCompat;
import android.support.v7.app.MediaRouteButton;
-import android.util.Log;
import android.view.ContextMenu;
import android.view.Display;
import android.view.GestureDetector;
@@ -46,7 +45,6 @@ import android.view.ViewGroup;
import android.view.WindowManager;
import android.view.animation.AnimationUtils;
import android.widget.AdapterView;
-import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
@@ -57,6 +55,7 @@ import android.widget.TextView;
import android.widget.ViewFlipper;
import github.daneren2005.dsub.R;
import github.daneren2005.dsub.activity.SubsonicFragmentActivity;
+import github.daneren2005.dsub.domain.Bookmark;
import github.daneren2005.dsub.domain.MusicDirectory;
import github.daneren2005.dsub.domain.PlayerState;
import github.daneren2005.dsub.domain.RepeatMode;
@@ -68,7 +67,6 @@ import github.daneren2005.dsub.util.Constants;
import github.daneren2005.dsub.util.SilentBackgroundTask;
import github.daneren2005.dsub.view.DownloadFileAdapter;
import github.daneren2005.dsub.view.FadeOutAnimation;
-import github.daneren2005.dsub.view.SongView;
import github.daneren2005.dsub.view.UpdateView;
import github.daneren2005.dsub.util.Util;
import github.daneren2005.dsub.view.VisualizerView;
@@ -1321,7 +1319,14 @@ public class NowPlayingFragment extends SubsonicFragment implements OnGestureLis
protected Void doInBackground() throws Throwable {
MusicDirectory.Entry currentSong = currentDownload.getSong();
MusicService musicService = MusicServiceFactory.getMusicService(context);
- musicService.createBookmark(currentSong.getId(), getDownloadService().getPlayerPosition(), comment, context, null);
+ int position = getDownloadService().getPlayerPosition();
+ musicService.createBookmark(currentSong.getId(), Util.getParentFromEntry(context, currentSong), getDownloadService().getPlayerPosition(), comment, context, null);
+
+ currentSong.setBookmark(new Bookmark(position));
+ MusicDirectory.Entry find = UpdateView.findEntry(currentSong);
+ if(find != null && find != currentSong) {
+ find.setBookmark(new Bookmark(position));
+ }
return null;
}
diff --git a/src/github/daneren2005/dsub/fragments/SelectBookmarkFragment.java b/src/github/daneren2005/dsub/fragments/SelectBookmarkFragment.java
index 16350f69..dfaf2d4d 100644
--- a/src/github/daneren2005/dsub/fragments/SelectBookmarkFragment.java
+++ b/src/github/daneren2005/dsub/fragments/SelectBookmarkFragment.java
@@ -140,7 +140,7 @@ public class SelectBookmarkFragment extends SelectListFragment<MusicDirectory.En
@Override
protected Void doInBackground() throws Throwable {
MusicService musicService = MusicServiceFactory.getMusicService(context);
- musicService.deleteBookmark(entry.getId(), context, null);
+ musicService.deleteBookmark(entry.getId(), Util.getParentFromEntry(context, entry), context, null);
return null;
}
diff --git a/src/github/daneren2005/dsub/fragments/SubsonicFragment.java b/src/github/daneren2005/dsub/fragments/SubsonicFragment.java
index e1c0d95d..7787c363 100644
--- a/src/github/daneren2005/dsub/fragments/SubsonicFragment.java
+++ b/src/github/daneren2005/dsub/fragments/SubsonicFragment.java
@@ -1326,7 +1326,9 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR
@Override
protected Void doInBackground() throws Throwable {
MusicService musicService = MusicServiceFactory.getMusicService(context);
- musicService.deleteBookmark(song.getId(), context, null);
+ musicService.deleteBookmark(song.getId(), Util.getParentFromEntry(context, song), context, null);
+
+ song.setBookmark(null);
return null;
}
diff --git a/src/github/daneren2005/dsub/service/CachedMusicService.java b/src/github/daneren2005/dsub/service/CachedMusicService.java
index 129fd564..eb40691e 100644
--- a/src/github/daneren2005/dsub/service/CachedMusicService.java
+++ b/src/github/daneren2005/dsub/service/CachedMusicService.java
@@ -32,6 +32,7 @@ import android.graphics.Bitmap;
import android.util.Log;
import github.daneren2005.dsub.domain.Artist;
+import github.daneren2005.dsub.domain.Bookmark;
import github.daneren2005.dsub.domain.ChatMessage;
import github.daneren2005.dsub.domain.Genre;
import github.daneren2005.dsub.domain.Indexes;
@@ -359,9 +360,9 @@ public class CachedMusicService implements MusicService {
MusicDirectory oldDir = FileUtil.deserialize(context, "starred", MusicDirectory.class);
if(oldDir != null) {
- List<Entry> newList = new ArrayList<Entry>();
+ final List<Entry> newList = new ArrayList<Entry>();
newList.addAll(dir.getChildren());
- List<Entry> oldList = oldDir.getChildren();
+ final List<Entry> oldList = oldDir.getChildren();
removeDuplicates(oldList, newList);
@@ -466,7 +467,7 @@ public class CachedMusicService implements MusicService {
new MusicDirectoryUpdater(context, cacheName, parent) {
@Override
public boolean checkResult(Entry check) {
- if (entry.getId().equals(check.getId()) && entry.isStarred() != starred) {
+ if (entry.getId().equals(check.getId()) && check.isStarred() != starred) {
return true;
}
@@ -799,10 +800,10 @@ public class CachedMusicService implements MusicService {
public MusicDirectory getBookmarks(boolean refresh, Context context, ProgressListener progressListener) throws Exception {
MusicDirectory bookmarks = musicService.getBookmarks(refresh, context, progressListener);
- MusicDirectory oldBookmarks = FileUtil.deserailize(context, "bookmarks", MusicDirectory.class);
+ MusicDirectory oldBookmarks = FileUtil.deserialize(context, "bookmarks", MusicDirectory.class);
if(oldBookmarks != null) {
- List<Entry> oldList = oldBookmarks.getChildren();
- List<Entry> newList = new ArrayList<>();
+ final List<Entry> oldList = oldBookmarks.getChildren();
+ final List<Entry> newList = new ArrayList<Entry>();
newList.addAll(bookmarks.getChildren());
removeDuplicates(oldList, newList);
@@ -812,7 +813,7 @@ public class CachedMusicService implements MusicService {
// Add new bookmarks for things in new list
setBookmarkCache(context, newList, false);
- if(oldList.size() > 0 || nextList.size() > 0) {
+ if(oldList.size() > 0 || newList.size() > 0) {
new PlaylistDirectoryUpdater(context) {
@Override
public boolean checkResult(Entry check) {
@@ -849,7 +850,7 @@ public class CachedMusicService implements MusicService {
@Override
public void createBookmark(String id, String parent, int position, String comment, Context context, ProgressListener progressListener) throws Exception {
- musicService.createBookmark(id, position, comment, context, progressListener);
+ musicService.createBookmark(id, null, position, comment, context, progressListener);
// Add to directory cache
setBookmarkCache(context, id, parent, position);
// Add to playlist cache
@@ -858,7 +859,7 @@ public class CachedMusicService implements MusicService {
@Override
public void deleteBookmark(String id, String parent, Context context, ProgressListener progressListener) throws Exception {
- musicService.deleteBookmark(id, context, progressListener);
+ musicService.deleteBookmark(id, null, context, progressListener);
// Delete from directory cache
setBookmarkCache(context, id, parent, -1);
// Delete from playlist cache
@@ -868,15 +869,22 @@ public class CachedMusicService implements MusicService {
private void setBookmarkCache(Context context, List<Entry> entries, boolean remove) {
for(final Entry entry: entries) {
if(remove) {
- setBookmarkCache(context, entry.getId(), entry.getParent(), -1);
+ setBookmarkCache(context, entry.getId(), Util.getParentFromEntry(context, entry), -1);
} else {
- setBookmarkCache(context, entry.getId(), entry.getParent(), entry.getBookmark().getPosition());
+ setBookmarkCache(context, entry.getId(), Util.getParentFromEntry(context, entry), entry.getBookmark().getPosition());
}
}
}
private void setBookmarkCache(Context context, final String id, final String parent, final int position) {
+ String cacheName;
+ if(isTagBrowsing) {
+ cacheName = "album";
+ } else {
+ cacheName = "directory";
+ }
+
// Update the parent directory with bookmark data
- new MusicDirectoryUpdater(context, "directory", parent) {
+ new MusicDirectoryUpdater(context, cacheName, parent) {
@Override
public boolean checkResult(Entry check) {
return shouldBookmarkUpdate(check, id, position);
@@ -904,7 +912,7 @@ public class CachedMusicService implements MusicService {
}
private boolean shouldBookmarkUpdate(Entry check, String id, int position) {
- if(id.equals(check.getId()) {
+ if(id.equals(check.getId())) {
if(position == -1 && check.getBookmark() != null) {
return true;
} else if(position >= 0 && (check.getBookmark() == null || check.getBookmark().getPosition() != position)) {
@@ -1054,7 +1062,7 @@ public class CachedMusicService implements MusicService {
private void removeDuplicates(List<Entry> oldList, List<Entry> newList) {
for(Iterator<Entry> it = oldList.iterator(); it.hasNext(); ) {
// Remove entries from newList
- if(newList.remove(it.next()) {
+ if(newList.remove(it.next())) {
// If it was removed, then remove it from old list as well
it.remove();
}
@@ -1097,10 +1105,10 @@ public class CachedMusicService implements MusicService {
// Only execute if something to check against
if(objects != null) {
- List<T> objects = new ArrayList<T>();
+ List<T> results = new ArrayList<T>();
for(T check: objects) {
if(checkResult(check)) {
- objects.push(check);
+ results.add(check);
if(singleUpdate) {
break;
}
@@ -1108,12 +1116,12 @@ public class CachedMusicService implements MusicService {
}
// Iterate through and update each object matched
- for(T object: objects) {
- updateResult(objects, object);
+ for(T result: results) {
+ updateResult(objects, result);
}
// Only reserialize if at least one match was found
- if(objects.size() > 0) {
+ if(results.size() > 0) {
save(objects);
}
}
@@ -1177,7 +1185,7 @@ public class CachedMusicService implements MusicService {
}
public abstract boolean checkResult(Entry check);
- public abstract boolean updateResult(Entry result);
+ public abstract void updateResult(Entry result);
public void execute() {
List<Playlist> playlists = FileUtil.deserialize(context, getCacheName(context, "playlist"), ArrayList.class);
diff --git a/src/github/daneren2005/dsub/service/MusicService.java b/src/github/daneren2005/dsub/service/MusicService.java
index 58df8904..d70f1c46 100644
--- a/src/github/daneren2005/dsub/service/MusicService.java
+++ b/src/github/daneren2005/dsub/service/MusicService.java
@@ -156,9 +156,9 @@ public interface MusicService {
MusicDirectory getBookmarks(boolean refresh, Context context, ProgressListener progressListener) throws Exception;
- void createBookmark(String id, int position, String comment, Context context, ProgressListener progressListener) throws Exception;
+ void createBookmark(String id, String parent, int position, String comment, Context context, ProgressListener progressListener) throws Exception;
- void deleteBookmark(String id, Context context, ProgressListener progressListener) throws Exception;
+ void deleteBookmark(String id, String parent, Context context, ProgressListener progressListener) throws Exception;
User getUser(boolean refresh, String username, Context context, ProgressListener progressListener) throws Exception;
diff --git a/src/github/daneren2005/dsub/service/OfflineMusicService.java b/src/github/daneren2005/dsub/service/OfflineMusicService.java
index 82d3de10..8aeba2b4 100644
--- a/src/github/daneren2005/dsub/service/OfflineMusicService.java
+++ b/src/github/daneren2005/dsub/service/OfflineMusicService.java
@@ -747,12 +747,12 @@ public class OfflineMusicService implements MusicService {
}
@Override
- public void createBookmark(String id, int position, String comment, Context context, ProgressListener progressListener) throws Exception {
+ public void createBookmark(String id, String parent, int position, String comment, Context context, ProgressListener progressListener) throws Exception {
throw new OfflineException(ERRORMSG);
}
@Override
- public void deleteBookmark(String id, Context context, ProgressListener progressListener) throws Exception {
+ public void deleteBookmark(String id, String parent, Context context, ProgressListener progressListener) throws Exception {
throw new OfflineException(ERRORMSG);
}
diff --git a/src/github/daneren2005/dsub/service/RESTMusicService.java b/src/github/daneren2005/dsub/service/RESTMusicService.java
index 13d1555c..025d07c5 100644
--- a/src/github/daneren2005/dsub/service/RESTMusicService.java
+++ b/src/github/daneren2005/dsub/service/RESTMusicService.java
@@ -1127,7 +1127,7 @@ public class RESTMusicService implements MusicService {
}
@Override
- public void createBookmark(String id, int position, String comment, Context context, ProgressListener progressListener) throws Exception {
+ public void createBookmark(String id, String parent, int position, String comment, Context context, ProgressListener progressListener) throws Exception {
checkServerVersion(context, "1.9", "Creating bookmarks not supported.");
Reader reader = getReader(context, progressListener, "createBookmark", null, Arrays.asList("id", "position", "comment"), Arrays.<Object>asList(id, position, comment));
@@ -1139,7 +1139,7 @@ public class RESTMusicService implements MusicService {
}
@Override
- public void deleteBookmark(String id, Context context, ProgressListener progressListener) throws Exception {
+ public void deleteBookmark(String id, String parent, Context context, ProgressListener progressListener) throws Exception {
checkServerVersion(context, "1.9", "Deleting bookmarks not supported.");
Reader reader = getReader(context, progressListener, "deleteBookmark", null, Arrays.asList("id"), Arrays.<Object>asList(id));
diff --git a/src/github/daneren2005/dsub/util/Util.java b/src/github/daneren2005/dsub/util/Util.java
index 1ea1a3be..258e4eb8 100644
--- a/src/github/daneren2005/dsub/util/Util.java
+++ b/src/github/daneren2005/dsub/util/Util.java
@@ -385,6 +385,20 @@ public final class Util {
return prefs.getBoolean(Constants.PREFERENCES_KEY_BROWSE_TAGS + instance, false);
}
+ public static String getParentFromEntry(Context context, MusicDirectory.Entry entry) {
+ if(Util.isTagBrowsing(context)) {
+ if(!entry.isDirectory()) {
+ return entry.getAlbumId();
+ } else if(entry.isAlbum()) {
+ return entry.getArtistId();
+ } else {
+ return null;
+ }
+ } else {
+ return entry.getParent();
+ }
+ }
+
public static boolean isOpenToLibrary(Context context) {
SharedPreferences prefs = getPreferences(context);
return prefs.getBoolean(Constants.PREFERENCES_KEY_OPEN_TO_LIBRARY, false);