From 43fa167ca8b9ffbcd73711a8853fe67ebf4a78a7 Mon Sep 17 00:00:00 2001 From: Tom Briden Date: Wed, 5 Jun 2013 14:38:27 +0100 Subject: Added hasOfflineScrobbles function to MusicService so the fragment can query and if the file exists can prompt to process ignore or delete --- .../dsub/fragments/SelectDirectoryFragment.java | 7 +- .../dsub/service/CachedMusicService.java | 8 ++ .../daneren2005/dsub/service/MusicService.java | 2 + .../dsub/service/OfflineMusicService.java | 13 ++- .../daneren2005/dsub/service/RESTMusicService.java | 108 +++++++++++---------- 5 files changed, 79 insertions(+), 59 deletions(-) diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java index 13f61625..65b11e21 100644 --- a/subsonic-android/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java +++ b/subsonic-android/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java @@ -347,6 +347,11 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Adapter protected Pair doInBackground() throws Throwable { 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); return new Pair(dir, valid); } @@ -692,4 +697,4 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Adapter return null; } } -} \ No newline at end of file +} diff --git a/subsonic-android/src/github/daneren2005/dsub/service/CachedMusicService.java b/subsonic-android/src/github/daneren2005/dsub/service/CachedMusicService.java index 314f065e..24132bea 100644 --- a/subsonic-android/src/github/daneren2005/dsub/service/CachedMusicService.java +++ b/subsonic-android/src/github/daneren2005/dsub/service/CachedMusicService.java @@ -38,6 +38,7 @@ import github.daneren2005.dsub.domain.SearchResult; import github.daneren2005.dsub.domain.Share; import github.daneren2005.dsub.domain.Version; import github.daneren2005.dsub.util.CancellableTask; +import github.daneren2005.dsub.util.FileUtil; import github.daneren2005.dsub.util.LRUCache; import github.daneren2005.dsub.util.ProgressListener; import github.daneren2005.dsub.util.TimeLimitedCache; @@ -295,6 +296,13 @@ public class CachedMusicService implements MusicService { public MusicDirectory getSongsByGenre(String genre, int count, int offset, Context context, ProgressListener progressListener) throws Exception { return musicService.getSongsByGenre(genre, count, offset, context, progressListener); } + + @Override + public boolean hasOfflineScrobbles(){ + return musicService.hasOfflineScrobbles(); + } + + private void checkSettingsChanged(Context context) { String newUrl = Util.getRestUrl(context, null); diff --git a/subsonic-android/src/github/daneren2005/dsub/service/MusicService.java b/subsonic-android/src/github/daneren2005/dsub/service/MusicService.java index f69ebfb1..1b769fa6 100644 --- a/subsonic-android/src/github/daneren2005/dsub/service/MusicService.java +++ b/subsonic-android/src/github/daneren2005/dsub/service/MusicService.java @@ -115,4 +115,6 @@ public interface MusicService { List getGenres(boolean refresh, Context context, ProgressListener progressListener) throws Exception; public MusicDirectory getSongsByGenre(String genre, int count, int offset, Context context, ProgressListener progressListener) throws Exception; + + boolean hasOfflineScrobbles(); } \ 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 9b4dde92..4fa026c0 100644 --- a/subsonic-android/src/github/daneren2005/dsub/service/OfflineMusicService.java +++ b/subsonic-android/src/github/daneren2005/dsub/service/OfflineMusicService.java @@ -19,8 +19,6 @@ package github.daneren2005.dsub.service; import java.io.File; -import java.io.FileInputStream; -import java.io.InputStream; import java.io.Reader; import java.io.FileReader; import java.util.ArrayList; @@ -34,9 +32,6 @@ import java.util.Set; import android.content.Context; import android.content.SharedPreferences; import android.graphics.Bitmap; -import android.graphics.BitmapFactory; -import android.media.MediaMetadataRetriever; -import android.os.Environment; import android.util.Log; import github.daneren2005.dsub.domain.Artist; import github.daneren2005.dsub.domain.Genre; @@ -48,7 +43,6 @@ import github.daneren2005.dsub.domain.MusicFolder; import github.daneren2005.dsub.domain.Playlist; import github.daneren2005.dsub.domain.SearchCritera; import github.daneren2005.dsub.domain.SearchResult; -import github.daneren2005.dsub.service.parser.PlaylistParser; import github.daneren2005.dsub.util.Constants; import github.daneren2005.dsub.util.FileUtil; import github.daneren2005.dsub.util.ProgressListener; @@ -516,6 +510,11 @@ public class OfflineMusicService extends RESTMusicService { return result; } + + @Override + public boolean hasOfflineScrobbles(){ + return false; + } private void listFilesRecursively(File parent, List children) { for (File file : FileUtil.listMediaFiles(parent)) { @@ -526,4 +525,4 @@ public class OfflineMusicService extends RESTMusicService { } } } -} +} \ No newline at end of file diff --git a/subsonic-android/src/github/daneren2005/dsub/service/RESTMusicService.java b/subsonic-android/src/github/daneren2005/dsub/service/RESTMusicService.java index e0bffc57..e609e033 100644 --- a/subsonic-android/src/github/daneren2005/dsub/service/RESTMusicService.java +++ b/subsonic-android/src/github/daneren2005/dsub/service/RESTMusicService.java @@ -162,57 +162,7 @@ public class RESTMusicService implements MusicService { Log.e(TAG, "Failed to create custom SSL socket factory, using default.", x); return org.apache.http.conn.ssl.SSLSocketFactory.getSocketFactory(); } - } - - public void processOfflineScrobbles(final Context context, final ProgressListener progressListener){ - File offlineScrobblesFile = FileUtil.getOfflineScrobblesFile(); - try{ - - BufferedReader br = new BufferedReader(new FileReader(offlineScrobblesFile)); - String line; - - ArrayList lines = new ArrayList(); - while ((line = br.readLine()) != null) { - lines.add(line); - } - br.close(); - offlineScrobblesFile.delete(); - - //TODO make a prompt: "Found " + lines.size() + " offline scrobbles. Scrobble? Ignore? Clear File?" - for(int i = 0; i < lines.size(); i++){ - line = lines.get(i); - String filename = line.substring(0, line.lastIndexOf(',')); - - try{ - long time = Long.parseLong(line.substring(line.lastIndexOf(',')+1)); - SearchCritera critera = new SearchCritera(filename, 0, 0, 1); - SearchResult result = searchNew(critera, context, progressListener); - if(result.getSongs().size() == 1){ - Log.i(TAG, "Query '" + filename + "' returned song " + result.getSongs().get(0).getTitle() + " by " + result.getSongs().get(0).getArtist() + " with id " + result.getSongs().get(0).getId()); - Log.i(TAG, "Scrobbling " + result.getSongs().get(0).getId() + " with time " + time); - scrobble(result.getSongs().get(0).getId(), true, time, context, progressListener); - } - else{ - throw new Exception("Song not found on server"); - } - } - catch(Exception e){ - Log.e(TAG, e.toString()); - BufferedWriter bw = new BufferedWriter(new FileWriter(offlineScrobblesFile, true)); - bw.write(line); - bw.newLine(); - bw.flush(); - bw.close(); - } - } - } - catch(FileNotFoundException fnfe){ - //ignore, we dont care - } - catch(Exception e){ - Log.e(TAG, e.toString()); - } - } + } @Override public void ping(Context context, ProgressListener progressListener) throws Exception { @@ -891,6 +841,62 @@ public class RESTMusicService implements MusicService { Util.close(reader); } } + + @Override + public boolean hasOfflineScrobbles(){ + return FileUtil.getOfflineScrobblesFile().exists(); + } + + public void processOfflineScrobbles(final Context context, final ProgressListener progressListener){ + File offlineScrobblesFile = FileUtil.getOfflineScrobblesFile(); + try{ + + BufferedReader br = new BufferedReader(new FileReader(offlineScrobblesFile)); + String line; + + ArrayList lines = new ArrayList(); + while ((line = br.readLine()) != null) { + lines.add(line); + } + br.close(); + offlineScrobblesFile.delete(); + + for(int i = 0; i < lines.size(); i++){ + line = lines.get(i); + String filename = line.substring(0, line.lastIndexOf(',')); + + try{ + long time = Long.parseLong(line.substring(line.lastIndexOf(',')+1)); + SearchCritera critera = new SearchCritera(filename, 0, 0, 1); + SearchResult result = searchNew(critera, context, progressListener); + if(result.getSongs().size() == 1){ + Log.i(TAG, "Query '" + filename + "' returned song " + result.getSongs().get(0).getTitle() + " by " + result.getSongs().get(0).getArtist() + " with id " + result.getSongs().get(0).getId()); + Log.i(TAG, "Scrobbling " + result.getSongs().get(0).getId() + " with time " + time); + scrobble(result.getSongs().get(0).getId(), true, time, context, progressListener); + } + else{ + throw new Exception("Song not found on server"); + } + } + catch(Exception e){ + Log.e(TAG, e.toString()); + BufferedWriter bw = new BufferedWriter(new FileWriter(offlineScrobblesFile, true)); + bw.write(line); + bw.newLine(); + bw.flush(); + bw.close(); + } + } + } + catch(FileNotFoundException fnfe){ + //ignore, we dont care + } + catch(Exception e){ + Log.e(TAG, e.toString()); + } + } + + private Reader getReader(Context context, ProgressListener progressListener, String method, HttpParams requestParams) throws Exception { return getReader(context, progressListener, method, requestParams, Collections.emptyList(), Collections.emptyList()); -- cgit v1.2.3