From 35d4d159a7cc4493a466dd2592120d4cf5f1a544 Mon Sep 17 00:00:00 2001 From: nico202 Date: Wed, 23 May 2018 18:01:10 +0200 Subject: [PATCH 01/12] Fix wrong generated url (prevented sync start) --- .idea/codeStyles/Project.xml | 29 +++++++++++++++++++ .idea/modules.xml | 8 +++++ .idea/runConfigurations.xml | 12 ++++++++ .idea/vcs.xml | 6 ++++ .../music_cyclon/service/BeetsFetcher.java | 6 ++-- music-cyclon.iml | 16 ++++++++++ 6 files changed, 74 insertions(+), 3 deletions(-) create mode 100644 .idea/codeStyles/Project.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/runConfigurations.xml create mode 100644 .idea/vcs.xml create mode 100644 music-cyclon.iml diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml new file mode 100644 index 0000000..30aa626 --- /dev/null +++ b/.idea/codeStyles/Project.xml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..e5a6416 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml new file mode 100644 index 0000000..7f68460 --- /dev/null +++ b/.idea/runConfigurations.xml @@ -0,0 +1,12 @@ + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/java/max/music_cyclon/service/BeetsFetcher.java b/app/src/main/java/max/music_cyclon/service/BeetsFetcher.java index ec6e3a4..ef1aaf7 100644 --- a/app/src/main/java/max/music_cyclon/service/BeetsFetcher.java +++ b/app/src/main/java/max/music_cyclon/service/BeetsFetcher.java @@ -33,14 +33,14 @@ public class BeetsFetcher { StringBuilder get; if (config.isAlbum(resources)) { - get = new StringBuilder("/album"); + get = new StringBuilder("/album/"); } else { - get = new StringBuilder("/item"); + get = new StringBuilder("/item/"); } String query = config.getQuery(resources); if (!query.isEmpty()) { - get.append("/query/").append(query); + get.append("query/").append(query); } get.append("?expand"); diff --git a/music-cyclon.iml b/music-cyclon.iml new file mode 100644 index 0000000..0fe7ea9 --- /dev/null +++ b/music-cyclon.iml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + \ No newline at end of file From d6ef0d1e6f229774bf2b716af54b96cb1bf54745 Mon Sep 17 00:00:00 2001 From: nico202 Date: Thu, 24 May 2018 17:47:34 +0200 Subject: [PATCH 02/12] fix random generation (fix bug if only 1 match found) --- app/src/main/java/max/music_cyclon/service/BeetsFetcher.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/max/music_cyclon/service/BeetsFetcher.java b/app/src/main/java/max/music_cyclon/service/BeetsFetcher.java index ef1aaf7..9bead5f 100644 --- a/app/src/main/java/max/music_cyclon/service/BeetsFetcher.java +++ b/app/src/main/java/max/music_cyclon/service/BeetsFetcher.java @@ -105,7 +105,8 @@ public class BeetsFetcher { ArrayList out = new ArrayList<>(); for (int i = 0; i < n; i++) { - out.add(list.get(RANDOM.nextInt(list.size() - 1))); + int item = list.size() > 1 ? RANDOM.nextInt(list.size() - 1) : 0; + out.add(list.get(item)); } return Collections.unmodifiableList(out); From 7c24564cfa7ab9c8606dc3ac3178a5848629413d Mon Sep 17 00:00:00 2001 From: nico202 Date: Thu, 24 May 2018 17:50:25 +0200 Subject: [PATCH 03/12] fix german string -> english --- app/src/main/java/max/music_cyclon/service/LibraryService.java | 2 +- app/src/main/res/values/strings.xml | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/max/music_cyclon/service/LibraryService.java b/app/src/main/java/max/music_cyclon/service/LibraryService.java index 1903b63..58c291e 100644 --- a/app/src/main/java/max/music_cyclon/service/LibraryService.java +++ b/app/src/main/java/max/music_cyclon/service/LibraryService.java @@ -168,7 +168,7 @@ public class LibraryService extends IntentService { e.printStackTrace(); } - updater.showMessage("Musik aktualisiert"); + updater.showMessage(getResources().getString(R.string.music_updated)); // Poweramp support Intent poweramp = new Intent(PowerampAPI.Scanner.ACTION_SCAN_DIRS); diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 7eb7b29..338dd10 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -7,6 +7,7 @@ Version Synchronizing Already synchronizing! + Music Updated! Default Rename From a6d270b7a4fa2541a20887ead0446c1ad236daf0 Mon Sep 17 00:00:00 2001 From: nico202 Date: Thu, 24 May 2018 18:17:37 +0200 Subject: [PATCH 04/12] format path from artist and filename --- .../music_cyclon/service/BeetsFetcher.java | 10 +++++-- .../java/max/music_cyclon/service/Item.java | 27 ++++++++++++++++++- 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/max/music_cyclon/service/BeetsFetcher.java b/app/src/main/java/max/music_cyclon/service/BeetsFetcher.java index 9bead5f..d044427 100644 --- a/app/src/main/java/max/music_cyclon/service/BeetsFetcher.java +++ b/app/src/main/java/max/music_cyclon/service/BeetsFetcher.java @@ -145,8 +145,14 @@ public class BeetsFetcher { case "id": item.setID(reader.nextInt()); break; - case "path": - item.setPath(reader.nextString()); + case "format": + item.setFormat(reader.nextString()); + break; + case "title": + item.setTitle(reader.nextString()); + break; + case "artist": + item.setArtist(reader.nextString()); break; default: reader.skipValue(); diff --git a/app/src/main/java/max/music_cyclon/service/Item.java b/app/src/main/java/max/music_cyclon/service/Item.java index 6d47458..a512a28 100644 --- a/app/src/main/java/max/music_cyclon/service/Item.java +++ b/app/src/main/java/max/music_cyclon/service/Item.java @@ -4,6 +4,9 @@ public class Item { private int id; private String path; + private String artist; + private String title; + private String format; public int getID() { return id; @@ -14,10 +17,32 @@ public class Item { } public String getPath() { - return path; + if (path != null) { + return path; + } else { + return "/" + artist + "/" + title + "_" + id + "." + format.toLowerCase(); + } + } + public String getArtist() { + return artist; + } + public String getTitle() { + return title; + } + public String getFormat() { + return format; } public void setPath(String path) { this.path = path; } + public void setTitle(String title) { + this.title = title; + } + public void setFormat(String format) { + this.format = format; + } + public void setArtist(String artist) { + this.artist = artist; + } } From c96312b2517d8d37564453c157e0cd3cb2c82bb9 Mon Sep 17 00:00:00 2001 From: nico202 Date: Thu, 24 May 2018 18:20:00 +0200 Subject: [PATCH 05/12] change library path, basic http auth support --- .../music_cyclon/service/BeetsFetcher.java | 7 +- .../music_cyclon/service/DownloadTask.java | 66 ++++++++++++------- .../music_cyclon/service/LibraryService.java | 14 +++- app/src/main/res/values/default_config.xml | 2 + app/src/main/res/values/strings.xml | 2 + app/src/main/res/xml/preferences.xml | 21 ++++++ 6 files changed, 83 insertions(+), 29 deletions(-) diff --git a/app/src/main/java/max/music_cyclon/service/BeetsFetcher.java b/app/src/main/java/max/music_cyclon/service/BeetsFetcher.java index d044427..7a04846 100644 --- a/app/src/main/java/max/music_cyclon/service/BeetsFetcher.java +++ b/app/src/main/java/max/music_cyclon/service/BeetsFetcher.java @@ -29,7 +29,8 @@ public class BeetsFetcher { this.resources = resources; } - public List fetch(SynchronizeConfig config) throws IOException { + public List fetch(SynchronizeConfig config, + String username, String password) throws IOException { StringBuilder get; if (config.isAlbum(resources)) { @@ -46,8 +47,11 @@ public class BeetsFetcher { get.append("?expand"); OkHttpClient client = new OkHttpClient(); + String auth = okhttp3.Credentials.basic(username != null ? username : "", + password != null ? password : ""); Request request = new Request.Builder() .url(address + get) + .header("Authorization", auth) .build(); Response response = client.newCall(request).execute(); @@ -67,7 +71,6 @@ public class BeetsFetcher { private List parseJson(InputStream stream, int size, boolean isAlbums) throws IOException { JsonReader reader = new JsonReader(new BufferedReader(new InputStreamReader(stream, "UTF-8"))); - List items = new ArrayList<>(); List> albums = new ArrayList<>(); diff --git a/app/src/main/java/max/music_cyclon/service/DownloadTask.java b/app/src/main/java/max/music_cyclon/service/DownloadTask.java index 70905f7..0745429 100644 --- a/app/src/main/java/max/music_cyclon/service/DownloadTask.java +++ b/app/src/main/java/max/music_cyclon/service/DownloadTask.java @@ -23,26 +23,38 @@ public class DownloadTask implements Runnable { private final SynchronizeConfig config; private final String url; private final String itemPath; - + private final String libraryPath; + private final String username; + private final String password; private final FileTracker tracker; private final ProgressUpdater progressUpdater; private CountDownLatch itemsLeftLatch; public static final OkHttpClient CLIENT = new OkHttpClient(); - public DownloadTask(SynchronizeConfig config, String url, String itemPath, - FileTracker tracker, ProgressUpdater progressUpdater) { + public DownloadTask(SynchronizeConfig config, String url, + String libraryPath, String itemPath, + FileTracker tracker, ProgressUpdater progressUpdater, + String username, String password + ) { this.config = config; this.url = url; this.itemPath = itemPath; + this.libraryPath = libraryPath; + + this.username = username; + this.password = password; this.tracker = tracker; this.progressUpdater = progressUpdater; } private InputStream prepareConnection() throws IOException { + String auth = okhttp3.Credentials.basic(username != null ? username : "", + password != null ? password : ""); Request request = new Request.Builder() .url(url) + .header("Authorization", auth) .build(); Response response = CLIENT.newCall(request).execute(); @@ -61,35 +73,41 @@ public class DownloadTask implements Runnable { @Override public void run() { - File root = new File(Environment.getExternalStorageDirectory(), "library"); + File root = new File(Environment.getExternalStorageDirectory(), + libraryPath); + if (itemPath != null) { + try { + File target = new File(root, itemPath); + if (! target.exists()) { + Adler32 checksum = new Adler32(); - try { - File target = new File(root, itemPath); - Adler32 checksum = new Adler32(); + InputStream input = prepareConnection(); - InputStream input = prepareConnection(); + if (input != null) { + Log.d("DOWNLOAD", "Writing file: " + target); + FileOutputStream output = FileUtils.openOutputStream(target); - if (input != null) { + byte[] buffer = new byte[4 * 1024]; + int n; + while (-1 != (n = input.read(buffer))) { + output.write(buffer, 0, n); + checksum.update(buffer, 0, n); + } - FileOutputStream output = FileUtils.openOutputStream(target); + output.flush(); + output.close(); + input.close(); + } - byte[] buffer = new byte[4 * 1024]; - int n; - while (-1 != (n = input.read(buffer))) { - output.write(buffer, 0, n); - checksum.update(buffer, 0, n); + tracker.track(config, target, checksum.getValue()); } - - output.flush(); - output.close(); - input.close(); + } catch (IOException e) { + Log.e("DOWNLOAD", "Failed to download", e); } - - tracker.track(config, target, checksum.getValue()); - } catch (IOException e) { - Log.e("DOWNLOAD", "Failed to download", e); + Log.i("DOWNLOAD", "Success"); + } else { + Log.e("DOWNLOAD", "Missing download path, FAILED!"); } - progressUpdater.increment(); itemsLeftLatch.countDown(); } diff --git a/app/src/main/java/max/music_cyclon/service/LibraryService.java b/app/src/main/java/max/music_cyclon/service/LibraryService.java index 58c291e..2ac4e6c 100644 --- a/app/src/main/java/max/music_cyclon/service/LibraryService.java +++ b/app/src/main/java/max/music_cyclon/service/LibraryService.java @@ -136,7 +136,11 @@ public class LibraryService extends IntentService { List items; try { updater.showOngoingMessage("Fetching music information for %s", config.getName()); - items = fetcher.fetch(config); + items = fetcher.fetch(config, + globalSettings.getString("username", null), + globalSettings.getString("password", null)); + Log.d("LISTOUT", "Length: " + items.size()); + } catch (IOException e) { Log.wtf("WTF", e); updater.showMessage("Remote not available"); @@ -149,7 +153,12 @@ public class LibraryService extends IntentService { for (Item item : items) { String url = address + "/item/" + item.getID() + "/file"; - tasks.add(new DownloadTask(config, url, item.getPath(), tracker, updater)); + tasks.add(new DownloadTask(config, url, + globalSettings.getString("library_path", "library"), + config.getName() + item.getPath(), tracker, updater, + globalSettings.getString("username", null), + globalSettings.getString("password", null) + )); } } @@ -176,7 +185,6 @@ public class LibraryService extends IntentService { poweramp.putExtra(PowerampAPI.Scanner.EXTRA_FULL_RESCAN, true); startService(poweramp); - finished(); } diff --git a/app/src/main/res/values/default_config.xml b/app/src/main/res/values/default_config.xml index a3c2da4..1b2d867 100644 --- a/app/src/main/res/values/default_config.xml +++ b/app/src/main/res/values/default_config.xml @@ -2,6 +2,8 @@ http://localhost:8337 2 + + 10 true diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 338dd10..dab879d 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -8,6 +8,8 @@ Synchronizing Already synchronizing! Music Updated! + + library Default Rename diff --git a/app/src/main/res/xml/preferences.xml b/app/src/main/res/xml/preferences.xml index 51cf3af..04385ad 100644 --- a/app/src/main/res/xml/preferences.xml +++ b/app/src/main/res/xml/preferences.xml @@ -14,5 +14,26 @@ android:key="threads" android:summary="Number of threads to use for downloading" android:title="Threads" /> + + + \ No newline at end of file From fb44d3e6c796cddd22baa9f938faf0d6661f32be Mon Sep 17 00:00:00 2001 From: nico202 Date: Fri, 25 May 2018 17:55:42 +0200 Subject: [PATCH 06/12] Remove poweramp support (commented) --- .../max/music_cyclon/service/LibraryService.java | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/max/music_cyclon/service/LibraryService.java b/app/src/main/java/max/music_cyclon/service/LibraryService.java index 2ac4e6c..7cd1ab0 100644 --- a/app/src/main/java/max/music_cyclon/service/LibraryService.java +++ b/app/src/main/java/max/music_cyclon/service/LibraryService.java @@ -18,7 +18,8 @@ import android.support.v4.app.NotificationCompat; import android.support.v4.content.ContextCompat; import android.util.Log; -import com.maxmpz.poweramp.player.PowerampAPI; +// Poweramp support +// import com.maxmpz.poweramp.player.PowerampAPI; import java.io.File; import java.io.IOException; @@ -179,11 +180,12 @@ public class LibraryService extends IntentService { updater.showMessage(getResources().getString(R.string.music_updated)); - // Poweramp support - Intent poweramp = new Intent(PowerampAPI.Scanner.ACTION_SCAN_DIRS); - poweramp.setPackage(PowerampAPI.PACKAGE_NAME); - poweramp.putExtra(PowerampAPI.Scanner.EXTRA_FULL_RESCAN, true); - startService(poweramp); + // I don't want to support proprietary things + // If you need to enable Poweramp support, uncomment this + // Intent poweramp = new Intent(PowerampAPI.Scanner.ACTION_SCAN_DIRS); + // poweramp.setPackage(PowerampAPI.PACKAGE_NAME); + // poweramp.putExtra(PowerampAPI.Scanner.EXTRA_FULL_RESCAN, true); + // startService(poweramp); finished(); } From a757b967d16c5627f16c445c3d2dd959e1906a76 Mon Sep 17 00:00:00 2001 From: nico202 Date: Thu, 24 May 2018 18:56:23 +0200 Subject: [PATCH 07/12] fix apk build (update gradle) --- .idea/caches/build_file_checksums.ser | Bin 0 -> 537 bytes .idea/gradle.xml | 18 +++++ .idea/misc.xml | 34 +++++++++ .idea/modules.xml | 1 + app/app.iml | 84 +++++++++++++++-------- app/build.gradle | 2 +- build.gradle | 6 +- gradle/wrapper/gradle-wrapper.properties | 4 +- music-cyclon.iml | 13 ++-- 9 files changed, 122 insertions(+), 40 deletions(-) create mode 100644 .idea/caches/build_file_checksums.ser create mode 100644 .idea/gradle.xml create mode 100644 .idea/misc.xml diff --git a/.idea/caches/build_file_checksums.ser b/.idea/caches/build_file_checksums.ser new file mode 100644 index 0000000000000000000000000000000000000000..d2e26ae26f08a72707c3481ed4b529f0123ccbe2 GIT binary patch literal 537 zcmZ4UmVvdnh`~NNKUXg?FQq6yGexf?KR>5fFEb@IQ7^qHF(oHeub?PDD>b=9F91S2 zm1gFoxMk*~I%lLNXBU^|7Q2L-Ts|(GuF1r}uGBYr_F>vMNC#JY1CYR(Fc`|U8WE7 + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..dc34569 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml index e5a6416..4cfe290 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -2,6 +2,7 @@ + diff --git a/app/app.iml b/app/app.iml index f70e089..fc61fe1 100644 --- a/app/app.iml +++ b/app/app.iml @@ -1,5 +1,5 @@ - + @@ -9,13 +9,9 @@ - + - + + - + + - + + - + + + + + + + + + + + + + + + - + - + + + + + + + + + + - - - - - - - - + + + + - - + + + + - + - - - - - + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index 68d6639..9765bcf 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -2,7 +2,7 @@ apply plugin: 'com.android.application' android { compileSdkVersion 23 - buildToolsVersion "23.0.3" + buildToolsVersion '27.0.3' defaultConfig { applicationId "max.music_cyclon" diff --git a/build.gradle b/build.gradle index e220f0b..0291d45 100644 --- a/build.gradle +++ b/build.gradle @@ -3,12 +3,10 @@ buildscript { repositories { jcenter() + google() } dependencies { - classpath 'com.android.tools.build:gradle:2.1.2' - - // NOTE: Do not place your application dependencies here; they belong - // in the individual module build.gradle files + classpath 'com.android.tools.build:gradle:3.1.2' } } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 6553df6..fa04b38 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Wed Jun 01 15:28:51 CEST 2016 +#Thu May 24 16:50:41 GMT 2018 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip diff --git a/music-cyclon.iml b/music-cyclon.iml index 0fe7ea9..2f126a7 100644 --- a/music-cyclon.iml +++ b/music-cyclon.iml @@ -1,15 +1,18 @@ - + - + - - + - + + + From fb1b0d316219437a0e6ca99d095983487f948ce5 Mon Sep 17 00:00:00 2001 From: nico202 Date: Fri, 25 May 2018 16:18:56 +0200 Subject: [PATCH 08/12] fix preference input types --- app/src/main/res/xml/preferences.xml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/src/main/res/xml/preferences.xml b/app/src/main/res/xml/preferences.xml index 04385ad..e5d2f04 100644 --- a/app/src/main/res/xml/preferences.xml +++ b/app/src/main/res/xml/preferences.xml @@ -17,23 +17,23 @@ - \ No newline at end of file + From b3cd39c72bf96267bbd80f4c735290d0ca4af7f8 Mon Sep 17 00:00:00 2001 From: nico202 Date: Thu, 24 May 2018 17:46:09 +0200 Subject: [PATCH 09/12] Use sets instead of lists where possible (don't download duplicates) --- .../music_cyclon/service/BeetsFetcher.java | 26 +++++++++++-------- .../music_cyclon/service/LibraryService.java | 3 ++- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/max/music_cyclon/service/BeetsFetcher.java b/app/src/main/java/max/music_cyclon/service/BeetsFetcher.java index 7a04846..0f24170 100644 --- a/app/src/main/java/max/music_cyclon/service/BeetsFetcher.java +++ b/app/src/main/java/max/music_cyclon/service/BeetsFetcher.java @@ -10,8 +10,10 @@ import java.io.InputStream; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Collections; +import java.util.HashSet; import java.util.List; import java.util.Random; +import java.util.Set; import max.music_cyclon.SynchronizeConfig; import okhttp3.OkHttpClient; @@ -29,7 +31,7 @@ public class BeetsFetcher { this.resources = resources; } - public List fetch(SynchronizeConfig config, + public Set fetch(SynchronizeConfig config, String username, String password) throws IOException { StringBuilder get; @@ -58,18 +60,18 @@ public class BeetsFetcher { if (response.code() != 200) { Log.e("ERROR", "Server returned HTTP " + response.message()); - return Collections.emptyList(); + return Collections.emptySet(); } InputStream stream = response.body().byteStream(); - List items = parseJson(stream, config.getSize(resources), config.isAlbum(resources)); + Set items = parseJson(stream, config.getSize(resources), config.isAlbum(resources)); stream.close(); return items; } - private List parseJson(InputStream stream, int size, boolean isAlbums) throws IOException { + private Set parseJson(InputStream stream, int size, boolean isAlbums) throws IOException { JsonReader reader = new JsonReader(new BufferedReader(new InputStreamReader(stream, "UTF-8"))); List items = new ArrayList<>(); List> albums = new ArrayList<>(); @@ -90,29 +92,31 @@ public class BeetsFetcher { // Select random if (isAlbums) { - List> randomAlbums = selectRandom(albums, size); + Set> randomAlbums = selectRandom(albums, size); - for (ArrayList album : randomAlbums) { + for (List album : randomAlbums) { items.addAll(album); } - return Collections.unmodifiableList(items); + + return Collections.unmodifiableSet(new HashSet(items)); } else { return selectRandom(items, size); } } - public List selectRandom(List list, int n) { + public Set selectRandom(List list, int n) { if (list.isEmpty()) { - return Collections.emptyList(); + return Collections.emptySet(); } - ArrayList out = new ArrayList<>(); + Set out = new HashSet(); + for (int i = 0; i < n; i++) { int item = list.size() > 1 ? RANDOM.nextInt(list.size() - 1) : 0; out.add(list.get(item)); } - return Collections.unmodifiableList(out); + return Collections.unmodifiableSet(out); } private ArrayList parseAlbum(JsonReader reader) throws IOException { diff --git a/app/src/main/java/max/music_cyclon/service/LibraryService.java b/app/src/main/java/max/music_cyclon/service/LibraryService.java index 7cd1ab0..668b6ca 100644 --- a/app/src/main/java/max/music_cyclon/service/LibraryService.java +++ b/app/src/main/java/max/music_cyclon/service/LibraryService.java @@ -26,6 +26,7 @@ import java.io.IOException; import java.lang.ref.WeakReference; import java.util.ArrayList; import java.util.List; +import java.util.Set; import java.util.concurrent.CountDownLatch; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; @@ -134,7 +135,7 @@ public class LibraryService extends IntentService { for (Parcelable parcelable : configs) { SynchronizeConfig config = (SynchronizeConfig) parcelable; - List items; + Set items; try { updater.showOngoingMessage("Fetching music information for %s", config.getName()); items = fetcher.fetch(config, From 1dfdc367e668dff4c5b8f2d9d53e9188d025a0fd Mon Sep 17 00:00:00 2001 From: nico202 Date: Fri, 25 May 2018 17:13:29 +0200 Subject: [PATCH 10/12] project changed by android studio alone --- app/app.iml | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/app/app.iml b/app/app.iml index fc61fe1..3115a87 100644 --- a/app/app.iml +++ b/app/app.iml @@ -86,22 +86,33 @@ + + + + + + + + + + + From aaf13b1899e7c65bd5e28b83561d6ed0b3ed58cf Mon Sep 17 00:00:00 2001 From: nico202 Date: Fri, 25 May 2018 17:15:49 +0200 Subject: [PATCH 11/12] version bump (0.3) --- app/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/build.gradle b/app/build.gradle index 9765bcf..97e5069 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -9,7 +9,7 @@ android { minSdkVersion 14 targetSdkVersion 23 versionCode 2 - versionName "0.2" + versionName "0.3" } compileOptions { sourceCompatibility JavaVersion.VERSION_1_7 From 9d254044d34514a0f5aa36deca3acad5d58365ce Mon Sep 17 00:00:00 2001 From: nico202 Date: Fri, 25 May 2018 17:20:34 +0200 Subject: [PATCH 12/12] remove extra newline --- app/src/main/res/xml/preferences.xml | 1 - 1 file changed, 1 deletion(-) diff --git a/app/src/main/res/xml/preferences.xml b/app/src/main/res/xml/preferences.xml index e5d2f04..8500ff7 100644 --- a/app/src/main/res/xml/preferences.xml +++ b/app/src/main/res/xml/preferences.xml @@ -7,7 +7,6 @@ android:key="address" android:summary="Address of the synchronisation server" android:title="Address" /> -