aboutsummaryrefslogtreecommitdiff
path: root/subsonic-android/src/github/daneren2005
diff options
context:
space:
mode:
authorScott Jackson <daneren2005@gmail.com>2013-06-14 20:47:39 -0700
committerScott Jackson <daneren2005@gmail.com>2013-06-14 20:47:39 -0700
commit6aa48f1b3faece3d949cc3980ac405a557bcc9c1 (patch)
treee84a07664b9172bd72f3ea21be7a84251e9ceffc /subsonic-android/src/github/daneren2005
parent8dd5b6136e8ae5dd41a9004617238f87a8d27281 (diff)
downloaddsub-6aa48f1b3faece3d949cc3980ac405a557bcc9c1.tar.gz
dsub-6aa48f1b3faece3d949cc3980ac405a557bcc9c1.tar.bz2
dsub-6aa48f1b3faece3d949cc3980ac405a557bcc9c1.zip
Abstract out search string parsing, use when playing offline mode songs in online mode
Diffstat (limited to 'subsonic-android/src/github/daneren2005')
-rw-r--r--subsonic-android/src/github/daneren2005/dsub/service/OfflineMusicService.java19
-rw-r--r--subsonic-android/src/github/daneren2005/dsub/service/RESTMusicService.java14
-rw-r--r--subsonic-android/src/github/daneren2005/dsub/util/Util.java19
3 files changed, 35 insertions, 17 deletions
diff --git a/subsonic-android/src/github/daneren2005/dsub/service/OfflineMusicService.java b/subsonic-android/src/github/daneren2005/dsub/service/OfflineMusicService.java
index bda112ff..1878fecf 100644
--- a/subsonic-android/src/github/daneren2005/dsub/service/OfflineMusicService.java
+++ b/subsonic-android/src/github/daneren2005/dsub/service/OfflineMusicService.java
@@ -443,25 +443,12 @@ public class OfflineMusicService extends RESTMusicService {
SharedPreferences.Editor offlineEditor = offline.edit();
if(id.indexOf(cacheLocn) != -1) {
- String scrobbleSearchCriteria = id.replace(cacheLocn, "");
- if(scrobbleSearchCriteria.startsWith("/")) {
- scrobbleSearchCriteria = scrobbleSearchCriteria.substring(1);
- }
-
- scrobbleSearchCriteria = scrobbleSearchCriteria.replace(".complete", "").replace(".partial", "");
- int index = scrobbleSearchCriteria.lastIndexOf(".");
- scrobbleSearchCriteria = index == -1 ? scrobbleSearchCriteria : scrobbleSearchCriteria.substring(0, index);
- String[] details = scrobbleSearchCriteria.split("/");
-
- //last.fm only uses artist and track title so broaden the search by just using those. doesn't matter if it find the track on a different album
- String artist = "artist:\"" + details[0] + "\"";
- String title = details[details.length - 1];
- title = "title:\"" + title.substring(title.indexOf('-') + 1) + "\"";
-
- scrobbleSearchCriteria = artist + " AND " + title;
+ String scrobbleSearchCriteria = Util.parseOfflineIDSearch(context, id, cacheLocn);
offlineEditor.putString(Constants.OFFLINE_SCROBBLE_SEARCH + scrobbles, scrobbleSearchCriteria);
+ offlineEditor.remove(Constants.OFFLINE_SCROBBLE_ID + scrobbles);
} else {
offlineEditor.putString(Constants.OFFLINE_SCROBBLE_ID + scrobbles, id);
+ offlineEditor.remove(Constants.OFFLINE_SCROBBLE_SEARCH + scrobbles);
}
offlineEditor.putLong(Constants.OFFLINE_SCROBBLE_TIME + scrobbles, System.currentTimeMillis());
diff --git a/subsonic-android/src/github/daneren2005/dsub/service/RESTMusicService.java b/subsonic-android/src/github/daneren2005/dsub/service/RESTMusicService.java
index 53eccf71..249efc10 100644
--- a/subsonic-android/src/github/daneren2005/dsub/service/RESTMusicService.java
+++ b/subsonic-android/src/github/daneren2005/dsub/service/RESTMusicService.java
@@ -491,7 +491,19 @@ public class RESTMusicService implements MusicService {
@Override
public void scrobble(String id, boolean submission, Context context, ProgressListener progressListener) throws Exception {
- scrobble(id, submission, 0, context, progressListener);
+ SharedPreferences prefs = Util.getPreferences(context);
+ String cacheLocn = prefs.getString(Constants.PREFERENCES_KEY_CACHE_LOCATION, null);
+
+ if(id.indexOf(cacheLocn) != -1 && submission) {
+ String scrobbleSearchCriteria = Util.parseOfflineIDSearch(context, id, cacheLocn);
+ SearchCritera critera = new SearchCritera(scrobbleSearchCriteria, 0, 0, 1);
+ SearchResult result = searchNew(critera, context, progressListener);
+ if(result.getSongs().size() == 1){
+ scrobble(result.getSongs().get(0).getId(), true, 0, context, progressListener);
+ }
+ } else {
+ scrobble(id, submission, 0, context, progressListener);
+ }
}
public void scrobble(String id, boolean submission, long time, Context context, ProgressListener progressListener) throws Exception {
diff --git a/subsonic-android/src/github/daneren2005/dsub/util/Util.java b/subsonic-android/src/github/daneren2005/dsub/util/Util.java
index 76bf6a04..25e7c690 100644
--- a/subsonic-android/src/github/daneren2005/dsub/util/Util.java
+++ b/subsonic-android/src/github/daneren2005/dsub/util/Util.java
@@ -340,6 +340,25 @@ public final class Util {
SharedPreferences offline = getOfflineSync(context);
return offline.getInt(Constants.OFFLINE_SCROBBLE_COUNT, 0);
}
+
+ public static String parseOfflineIDSearch(Context context, String id, String cacheLocation) {
+ String name = id.replace(cacheLocation, "");
+ if(name.startsWith("/")) {
+ name = name.substring(1);
+ }
+ name = name.replace(".complete", "").replace(".partial", "");
+ int index = name.lastIndexOf(".");
+ name = index == -1 ? name : name.substring(0, index);
+ String[] details = name.split("/");
+
+ String artist = "artist:\"" + details[0] + "\"";
+ String title = details[details.length - 1];
+ title = "title:\"" + title.substring(title.indexOf('-') + 1) + "\"";
+
+ name = artist + " AND " + title;
+
+ return name;
+ }
public static String getContentType(HttpEntity entity) {
if (entity == null || entity.getContentType() == null) {