diff options
6 files changed, 79 insertions, 12 deletions
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 @@ <string name="select_album.donate_dialog_now">Now</string>
<string name="select_album.donate_dialog_later">Later</string>
<string name="select_album.donate_dialog_0_trial_days_left">Trial period is over</string>
+ <string name="select_album.offline_scrobbles_dialog_title">Offline scrobbles file found.</string>
+ <string name="select_album.offline_scrobbles_dialog_message">Process offline scrobbles file?</string>
+ <string name="select_album.offline_scrobbles_dialog_yes">Yes</string>
+ <string name="select_album.offline_scrobbles_dialog_no">No</string>
+ <string name="select_album.offline_scrobbles_dialog_delete">Delete file<string>
<string name="select_genre.empty">No genres found</string>
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{ |