diff options
author | Scott Jackson <daneren2005@gmail.com> | 2014-01-24 07:43:58 -0800 |
---|---|---|
committer | Scott Jackson <daneren2005@gmail.com> | 2014-01-24 07:43:58 -0800 |
commit | 11e9575df92b561e620a8b0a31dae5ec0a9b1c90 (patch) | |
tree | 7470e5edf1b10ee1b8052f46c15f66a36beef665 /src/github | |
parent | 1b9f7abb93639f9244a4c888b4c2c0630c297bf0 (diff) | |
download | dsub-11e9575df92b561e620a8b0a31dae5ec0a9b1c90.tar.gz dsub-11e9575df92b561e620a8b0a31dae5ec0a9b1c90.tar.bz2 dsub-11e9575df92b561e620a8b0a31dae5ec0a9b1c90.zip |
#265 Add a method to mass unstar songs
Diffstat (limited to 'src/github')
7 files changed, 78 insertions, 17 deletions
diff --git a/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java b/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java index 4776295e..eb782163 100644 --- a/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java +++ b/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java @@ -200,6 +200,10 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Adapter }
}
}
+
+ if("starred".equals(albumListType)) {
+ menuInflater.inflate(R.menu.unstar, menu);
+ }
}
@Override
@@ -247,6 +251,10 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Adapter case R.id.menu_show_all:
showAll = true;
refresh(true);
+ return true;
+ case R.id.menu_unstar:
+ unstarSelected();
+ return true;
}
if(super.onOptionsItemSelected(item)) {
@@ -864,6 +872,52 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Adapter });
}
+ public void unstarSelected() {
+ if(getSelectedSongs().size() == 0) {
+ selectAll(true, false);
+ }
+ final List<MusicDirectory.Entry> selected = getSelectedSongs();
+ if(selected.size() == 0) {
+ return;
+ }
+
+ new LoadingTask<Void>(context, true) {
+ @Override
+ protected Void doInBackground() throws Throwable {
+ MusicService musicService = MusicServiceFactory.getMusicService(context);
+ List<String> ids = new ArrayList<String>();
+ for(MusicDirectory.Entry entry: selected) {
+ ids.add(entry.getId());
+ }
+ musicService.setStarred(ids, null, null, false, context, this);
+ return null;
+ }
+
+ @Override
+ protected void done(Void result) {
+ Util.toast(context, context.getResources().getString(R.string.starring_content_unstarred, Integer.toString(selected.size())));
+
+ for(MusicDirectory.Entry entry: selected) {
+ entries.remove(entry);
+ }
+ entryAdapter.notifyDataSetChanged();
+ selectAll(false, false);
+ }
+
+ @Override
+ protected void error(Throwable error) {
+ String msg;
+ if (error instanceof OfflineException || error instanceof ServerTooOldException) {
+ msg = getErrorMessage(error);
+ } else {
+ msg = context.getResources().getString(R.string.starring_content_error, Integer.toString(selected.size())) + " " + getErrorMessage(error);
+ }
+
+ Util.toast(context, msg, false);
+ }
+ }.execute();
+ }
+
private void checkLicenseAndTrialPeriod(LoadingTask onValid) {
if (licenseValid) {
onValid.execute();
diff --git a/src/github/daneren2005/dsub/fragments/SubsonicFragment.java b/src/github/daneren2005/dsub/fragments/SubsonicFragment.java index 19cfe7d4..c99d5d1c 100644 --- a/src/github/daneren2005/dsub/fragments/SubsonicFragment.java +++ b/src/github/daneren2005/dsub/fragments/SubsonicFragment.java @@ -71,6 +71,7 @@ import java.io.Serializable; import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;
@@ -600,7 +601,7 @@ public class SubsonicFragment extends Fragment { if(entry.isDirectory() && Util.isTagBrowsing(context) && !Util.isOffline(context)) {
musicService.setStarred(null, null, entry.getId(), starred, context, null);
} else {
- musicService.setStarred(entry.getId(), null, null, starred, context, null);
+ musicService.setStarred(Arrays.asList(entry.getId()), null, null, starred, context, null);
}
// Make sure to clear parent cache
@@ -643,7 +644,7 @@ public class SubsonicFragment extends Fragment { if(Util.isTagBrowsing(context) && !Util.isOffline(context)) {
musicService.setStarred(null, entry.getId(), null, starred, context, null);
} else {
- musicService.setStarred(entry.getId(), null, null, starred, context, null);
+ musicService.setStarred(Arrays.asList(entry.getId()), null, null, starred, context, null);
}
return null;
}
diff --git a/src/github/daneren2005/dsub/service/CachedMusicService.java b/src/github/daneren2005/dsub/service/CachedMusicService.java index 99f21d6e..048e2827 100644 --- a/src/github/daneren2005/dsub/service/CachedMusicService.java +++ b/src/github/daneren2005/dsub/service/CachedMusicService.java @@ -27,8 +27,6 @@ import org.apache.http.HttpResponse; import android.content.Context; import android.graphics.Bitmap; -import android.support.v4.util.LruCache; -import android.util.Log; import github.daneren2005.dsub.domain.Bookmark; import github.daneren2005.dsub.domain.ChatMessage; @@ -351,7 +349,7 @@ public class CachedMusicService implements MusicService { } @Override - public void setStarred(String id, String artistId, String albumId, boolean starred, Context context, ProgressListener progressListener) throws Exception { + public void setStarred(List<String> id, String artistId, String albumId, boolean starred, Context context, ProgressListener progressListener) throws Exception { musicService.setStarred(id, artistId, albumId, starred, context, progressListener); } diff --git a/src/github/daneren2005/dsub/service/MusicService.java b/src/github/daneren2005/dsub/service/MusicService.java index 28fc2036..a88dd04a 100644 --- a/src/github/daneren2005/dsub/service/MusicService.java +++ b/src/github/daneren2005/dsub/service/MusicService.java @@ -117,7 +117,7 @@ public interface MusicService { RemoteStatus setJukeboxGain(float gain, Context context, ProgressListener progressListener) throws Exception; - void setStarred(String id, String artistId, String albumId, boolean starred, Context context, ProgressListener progressListener) throws Exception; + void setStarred(List<String> id, String artistId, String albumId, boolean starred, Context context, ProgressListener progressListener) throws Exception; List<Share> getShares(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 c5803728..10d3c311 100644 --- a/src/github/daneren2005/dsub/service/OfflineMusicService.java +++ b/src/github/daneren2005/dsub/service/OfflineMusicService.java @@ -559,7 +559,7 @@ public class OfflineMusicService extends RESTMusicService { } @Override - public void setStarred(String id, String artistId, String albumId, boolean starred, Context context, ProgressListener progressListener) throws Exception { + public void setStarred(List<String> ids, String artistId, String albumId, boolean starred, Context context, ProgressListener progressListener) throws Exception { SharedPreferences prefs = Util.getPreferences(context); String cacheLocn = prefs.getString(Constants.PREFERENCES_KEY_CACHE_LOCATION, null); @@ -567,7 +567,8 @@ public class OfflineMusicService extends RESTMusicService { int stars = offline.getInt(Constants.OFFLINE_STAR_COUNT, 0); stars++; SharedPreferences.Editor offlineEditor = offline.edit(); - + + String id = ids.get(0); if(id.indexOf(cacheLocn) != -1) { String searchCriteria = Util.parseOfflineIDSearch(context, id, cacheLocn); offlineEditor.putString(Constants.OFFLINE_STAR_SEARCH + stars, searchCriteria); diff --git a/src/github/daneren2005/dsub/service/RESTMusicService.java b/src/github/daneren2005/dsub/service/RESTMusicService.java index f980422d..f4816bcd 100644 --- a/src/github/daneren2005/dsub/service/RESTMusicService.java +++ b/src/github/daneren2005/dsub/service/RESTMusicService.java @@ -63,7 +63,6 @@ import android.content.Context; import android.content.SharedPreferences; import android.content.pm.PackageInfo; import android.graphics.Bitmap; -import android.graphics.BitmapFactory; import android.net.ConnectivityManager; import android.net.NetworkInfo; import android.util.Log; @@ -822,15 +821,22 @@ public class RESTMusicService implements MusicService { } @Override - public void setStarred(String id, String artistId, String albumId, boolean starred, Context context, ProgressListener progressListener) throws Exception { + public void setStarred(List<String> ids, String artistId, String albumId, boolean starred, Context context, ProgressListener progressListener) throws Exception { checkServerVersion(context, "1.8", "Starring is not supported."); List<String> names = new ArrayList<String>(); List<Object> values = new ArrayList<Object>(); - if(id != null) { - names.add("id"); - values.add(getOfflineSongId(id, context, progressListener)); + if(ids != null) { + if(ids.size() > 1) { + for (String id : ids) { + names.add("id"); + values.add(id); + } + } else { + names.add("id"); + values.add(getOfflineSongId(ids.get(0), context, progressListener)); + } } else if(artistId != null) { names.add("artistId"); values.add(artistId); @@ -1216,7 +1222,7 @@ public class RESTMusicService implements MusicService { String id = offline.getString(Constants.OFFLINE_STAR_ID + i, null); boolean starred = offline.getBoolean(Constants.OFFLINE_STAR_SETTING + i, false); if(id != null) { - setStarred(id, null, null, starred, context, progressListener); + setStarred(Arrays.asList(id), null, null, starred, context, progressListener); } else { String search = offline.getString(Constants.OFFLINE_STAR_SEARCH + i, ""); try{ @@ -1224,10 +1230,10 @@ public class RESTMusicService implements MusicService { SearchResult result = searchNew(critera, context, progressListener); if(result.getSongs().size() == 1){ Log.i(TAG, "Query '" + search + "' returned song " + result.getSongs().get(0).getTitle() + " by " + result.getSongs().get(0).getArtist() + " with id " + result.getSongs().get(0).getId()); - setStarred(result.getSongs().get(0).getId(), null, null, starred, context, progressListener); + setStarred(Arrays.asList(result.getSongs().get(0).getId()), null, null, starred, context, progressListener); } else if(result.getAlbums().size() == 1){ Log.i(TAG, "Query '" + search + "' returned song " + result.getAlbums().get(0).getTitle() + " by " + result.getAlbums().get(0).getArtist() + " with id " + result.getAlbums().get(0).getId()); - setStarred(result.getAlbums().get(0).getId(), null, null, starred, context, progressListener); + setStarred(Arrays.asList(result.getAlbums().get(0).getId()), null, null, starred, context, progressListener); } else{ throw new Exception("Song not found on server"); diff --git a/src/github/daneren2005/dsub/util/compat/RemoteControlClientKK.java b/src/github/daneren2005/dsub/util/compat/RemoteControlClientKK.java index 2c041d71..532aec5b 100644 --- a/src/github/daneren2005/dsub/util/compat/RemoteControlClientKK.java +++ b/src/github/daneren2005/dsub/util/compat/RemoteControlClientKK.java @@ -22,6 +22,7 @@ import github.daneren2005.dsub.service.MusicServiceFactory; import github.daneren2005.dsub.util.SilentBackgroundTask; import github.daneren2005.dsub.util.Util; import java.io.File; +import java.util.Arrays; @TargetApi(19) public class RemoteControlClientKK extends RemoteControlClientJB { @@ -64,7 +65,7 @@ public class RemoteControlClientKK extends RemoteControlClientJB { protected Void doInBackground(Void... params) { try { MusicService musicService = MusicServiceFactory.getMusicService(downloadService); - musicService.setStarred(entry.getId(), null, null, starred, downloadService, null); + musicService.setStarred(Arrays.asList(entry.getId()), null, null, starred, downloadService, null); // Make sure to clear parent cache String s = Util.getRestUrl(downloadService, null) + entry.getParent(); |