From e47d6acbf18b8f957b2d208bbd3ad3e14c46929f Mon Sep 17 00:00:00 2001 From: gdlbo <41114720+gdlbo@users.noreply.github.com> Date: Sun, 30 Oct 2022 00:54:59 +0300 Subject: [PATCH] fixed show cached pl --- .../catalog/inject/CatalogJsonInjector.java | 50 +++---------------- 1 file changed, 8 insertions(+), 42 deletions(-) diff --git a/app/src/main/java/ru/vtosters/lite/music/catalog/inject/CatalogJsonInjector.java b/app/src/main/java/ru/vtosters/lite/music/catalog/inject/CatalogJsonInjector.java index a905a8b45..e72c5845c 100644 --- a/app/src/main/java/ru/vtosters/lite/music/catalog/inject/CatalogJsonInjector.java +++ b/app/src/main/java/ru/vtosters/lite/music/catalog/inject/CatalogJsonInjector.java @@ -43,10 +43,13 @@ public class CatalogJsonInjector { oldItems = catalog.optJSONArray("sections"); } - if (oldItems != null && oldItems.optJSONObject(0).optString("url").contains("general")) { + var useOldAppVer = getBoolValue("useOldAppVer", false); + var isUsersCatalog = oldItems.optJSONObject(0).optString("url").equals("https://vk.com/audios" + getUserId() + "?section=" + (useOldAppVer ? "all" : "general")); + + if (oldItems != null && isUsersCatalog) { var blocks = oldItems.optJSONObject(0).optJSONArray("blocks"); - if (!getBoolValue("useOldAppVer", false)) { + if (!useOldAppVer) { if (blocks != null) { for (int i = 0; i < blocks.length(); i++) { var block = blocks.optJSONObject(i); @@ -65,21 +68,6 @@ public class CatalogJsonInjector { } } - if (podcastcatalog()) { - var podcasts = fetchCatalogPodcast(); - if (podcasts != null) { - var catalogarr = podcasts.optJSONObject("catalog").optJSONArray("sections").optJSONObject(0); - - var title = catalogarr.optString("title"); - var id = catalogarr.optString("id"); - var url = catalogarr.optString("url"); - - if (dev()) Log.d("VKMusic", "Added " + title + " in music sections"); - - oldItems.put(new JSONObject().put("id", id).put("title", title).put("url", url)); - } - } - var playlists = fetchCatalogId("https://vk.com/audio?section=my_playlists"); if (playlists != null) { var catalogarr = playlists.optJSONObject("catalog").optJSONArray("sections").optJSONObject(0); @@ -150,7 +138,7 @@ public class CatalogJsonInjector { } } - if (blocks != null && (!getBoolValue("useOldAppVer", false) || noPlaylists)) { + if (blocks != null && (!useOldAppVer || noPlaylists)) { var newBlocks = new JSONArray(); newBlocks @@ -176,7 +164,7 @@ public class CatalogJsonInjector { try { var section = json.optJSONObject("section"); var useOldAppVer = getBoolValue("useOldAppVer", false); - var isUsersCatalog = section.optString("url").contains("https://vk.com/audios" + getUserId() + "?section=" + (useOldAppVer ? "all" : "general")); + var isUsersCatalog = section.optString("url").equals("https://vk.com/audios" + getUserId() + "?section=" + (useOldAppVer ? "all" : "general")); if (isUsersCatalog && CacheDatabaseDelegate.hasTracks() && !LibVKXClient.isIntegrationEnabled()) { var blocks = section.getJSONArray("blocks"); @@ -282,7 +270,7 @@ public class CatalogJsonInjector { if (section.isEmpty()) return null; var request = new Request.a() - .b("https://" + getApi() + "/method/catalog.getAudio" + .b("https://" + getApi() + "/method/" + "catalog.getAudio" + "?v=5.119" + "&https=1" + "&need_blocks=1" @@ -303,26 +291,4 @@ public class CatalogJsonInjector { return null; } - - private static JSONObject fetchCatalogPodcast() { - var request = new Request.a() - .b("https://" + getApi() + "/method/catalog.getPodcasts" - + "?v=5.119" - + "&https=1" - + "&need_blocks=1" - + "&lang=" - + getLocale() - + "&device_id=" - + DeviceIdProvider.d(AndroidUtils.getGlobalContext()) - + "&access_token=" - + AccountManagerUtils.getUserToken()) - .a(Headers.a("User-Agent", Network.l.c().a(), "Content-Type", "application/x-www-form-urlencoded; charset=utf-8")).a(); - try { - return new JSONObject(mClient.a(request).execute().a().g()).getJSONObject("response"); - } catch (JSONException | IOException e) { - Log.d("VTLMusic", "Error: " + e.getMessage()); - } - - return null; - } }