added cached playlist in online

This commit is contained in:
gdlbo
2022-09-30 21:03:34 +03:00
parent 86ab876cff
commit d4cebf403a
3 changed files with 94 additions and 14 deletions
@@ -3,6 +3,9 @@ package ru.vtosters.lite.hooks;
import static ru.vtosters.lite.foaf.FoafBase.getBypassedOnlineInfo;
import static ru.vtosters.lite.hooks.DateHook.getLocale;
import static ru.vtosters.lite.hooks.OnlineFormatterHook.onlineHookProfiles;
import static ru.vtosters.lite.music.cache.helpers.PlaylistHelper.*;
import static ru.vtosters.lite.music.cache.helpers.PlaylistHelper.getCatalogHeader;
import static ru.vtosters.lite.music.cache.helpers.PlaylistHelper.getCatalogSeparator;
import static ru.vtosters.lite.proxy.ProxyUtils.getApi;
import static ru.vtosters.lite.proxy.ProxyUtils.getStatic;
import static ru.vtosters.lite.utils.AndroidUtils.getDefaultPrefs;
@@ -33,9 +36,12 @@ import java.util.LinkedHashSet;
import java.util.Objects;
import java.util.Random;
import bruhcollective.itaysonlab.libvkx.client.LibVKXClient;
import okhttp3.Headers;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import ru.vtosters.lite.music.cache.CacheDatabaseDelegate;
import ru.vtosters.lite.music.cache.helpers.PlaylistHelper;
import ru.vtosters.lite.utils.AccountManagerUtils;
import ru.vtosters.lite.utils.AndroidUtils;
@@ -374,6 +380,8 @@ public class JsonInjectors {
}
if (oldItems != null && oldItems.optJSONObject(0).optString("url").contains("general")) {
json.optJSONArray("playlists").put(getPlaylist());
if (podcastcatalog()) {
var podcasts = fetchCatalogPodcast();
if (podcasts != null) {
@@ -442,6 +450,26 @@ public class JsonInjectors {
if (dev()) Log.d("VKMusic", "Added " + title + " as default music section");
}
}
if (CacheDatabaseDelegate.hasTracks() && !LibVKXClient.isIntegrationEnabled()){ // inj in playlist list
var blocks = oldItems.optJSONObject(0).optJSONArray("blocks");
var newBlocks = new JSONArray();
if (blocks != null){
newBlocks
.put(getCatalogHeader())
.put(getCatalogPlaylist())
.put(getCatalogSeparator());
Log.d("VKMusic", "added cache catalog playlist");
for (int i = 0; i < blocks.length(); i++) {
newBlocks.put(blocks.optJSONObject(i));
}
oldItems.optJSONObject(0).put("blocks", newBlocks);
}
}
}
return json;
@@ -1,5 +1,7 @@
package ru.vtosters.lite.music.cache.helpers;
import static ru.vtosters.lite.utils.AccountManagerUtils.getUserId;
import static ru.vtosters.lite.utils.AccountManagerUtils.getUserPhoto;
import static ru.vtosters.lite.utils.AndroidUtils.getString;
import com.vk.dto.music.Playlist;
@@ -19,15 +21,7 @@ public class PlaylistHelper {
public static Playlist createCachedPlaylistMetadata() {
try {
var obj = new JSONObject()
.put("id", -1)
.put("owner_id", AccountManagerUtils.getUserId())
.put("type", 0)
.put("album_type", "playlist")
.put("title", getString("cached_tracks_title"))
.put("description", getString("cached_tracks_desc"))
.put("count", 0);
return new Playlist(obj);
return new Playlist(getPlaylist());
} catch (JSONException e) {
e.printStackTrace();
return null;
@@ -90,4 +84,66 @@ public class PlaylistHelper {
}
return list;
}
public static JSONObject getPlaylist() throws JSONException {
var link = getUserPhoto();
return new JSONObject()
.put("id", -1)
.put("owner_id", getUserId())
.put("type", 0)
.put("album_type", "playlist")
.put("title", getString("cached_tracks_title"))
.put("description", getString("cached_tracks_desc"))
.put("access_key", "cache")
.put("genres", new JSONArray())
.put("is_following", false)
.put("followers", 0)
.put("plays", 0)
.put("create_time", 0)
.put("update_time", 0)
.put("subtitle", "")
.put("photo", new JSONObject()
.put("photo_34", link)
.put("photo_68", link)
.put("photo_135", link)
.put("photo_270", link)
.put("photo_300", link)
.put("photo_600", link)
.put("photo_1200", link)
.put("width", 600)
.put("height", 600))
.put("meta", new JSONObject()
.put("view", "compact"))
.put("count", 0);
}
public static JSONObject getCatalogPlaylist() throws JSONException {
return new JSONObject()
.put("id", "cache")
.put("data_type", "music_playlists")
.put("layout", new JSONObject()
.put("name", "large_slider")
.put("is_editable", 0)
.put("owner_id", getUserId()))
.put("playlists_ids", new JSONArray()
.put(getUserId() + "_-1"));
}
public static JSONObject getCatalogHeader() throws JSONException {
return new JSONObject()
.put("id", "cache")
.put("data_type", "none")
.put("layout", new JSONObject()
.put("name", "header")
.put("title", getString("cached_tracks_title")));
}
public static JSONObject getCatalogSeparator() throws JSONException {
return new JSONObject()
.put("id", "cache")
.put("data_type", "none")
.put("layout", new JSONObject()
.put("name", "separator"));
}
}
@@ -32,14 +32,10 @@ public class PlaylistInjector {
}
public static boolean eligibleForOfflineCaching() {
Log.d("PlaylistInjector", "eligibleForOfflineCaching");
return !NetworkUtils.isNetworkConnected() && CacheDatabaseDelegate.hasTracks();
return CacheDatabaseDelegate.hasTracks();
}
public static Observable<AudioGetPlaylist.c> injectGetPlaylist(AudioGetPlaylist audioGetPlaylist) {
Log.d("PlaylistInjector", "injectGetPlaylist");
try {
if (!eligibleForOfflineCaching())
return null;