diff options
author | Scott Jackson <daneren2005@gmail.com> | 2013-06-24 21:44:32 -0700 |
---|---|---|
committer | Scott Jackson <daneren2005@gmail.com> | 2013-06-24 21:44:32 -0700 |
commit | ea091214d5ba7369d1c0d56fba42238456019c26 (patch) | |
tree | c2b9a52ac46c0f92190651cdbc1e4d642d22cba7 /subsonic-android | |
parent | 706326a851bb3994f696788b56f641f0f3a15b9a (diff) | |
download | dsub-ea091214d5ba7369d1c0d56fba42238456019c26.tar.gz dsub-ea091214d5ba7369d1c0d56fba42238456019c26.tar.bz2 dsub-ea091214d5ba7369d1c0d56fba42238456019c26.zip |
Added offline starring, removed retry for now
Diffstat (limited to 'subsonic-android')
10 files changed, 95 insertions, 24 deletions
diff --git a/subsonic-android/res/menu/nowplaying_context_offline.xml b/subsonic-android/res/menu/nowplaying_context_offline.xml index 78fa6ba8..1446353f 100644 --- a/subsonic-android/res/menu/nowplaying_context_offline.xml +++ b/subsonic-android/res/menu/nowplaying_context_offline.xml @@ -15,5 +15,9 @@ <item android:id="@+id/menu_delete" - android:title="@string/download.menu_delete"/> + android:title="@string/download.menu_delete"/> + + <item + android:id="@+id/menu_star" + android:title="@string/common.star"/> </menu> diff --git a/subsonic-android/res/values/strings.xml b/subsonic-android/res/values/strings.xml index 74153fc2..150933fd 100644 --- a/subsonic-android/res/values/strings.xml +++ b/subsonic-android/res/values/strings.xml @@ -118,10 +118,12 @@ <string name="select_album.donate_dialog_0_trial_days_left">Trial period is over</string>
<string name="offline.sync_dialog_title">Offline songs waiting to be synced</string>
- <string name="offline.sync_dialog_message">Process %1$d offline scrobbles?</string>
+ <string name="offline.sync_dialog_message">Process %1$d offline scrobbles?
+ \nProcess %2$d offline stars?
+ </string>
<string name="offline.sync_dialog_default">Use action as default</string>
- <string name="offline.sync_success">Successfully scrobbled %1$d songs</string>
- <string name="offline.sync_partial">Successfully scrobbled %1$d of %2$d songs</string>
+ <string name="offline.sync_success">Successfully synced %1$d songs</string>
+ <string name="offline.sync_partial">Successfully synced %1$d of %2$d songs</string>
<string name="offline.sync_error">Failed to sync songs</string>
<string name="select_genre.empty">No genres found</string>
diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/DownloadFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/DownloadFragment.java index 19fccfc3..5e1b503c 100644 --- a/subsonic-android/src/github/daneren2005/dsub/fragments/DownloadFragment.java +++ b/subsonic-android/src/github/daneren2005/dsub/fragments/DownloadFragment.java @@ -149,7 +149,6 @@ public class DownloadFragment extends SubsonicFragment implements OnGestureListe toggleListButton =rootView.findViewById(R.id.download_toggle_list);
starButton = (ImageButton)rootView.findViewById(R.id.download_star);
- starButton.setVisibility(Util.isOffline(context) ? View.GONE : View.VISIBLE);
starButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/MainFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/MainFragment.java index bf8cfdbb..4f7a213e 100644 --- a/subsonic-android/src/github/daneren2005/dsub/fragments/MainFragment.java +++ b/subsonic-android/src/github/daneren2005/dsub/fragments/MainFragment.java @@ -206,9 +206,10 @@ public class MainFragment extends SubsonicFragment { context.getPagerAdapter().invalidate();
if(isOffline) {
- int count = Util.offlineScrobblesCount(context);
- if(count > 0){
- showOfflineSyncDialog(count);
+ int scrobblesCount = Util.offlineScrobblesCount(context);
+ int starsCount = Util.offlineStarsCount(context);
+ if(scrobblesCount > 0 || starsCount > 0){
+ showOfflineSyncDialog(scrobblesCount, starsCount);
}
}
}
@@ -229,11 +230,11 @@ public class MainFragment extends SubsonicFragment { }
}
- private void showOfflineSyncDialog(final int scrobbleCount) {
+ private void showOfflineSyncDialog(final int scrobbleCount, final int starsCount) {
String syncDefault = Util.getSyncDefault(context);
if(syncDefault != null) {
if("sync".equals(syncDefault)) {
- syncOffline(scrobbleCount);
+ syncOffline(scrobbleCount, starsCount);
return;
} else if("delete".equals(syncDefault)) {
deleteOffline();
@@ -247,7 +248,7 @@ public class MainFragment extends SubsonicFragment { AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setIcon(android.R.drawable.ic_dialog_info)
.setTitle(R.string.offline_sync_dialog_title)
- .setMessage(context.getResources().getString(R.string.offline_sync_dialog_message, scrobbleCount))
+ .setMessage(context.getResources().getString(R.string.offline_sync_dialog_message, scrobbleCount, starsCount))
.setView(checkBoxView)
.setPositiveButton(R.string.common_ok, new DialogInterface.OnClickListener() {
@Override
@@ -255,7 +256,7 @@ public class MainFragment extends SubsonicFragment { if(checkBox.isChecked()) {
Util.setSyncDefault(context, "sync");
}
- syncOffline(scrobbleCount);
+ syncOffline(scrobbleCount, starsCount);
}
}).setNeutralButton(R.string.common_cancel, new DialogInterface.OnClickListener() {
@Override
@@ -275,12 +276,12 @@ public class MainFragment extends SubsonicFragment { builder.create().show();
}
- private void syncOffline(final int scrobbleCount) {
+ private void syncOffline(final int scrobbleCount, final int starsCount) {
new SilentBackgroundTask<Integer>(context) {
@Override
protected Integer doInBackground() throws Throwable {
MusicService musicService = MusicServiceFactory.getMusicService(context);
- return musicService.processOfflineScrobbles(context, null);
+ return musicService.processOfflineSyncs(context, null);
}
@Override
@@ -288,7 +289,7 @@ public class MainFragment extends SubsonicFragment { if(result == scrobbleCount) {
Util.toast(context, context.getResources().getString(R.string.offline_sync_success, result));
} else {
- Util.toast(context, context.getResources().getString(R.string.offline_sync_partial, result, scrobbleCount));
+ Util.toast(context, context.getResources().getString(R.string.offline_sync_partial, result, scrobbleCount + starsCount));
}
}
diff --git a/subsonic-android/src/github/daneren2005/dsub/service/CachedMusicService.java b/subsonic-android/src/github/daneren2005/dsub/service/CachedMusicService.java index 59e81c3b..a6d6e8f8 100644 --- a/subsonic-android/src/github/daneren2005/dsub/service/CachedMusicService.java +++ b/subsonic-android/src/github/daneren2005/dsub/service/CachedMusicService.java @@ -303,8 +303,8 @@ public class CachedMusicService implements MusicService { } @Override - public int processOfflineScrobbles(final Context context, final ProgressListener progressListener) throws Exception{ - return musicService.processOfflineScrobbles(context, progressListener); + public int processOfflineSyncs(final Context context, final ProgressListener progressListener) throws Exception{ + return musicService.processOfflineSyncs(context, progressListener); } diff --git a/subsonic-android/src/github/daneren2005/dsub/service/MusicService.java b/subsonic-android/src/github/daneren2005/dsub/service/MusicService.java index 1689835f..c6efffc3 100644 --- a/subsonic-android/src/github/daneren2005/dsub/service/MusicService.java +++ b/subsonic-android/src/github/daneren2005/dsub/service/MusicService.java @@ -118,5 +118,5 @@ public interface MusicService { public MusicDirectory getSongsByGenre(String genre, int count, int offset, Context context, ProgressListener progressListener) throws Exception; - int processOfflineScrobbles(final Context context, final ProgressListener progressListener) throws Exception; + int processOfflineSyncs(final Context context, final ProgressListener progressListener) throws Exception; }
\ No newline at end of file diff --git a/subsonic-android/src/github/daneren2005/dsub/service/OfflineMusicService.java b/subsonic-android/src/github/daneren2005/dsub/service/OfflineMusicService.java index 230b87d3..ba194562 100644 --- a/subsonic-android/src/github/daneren2005/dsub/service/OfflineMusicService.java +++ b/subsonic-android/src/github/daneren2005/dsub/service/OfflineMusicService.java @@ -545,7 +545,26 @@ public class OfflineMusicService extends RESTMusicService { @Override public void setStarred(String id, boolean starred, Context context, ProgressListener progressListener) throws Exception { - throw new OfflineException("Starring not available in offline mode"); + SharedPreferences prefs = Util.getPreferences(context); + String cacheLocn = prefs.getString(Constants.PREFERENCES_KEY_CACHE_LOCATION, null); + + SharedPreferences offline = Util.getOfflineSync(context); + int stars = offline.getInt(Constants.OFFLINE_STAR_COUNT, 0); + stars++; + SharedPreferences.Editor offlineEditor = offline.edit(); + + if(id.indexOf(cacheLocn) != -1) { + String searchCriteria = Util.parseOfflineIDSearch(context, id, cacheLocn); + offlineEditor.putString(Constants.OFFLINE_STAR_SEARCH + stars, searchCriteria); + offlineEditor.remove(Constants.OFFLINE_STAR_ID + stars); + } else { + offlineEditor.putString(Constants.OFFLINE_STAR_ID + stars, id); + offlineEditor.remove(Constants.OFFLINE_STAR_SEARCH + stars); + } + + offlineEditor.putBoolean(Constants.OFFLINE_STAR_SETTING + stars, starred); + offlineEditor.putInt(Constants.OFFLINE_STAR_COUNT, stars); + offlineEditor.commit(); } @Override @@ -578,7 +597,7 @@ public class OfflineMusicService extends RESTMusicService { } @Override - public int processOfflineScrobbles(final Context context, final ProgressListener progressListener) throws Exception{ + public int processOfflineSyncs(final Context context, final ProgressListener progressListener) throws Exception{ throw new OfflineException("Offline scrobble cached can not be processes while in offline mode"); } diff --git a/subsonic-android/src/github/daneren2005/dsub/service/RESTMusicService.java b/subsonic-android/src/github/daneren2005/dsub/service/RESTMusicService.java index fae950c7..e5e41d00 100644 --- a/subsonic-android/src/github/daneren2005/dsub/service/RESTMusicService.java +++ b/subsonic-android/src/github/daneren2005/dsub/service/RESTMusicService.java @@ -885,7 +885,11 @@ public class RESTMusicService implements MusicService { } @Override - public int processOfflineScrobbles(final Context context, final ProgressListener progressListener) throws Exception{ + public int processOfflineSyncs(final Context context, final ProgressListener progressListener) throws Exception{ + return processOfflineScrobbles(context, progressListener) + processOfflineStars(context, progressListener); + } + + public int processOfflineScrobbles(final Context context, final ProgressListener progressListener) throws Exception { SharedPreferences offline = Util.getOfflineSync(context); SharedPreferences.Editor offlineEditor = offline.edit(); int count = offline.getInt(Constants.OFFLINE_SCROBBLE_COUNT, 0); @@ -912,13 +916,47 @@ public class RESTMusicService implements MusicService { catch(Exception e){ Log.e(TAG, e.toString()); retry++; - offlineEditor.putString(Constants.OFFLINE_SCROBBLE_SEARCH + retry, search); - offlineEditor.putLong(Constants.OFFLINE_SCROBBLE_TIME + retry, time); } } } - offlineEditor.putInt(Constants.OFFLINE_SCROBBLE_COUNT, retry); + offlineEditor.putInt(Constants.OFFLINE_SCROBBLE_COUNT, 0); + offlineEditor.commit(); + + return count - retry; + } + + public int processOfflineStars(final Context context, final ProgressListener progressListener) throws Exception { + SharedPreferences offline = Util.getOfflineSync(context); + SharedPreferences.Editor offlineEditor = offline.edit(); + int count = offline.getInt(Constants.OFFLINE_STAR_COUNT, 0); + int retry = 0; + for(int i = 1; i <= count; i++) { + 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, starred, context, progressListener); + } else { + String search = offline.getString(Constants.OFFLINE_STAR_SEARCH + i, ""); + try{ + SearchCritera critera = new SearchCritera(search, 0, 0, 1); + 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(), starred, context, progressListener); + } + else{ + throw new Exception("Song not found on server"); + } + } + catch(Exception e){ + Log.e(TAG, e.toString()); + retry++; + } + } + } + + offlineEditor.putInt(Constants.OFFLINE_STAR_COUNT, 0); offlineEditor.commit(); return count - retry; diff --git a/subsonic-android/src/github/daneren2005/dsub/util/Constants.java b/subsonic-android/src/github/daneren2005/dsub/util/Constants.java index 7c7f67a4..2d7edbab 100644 --- a/subsonic-android/src/github/daneren2005/dsub/util/Constants.java +++ b/subsonic-android/src/github/daneren2005/dsub/util/Constants.java @@ -115,6 +115,10 @@ public final class Constants { public static final String OFFLINE_SCROBBLE_ID = "scrobbleID"; public static final String OFFLINE_SCROBBLE_SEARCH = "scrobbleTitle"; public static final String OFFLINE_SCROBBLE_TIME = "scrobbleTime"; + public static final String OFFLINE_STAR_COUNT = "starCount"; + public static final String OFFLINE_STAR_ID = "starID"; + public static final String OFFLINE_STAR_SEARCH = "starTitle"; + public static final String OFFLINE_STAR_SETTING = "starSetting"; public static final String CACHE_KEY_IGNORE = "ignoreArticles"; diff --git a/subsonic-android/src/github/daneren2005/dsub/util/Util.java b/subsonic-android/src/github/daneren2005/dsub/util/Util.java index b8cc9471..702c732a 100644 --- a/subsonic-android/src/github/daneren2005/dsub/util/Util.java +++ b/subsonic-android/src/github/daneren2005/dsub/util/Util.java @@ -377,6 +377,10 @@ public final class Util { SharedPreferences offline = getOfflineSync(context); return offline.getInt(Constants.OFFLINE_SCROBBLE_COUNT, 0); } + public static int offlineStarsCount(Context context) { + SharedPreferences offline = getOfflineSync(context); + return offline.getInt(Constants.OFFLINE_STAR_COUNT, 0); + } public static String parseOfflineIDSearch(Context context, String id, String cacheLocation) { String name = id.replace(cacheLocation, ""); |