Merge pull request #43 from dddddd-mmmmmm/master
#37 Use query parameters instead of body
This commit is contained in:
commit
625f7ba97e
|
@ -16,6 +16,7 @@
|
||||||
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
|
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
|
||||||
<uses-permission android:name="android.permission.CHANGE_WIFI_MULTICAST_STATE" />
|
<uses-permission android:name="android.permission.CHANGE_WIFI_MULTICAST_STATE" />
|
||||||
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
|
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
|
||||||
|
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
|
||||||
<uses-permission
|
<uses-permission
|
||||||
android:name="android.permission.READ_PHONE_STATE"
|
android:name="android.permission.READ_PHONE_STATE"
|
||||||
android:maxSdkVersion="22" />
|
android:maxSdkVersion="22" />
|
||||||
|
|
|
@ -640,12 +640,12 @@ public class CachedMusicService implements MusicService {
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getCacheName(Context context, String name, String id) {
|
private String getCacheName(Context context, String name, String id) {
|
||||||
String s = musicService.getRestUrl(context, null, false) + id;
|
String s = musicService.getRestUrl(context, null, false, null) + id;
|
||||||
return name + "-" + s.hashCode() + ".ser";
|
return name + "-" + s.hashCode() + ".ser";
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getCacheName(Context context, String name) {
|
private String getCacheName(Context context, String name) {
|
||||||
String s = musicService.getRestUrl(context, null, false);
|
String s = musicService.getRestUrl(context, null, false, null);
|
||||||
return name + "-" + s.hashCode() + ".ser";
|
return name + "-" + s.hashCode() + ".ser";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -672,7 +672,7 @@ public class CachedMusicService implements MusicService {
|
||||||
|
|
||||||
private void checkSettingsChanged(Context context) {
|
private void checkSettingsChanged(Context context) {
|
||||||
int instance = musicService.getInstance(context);
|
int instance = musicService.getInstance(context);
|
||||||
String newUrl = musicService.getRestUrl(context, null, false);
|
String newUrl = musicService.getRestUrl(context, null, false, null);
|
||||||
if (!Util.equals(newUrl, restUrl)) {
|
if (!Util.equals(newUrl, restUrl)) {
|
||||||
cachedMusicFolders.clear();
|
cachedMusicFolders.clear();
|
||||||
cachedIndexes.clear();
|
cachedIndexes.clear();
|
||||||
|
|
|
@ -21,6 +21,7 @@ package net.nullsum.audinaut.service;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import net.nullsum.audinaut.domain.Genre;
|
import net.nullsum.audinaut.domain.Genre;
|
||||||
|
@ -54,7 +55,9 @@ import net.nullsum.audinaut.util.Util;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import okhttp3.FormBody;
|
import okhttp3.FormBody;
|
||||||
|
@ -75,7 +78,7 @@ public class RESTMusicService implements MusicService {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void ping(Context context, ProgressListener progressListener) throws Exception {
|
public void ping(Context context, ProgressListener progressListener) throws Exception {
|
||||||
String url = getRestUrl(context, "ping");
|
String url = getRestUrl(context, "ping", null);
|
||||||
|
|
||||||
Request request = new Request.Builder()
|
Request request = new Request.Builder()
|
||||||
.url(url)
|
.url(url)
|
||||||
|
@ -87,7 +90,7 @@ public class RESTMusicService implements MusicService {
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<MusicFolder> getMusicFolders(boolean refresh, Context context, ProgressListener progressListener) throws Exception {
|
public List<MusicFolder> getMusicFolders(boolean refresh, Context context, ProgressListener progressListener) throws Exception {
|
||||||
String url = getRestUrl(context, "getMusicFolders");
|
String url = getRestUrl(context, "getMusicFolders", null);
|
||||||
|
|
||||||
Request request = new Request.Builder()
|
Request request = new Request.Builder()
|
||||||
.url(url)
|
.url(url)
|
||||||
|
@ -100,19 +103,21 @@ public class RESTMusicService implements MusicService {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Indexes getIndexes(String musicFolderId, boolean refresh, Context context, ProgressListener progressListener) throws Exception {
|
public Indexes getIndexes(String musicFolderId, boolean refresh, Context context, ProgressListener progressListener) throws Exception {
|
||||||
String url = getRestUrl(context, "getArtists");
|
|
||||||
|
|
||||||
Builder builder = new FormBody.Builder();
|
|
||||||
|
|
||||||
|
Map<String, String> parameters = new HashMap<>();
|
||||||
|
|
||||||
if (musicFolderId != null) {
|
if (musicFolderId != null) {
|
||||||
builder.add("musicFolderId", musicFolderId);
|
parameters.put("musicFolderId", musicFolderId);
|
||||||
|
} else {
|
||||||
|
parameters = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
RequestBody formBody = builder.build();
|
String url = getRestUrl(context, "getArtists", parameters);
|
||||||
|
|
||||||
Request request = new Request.Builder()
|
Request request = new Request.Builder()
|
||||||
.url(url)
|
.url(url)
|
||||||
.post(formBody)
|
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
try (Response response = client.newCall(request).execute()) {
|
try (Response response = client.newCall(request).execute()) {
|
||||||
|
@ -158,15 +163,14 @@ public class RESTMusicService implements MusicService {
|
||||||
}
|
}
|
||||||
|
|
||||||
private MusicDirectory getMusicDirectoryImpl(String id, String name, Context context) throws Exception {
|
private MusicDirectory getMusicDirectoryImpl(String id, String name, Context context) throws Exception {
|
||||||
String url = getRestUrl(context, "getMusicDirectory");
|
Map<String, String> parameters = new HashMap<>();
|
||||||
|
|
||||||
RequestBody formBody = new FormBody.Builder()
|
parameters.put("id", id);
|
||||||
.add("id", id)
|
|
||||||
.build();
|
String url = getRestUrl(context, "getMusicDirectory", parameters);
|
||||||
|
|
||||||
Request request = new Request.Builder()
|
Request request = new Request.Builder()
|
||||||
.url(url)
|
.url(url)
|
||||||
.post(formBody)
|
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
try (Response response = client.newCall(request).execute()) {
|
try (Response response = client.newCall(request).execute()) {
|
||||||
|
@ -176,15 +180,15 @@ public class RESTMusicService implements MusicService {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MusicDirectory getArtist(String id, String name, boolean refresh, Context context, ProgressListener progressListener) throws Exception {
|
public MusicDirectory getArtist(String id, String name, boolean refresh, Context context, ProgressListener progressListener) throws Exception {
|
||||||
String url = getRestUrl(context, "getArtist");
|
|
||||||
|
|
||||||
RequestBody formBody = new FormBody.Builder()
|
Map<String, String> parameters = new HashMap<>();
|
||||||
.add("id", id)
|
|
||||||
.build();
|
parameters.put("id", id);
|
||||||
|
|
||||||
|
String url = getRestUrl(context, "getArtist", parameters);
|
||||||
|
|
||||||
Request request = new Request.Builder()
|
Request request = new Request.Builder()
|
||||||
.url(url)
|
.url(url)
|
||||||
.post(formBody)
|
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
try (Response response = client.newCall(request).execute()) {
|
try (Response response = client.newCall(request).execute()) {
|
||||||
|
@ -194,15 +198,14 @@ public class RESTMusicService implements MusicService {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MusicDirectory getAlbum(String id, String name, boolean refresh, Context context, ProgressListener progressListener) throws Exception {
|
public MusicDirectory getAlbum(String id, String name, boolean refresh, Context context, ProgressListener progressListener) throws Exception {
|
||||||
String url = getRestUrl(context, "getAlbum");
|
Map<String, String> parameters = new HashMap<>();
|
||||||
|
|
||||||
RequestBody formBody = new FormBody.Builder()
|
parameters.put("id", id);
|
||||||
.add("id", id)
|
|
||||||
.build();
|
String url = getRestUrl(context, "getAlbum", parameters);
|
||||||
|
|
||||||
Request request = new Request.Builder()
|
Request request = new Request.Builder()
|
||||||
.url(url)
|
.url(url)
|
||||||
.post(formBody)
|
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
try (Response response = client.newCall(request).execute()) {
|
try (Response response = client.newCall(request).execute()) {
|
||||||
|
@ -212,20 +215,17 @@ public class RESTMusicService implements MusicService {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SearchResult search(SearchCritera critera, Context context, ProgressListener progressListener) throws Exception {
|
public SearchResult search(SearchCritera critera, Context context, ProgressListener progressListener) throws Exception {
|
||||||
String url = getRestUrl(context, "search3");
|
Map<String, String> parameters = new HashMap<>();
|
||||||
|
|
||||||
Builder builder = new FormBody.Builder();
|
parameters.put("query", critera.getQuery());
|
||||||
|
parameters.put("artistCount", Integer.toString(critera.getArtistCount()));
|
||||||
|
parameters.put("albumCount", Integer.toString(critera.getAlbumCount()));
|
||||||
|
parameters.put("songCount", Integer.toString(critera.getSongCount()));
|
||||||
|
|
||||||
builder.add("query", critera.getQuery());
|
String url = getRestUrl(context, "search3", parameters);
|
||||||
builder.add("artistCount", Integer.toString(critera.getArtistCount()));
|
|
||||||
builder.add("albumCount", Integer.toString(critera.getAlbumCount()));
|
|
||||||
builder.add("songCount", Integer.toString(critera.getSongCount()));
|
|
||||||
|
|
||||||
RequestBody formBody = builder.build();
|
|
||||||
|
|
||||||
Request request = new Request.Builder()
|
Request request = new Request.Builder()
|
||||||
.url(url)
|
.url(url)
|
||||||
.post(formBody)
|
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
try (Response response = client.newCall(request).execute()) {
|
try (Response response = client.newCall(request).execute()) {
|
||||||
|
@ -235,15 +235,14 @@ public class RESTMusicService implements MusicService {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MusicDirectory getPlaylist(boolean refresh, String id, String name, Context context, ProgressListener progressListener) throws Exception {
|
public MusicDirectory getPlaylist(boolean refresh, String id, String name, Context context, ProgressListener progressListener) throws Exception {
|
||||||
String url = getRestUrl(context, "getPlaylist");
|
Map<String, String> parameters = new HashMap<>();
|
||||||
|
|
||||||
RequestBody formBody = new FormBody.Builder()
|
parameters.put("id", id);
|
||||||
.add("id", id)
|
|
||||||
.build();
|
String url = getRestUrl(context, "getPlaylist", parameters);
|
||||||
|
|
||||||
Request request = new Request.Builder()
|
Request request = new Request.Builder()
|
||||||
.url(url)
|
.url(url)
|
||||||
.post(formBody)
|
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
try (Response response = client.newCall(request).execute()) {
|
try (Response response = client.newCall(request).execute()) {
|
||||||
|
@ -253,7 +252,7 @@ public class RESTMusicService implements MusicService {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Playlist> getPlaylists(boolean refresh, Context context, ProgressListener progressListener) throws Exception {
|
public List<Playlist> getPlaylists(boolean refresh, Context context, ProgressListener progressListener) throws Exception {
|
||||||
String url = getRestUrl(context, "getPlaylists");
|
String url = getRestUrl(context, "getPlaylists", null);
|
||||||
|
|
||||||
Request request = new Request.Builder()
|
Request request = new Request.Builder()
|
||||||
.url(url)
|
.url(url)
|
||||||
|
@ -266,27 +265,24 @@ public class RESTMusicService implements MusicService {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void createPlaylist(String id, String name, List<MusicDirectory.Entry> entries, Context context, ProgressListener progressListener) throws Exception {
|
public void createPlaylist(String id, String name, List<MusicDirectory.Entry> entries, Context context, ProgressListener progressListener) throws Exception {
|
||||||
String url = getRestUrl(context, "createPlaylist");
|
Map<String, String> parameters = new HashMap<>();
|
||||||
|
|
||||||
Builder builder = new FormBody.Builder();
|
|
||||||
|
|
||||||
if (id != null) {
|
if (id != null) {
|
||||||
builder.add("playlistId", id);
|
parameters.put("playlistId", id);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (name != null) {
|
if (name != null) {
|
||||||
builder.add("name", name);
|
parameters.put("name", name);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (MusicDirectory.Entry entry : entries) {
|
for (MusicDirectory.Entry entry : entries) {
|
||||||
builder.add("songId", getOfflineSongId(entry.getId(), context, progressListener));
|
parameters.put("songId", getOfflineSongId(entry.getId(), context, progressListener));
|
||||||
}
|
}
|
||||||
|
|
||||||
RequestBody formBody = builder.build();
|
String url = getRestUrl(context, "createPlaylist", parameters);
|
||||||
|
|
||||||
Request request = new Request.Builder()
|
Request request = new Request.Builder()
|
||||||
.url(url)
|
.url(url)
|
||||||
.post(formBody)
|
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
try (Response response = client.newCall(request).execute()) {
|
try (Response response = client.newCall(request).execute()) {
|
||||||
|
@ -296,15 +292,14 @@ public class RESTMusicService implements MusicService {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void deletePlaylist(String id, Context context, ProgressListener progressListener) throws Exception {
|
public void deletePlaylist(String id, Context context, ProgressListener progressListener) throws Exception {
|
||||||
String url = getRestUrl(context, "deletePlaylist");
|
Map<String, String> parameters = new HashMap<>();
|
||||||
|
|
||||||
RequestBody formBody = new FormBody.Builder()
|
parameters.put("id", id);
|
||||||
.add("id", id)
|
|
||||||
.build();
|
String url = getRestUrl(context, "deletePlaylist", parameters);
|
||||||
|
|
||||||
Request request = new Request.Builder()
|
Request request = new Request.Builder()
|
||||||
.url(url)
|
.url(url)
|
||||||
.post(formBody)
|
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
try (Response response = client.newCall(request).execute()) {
|
try (Response response = client.newCall(request).execute()) {
|
||||||
|
@ -314,19 +309,17 @@ public class RESTMusicService implements MusicService {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addToPlaylist(String id, List<MusicDirectory.Entry> toAdd, Context context, ProgressListener progressListener) throws Exception {
|
public void addToPlaylist(String id, List<MusicDirectory.Entry> toAdd, Context context, ProgressListener progressListener) throws Exception {
|
||||||
String url = getRestUrl(context, "updatePlaylist");
|
Map<String, String> parameters = new HashMap<>();
|
||||||
|
|
||||||
Builder builder = new FormBody.Builder();
|
parameters.put("playlistId", id);
|
||||||
builder.add("playlistId", id);
|
|
||||||
for (MusicDirectory.Entry song : toAdd) {
|
for (MusicDirectory.Entry song : toAdd) {
|
||||||
builder.add("songIdToAdd", getOfflineSongId(song.getId(), context, progressListener));
|
parameters.put("songIdToAdd", getOfflineSongId(song.getId(), context, progressListener));
|
||||||
}
|
}
|
||||||
|
|
||||||
RequestBody formBody = builder.build();
|
String url = getRestUrl(context, "updatePlaylist", parameters);
|
||||||
|
|
||||||
Request request = new Request.Builder()
|
Request request = new Request.Builder()
|
||||||
.url(url)
|
.url(url)
|
||||||
.post(formBody)
|
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
try (Response response = client.newCall(request).execute()) {
|
try (Response response = client.newCall(request).execute()) {
|
||||||
|
@ -336,20 +329,18 @@ public class RESTMusicService implements MusicService {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void removeFromPlaylist(String id, List<Integer> toRemove, Context context, ProgressListener progressListener) throws Exception {
|
public void removeFromPlaylist(String id, List<Integer> toRemove, Context context, ProgressListener progressListener) throws Exception {
|
||||||
String url = getRestUrl(context, "updatePlaylist");
|
Map<String, String> parameters = new HashMap<>();
|
||||||
|
|
||||||
Builder builder = new FormBody.Builder();
|
parameters.put("playlistId", id);
|
||||||
builder.add("playlistId", id);
|
|
||||||
|
|
||||||
for (Integer song : toRemove) {
|
for (Integer song : toRemove) {
|
||||||
builder.add("songIndexToRemove", Integer.toString(song));
|
parameters.put("songIndexToRemove", Integer.toString(song));
|
||||||
}
|
}
|
||||||
|
|
||||||
RequestBody formBody = builder.build();
|
String url = getRestUrl(context, "updatePlaylist", parameters);
|
||||||
|
|
||||||
Request request = new Request.Builder()
|
Request request = new Request.Builder()
|
||||||
.url(url)
|
.url(url)
|
||||||
.post(formBody)
|
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
try (Response response = client.newCall(request).execute()) {
|
try (Response response = client.newCall(request).execute()) {
|
||||||
|
@ -359,25 +350,23 @@ public class RESTMusicService implements MusicService {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void overwritePlaylist(String id, String name, int toRemove, List<MusicDirectory.Entry> toAdd, Context context, ProgressListener progressListener) throws Exception {
|
public void overwritePlaylist(String id, String name, int toRemove, List<MusicDirectory.Entry> toAdd, Context context, ProgressListener progressListener) throws Exception {
|
||||||
String url = getRestUrl(context, "updatePlaylist");
|
Map<String, String> parameters = new HashMap<>();
|
||||||
|
|
||||||
Builder builder = new FormBody.Builder();
|
parameters.put("playlistId", id);
|
||||||
builder.add("playlistId", id);
|
parameters.put("name", name);
|
||||||
builder.add("name", name);
|
|
||||||
|
|
||||||
for (MusicDirectory.Entry song : toAdd) {
|
for (MusicDirectory.Entry song : toAdd) {
|
||||||
builder.add("songIdToAdd", getOfflineSongId(song.getId(), context, progressListener));
|
parameters.put("songIdToAdd", getOfflineSongId(song.getId(), context, progressListener));
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < toRemove; i++) {
|
for (int i = 0; i < toRemove; i++) {
|
||||||
builder.add("songIndexToRemove", Integer.toString(i));
|
parameters.put("songIndexToRemove", Integer.toString(i));
|
||||||
}
|
}
|
||||||
|
|
||||||
RequestBody formBody = builder.build();
|
String url = getRestUrl(context, "updatePlaylist", parameters);
|
||||||
|
|
||||||
Request request = new Request.Builder()
|
Request request = new Request.Builder()
|
||||||
.url(url)
|
.url(url)
|
||||||
.post(formBody)
|
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
try (Response response = client.newCall(request).execute()) {
|
try (Response response = client.newCall(request).execute()) {
|
||||||
|
@ -387,19 +376,17 @@ public class RESTMusicService implements MusicService {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updatePlaylist(String id, String name, String comment, boolean pub, Context context, ProgressListener progressListener) throws Exception {
|
public void updatePlaylist(String id, String name, String comment, boolean pub, Context context, ProgressListener progressListener) throws Exception {
|
||||||
String url = getRestUrl(context, "updatePlaylist");
|
Map<String, String> parameters = new HashMap<>();
|
||||||
|
|
||||||
Builder builder = new FormBody.Builder();
|
parameters.put("playlistId", id);
|
||||||
builder.add("playlistId", id);
|
parameters.put("name", name);
|
||||||
builder.add("name", name);
|
parameters.put("comment", comment);
|
||||||
builder.add("comment", comment);
|
parameters.put("public", Boolean.toString(pub));
|
||||||
builder.add("public", Boolean.toString(pub));
|
|
||||||
|
|
||||||
RequestBody formBody = builder.build();
|
String url = getRestUrl(context, "updatePlaylist", parameters);
|
||||||
|
|
||||||
Request request = new Request.Builder()
|
Request request = new Request.Builder()
|
||||||
.url(url)
|
.url(url)
|
||||||
.post(formBody)
|
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
try (Response response = client.newCall(request).execute()) {
|
try (Response response = client.newCall(request).execute()) {
|
||||||
|
@ -409,27 +396,25 @@ public class RESTMusicService implements MusicService {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MusicDirectory getAlbumList(String type, int size, int offset, boolean refresh, Context context, ProgressListener progressListener) throws Exception {
|
public MusicDirectory getAlbumList(String type, int size, int offset, boolean refresh, Context context, ProgressListener progressListener) throws Exception {
|
||||||
String url = getRestUrl(context, "getAlbumList2");
|
Map<String, String> parameters = new HashMap<>();
|
||||||
|
|
||||||
Builder builder = new FormBody.Builder();
|
parameters.put("type", type);
|
||||||
builder.add("type", type);
|
parameters.put("size", Integer.toString(size));
|
||||||
builder.add("size", Integer.toString(size));
|
parameters.put("offset", Integer.toString(offset));
|
||||||
builder.add("offset", Integer.toString(offset));
|
|
||||||
|
|
||||||
// Add folder if it was set and is non null
|
// Add folder if it was set and is non null
|
||||||
int instance = getInstance(context);
|
int instance = getInstance(context);
|
||||||
if (Util.getAlbumListsPerFolder(context, instance)) {
|
if (Util.getAlbumListsPerFolder(context, instance)) {
|
||||||
String folderId = Util.getSelectedMusicFolderId(context, instance);
|
String folderId = Util.getSelectedMusicFolderId(context, instance);
|
||||||
if (folderId != null) {
|
if (folderId != null) {
|
||||||
builder.add("musicFolderId", folderId);
|
parameters.put("musicFolderId", folderId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
RequestBody formBody = builder.build();
|
String url = getRestUrl(context, "getAlbumList2", parameters);
|
||||||
|
|
||||||
Request request = new Request.Builder()
|
Request request = new Request.Builder()
|
||||||
.url(url)
|
.url(url)
|
||||||
.post(formBody)
|
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
try (Response response = client.newCall(request).execute()) {
|
try (Response response = client.newCall(request).execute()) {
|
||||||
|
@ -439,37 +424,35 @@ public class RESTMusicService implements MusicService {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MusicDirectory getAlbumList(String type, String extra, int size, int offset, boolean refresh, Context context, ProgressListener progressListener) throws Exception {
|
public MusicDirectory getAlbumList(String type, String extra, int size, int offset, boolean refresh, Context context, ProgressListener progressListener) throws Exception {
|
||||||
String url = getRestUrl(context, "getAlbumList2");
|
Map<String, String> parameters = new HashMap<>();
|
||||||
|
|
||||||
Builder builder = new FormBody.Builder();
|
parameters.put("size", Integer.toString(size));
|
||||||
builder.add("size", Integer.toString(size));
|
parameters.put("offset", Integer.toString(offset));
|
||||||
builder.add("offset", Integer.toString(offset));
|
|
||||||
|
|
||||||
int instance = getInstance(context);
|
int instance = getInstance(context);
|
||||||
if ("genres".equals(type)) {
|
if ("genres".equals(type)) {
|
||||||
builder.add("type", "byGenre");
|
parameters.put("type", "byGenre");
|
||||||
builder.add("genre", extra);
|
parameters.put("genre", extra);
|
||||||
} else if ("years".equals(type)) {
|
} else if ("years".equals(type)) {
|
||||||
int decade = Integer.parseInt(extra);
|
int decade = Integer.parseInt(extra);
|
||||||
|
|
||||||
builder.add("type", "byYear");
|
parameters.put("type", "byYear");
|
||||||
builder.add("fromYear", Integer.toString(decade + 9));
|
parameters.put("fromYear", Integer.toString(decade + 9));
|
||||||
builder.add("toYear", Integer.toString(decade));
|
parameters.put("toYear", Integer.toString(decade));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add folder if it was set and is non null
|
// Add folder if it was set and is non null
|
||||||
if (Util.getAlbumListsPerFolder(context, instance)) {
|
if (Util.getAlbumListsPerFolder(context, instance)) {
|
||||||
String folderId = Util.getSelectedMusicFolderId(context, instance);
|
String folderId = Util.getSelectedMusicFolderId(context, instance);
|
||||||
if (folderId != null) {
|
if (folderId != null) {
|
||||||
builder.add("musicFolderId", folderId);
|
parameters.put("musicFolderId", folderId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
RequestBody formBody = builder.build();
|
String url = getRestUrl(context, "getAlbumList2", parameters);
|
||||||
|
|
||||||
Request request = new Request.Builder()
|
Request request = new Request.Builder()
|
||||||
.url(url)
|
.url(url)
|
||||||
.post(formBody)
|
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
try (Response response = client.newCall(request).execute()) {
|
try (Response response = client.newCall(request).execute()) {
|
||||||
|
@ -479,9 +462,10 @@ public class RESTMusicService implements MusicService {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MusicDirectory getSongList(String type, int size, int offset, Context context, ProgressListener progressListener) throws Exception {
|
public MusicDirectory getSongList(String type, int size, int offset, Context context, ProgressListener progressListener) throws Exception {
|
||||||
Builder builder = new FormBody.Builder();
|
Map<String, String> parameters = new HashMap<>();
|
||||||
builder.add("size", Integer.toString(size));
|
|
||||||
builder.add("offset", Integer.toString(offset));
|
parameters.put("size", Integer.toString(size));
|
||||||
|
parameters.put("offset", Integer.toString(offset));
|
||||||
|
|
||||||
String method;
|
String method;
|
||||||
switch (type) {
|
switch (type) {
|
||||||
|
@ -501,13 +485,10 @@ public class RESTMusicService implements MusicService {
|
||||||
method = "getNewaddedSongs";
|
method = "getNewaddedSongs";
|
||||||
}
|
}
|
||||||
|
|
||||||
String url = getRestUrl(context, method);
|
String url = getRestUrl(context, method, parameters);
|
||||||
|
|
||||||
RequestBody formBody = builder.build();
|
|
||||||
|
|
||||||
Request request = new Request.Builder()
|
Request request = new Request.Builder()
|
||||||
.url(url)
|
.url(url)
|
||||||
.post(formBody)
|
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
try (Response response = client.newCall(request).execute()) {
|
try (Response response = client.newCall(request).execute()) {
|
||||||
|
@ -517,11 +498,12 @@ public class RESTMusicService implements MusicService {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MusicDirectory getRandomSongs(int size, String musicFolderId, String genre, String startYear, String endYear, Context context, ProgressListener progressListener) throws Exception {
|
public MusicDirectory getRandomSongs(int size, String musicFolderId, String genre, String startYear, String endYear, Context context, ProgressListener progressListener) throws Exception {
|
||||||
Builder builder = new FormBody.Builder();
|
Map<String, String> parameters = new HashMap<>();
|
||||||
builder.add("size", Integer.toString(size));
|
|
||||||
|
parameters.put("size", Integer.toString(size));
|
||||||
|
|
||||||
if (genre != null && !"".equals(genre)) {
|
if (genre != null && !"".equals(genre)) {
|
||||||
builder.add("genre", genre);
|
parameters.put("genre", genre);
|
||||||
}
|
}
|
||||||
if (startYear != null && !"".equals(startYear)) {
|
if (startYear != null && !"".equals(startYear)) {
|
||||||
// Check to make sure user isn't doing 2015 -> 2010 since Subsonic will return no results
|
// Check to make sure user isn't doing 2015 -> 2010 since Subsonic will return no results
|
||||||
|
@ -540,19 +522,16 @@ public class RESTMusicService implements MusicService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
builder.add("fromYear", startYear);
|
parameters.put("fromYear", startYear);
|
||||||
}
|
}
|
||||||
if (endYear != null && !"".equals(endYear)) {
|
if (endYear != null && !"".equals(endYear)) {
|
||||||
builder.add("toYear", endYear);
|
parameters.put("toYear", endYear);
|
||||||
}
|
}
|
||||||
|
|
||||||
String url = getRestUrl(context, "getRandomSongs");
|
String url = getRestUrl(context, "getRandomSongs", parameters);
|
||||||
|
|
||||||
RequestBody formBody = builder.build();
|
|
||||||
|
|
||||||
Request request = new Request.Builder()
|
Request request = new Request.Builder()
|
||||||
.url(url)
|
.url(url)
|
||||||
.post(formBody)
|
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
try (Response response = client.newCall(request).execute()) {
|
try (Response response = client.newCall(request).execute()) {
|
||||||
|
@ -572,16 +551,14 @@ public class RESTMusicService implements MusicService {
|
||||||
return bitmap;
|
return bitmap;
|
||||||
}
|
}
|
||||||
|
|
||||||
String url = getRestUrl(context, "getCoverArt");
|
Map<String, String> parameters = new HashMap<>();
|
||||||
|
|
||||||
Builder builder = new FormBody.Builder();
|
parameters.put("id", entry.getCoverArt());
|
||||||
builder.add("id", entry.getCoverArt());
|
|
||||||
|
|
||||||
RequestBody formBody = builder.build();
|
String url = getRestUrl(context, "getCoverArt", parameters);
|
||||||
|
|
||||||
Request request = new Request.Builder()
|
Request request = new Request.Builder()
|
||||||
.url(url)
|
.url(url)
|
||||||
.post(formBody)
|
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
try (Response response = client.newCall(request).execute()) {
|
try (Response response = client.newCall(request).execute()) {
|
||||||
|
@ -619,13 +596,12 @@ public class RESTMusicService implements MusicService {
|
||||||
.readTimeout(30, TimeUnit.SECONDS)
|
.readTimeout(30, TimeUnit.SECONDS)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
String url = getRestUrl(context, "stream");
|
Map<String, String> parameters = new HashMap<>();
|
||||||
|
|
||||||
Builder builder = new FormBody.Builder();
|
parameters.put("id", song.getId());
|
||||||
builder.add("id", song.getId());
|
parameters.put("maxBitRate", Integer.toString(maxBitrate));
|
||||||
builder.add("maxBitRate", Integer.toString(maxBitrate));
|
|
||||||
|
|
||||||
RequestBody formBody = builder.build();
|
String url = getRestUrl(context, "stream", parameters);
|
||||||
|
|
||||||
Request.Builder requestBuilder = new Request.Builder();
|
Request.Builder requestBuilder = new Request.Builder();
|
||||||
if (offset > 0) {
|
if (offset > 0) {
|
||||||
|
@ -633,7 +609,6 @@ public class RESTMusicService implements MusicService {
|
||||||
}
|
}
|
||||||
|
|
||||||
requestBuilder.url(url);
|
requestBuilder.url(url);
|
||||||
requestBuilder.post(formBody);
|
|
||||||
|
|
||||||
Request request = requestBuilder.build();
|
Request request = requestBuilder.build();
|
||||||
|
|
||||||
|
@ -643,7 +618,7 @@ public class RESTMusicService implements MusicService {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Genre> getGenres(boolean refresh, Context context, ProgressListener progressListener) throws Exception {
|
public List<Genre> getGenres(boolean refresh, Context context, ProgressListener progressListener) throws Exception {
|
||||||
String url = getRestUrl(context, "getGenres");
|
String url = getRestUrl(context, "getGenres", null);
|
||||||
|
|
||||||
Request request = new Request.Builder()
|
Request request = new Request.Builder()
|
||||||
.url(url)
|
.url(url)
|
||||||
|
@ -656,27 +631,25 @@ public class RESTMusicService implements MusicService {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MusicDirectory getSongsByGenre(String genre, int count, int offset, Context context, ProgressListener progressListener) throws Exception {
|
public MusicDirectory getSongsByGenre(String genre, int count, int offset, Context context, ProgressListener progressListener) throws Exception {
|
||||||
Builder builder = new FormBody.Builder();
|
Map<String, String> parameters = new HashMap<>();
|
||||||
builder.add("genre", genre);
|
|
||||||
builder.add("count", Integer.toString(count));
|
parameters.put("genre", genre);
|
||||||
builder.add("offset", Integer.toString(offset));
|
parameters.put("count", Integer.toString(count));
|
||||||
|
parameters.put("offset", Integer.toString(offset));
|
||||||
|
|
||||||
// Add folder if it was set and is non null
|
// Add folder if it was set and is non null
|
||||||
int instance = getInstance(context);
|
int instance = getInstance(context);
|
||||||
if (Util.getAlbumListsPerFolder(context, instance)) {
|
if (Util.getAlbumListsPerFolder(context, instance)) {
|
||||||
String folderId = Util.getSelectedMusicFolderId(context, instance);
|
String folderId = Util.getSelectedMusicFolderId(context, instance);
|
||||||
if (folderId != null) {
|
if (folderId != null) {
|
||||||
builder.add("musicFolderId", folderId);
|
parameters.put("musicFolderId", folderId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
String url = getRestUrl(context, "getSongsByGenre");
|
String url = getRestUrl(context, "getSongsByGenre", parameters);
|
||||||
|
|
||||||
RequestBody formBody = builder.build();
|
|
||||||
|
|
||||||
Request request = new Request.Builder()
|
Request request = new Request.Builder()
|
||||||
.url(url)
|
.url(url)
|
||||||
.post(formBody)
|
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
try (Response response = client.newCall(request).execute()) {
|
try (Response response = client.newCall(request).execute()) {
|
||||||
|
@ -686,15 +659,14 @@ public class RESTMusicService implements MusicService {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public User getUser(boolean refresh, String username, Context context, ProgressListener progressListener) throws Exception {
|
public User getUser(boolean refresh, String username, Context context, ProgressListener progressListener) throws Exception {
|
||||||
String url = getRestUrl(context, "getUser");
|
Map<String, String> parameters = new HashMap<>();
|
||||||
|
|
||||||
RequestBody formBody = new FormBody.Builder()
|
parameters.put("username", username);
|
||||||
.add("username", username)
|
|
||||||
.build();
|
String url = getRestUrl(context, "getUser", parameters);
|
||||||
|
|
||||||
Request request = new Request.Builder()
|
Request request = new Request.Builder()
|
||||||
.url(url)
|
.url(url)
|
||||||
.post(formBody)
|
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
try (Response response = client.newCall(request).execute()) {
|
try (Response response = client.newCall(request).execute()) {
|
||||||
|
@ -742,15 +714,15 @@ public class RESTMusicService implements MusicService {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public String getRestUrl(Context context, String method) {
|
public String getRestUrl(Context context, String method, @Nullable Map<String, String> parameters) {
|
||||||
return getRestUrl(context, method, true);
|
return getRestUrl(context, method, true, parameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getRestUrl(Context context, String method, boolean allowAltAddress) {
|
public String getRestUrl(Context context, String method, boolean allowAltAddress, @Nullable Map<String, String> parameters) {
|
||||||
if (instance == null) {
|
if (instance == null) {
|
||||||
return Util.getRestUrl(context, method, allowAltAddress);
|
return Util.getRestUrl(context, method, allowAltAddress, parameters);
|
||||||
} else {
|
} else {
|
||||||
return Util.getRestUrl(context, method, instance, allowAltAddress);
|
return Util.getRestUrl(context, method, instance, allowAltAddress, parameters);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -292,7 +292,7 @@ public class FileUtil {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Do a special lookup since 4.7+ doesn't match artist/album to entry.getPath
|
// Do a special lookup since 4.7+ doesn't match artist/album to entry.getPath
|
||||||
String s = Util.getRestUrl(context, null, false) + entry.getId();
|
String s = Util.getRestUrl(context, null, false, null) + entry.getId();
|
||||||
String cacheName = "album-" + s.hashCode() + ".ser";
|
String cacheName = "album-" + s.hashCode() + ".ser";
|
||||||
MusicDirectory entryDir = FileUtil.deserialize(context, cacheName, MusicDirectory.class);
|
MusicDirectory entryDir = FileUtil.deserialize(context, cacheName, MusicDirectory.class);
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,7 @@ public final class SyncUtil {
|
||||||
|
|
||||||
private static void checkRestURL(Context context) {
|
private static void checkRestURL(Context context) {
|
||||||
int instance = Util.getActiveServer(context);
|
int instance = Util.getActiveServer(context);
|
||||||
String newURL = Util.getRestUrl(context, null, instance, false);
|
String newURL = Util.getRestUrl(context, null, instance, false, null);
|
||||||
if (url == null || !url.equals(newURL)) {
|
if (url == null || !url.equals(newURL)) {
|
||||||
syncedPlaylists = null;
|
syncedPlaylists = null;
|
||||||
url = newURL;
|
url = newURL;
|
||||||
|
@ -72,7 +72,7 @@ public final class SyncUtil {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String getPlaylistSyncFile(Context context, int instance) {
|
private static String getPlaylistSyncFile(Context context, int instance) {
|
||||||
return "sync-playlist-" + (Util.getRestUrl(context, null, instance, false)).hashCode() + ".ser";
|
return "sync-playlist-" + (Util.getRestUrl(context, null, instance, false, null)).hashCode() + ".ser";
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void removeMostRecentSyncFiles(Context context) {
|
public static void removeMostRecentSyncFiles(Context context) {
|
||||||
|
@ -84,7 +84,7 @@ public final class SyncUtil {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String getMostRecentSyncFile(Context context, int instance) {
|
private static String getMostRecentSyncFile(Context context, int instance) {
|
||||||
return "sync-most_recent-" + (Util.getRestUrl(context, null, instance, false)).hashCode() + ".ser";
|
return "sync-most_recent-" + (Util.getRestUrl(context, null, instance, false, null)).hashCode() + ".ser";
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class SyncSet implements Serializable {
|
public static class SyncSet implements Serializable {
|
||||||
|
|
|
@ -36,6 +36,7 @@ import android.net.NetworkInfo;
|
||||||
import android.net.wifi.WifiManager;
|
import android.net.wifi.WifiManager;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Environment;
|
import android.os.Environment;
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
import android.support.annotation.StringRes;
|
import android.support.annotation.StringRes;
|
||||||
import android.support.v7.app.AlertDialog;
|
import android.support.v7.app.AlertDialog;
|
||||||
import android.text.SpannableString;
|
import android.text.SpannableString;
|
||||||
|
@ -70,6 +71,7 @@ import java.text.DecimalFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
import okhttp3.HttpUrl;
|
import okhttp3.HttpUrl;
|
||||||
|
@ -277,21 +279,22 @@ public final class Util {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getRestUrl(Context context) {
|
public static String getRestUrl(Context context) {
|
||||||
return getRestUrl(context, null, true);
|
return getRestUrl(context, null, true, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getRestUrl(Context context, String method, boolean allowAltAddress) {
|
// used
|
||||||
|
public static String getRestUrl(Context context, String method, boolean allowAltAddress, @Nullable Map<String, String> parameters) {
|
||||||
SharedPreferences prefs = getPreferences(context);
|
SharedPreferences prefs = getPreferences(context);
|
||||||
int instance = prefs.getInt(Constants.PREFERENCES_KEY_SERVER_INSTANCE, 1);
|
int instance = prefs.getInt(Constants.PREFERENCES_KEY_SERVER_INSTANCE, 1);
|
||||||
return getRestUrl(context, method, prefs, instance, allowAltAddress);
|
return getRestUrl(context, method, prefs, instance, allowAltAddress, parameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getRestUrl(Context context, String method, int instance, boolean allowAltAddress) {
|
public static String getRestUrl(Context context, String method, int instance, boolean allowAltAddress, @Nullable Map<String, String> parameters) {
|
||||||
SharedPreferences prefs = getPreferences(context);
|
SharedPreferences prefs = getPreferences(context);
|
||||||
return getRestUrl(context, method, prefs, instance, allowAltAddress);
|
return getRestUrl(context, method, prefs, instance, allowAltAddress, parameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String getRestUrl(Context context, String method, SharedPreferences prefs, int instance, boolean allowAltAddress) {
|
private static String getRestUrl(Context context, String method, SharedPreferences prefs, int instance, boolean allowAltAddress, @Nullable Map<String, String> parameters) {
|
||||||
String serverUrl = prefs.getString(Constants.PREFERENCES_KEY_SERVER_URL + instance, null);
|
String serverUrl = prefs.getString(Constants.PREFERENCES_KEY_SERVER_URL + instance, null);
|
||||||
|
|
||||||
HttpUrl.Builder builder;
|
HttpUrl.Builder builder;
|
||||||
|
@ -334,6 +337,12 @@ public final class Util {
|
||||||
builder.addQueryParameter("v", Constants.REST_PROTOCOL_VERSION_SUBSONIC);
|
builder.addQueryParameter("v", Constants.REST_PROTOCOL_VERSION_SUBSONIC);
|
||||||
builder.addQueryParameter("c", Constants.REST_CLIENT_ID);
|
builder.addQueryParameter("c", Constants.REST_CLIENT_ID);
|
||||||
|
|
||||||
|
if (parameters != null) {
|
||||||
|
for (Map.Entry<String, String> parameter : parameters.entrySet()) {
|
||||||
|
builder.addQueryParameter(parameter.getKey(), parameter.getValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return builder.build().toString();
|
return builder.build().toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -352,7 +361,7 @@ public final class Util {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String getBlockTokenUsePref(Context context, int instance) {
|
private static String getBlockTokenUsePref(Context context, int instance) {
|
||||||
return Constants.CACHE_BLOCK_TOKEN_USE + Util.getRestUrl(context, null, instance, false);
|
return Constants.CACHE_BLOCK_TOKEN_USE + Util.getRestUrl(context, null, instance, false, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setBlockTokenUse(Context context, int instance) {
|
public static void setBlockTokenUse(Context context, int instance) {
|
||||||
|
@ -366,7 +375,7 @@ public final class Util {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getCacheName(Context context, String name, String id) {
|
public static String getCacheName(Context context, String name, String id) {
|
||||||
String s = getRestUrl(context, null, getActiveServer(context), false) + id;
|
String s = getRestUrl(context, null, getActiveServer(context), false, null) + id;
|
||||||
return name + "-" + s.hashCode() + ".ser";
|
return name + "-" + s.hashCode() + ".ser";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue