From 2301e2e015f4f0ca22f57fade397c036db00d235 Mon Sep 17 00:00:00 2001 From: dddddd-mmmmmm <36978885+dddddd-mmmmmm@users.noreply.github.com> Date: Wed, 27 Feb 2019 12:23:10 +1100 Subject: [PATCH 1/5] Fix typo in folder structure. audinuat -> audinaut --- .../kotlin/net/nullsum/{audinuat => audinaut}/domain/Artist.kt | 0 .../kotlin/net/nullsum/{audinuat => audinaut}/domain/Genre.kt | 0 .../kotlin/net/nullsum/{audinuat => audinaut}/domain/Indexes.kt | 0 .../net/nullsum/{audinuat => audinaut}/domain/PlayerState.kt | 0 .../net/nullsum/{audinuat => audinaut}/domain/RepeatMode.kt | 0 .../nullsum/{audinuat => audinaut}/service/MusicServiceFactory.kt | 0 6 files changed, 0 insertions(+), 0 deletions(-) rename app/src/main/kotlin/net/nullsum/{audinuat => audinaut}/domain/Artist.kt (100%) rename app/src/main/kotlin/net/nullsum/{audinuat => audinaut}/domain/Genre.kt (100%) rename app/src/main/kotlin/net/nullsum/{audinuat => audinaut}/domain/Indexes.kt (100%) rename app/src/main/kotlin/net/nullsum/{audinuat => audinaut}/domain/PlayerState.kt (100%) rename app/src/main/kotlin/net/nullsum/{audinuat => audinaut}/domain/RepeatMode.kt (100%) rename app/src/main/kotlin/net/nullsum/{audinuat => audinaut}/service/MusicServiceFactory.kt (100%) diff --git a/app/src/main/kotlin/net/nullsum/audinuat/domain/Artist.kt b/app/src/main/kotlin/net/nullsum/audinaut/domain/Artist.kt similarity index 100% rename from app/src/main/kotlin/net/nullsum/audinuat/domain/Artist.kt rename to app/src/main/kotlin/net/nullsum/audinaut/domain/Artist.kt diff --git a/app/src/main/kotlin/net/nullsum/audinuat/domain/Genre.kt b/app/src/main/kotlin/net/nullsum/audinaut/domain/Genre.kt similarity index 100% rename from app/src/main/kotlin/net/nullsum/audinuat/domain/Genre.kt rename to app/src/main/kotlin/net/nullsum/audinaut/domain/Genre.kt diff --git a/app/src/main/kotlin/net/nullsum/audinuat/domain/Indexes.kt b/app/src/main/kotlin/net/nullsum/audinaut/domain/Indexes.kt similarity index 100% rename from app/src/main/kotlin/net/nullsum/audinuat/domain/Indexes.kt rename to app/src/main/kotlin/net/nullsum/audinaut/domain/Indexes.kt diff --git a/app/src/main/kotlin/net/nullsum/audinuat/domain/PlayerState.kt b/app/src/main/kotlin/net/nullsum/audinaut/domain/PlayerState.kt similarity index 100% rename from app/src/main/kotlin/net/nullsum/audinuat/domain/PlayerState.kt rename to app/src/main/kotlin/net/nullsum/audinaut/domain/PlayerState.kt diff --git a/app/src/main/kotlin/net/nullsum/audinuat/domain/RepeatMode.kt b/app/src/main/kotlin/net/nullsum/audinaut/domain/RepeatMode.kt similarity index 100% rename from app/src/main/kotlin/net/nullsum/audinuat/domain/RepeatMode.kt rename to app/src/main/kotlin/net/nullsum/audinaut/domain/RepeatMode.kt diff --git a/app/src/main/kotlin/net/nullsum/audinuat/service/MusicServiceFactory.kt b/app/src/main/kotlin/net/nullsum/audinaut/service/MusicServiceFactory.kt similarity index 100% rename from app/src/main/kotlin/net/nullsum/audinuat/service/MusicServiceFactory.kt rename to app/src/main/kotlin/net/nullsum/audinaut/service/MusicServiceFactory.kt From 2015039c3d1eb5ee4b5ca3b201d1fb795403988b Mon Sep 17 00:00:00 2001 From: dddddd-mmmmmm <36978885+dddddd-mmmmmm@users.noreply.github.com> Date: Fri, 1 Mar 2019 10:04:52 +1100 Subject: [PATCH 2/5] Add support for adding parameters to the Rest URL. --- .../audinaut/service/RESTMusicService.java | 60 ++++++++++--------- .../java/net/nullsum/audinaut/util/Util.java | 25 +++++--- 2 files changed, 48 insertions(+), 37 deletions(-) diff --git a/app/src/main/java/net/nullsum/audinaut/service/RESTMusicService.java b/app/src/main/java/net/nullsum/audinaut/service/RESTMusicService.java index 7a706f5..8ed0907 100644 --- a/app/src/main/java/net/nullsum/audinaut/service/RESTMusicService.java +++ b/app/src/main/java/net/nullsum/audinaut/service/RESTMusicService.java @@ -21,6 +21,7 @@ package net.nullsum.audinaut.service; import android.content.Context; import android.content.SharedPreferences; import android.graphics.Bitmap; +import android.support.annotation.Nullable; import android.util.Log; import net.nullsum.audinaut.domain.Genre; @@ -55,6 +56,7 @@ import java.io.FileOutputStream; import java.io.InputStream; import java.io.OutputStream; import java.util.List; +import java.util.Map; import java.util.concurrent.TimeUnit; import okhttp3.FormBody; @@ -75,7 +77,7 @@ public class RESTMusicService implements MusicService { @Override 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() .url(url) @@ -87,7 +89,7 @@ public class RESTMusicService implements MusicService { } public List 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() .url(url) @@ -100,7 +102,7 @@ public class RESTMusicService implements MusicService { @Override public Indexes getIndexes(String musicFolderId, boolean refresh, Context context, ProgressListener progressListener) throws Exception { - String url = getRestUrl(context, "getArtists"); + String url = getRestUrl(context, "getArtists", null); Builder builder = new FormBody.Builder(); @@ -158,7 +160,7 @@ public class RESTMusicService implements MusicService { } private MusicDirectory getMusicDirectoryImpl(String id, String name, Context context) throws Exception { - String url = getRestUrl(context, "getMusicDirectory"); + String url = getRestUrl(context, "getMusicDirectory", null); RequestBody formBody = new FormBody.Builder() .add("id", id) @@ -176,7 +178,7 @@ public class RESTMusicService implements MusicService { @Override public MusicDirectory getArtist(String id, String name, boolean refresh, Context context, ProgressListener progressListener) throws Exception { - String url = getRestUrl(context, "getArtist"); + String url = getRestUrl(context, "getArtist", null); RequestBody formBody = new FormBody.Builder() .add("id", id) @@ -194,7 +196,7 @@ public class RESTMusicService implements MusicService { @Override public MusicDirectory getAlbum(String id, String name, boolean refresh, Context context, ProgressListener progressListener) throws Exception { - String url = getRestUrl(context, "getAlbum"); + String url = getRestUrl(context, "getAlbum", null); RequestBody formBody = new FormBody.Builder() .add("id", id) @@ -212,7 +214,7 @@ public class RESTMusicService implements MusicService { @Override public SearchResult search(SearchCritera critera, Context context, ProgressListener progressListener) throws Exception { - String url = getRestUrl(context, "search3"); + String url = getRestUrl(context, "search3", null); Builder builder = new FormBody.Builder(); @@ -235,7 +237,7 @@ public class RESTMusicService implements MusicService { @Override public MusicDirectory getPlaylist(boolean refresh, String id, String name, Context context, ProgressListener progressListener) throws Exception { - String url = getRestUrl(context, "getPlaylist"); + String url = getRestUrl(context, "getPlaylist", null); RequestBody formBody = new FormBody.Builder() .add("id", id) @@ -253,7 +255,7 @@ public class RESTMusicService implements MusicService { @Override public List 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() .url(url) @@ -266,7 +268,7 @@ public class RESTMusicService implements MusicService { @Override public void createPlaylist(String id, String name, List entries, Context context, ProgressListener progressListener) throws Exception { - String url = getRestUrl(context, "createPlaylist"); + String url = getRestUrl(context, "createPlaylist", null); Builder builder = new FormBody.Builder(); @@ -296,7 +298,7 @@ public class RESTMusicService implements MusicService { @Override public void deletePlaylist(String id, Context context, ProgressListener progressListener) throws Exception { - String url = getRestUrl(context, "deletePlaylist"); + String url = getRestUrl(context, "deletePlaylist", null); RequestBody formBody = new FormBody.Builder() .add("id", id) @@ -314,7 +316,7 @@ public class RESTMusicService implements MusicService { @Override public void addToPlaylist(String id, List toAdd, Context context, ProgressListener progressListener) throws Exception { - String url = getRestUrl(context, "updatePlaylist"); + String url = getRestUrl(context, "updatePlaylist", null); Builder builder = new FormBody.Builder(); builder.add("playlistId", id); @@ -336,7 +338,7 @@ public class RESTMusicService implements MusicService { @Override public void removeFromPlaylist(String id, List toRemove, Context context, ProgressListener progressListener) throws Exception { - String url = getRestUrl(context, "updatePlaylist"); + String url = getRestUrl(context, "updatePlaylist", null); Builder builder = new FormBody.Builder(); builder.add("playlistId", id); @@ -359,7 +361,7 @@ public class RESTMusicService implements MusicService { @Override public void overwritePlaylist(String id, String name, int toRemove, List toAdd, Context context, ProgressListener progressListener) throws Exception { - String url = getRestUrl(context, "updatePlaylist"); + String url = getRestUrl(context, "updatePlaylist", null); Builder builder = new FormBody.Builder(); builder.add("playlistId", id); @@ -387,7 +389,7 @@ public class RESTMusicService implements MusicService { @Override public void updatePlaylist(String id, String name, String comment, boolean pub, Context context, ProgressListener progressListener) throws Exception { - String url = getRestUrl(context, "updatePlaylist"); + String url = getRestUrl(context, "updatePlaylist", null); Builder builder = new FormBody.Builder(); builder.add("playlistId", id); @@ -409,7 +411,7 @@ public class RESTMusicService implements MusicService { @Override public MusicDirectory getAlbumList(String type, int size, int offset, boolean refresh, Context context, ProgressListener progressListener) throws Exception { - String url = getRestUrl(context, "getAlbumList2"); + String url = getRestUrl(context, "getAlbumList2", null); Builder builder = new FormBody.Builder(); builder.add("type", type); @@ -439,7 +441,7 @@ public class RESTMusicService implements MusicService { @Override public MusicDirectory getAlbumList(String type, String extra, int size, int offset, boolean refresh, Context context, ProgressListener progressListener) throws Exception { - String url = getRestUrl(context, "getAlbumList2"); + String url = getRestUrl(context, "getAlbumList2", null); Builder builder = new FormBody.Builder(); builder.add("size", Integer.toString(size)); @@ -501,7 +503,7 @@ public class RESTMusicService implements MusicService { method = "getNewaddedSongs"; } - String url = getRestUrl(context, method); + String url = getRestUrl(context, method, null); RequestBody formBody = builder.build(); @@ -546,7 +548,7 @@ public class RESTMusicService implements MusicService { builder.add("toYear", endYear); } - String url = getRestUrl(context, "getRandomSongs"); + String url = getRestUrl(context, "getRandomSongs", null); RequestBody formBody = builder.build(); @@ -572,7 +574,7 @@ public class RESTMusicService implements MusicService { return bitmap; } - String url = getRestUrl(context, "getCoverArt"); + String url = getRestUrl(context, "getCoverArt", null); Builder builder = new FormBody.Builder(); builder.add("id", entry.getCoverArt()); @@ -619,7 +621,7 @@ public class RESTMusicService implements MusicService { .readTimeout(30, TimeUnit.SECONDS) .build(); - String url = getRestUrl(context, "stream"); + String url = getRestUrl(context, "stream", null); Builder builder = new FormBody.Builder(); builder.add("id", song.getId()); @@ -643,7 +645,7 @@ public class RESTMusicService implements MusicService { @Override public List 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() .url(url) @@ -670,7 +672,7 @@ public class RESTMusicService implements MusicService { } } - String url = getRestUrl(context, "getSongsByGenre"); + String url = getRestUrl(context, "getSongsByGenre", null); RequestBody formBody = builder.build(); @@ -686,7 +688,7 @@ public class RESTMusicService implements MusicService { @Override public User getUser(boolean refresh, String username, Context context, ProgressListener progressListener) throws Exception { - String url = getRestUrl(context, "getUser"); + String url = getRestUrl(context, "getUser", null); RequestBody formBody = new FormBody.Builder() .add("username", username) @@ -742,15 +744,15 @@ public class RESTMusicService implements MusicService { } - public String getRestUrl(Context context, String method) { - return getRestUrl(context, method, true); + public String getRestUrl(Context context, String method, @Nullable Map parameters) { + 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 parameters) { if (instance == null) { - return Util.getRestUrl(context, method, allowAltAddress); + return Util.getRestUrl(context, method, allowAltAddress, parameters); } else { - return Util.getRestUrl(context, method, instance, allowAltAddress); + return Util.getRestUrl(context, method, instance, allowAltAddress, parameters); } } } diff --git a/app/src/main/java/net/nullsum/audinaut/util/Util.java b/app/src/main/java/net/nullsum/audinaut/util/Util.java index 0e46568..b464401 100644 --- a/app/src/main/java/net/nullsum/audinaut/util/Util.java +++ b/app/src/main/java/net/nullsum/audinaut/util/Util.java @@ -36,6 +36,7 @@ import android.net.NetworkInfo; import android.net.wifi.WifiManager; import android.os.Build; import android.os.Environment; +import android.support.annotation.Nullable; import android.support.annotation.StringRes; import android.support.v7.app.AlertDialog; import android.text.SpannableString; @@ -70,6 +71,7 @@ import java.text.DecimalFormat; import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.Map; import java.util.Random; import okhttp3.HttpUrl; @@ -277,21 +279,22 @@ public final class Util { } 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 parameters) { SharedPreferences prefs = getPreferences(context); 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 parameters) { 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 parameters) { String serverUrl = prefs.getString(Constants.PREFERENCES_KEY_SERVER_URL + instance, null); HttpUrl.Builder builder; @@ -334,6 +337,12 @@ public final class Util { builder.addQueryParameter("v", Constants.REST_PROTOCOL_VERSION_SUBSONIC); builder.addQueryParameter("c", Constants.REST_CLIENT_ID); + if (parameters != null) { + for (Map.Entry parameter : parameters.entrySet()) { + builder.addQueryParameter(parameter.getKey(), parameter.getValue()); + } + } + return builder.build().toString(); } @@ -352,7 +361,7 @@ public final class Util { } 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) { @@ -366,7 +375,7 @@ public final class Util { } 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"; } From 13ffabdb203ec00c66d403b13a445f05725f878f Mon Sep 17 00:00:00 2001 From: dddddd-mmmmmm <36978885+dddddd-mmmmmm@users.noreply.github.com> Date: Fri, 1 Mar 2019 15:28:58 +1100 Subject: [PATCH 3/5] nvllsvm/audinaut#37 Use query parameters instead of form bodies. --- .../audinaut/service/RESTMusicService.java | 242 ++++++++---------- 1 file changed, 106 insertions(+), 136 deletions(-) diff --git a/app/src/main/java/net/nullsum/audinaut/service/RESTMusicService.java b/app/src/main/java/net/nullsum/audinaut/service/RESTMusicService.java index 8ed0907..4b5e0d1 100644 --- a/app/src/main/java/net/nullsum/audinaut/service/RESTMusicService.java +++ b/app/src/main/java/net/nullsum/audinaut/service/RESTMusicService.java @@ -55,6 +55,7 @@ import net.nullsum.audinaut.util.Util; import java.io.FileOutputStream; import java.io.InputStream; import java.io.OutputStream; +import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.concurrent.TimeUnit; @@ -102,19 +103,21 @@ public class RESTMusicService implements MusicService { @Override public Indexes getIndexes(String musicFolderId, boolean refresh, Context context, ProgressListener progressListener) throws Exception { - String url = getRestUrl(context, "getArtists", null); - Builder builder = new FormBody.Builder(); + + + Map parameters = new HashMap<>(); 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() .url(url) - .post(formBody) .build(); try (Response response = client.newCall(request).execute()) { @@ -160,15 +163,14 @@ public class RESTMusicService implements MusicService { } private MusicDirectory getMusicDirectoryImpl(String id, String name, Context context) throws Exception { - String url = getRestUrl(context, "getMusicDirectory", null); + Map parameters = new HashMap<>(); - RequestBody formBody = new FormBody.Builder() - .add("id", id) - .build(); + parameters.put("id", id); + + String url = getRestUrl(context, "getMusicDirectory", parameters); Request request = new Request.Builder() .url(url) - .post(formBody) .build(); try (Response response = client.newCall(request).execute()) { @@ -178,15 +180,15 @@ public class RESTMusicService implements MusicService { @Override public MusicDirectory getArtist(String id, String name, boolean refresh, Context context, ProgressListener progressListener) throws Exception { - String url = getRestUrl(context, "getArtist", null); - RequestBody formBody = new FormBody.Builder() - .add("id", id) - .build(); + Map parameters = new HashMap<>(); + + parameters.put("id", id); + + String url = getRestUrl(context, "getArtist", parameters); Request request = new Request.Builder() .url(url) - .post(formBody) .build(); try (Response response = client.newCall(request).execute()) { @@ -196,15 +198,14 @@ public class RESTMusicService implements MusicService { @Override public MusicDirectory getAlbum(String id, String name, boolean refresh, Context context, ProgressListener progressListener) throws Exception { - String url = getRestUrl(context, "getAlbum", null); + Map parameters = new HashMap<>(); - RequestBody formBody = new FormBody.Builder() - .add("id", id) - .build(); + parameters.put("id", id); + + String url = getRestUrl(context, "getAlbum", parameters); Request request = new Request.Builder() .url(url) - .post(formBody) .build(); try (Response response = client.newCall(request).execute()) { @@ -214,20 +215,17 @@ public class RESTMusicService implements MusicService { @Override public SearchResult search(SearchCritera critera, Context context, ProgressListener progressListener) throws Exception { - String url = getRestUrl(context, "search3", null); + Map 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()); - 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(); + String url = getRestUrl(context, "search3", parameters); Request request = new Request.Builder() .url(url) - .post(formBody) .build(); try (Response response = client.newCall(request).execute()) { @@ -237,15 +235,14 @@ public class RESTMusicService implements MusicService { @Override public MusicDirectory getPlaylist(boolean refresh, String id, String name, Context context, ProgressListener progressListener) throws Exception { - String url = getRestUrl(context, "getPlaylist", null); + Map parameters = new HashMap<>(); - RequestBody formBody = new FormBody.Builder() - .add("id", id) - .build(); + parameters.put("id", id); + + String url = getRestUrl(context, "getPlaylist", parameters); Request request = new Request.Builder() .url(url) - .post(formBody) .build(); try (Response response = client.newCall(request).execute()) { @@ -268,27 +265,24 @@ public class RESTMusicService implements MusicService { @Override public void createPlaylist(String id, String name, List entries, Context context, ProgressListener progressListener) throws Exception { - String url = getRestUrl(context, "createPlaylist", null); - - Builder builder = new FormBody.Builder(); + Map parameters = new HashMap<>(); if (id != null) { - builder.add("playlistId", id); + parameters.put("playlistId", id); } if (name != null) { - builder.add("name", name); + parameters.put("name", name); } 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() .url(url) - .post(formBody) .build(); try (Response response = client.newCall(request).execute()) { @@ -298,15 +292,14 @@ public class RESTMusicService implements MusicService { @Override public void deletePlaylist(String id, Context context, ProgressListener progressListener) throws Exception { - String url = getRestUrl(context, "deletePlaylist", null); + Map parameters = new HashMap<>(); - RequestBody formBody = new FormBody.Builder() - .add("id", id) - .build(); + parameters.put("id", id); + + String url = getRestUrl(context, "deletePlaylist", parameters); Request request = new Request.Builder() .url(url) - .post(formBody) .build(); try (Response response = client.newCall(request).execute()) { @@ -316,19 +309,17 @@ public class RESTMusicService implements MusicService { @Override public void addToPlaylist(String id, List toAdd, Context context, ProgressListener progressListener) throws Exception { - String url = getRestUrl(context, "updatePlaylist", null); + Map parameters = new HashMap<>(); - Builder builder = new FormBody.Builder(); - builder.add("playlistId", id); + parameters.put("playlistId", id); 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() .url(url) - .post(formBody) .build(); try (Response response = client.newCall(request).execute()) { @@ -338,20 +329,18 @@ public class RESTMusicService implements MusicService { @Override public void removeFromPlaylist(String id, List toRemove, Context context, ProgressListener progressListener) throws Exception { - String url = getRestUrl(context, "updatePlaylist", null); + Map parameters = new HashMap<>(); - Builder builder = new FormBody.Builder(); - builder.add("playlistId", id); + parameters.put("playlistId", id); 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() .url(url) - .post(formBody) .build(); try (Response response = client.newCall(request).execute()) { @@ -361,25 +350,23 @@ public class RESTMusicService implements MusicService { @Override public void overwritePlaylist(String id, String name, int toRemove, List toAdd, Context context, ProgressListener progressListener) throws Exception { - String url = getRestUrl(context, "updatePlaylist", null); + Map parameters = new HashMap<>(); - Builder builder = new FormBody.Builder(); - builder.add("playlistId", id); - builder.add("name", name); + parameters.put("playlistId", id); + parameters.put("name", name); 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++) { - 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() .url(url) - .post(formBody) .build(); try (Response response = client.newCall(request).execute()) { @@ -389,19 +376,17 @@ public class RESTMusicService implements MusicService { @Override public void updatePlaylist(String id, String name, String comment, boolean pub, Context context, ProgressListener progressListener) throws Exception { - String url = getRestUrl(context, "updatePlaylist", null); + Map parameters = new HashMap<>(); - Builder builder = new FormBody.Builder(); - builder.add("playlistId", id); - builder.add("name", name); - builder.add("comment", comment); - builder.add("public", Boolean.toString(pub)); + parameters.put("playlistId", id); + parameters.put("name", name); + parameters.put("comment", comment); + parameters.put("public", Boolean.toString(pub)); - RequestBody formBody = builder.build(); + String url = getRestUrl(context, "updatePlaylist", parameters); Request request = new Request.Builder() .url(url) - .post(formBody) .build(); try (Response response = client.newCall(request).execute()) { @@ -411,27 +396,25 @@ public class RESTMusicService implements MusicService { @Override public MusicDirectory getAlbumList(String type, int size, int offset, boolean refresh, Context context, ProgressListener progressListener) throws Exception { - String url = getRestUrl(context, "getAlbumList2", null); + Map parameters = new HashMap<>(); - Builder builder = new FormBody.Builder(); - builder.add("type", type); - builder.add("size", Integer.toString(size)); - builder.add("offset", Integer.toString(offset)); + parameters.put("type", type); + parameters.put("size", Integer.toString(size)); + parameters.put("offset", Integer.toString(offset)); // Add folder if it was set and is non null int instance = getInstance(context); if (Util.getAlbumListsPerFolder(context, instance)) { String folderId = Util.getSelectedMusicFolderId(context, instance); 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() .url(url) - .post(formBody) .build(); try (Response response = client.newCall(request).execute()) { @@ -441,37 +424,35 @@ public class RESTMusicService implements MusicService { @Override public MusicDirectory getAlbumList(String type, String extra, int size, int offset, boolean refresh, Context context, ProgressListener progressListener) throws Exception { - String url = getRestUrl(context, "getAlbumList2", null); + Map parameters = new HashMap<>(); - Builder builder = new FormBody.Builder(); - builder.add("size", Integer.toString(size)); - builder.add("offset", Integer.toString(offset)); + parameters.put("size", Integer.toString(size)); + parameters.put("offset", Integer.toString(offset)); int instance = getInstance(context); if ("genres".equals(type)) { - builder.add("type", "byGenre"); - builder.add("genre", extra); + parameters.put("type", "byGenre"); + parameters.put("genre", extra); } else if ("years".equals(type)) { int decade = Integer.parseInt(extra); - builder.add("type", "byYear"); - builder.add("fromYear", Integer.toString(decade + 9)); - builder.add("toYear", Integer.toString(decade)); + parameters.put("type", "byYear"); + parameters.put("fromYear", Integer.toString(decade + 9)); + parameters.put("toYear", Integer.toString(decade)); } // Add folder if it was set and is non null if (Util.getAlbumListsPerFolder(context, instance)) { String folderId = Util.getSelectedMusicFolderId(context, instance); 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() .url(url) - .post(formBody) .build(); try (Response response = client.newCall(request).execute()) { @@ -481,9 +462,10 @@ public class RESTMusicService implements MusicService { @Override public MusicDirectory getSongList(String type, int size, int offset, Context context, ProgressListener progressListener) throws Exception { - Builder builder = new FormBody.Builder(); - builder.add("size", Integer.toString(size)); - builder.add("offset", Integer.toString(offset)); + Map parameters = new HashMap<>(); + + parameters.put("size", Integer.toString(size)); + parameters.put("offset", Integer.toString(offset)); String method; switch (type) { @@ -503,13 +485,10 @@ public class RESTMusicService implements MusicService { method = "getNewaddedSongs"; } - String url = getRestUrl(context, method, null); - - RequestBody formBody = builder.build(); + String url = getRestUrl(context, method, parameters); Request request = new Request.Builder() .url(url) - .post(formBody) .build(); try (Response response = client.newCall(request).execute()) { @@ -519,11 +498,12 @@ public class RESTMusicService implements MusicService { @Override public MusicDirectory getRandomSongs(int size, String musicFolderId, String genre, String startYear, String endYear, Context context, ProgressListener progressListener) throws Exception { - Builder builder = new FormBody.Builder(); - builder.add("size", Integer.toString(size)); + Map parameters = new HashMap<>(); + + parameters.put("size", Integer.toString(size)); if (genre != null && !"".equals(genre)) { - builder.add("genre", genre); + parameters.put("genre", genre); } if (startYear != null && !"".equals(startYear)) { // Check to make sure user isn't doing 2015 -> 2010 since Subsonic will return no results @@ -542,19 +522,16 @@ public class RESTMusicService implements MusicService { } } - builder.add("fromYear", startYear); + parameters.put("fromYear", startYear); } if (endYear != null && !"".equals(endYear)) { - builder.add("toYear", endYear); + parameters.put("toYear", endYear); } - String url = getRestUrl(context, "getRandomSongs", null); - - RequestBody formBody = builder.build(); + String url = getRestUrl(context, "getRandomSongs", parameters); Request request = new Request.Builder() .url(url) - .post(formBody) .build(); try (Response response = client.newCall(request).execute()) { @@ -574,16 +551,14 @@ public class RESTMusicService implements MusicService { return bitmap; } - String url = getRestUrl(context, "getCoverArt", null); + Map parameters = new HashMap<>(); - Builder builder = new FormBody.Builder(); - builder.add("id", entry.getCoverArt()); + parameters.put("id", entry.getCoverArt()); - RequestBody formBody = builder.build(); + String url = getRestUrl(context, "getCoverArt", parameters); Request request = new Request.Builder() .url(url) - .post(formBody) .build(); try (Response response = client.newCall(request).execute()) { @@ -621,13 +596,12 @@ public class RESTMusicService implements MusicService { .readTimeout(30, TimeUnit.SECONDS) .build(); - String url = getRestUrl(context, "stream", null); + Map parameters = new HashMap<>(); - Builder builder = new FormBody.Builder(); - builder.add("id", song.getId()); - builder.add("maxBitRate", Integer.toString(maxBitrate)); + parameters.put("id", song.getId()); + parameters.put("maxBitRate", Integer.toString(maxBitrate)); - RequestBody formBody = builder.build(); + String url = getRestUrl(context, "stream", parameters); Request.Builder requestBuilder = new Request.Builder(); if (offset > 0) { @@ -635,7 +609,6 @@ public class RESTMusicService implements MusicService { } requestBuilder.url(url); - requestBuilder.post(formBody); Request request = requestBuilder.build(); @@ -658,27 +631,25 @@ public class RESTMusicService implements MusicService { @Override public MusicDirectory getSongsByGenre(String genre, int count, int offset, Context context, ProgressListener progressListener) throws Exception { - Builder builder = new FormBody.Builder(); - builder.add("genre", genre); - builder.add("count", Integer.toString(count)); - builder.add("offset", Integer.toString(offset)); + Map parameters = new HashMap<>(); + + parameters.put("genre", genre); + parameters.put("count", Integer.toString(count)); + parameters.put("offset", Integer.toString(offset)); // Add folder if it was set and is non null int instance = getInstance(context); if (Util.getAlbumListsPerFolder(context, instance)) { String folderId = Util.getSelectedMusicFolderId(context, instance); if (folderId != null) { - builder.add("musicFolderId", folderId); + parameters.put("musicFolderId", folderId); } } - String url = getRestUrl(context, "getSongsByGenre", null); - - RequestBody formBody = builder.build(); + String url = getRestUrl(context, "getSongsByGenre", parameters); Request request = new Request.Builder() .url(url) - .post(formBody) .build(); try (Response response = client.newCall(request).execute()) { @@ -688,15 +659,14 @@ public class RESTMusicService implements MusicService { @Override public User getUser(boolean refresh, String username, Context context, ProgressListener progressListener) throws Exception { - String url = getRestUrl(context, "getUser", null); + Map parameters = new HashMap<>(); - RequestBody formBody = new FormBody.Builder() - .add("username", username) - .build(); + parameters.put("username", username); + + String url = getRestUrl(context, "getUser", parameters); Request request = new Request.Builder() .url(url) - .post(formBody) .build(); try (Response response = client.newCall(request).execute()) { From 05ce1509ecd93610a1d9c0ced9ddfde01c0e402a Mon Sep 17 00:00:00 2001 From: dddddd-mmmmmm <36978885+dddddd-mmmmmm@users.noreply.github.com> Date: Fri, 1 Mar 2019 15:37:52 +1100 Subject: [PATCH 4/5] Fix broken getRESTUrl() calls from other Util classes. --- .../net/nullsum/audinaut/service/CachedMusicService.java | 6 +++--- app/src/main/java/net/nullsum/audinaut/util/FileUtil.java | 2 +- app/src/main/java/net/nullsum/audinaut/util/SyncUtil.java | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/net/nullsum/audinaut/service/CachedMusicService.java b/app/src/main/java/net/nullsum/audinaut/service/CachedMusicService.java index cd5f2db..0052a74 100644 --- a/app/src/main/java/net/nullsum/audinaut/service/CachedMusicService.java +++ b/app/src/main/java/net/nullsum/audinaut/service/CachedMusicService.java @@ -640,12 +640,12 @@ public class CachedMusicService implements MusicService { } 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"; } 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"; } @@ -672,7 +672,7 @@ public class CachedMusicService implements MusicService { private void checkSettingsChanged(Context 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)) { cachedMusicFolders.clear(); cachedIndexes.clear(); diff --git a/app/src/main/java/net/nullsum/audinaut/util/FileUtil.java b/app/src/main/java/net/nullsum/audinaut/util/FileUtil.java index 9d88350..be88fb2 100644 --- a/app/src/main/java/net/nullsum/audinaut/util/FileUtil.java +++ b/app/src/main/java/net/nullsum/audinaut/util/FileUtil.java @@ -292,7 +292,7 @@ public class FileUtil { } // 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"; MusicDirectory entryDir = FileUtil.deserialize(context, cacheName, MusicDirectory.class); diff --git a/app/src/main/java/net/nullsum/audinaut/util/SyncUtil.java b/app/src/main/java/net/nullsum/audinaut/util/SyncUtil.java index e694bfa..e191140 100644 --- a/app/src/main/java/net/nullsum/audinaut/util/SyncUtil.java +++ b/app/src/main/java/net/nullsum/audinaut/util/SyncUtil.java @@ -15,7 +15,7 @@ public final class SyncUtil { private static void checkRestURL(Context 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)) { syncedPlaylists = null; url = newURL; @@ -72,7 +72,7 @@ public final class SyncUtil { } 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) { @@ -84,7 +84,7 @@ public final class SyncUtil { } 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 { From 01d4b270cf501856b5281b8fb6245b205520a60e Mon Sep 17 00:00:00 2001 From: dddddd-mmmmmm <36978885+dddddd-mmmmmm@users.noreply.github.com> Date: Fri, 1 Mar 2019 15:42:05 +1100 Subject: [PATCH 5/5] Add FOREGROUND_SERVICE permission as required for target SDK version 28 (Pie). --- app/src/main/AndroidManifest.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 083f3d1..cee22e8 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -16,6 +16,7 @@ +