aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java/github
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/java/github')
-rw-r--r--app/src/main/java/github/daneren2005/dsub/service/OfflineMusicService.java14
-rw-r--r--app/src/main/java/github/daneren2005/dsub/service/RESTMusicService.java18
-rw-r--r--app/src/main/java/github/daneren2005/dsub/util/SongDBHandler.java2
3 files changed, 25 insertions, 9 deletions
diff --git a/app/src/main/java/github/daneren2005/dsub/service/OfflineMusicService.java b/app/src/main/java/github/daneren2005/dsub/service/OfflineMusicService.java
index c8253c91..11a723ce 100644
--- a/app/src/main/java/github/daneren2005/dsub/service/OfflineMusicService.java
+++ b/app/src/main/java/github/daneren2005/dsub/service/OfflineMusicService.java
@@ -56,8 +56,10 @@ import github.daneren2005.dsub.domain.Share;
import github.daneren2005.dsub.domain.User;
import github.daneren2005.dsub.util.Constants;
import github.daneren2005.dsub.util.FileUtil;
+import github.daneren2005.dsub.util.Pair;
import github.daneren2005.dsub.util.ProgressListener;
import github.daneren2005.dsub.util.SilentBackgroundTask;
+import github.daneren2005.dsub.util.SongDBHandler;
import github.daneren2005.dsub.util.Util;
import java.io.*;
import java.util.Comparator;
@@ -556,9 +558,15 @@ public class OfflineMusicService implements MusicService {
SharedPreferences.Editor offlineEditor = offline.edit();
if(id.indexOf(cacheLocn) != -1) {
- String scrobbleSearchCriteria = Util.parseOfflineIDSearch(context, id, cacheLocn);
- offlineEditor.putString(Constants.OFFLINE_SCROBBLE_SEARCH + scrobbles, scrobbleSearchCriteria);
- offlineEditor.remove(Constants.OFFLINE_SCROBBLE_ID + scrobbles);
+ Pair<Integer, String> cachedSongId = SongDBHandler.getHandler(context).getIdFromPath(id);
+ if(cachedSongId != null) {
+ offlineEditor.putString(Constants.OFFLINE_SCROBBLE_ID + scrobbles, cachedSongId.getSecond());
+ offlineEditor.remove(Constants.OFFLINE_SCROBBLE_SEARCH + scrobbles);
+ } else {
+ 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);
diff --git a/app/src/main/java/github/daneren2005/dsub/service/RESTMusicService.java b/app/src/main/java/github/daneren2005/dsub/service/RESTMusicService.java
index 9ec77897..9af512e3 100644
--- a/app/src/main/java/github/daneren2005/dsub/service/RESTMusicService.java
+++ b/app/src/main/java/github/daneren2005/dsub/service/RESTMusicService.java
@@ -69,6 +69,7 @@ import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Looper;
import android.util.Log;
+
import github.daneren2005.dsub.R;
import github.daneren2005.dsub.domain.*;
import github.daneren2005.dsub.service.parser.AlbumListParser;
@@ -99,10 +100,12 @@ import github.daneren2005.dsub.service.parser.VideosParser;
import github.daneren2005.dsub.service.ssl.SSLSocketFactory;
import github.daneren2005.dsub.service.ssl.TrustSelfSignedStrategy;
import github.daneren2005.dsub.util.BackgroundTask;
+import github.daneren2005.dsub.util.Pair;
import github.daneren2005.dsub.util.SilentBackgroundTask;
import github.daneren2005.dsub.util.Constants;
import github.daneren2005.dsub.util.FileUtil;
import github.daneren2005.dsub.util.ProgressListener;
+import github.daneren2005.dsub.util.SongDBHandler;
import github.daneren2005.dsub.util.Util;
import java.io.*;
import java.util.zip.GZIPInputStream;
@@ -1796,11 +1799,16 @@ public class RESTMusicService implements MusicService {
SharedPreferences prefs = Util.getPreferences(context);
String cacheLocn = prefs.getString(Constants.PREFERENCES_KEY_CACHE_LOCATION, null);
if(cacheLocn != null && id.indexOf(cacheLocn) != -1) {
- String searchCriteria = Util.parseOfflineIDSearch(context, id, cacheLocn);
- SearchCritera critera = new SearchCritera(searchCriteria, 0, 0, 1);
- SearchResult result = searchNew(critera, context, progressListener);
- if(result.getSongs().size() == 1){
- id = result.getSongs().get(0).getId();
+ Pair<Integer, String> cachedSongId = SongDBHandler.getHandler(context).getIdFromPath(Util.getRestUrlHash(context, getInstance(context)), id);
+ if(cachedSongId != null) {
+ id = cachedSongId.getSecond();
+ } else {
+ String searchCriteria = Util.parseOfflineIDSearch(context, id, cacheLocn);
+ SearchCritera critera = new SearchCritera(searchCriteria, 0, 0, 1);
+ SearchResult result = searchNew(critera, context, progressListener);
+ if (result.getSongs().size() == 1) {
+ id = result.getSongs().get(0).getId();
+ }
}
}
diff --git a/app/src/main/java/github/daneren2005/dsub/util/SongDBHandler.java b/app/src/main/java/github/daneren2005/dsub/util/SongDBHandler.java
index ba0851c2..63de6d48 100644
--- a/app/src/main/java/github/daneren2005/dsub/util/SongDBHandler.java
+++ b/app/src/main/java/github/daneren2005/dsub/util/SongDBHandler.java
@@ -152,7 +152,7 @@ public class SongDBHandler extends SQLiteOpenHelper {
public Pair<Integer, String> getOnlineSongId(int serverKey, DownloadFile downloadFile) {
return getOnlineSongId(serverKey, downloadFile.getSong().getId(), downloadFile.getSaveFile().getAbsolutePath(), true);
}
- protected Pair<Integer, String> getOnlineSongId(int serverKey, String id, String savePath, boolean requireServerKey) {
+ public Pair<Integer, String> getOnlineSongId(int serverKey, String id, String savePath, boolean requireServerKey) {
SharedPreferences prefs = Util.getPreferences(context);
String cacheLocn = prefs.getString(Constants.PREFERENCES_KEY_CACHE_LOCATION, null);
if(cacheLocn != null && id.indexOf(cacheLocn) != -1) {