diff options
author | Tom Briden <tom.briden@veritape.com> | 2013-06-05 15:45:37 +0100 |
---|---|---|
committer | Tom Briden <tom.briden@veritape.com> | 2013-06-05 15:45:37 +0100 |
commit | ad6c9503cbb56eda5b0ff3a0060b625f827e753c (patch) | |
tree | 369576f8f120ae61322e54d10f84af9b660a5834 /subsonic-android/src/github/daneren2005 | |
parent | 43fa167ca8b9ffbcd73711a8853fe67ebf4a78a7 (diff) | |
download | dsub-ad6c9503cbb56eda5b0ff3a0060b625f827e753c.tar.gz dsub-ad6c9503cbb56eda5b0ff3a0060b625f827e753c.tar.bz2 dsub-ad6c9503cbb56eda5b0ff3a0060b625f827e753c.zip |
Added dialog when offline scrobble file found to scrobble now, ignore or just delete it
Made processOfflineScrobbles a musicservice function so it can be called from fragment
Diffstat (limited to 'subsonic-android/src/github/daneren2005')
5 files changed, 74 insertions, 12 deletions
diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java index 65b11e21..c4da3070 100644 --- a/subsonic-android/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java +++ b/subsonic-android/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java @@ -27,6 +27,7 @@ import github.daneren2005.dsub.service.MusicServiceFactory; import github.daneren2005.dsub.service.OfflineException;
import github.daneren2005.dsub.service.ServerTooOldException;
import github.daneren2005.dsub.util.Constants;
+import github.daneren2005.dsub.util.FileUtil;
import github.daneren2005.dsub.util.LoadingTask;
import github.daneren2005.dsub.util.Pair;
import github.daneren2005.dsub.util.TabBackgroundTask;
@@ -276,6 +277,12 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Adapter } else {
getMusicDirectory(id, name, refresh);
}
+
+ //this may be done better elsewhere but it works for now :)
+ MusicService musicService = MusicServiceFactory.getMusicService(context);
+ if(musicService.hasOfflineScrobbles()){
+ showOfflineScrobblesDialog();
+ }
}
private void getMusicDirectory(final String id, final String name, final boolean refresh) {
@@ -345,14 +352,9 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Adapter @Override
protected Pair<MusicDirectory, Boolean> doInBackground() throws Throwable {
- MusicService musicService = MusicServiceFactory.getMusicService(context);
+ MusicService musicService = MusicServiceFactory.getMusicService(context);
MusicDirectory dir = load(musicService);
- //this may be done better elsewhere but i'm guessing licence is checked infrequently enough for it to be ok here
- if(musicService.hasOfflineScrobbles()){
-
- }
-
- boolean valid = musicService.isLicenseValid(context, this);
+ boolean valid = musicService.isLicenseValid(context, this);
return new Pair<MusicDirectory, Boolean>(dir, valid);
}
@@ -640,6 +642,56 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Adapter builder.create().show();
}
+
+ private void showOfflineScrobblesDialog() {
+
+
+ AlertDialog.Builder builder = new AlertDialog.Builder(context);
+ builder.setIcon(android.R.drawable.ic_dialog_info);
+
+ builder.setTitle(R.string.select_album_offline_scrobbles_dialog_title);
+
+ builder.setMessage(R.string.select_album_offline_scrobbles_dialog_message);
+
+ //want this on the left and delete on the right hence the backwards button types
+ builder.setNegativeButton(R.string.select_album_offline_scrobbles_dialog_yes,
+
+ new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialogInterface, int i) {
+ new Thread("Scrobble offline") {
+ @Override
+ public void run() {
+ try {
+ MusicService musicService = MusicServiceFactory.getMusicService(context);
+ musicService.processOfflineScrobbles(context, null);
+ } catch (Exception x) {
+ Log.i(TAG, "Failed to process offline sc/robbles");
+ }
+ }
+ }.start();
+ }
+ });
+
+ builder.setPositiveButton(R.string.select_album_offline_scrobbles_dialog_delete,
+ new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialogInterface, int i) {
+ dialogInterface.dismiss();
+ FileUtil.getOfflineScrobblesFile().delete();
+ }
+ });
+
+ builder.setNeutralButton(R.string.select_album_offline_scrobbles_dialog_no,
+ new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialogInterface, int i) {
+ dialogInterface.dismiss();
+ }
+ });
+
+ builder.create().show();
+ }
private View createHeader(List<MusicDirectory.Entry> entries) {
View header = entryList.findViewById(R.id.select_album_header);
diff --git a/subsonic-android/src/github/daneren2005/dsub/service/CachedMusicService.java b/subsonic-android/src/github/daneren2005/dsub/service/CachedMusicService.java index 24132bea..49542045 100644 --- a/subsonic-android/src/github/daneren2005/dsub/service/CachedMusicService.java +++ b/subsonic-android/src/github/daneren2005/dsub/service/CachedMusicService.java @@ -301,6 +301,11 @@ public class CachedMusicService implements MusicService { public boolean hasOfflineScrobbles(){ return musicService.hasOfflineScrobbles(); } + + @Override + public void processOfflineScrobbles(final Context context, final ProgressListener progressListener) throws Exception{ + musicService.processOfflineScrobbles(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 1b769fa6..c99551b4 100644 --- a/subsonic-android/src/github/daneren2005/dsub/service/MusicService.java +++ b/subsonic-android/src/github/daneren2005/dsub/service/MusicService.java @@ -117,4 +117,6 @@ public interface MusicService { public MusicDirectory getSongsByGenre(String genre, int count, int offset, Context context, ProgressListener progressListener) throws Exception; boolean hasOfflineScrobbles(); + + void processOfflineScrobbles(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 4fa026c0..c2a85488 100644 --- a/subsonic-android/src/github/daneren2005/dsub/service/OfflineMusicService.java +++ b/subsonic-android/src/github/daneren2005/dsub/service/OfflineMusicService.java @@ -515,6 +515,11 @@ public class OfflineMusicService extends RESTMusicService { public boolean hasOfflineScrobbles(){ return false; } + + @Override + public void processOfflineScrobbles(final Context context, final ProgressListener progressListener) throws Exception{ + throw new OfflineException("Offline scrobble cached can not be processes while in offline mode"); + } private void listFilesRecursively(File parent, List<File> children) { for (File file : FileUtil.listMediaFiles(parent)) { diff --git a/subsonic-android/src/github/daneren2005/dsub/service/RESTMusicService.java b/subsonic-android/src/github/daneren2005/dsub/service/RESTMusicService.java index e609e033..27a51145 100644 --- a/subsonic-android/src/github/daneren2005/dsub/service/RESTMusicService.java +++ b/subsonic-android/src/github/daneren2005/dsub/service/RESTMusicService.java @@ -177,10 +177,7 @@ public class RESTMusicService implements MusicService { @Override public boolean isLicenseValid(Context context, ProgressListener progressListener) throws Exception { - //TODO run on a thread - processOfflineScrobbles(context, progressListener); - - Reader reader = getReader(context, progressListener, "getLicense", null); + Reader reader = getReader(context, progressListener, "getLicense", null); try { ServerInfo serverInfo = new LicenseParser(context).parse(reader); return serverInfo.isLicenseValid(); @@ -847,7 +844,8 @@ public class RESTMusicService implements MusicService { return FileUtil.getOfflineScrobblesFile().exists(); } - public void processOfflineScrobbles(final Context context, final ProgressListener progressListener){ + @Override + public void processOfflineScrobbles(final Context context, final ProgressListener progressListener) throws Exception{ File offlineScrobblesFile = FileUtil.getOfflineScrobblesFile(); try{ |