From ad6c9503cbb56eda5b0ff3a0060b625f827e753c Mon Sep 17 00:00:00 2001 From: Tom Briden Date: Wed, 5 Jun 2013 15:45:37 +0100 Subject: 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 --- subsonic-android/res/values/strings.xml | 5 ++ .../dsub/fragments/SelectDirectoryFragment.java | 66 +++++++++++++++++++--- .../dsub/service/CachedMusicService.java | 5 ++ .../daneren2005/dsub/service/MusicService.java | 2 + .../dsub/service/OfflineMusicService.java | 5 ++ .../daneren2005/dsub/service/RESTMusicService.java | 8 +-- 6 files changed, 79 insertions(+), 12 deletions(-) (limited to 'subsonic-android') diff --git a/subsonic-android/res/values/strings.xml b/subsonic-android/res/values/strings.xml index b5e8f3e1..5aa09d76 100644 --- a/subsonic-android/res/values/strings.xml +++ b/subsonic-android/res/values/strings.xml @@ -114,6 +114,11 @@ Now Later Trial period is over + Offline scrobbles file found. + Process offline scrobbles file? + Yes + No + Delete file No genres found 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 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(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 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 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{ -- cgit v1.2.3