From 81c3e7e7f6bc1af7f62b0f0ec1075c0dbaa7f4e2 Mon Sep 17 00:00:00 2001 From: wb9688 Date: Sat, 25 Apr 2020 08:52:25 +0200 Subject: [PATCH] Use our nanojson fork --- app/build.gradle | 4 ++-- .../services/ImportExportJsonHelper.java | 14 ++++++++------ .../newpipe/settings/tabs/TabsJsonHelper.java | 5 +++-- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index b99e89271..4f2ca47f9 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -142,7 +142,7 @@ dependencies { exclude module: 'support-annotations' }) - implementation 'com.github.TeamNewPipe:NewPipeExtractor:a5155fb562ca99ca4a9c8caa2fd60f2f0a305eb0' + implementation 'com.github.TeamNewPipe:NewPipeExtractor:2780e716b3694ba0f6fe8516847984eadb251f2d' testImplementation 'junit:junit:4.12' testImplementation 'org.mockito:mockito-core:2.23.0' @@ -162,7 +162,7 @@ dependencies { implementation 'androidx.lifecycle:lifecycle-extensions:2.0.0' // Originally in NewPipeExtractor - implementation 'com.grack:nanojson:1.1' + implementation 'com.github.TeamNewPipe:nanojson:1d9e1aea9049fc9f85e68b43ba39fe7be1c1f751' implementation 'org.jsoup:jsoup:1.9.2' implementation 'ch.acra:acra:4.9.2' //4.11 diff --git a/app/src/main/java/org/schabi/newpipe/local/subscription/services/ImportExportJsonHelper.java b/app/src/main/java/org/schabi/newpipe/local/subscription/services/ImportExportJsonHelper.java index 5d9a54ce7..e6e081689 100644 --- a/app/src/main/java/org/schabi/newpipe/local/subscription/services/ImportExportJsonHelper.java +++ b/app/src/main/java/org/schabi/newpipe/local/subscription/services/ImportExportJsonHelper.java @@ -74,14 +74,16 @@ public final class ImportExportJsonHelper { final List channels = new ArrayList<>(); try { - JsonObject parentObject = JsonParser.object().from(in); - JsonArray channelsArray = parentObject.getArray(JSON_SUBSCRIPTIONS_ARRAY_KEY); - if (eventListener != null) { - eventListener.onSizeReceived(channelsArray.size()); + final JsonObject parentObject = JsonParser.object().from(in); + + if (!parentObject.has(JSON_SUBSCRIPTIONS_ARRAY_KEY)) { + throw new InvalidSourceException("Channels array is null"); } - if (channelsArray == null) { - throw new InvalidSourceException("Channels array is null"); + final JsonArray channelsArray = parentObject.getArray(JSON_SUBSCRIPTIONS_ARRAY_KEY); + + if (eventListener != null) { + eventListener.onSizeReceived(channelsArray.size()); } for (Object o : channelsArray) { diff --git a/app/src/main/java/org/schabi/newpipe/settings/tabs/TabsJsonHelper.java b/app/src/main/java/org/schabi/newpipe/settings/tabs/TabsJsonHelper.java index f1639fe53..d18aad9d3 100644 --- a/app/src/main/java/org/schabi/newpipe/settings/tabs/TabsJsonHelper.java +++ b/app/src/main/java/org/schabi/newpipe/settings/tabs/TabsJsonHelper.java @@ -51,13 +51,14 @@ public final class TabsJsonHelper { final JsonObject outerJsonObject; try { outerJsonObject = JsonParser.object().from(tabsJson); - final JsonArray tabsArray = outerJsonObject.getArray(JSON_TABS_ARRAY_KEY); - if (tabsArray == null) { + if (!outerJsonObject.has(JSON_TABS_ARRAY_KEY)) { throw new InvalidJsonException("JSON doesn't contain \"" + JSON_TABS_ARRAY_KEY + "\" array"); } + final JsonArray tabsArray = outerJsonObject.getArray(JSON_TABS_ARRAY_KEY); + for (Object o : tabsArray) { if (!(o instanceof JsonObject)) { continue;