Skip to content

Commit

Permalink
updated
Browse files Browse the repository at this point in the history
  • Loading branch information
sunmisc committed Sep 5, 2024
1 parent be70f00 commit 502ccca
Show file tree
Hide file tree
Showing 30 changed files with 412 additions and 431 deletions.
98 changes: 98 additions & 0 deletions app/src/main/java/com/vk/music/e/MusicCatalogConfiguration.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
package com.vk.music.e;

import android.os.Bundle;

import com.vk.catalog2.core.CatalogEntryPointParams;
import com.vk.catalog2.core.VkCatalogConfiguration;
import com.vk.catalog2.core.api.dto.CatalogCatalog;
import com.vk.catalog2.core.api.dto.CatalogDataType;
import com.vk.catalog2.core.api.dto.CatalogResponse;
import com.vk.catalog2.core.api.dto.CatalogViewType;
import com.vk.catalog2.core.api.music.CatalogGetAudio;
import com.vk.catalog2.core.blocks.UIBlock;
import com.vk.catalog2.core.blocks.UIBlockButtons;
import com.vk.catalog2.core.holders.common.CatalogViewHolder;
import com.vk.catalog2.core.holders.music.MusicActionButtonVh;
import com.vk.catalog2.core.ui.j.CatalogRecyclerGridOffsetsItemDecorator;
import com.vk.catalog2.core.ui.j.CatalogRecyclerHorizontalOffsetsItemDecorator;
import com.vk.catalog2.core.ui.j.CatalogRecyclerVerticalOffsetsItemDecorator;

import io.reactivex.Observable;
import ru.vtosters.hooks.music.injectors.TracklistInjector;

public final class MusicCatalogConfiguration extends VkCatalogConfiguration {

private final String url;

public MusicCatalogConfiguration(int i, String str, String str2) {
super(i, str);
this.url = str2;
}

public MusicCatalogConfiguration(Bundle paramBundle) {
this(paramBundle.getInt("owner_id"), paramBundle.getString("ref"), paramBundle.getString("url"));
}
@Override
public CatalogRecyclerHorizontalOffsetsItemDecorator c() {
return super.c();
}
@Override
public CatalogRecyclerGridOffsetsItemDecorator f() {
return super.f();
}
@Override
public CatalogRecyclerVerticalOffsetsItemDecorator i() {
return super.i();
}


@Override
public CatalogViewHolder a(CatalogDataType var1, CatalogViewType var2,
UIBlock var3, CatalogEntryPointParams var4) {
if (var3 instanceof UIBlockButtons && var3.z1() == CatalogViewType.BUTTONS_HORIZONTAL &&
((UIBlockButtons)var3).B1().size() != 1) {
CatalogViewHolder var6;
if (com.vk.music.e.c.$EnumSwitchMapping$1[(var1).ordinal()] != 1) {
var6 = super.a(var1, var2, var3, var4);
} else {
int var5 = com.vk.music.e.c.$EnumSwitchMapping$0[(var2).ordinal()];
if (var5 != 1) {
if (var5 != 2) {
var6 = super.a(var1, var2, var3, var4);
} else {
var6 = new MusicActionButtonVh(
com.vtosters.lite.R.drawable.ic_shuffle_outline_28,
com.vtosters.lite.R.layout.catalog_action_horizontal_list_music,
com.vtosters.lite.R.string.audio_shuffle_all,
var4.k()
);
}
} else {
var6 = new MusicActionButtonVh(com.vtosters.lite.R.drawable.ic_play_28,
com.vtosters.lite.R.layout.catalog_action_horizontal_list_music,
com.vtosters.lite.R.string.music_artist_listen_all_btn,
var4.k());
}
}

return var6;
} else {
return super.a(var1, var2, var3, var4);
}
}


@Override
public Bundle e() {
Bundle e = super.e();
e.putString("url", this.url);
return e;
}
@Override
public Observable<CatalogResponse<CatalogCatalog>> a(int paramInt, String paramString) {

return TracklistInjector.eligibleForOfflineCaching()
? TracklistInjector.createOfflineRx(j())
: new CatalogGetAudio(j(), paramInt, paramString, this.url).m();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import com.vk.music.common.MusicPlaybackLaunchContext;
import com.vtosters.lite.R;
import ru.vtosters.lite.downloaders.AudioDownloader;
import ru.vtosters.lite.music.cache.MusicCacheImpl;
import ru.vtosters.lite.music.cache.delegate.MusicCacheImpl;
import ru.vtosters.lite.music.cache.delegate.PlaylistCacheDbDelegate;
import ru.vtosters.lite.utils.AndroidUtils;
import ru.vtosters.lite.utils.music.VKXUtils;
Expand Down Expand Up @@ -97,7 +97,10 @@ public static ArrayList<MusicAction> hook(ArrayList<MusicAction> actions, Playli
return actions;
}

public static boolean injectOnClick(int actionId, MusicTrack track, MusicPlaybackLaunchContext context, Playlist playlist) { // musictrack inj
public static boolean injectOnClick(int actionId, MusicTrack track,
MusicPlaybackLaunchContext context,

Playlist playlist) { // musictrack inj
if (actionId == R.id.play_in_vkx)
return tryPlayInVKX(track, context, playlist);

Expand All @@ -122,7 +125,7 @@ public static boolean injectOnClick(int actionId, MusicTrack track, MusicPlaybac
}

if (actionId == R.id.remove_from_cache) {
MusicCacheImpl.removeTrack(asId(track));
MusicCacheImpl.removeTrack(playlist.b, playlist.a, asId(track));
AndroidUtils.sendToast(AndroidUtils.getString("audio_deleted_from_cache"));
return true;
} else if (actionId == R.id.add_to_cache) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package ru.vtosters.hooks.music;

import ru.vtosters.lite.music.cache.MusicCacheImpl;
import ru.vtosters.lite.music.cache.delegate.MusicCacheImpl;
import ru.vtosters.lite.utils.music.MusicCacheStorageUtils;

import java.io.File;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class PlaylistFormatterHook {
// basically we replace the author name with subtitle
// because for some reason VK decided to merge title and subtitle into one field in 5.56
public static String getOwnerText(Context context, Playlist playlist) {
if (playlist.h != null && playlist.h.length() > 0) {
if (playlist.h != null && !playlist.h.isEmpty()) {
return playlist.h;
}
String string = context.getString(com.vk.music.m.i.music_my_playlist);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import org.json.JSONException;
import org.json.JSONObject;
import ru.vtosters.hooks.other.Preferences;
import ru.vtosters.lite.music.cache.MusicCacheImpl;
import ru.vtosters.lite.music.cache.delegate.MusicCacheImpl;
import ru.vtosters.lite.music.cache.helpers.PlaylistHelper;
import ru.vtosters.lite.utils.AccountManagerUtils;
import ru.vtosters.lite.utils.AndroidUtils;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@
import org.json.JSONException;
import org.json.JSONObject;
import ru.vtosters.lite.downloaders.AudioDownloader;
import ru.vtosters.lite.music.cache.MusicCacheImpl;
import ru.vtosters.lite.music.cache.delegate.MusicCacheImpl;
import ru.vtosters.lite.music.cache.helpers.PlaylistHelper;
import ru.vtosters.lite.music.cache.helpers.TracklistHelper;
import ru.vtosters.lite.utils.AccountManagerUtils;

import java.util.ArrayList;
Expand All @@ -37,7 +36,8 @@ private static boolean isCacheEmpty() {
}

private static boolean isVirtualPlaylist(String accessKey) {
return accessKey != null && (accessKey.equals("cache") || accessKey.equals("cacheAlbum"));
return accessKey != null && (accessKey.equals("cache") ||
accessKey.equals("cacheAlbum"));
}

private static boolean isAlbumVirtualPlaylist(String accessKey) {
Expand Down Expand Up @@ -101,10 +101,6 @@ private static Observable<AudioGetPlaylist.c> handleMusicCacheImpl(int id, int o

// Main method to inject the playlist
public static Observable<AudioGetPlaylist.c> injectGetPlaylist(AudioGetPlaylist audioGetPlaylist) {
if (isCacheEmpty()) {
return null;
}

Map<String, String> requestArgs = audioGetPlaylist.b();
String id = requestArgs.get("id");
String ownerId = requestArgs.get("owner_id");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.vk.music.model.PlayerModelImpl;
import ru.vtosters.lite.music.cache.helpers.TracklistHelper;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

Expand All @@ -18,7 +19,9 @@ public static void shuffleTracks(PlayerModelImpl playerModelImpl) {
}

private static List<MusicTrack> getShuffledList() {
List<MusicTrack> shuffled = TracklistHelper.getMyCachedMusicTracks();
List<MusicTrack> shuffled = new ArrayList<>(
TracklistHelper.getTracks()
);
Collections.shuffle(shuffled);
return shuffled;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,29 @@
import android.util.Log;
import bruhcollective.itaysonlab.libvkx.client.LibVKXClient;
import com.vk.catalog2.core.CatalogParser;
import com.vk.catalog2.core.api.dto.CatalogCatalog;
import com.vk.catalog2.core.api.dto.CatalogResponse;
import com.vk.core.concurrent.VkExecutors;
import com.vk.dto.music.MusicTrack;
import com.vtosters.lite.R;
import io.reactivex.Observable;
import io.reactivex.ObservableOnSubscribe;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import ru.vtosters.lite.music.cache.MusicCacheImpl;

import io.reactivex.schedulers.AndroidSchedulers;
import ru.vtosters.lite.music.cache.delegate.MusicCacheImpl;
import ru.vtosters.lite.music.cache.delegate.PlaylistCacheDbDelegate;
import ru.vtosters.lite.music.cache.helpers.PlaylistHelper;
import ru.vtosters.lite.music.cache.helpers.TracklistHelper;
import ru.vtosters.lite.utils.AccountManagerUtils;
import ru.vtosters.lite.utils.AndroidUtils;
import ru.vtosters.lite.utils.NetworkUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import java.util.stream.Collectors;

import static ru.vtosters.lite.music.cache.helpers.PlaylistHelper.*;

Expand All @@ -31,41 +35,32 @@ public static boolean eligibleForOfflineCaching() {
return !NetworkUtils.isNetworkConnected();
}

public static Observable<CatalogResponse> createOfflineRx(CatalogParser parser) {
public static Observable<CatalogResponse<CatalogCatalog>>
createOfflineRx(CatalogParser parser) {
Log.d("TracklistInjector", "createOfflineRx");

return Observable.a((ObservableOnSubscribe<CatalogResponse>) observableEmitter -> {
return Observable.a((ObservableOnSubscribe) observer -> {
if (LibVKXClient.isIntegrationEnabled()) {
LibVKXClient.getInstance().runOnService((service) -> {
LibVKXClient.getInstance().runOnService(service -> {
try {
try {
Log.d("TracklistInjector", "Using vkx cache catalog");
observableEmitter.b(parser.c(new JSONObject(service.getCacheCatalog())));
} catch (Exception e) {
e.fillInStackTrace();
List<MusicTrack> tracks = new ArrayList<>();
List<String> cache = service.getCache();

for (String json : cache) {
Log.d("TracklistInjector", "added " + json);
tracks.add(new MusicTrack(new JSONObject(json)));
}

Log.d("TracklistInjector", "Using own cache catalog from vkx");
observableEmitter.b(parser.c(createVirtualCatalog(tracks)));
}
Log.d("TracklistInjector", "Using vkx cache catalog");
observer.b(parser.c(new JSONObject(service.getCacheCatalog())));
} catch (Exception e) {
e.fillInStackTrace();
}
});
} else {
if (MusicCacheImpl.isEmpty()) {
observableEmitter.b(parser.c(getEmptyCatalog()));
} else {
observableEmitter.b(parser.c(createVirtualCatalog(TracklistHelper.getMyCachedMusicTracks())));
}
}
});
observer.b(parser.c(
createVirtualCatalog(
MusicCacheImpl.getPlaylistSongs(
AccountManagerUtils.getUserId(),
-1,
// todo:
0, Integer.MAX_VALUE
)
))
);
}).b(VkExecutors.x.m()).a(AndroidSchedulers.a());
}

private static JSONObject getEmptyCatalog() throws JSONException {
Expand Down Expand Up @@ -151,6 +146,7 @@ private static JSONObject getShuffleButton() throws JSONException {

public static void injectIntoExistingCatalog(JSONObject catalogNode) {
try {
System.out.println("kasdkakdakdk ak "+catalogNode.toString());
JSONObject catalog = catalogNode.getJSONObject("catalog");
JSONArray sectionsNode = catalog.getJSONArray("sections");
JSONObject firstSection = sectionsNode.getJSONObject(0);
Expand Down Expand Up @@ -231,7 +227,12 @@ public static JSONObject createVirtualCatalog(List<MusicTrack> tracks) throws JS
.put("id", getRandomId())
.put("data_type", "music_audios")
.put("url", "synth:cache:list")
.put("audios_ids", TracklistHelper.tracksToIds(tracks));
.put("audio_count", "4")
.put("audios_ids", new JSONArray(
tracks.stream()
.map(MusicTrack::y1)
.collect(Collectors.toList()))
);

var layout = new JSONObject()
.put("name", "list")
Expand All @@ -243,7 +244,7 @@ public static JSONObject createVirtualCatalog(List<MusicTrack> tracks) throws JS

if (MusicCacheImpl.hasPlaylist()) {
blocks.put(getCatalogHeader("Кешированные плейлисты"))
.put(getCatalogPlaylist());
.put(getCatalogPlaylist0());
}

if (!PlaylistCacheDbDelegate.isPlaylistEmpty(
Expand All @@ -262,8 +263,7 @@ public static JSONObject createVirtualCatalog(List<MusicTrack> tracks) throws JS
.put("url", "synth:cache")
.put("blocks", blocks);

var sections = new JSONArray()
.put(section);
var sections = new JSONArray().put(section);

var catalog = new JSONObject()
.put("sections", sections)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import ru.vtosters.hooks.music.MusicCacheFilesHook;
import ru.vtosters.hooks.other.Preferences;
import ru.vtosters.lite.concurrent.VTExecutors;
import ru.vtosters.lite.music.cache.MusicCacheImpl;
import ru.vtosters.lite.music.cache.delegate.MusicCacheImpl;
import ru.vtosters.lite.music.cache.delegate.PlaylistCacheDbDelegate;
import ru.vtosters.lite.music.cache.helpers.PlaylistHelper;
import ru.vtosters.lite.music.callback.MusicCallbackBuilder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import ru.vtosters.hooks.other.Preferences;
import ru.vtosters.lite.di.singleton.VtOkHttpClient;
import ru.vtosters.lite.downloaders.AudioDownloader;
import ru.vtosters.lite.music.cache.MusicCacheImpl;
import ru.vtosters.lite.music.cache.delegate.MusicCacheImpl;
import ru.vtosters.lite.utils.AccountManagerUtils;
import ru.vtosters.lite.utils.AndroidUtils;
import ru.vtosters.lite.utils.music.MusicTrackUtils;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ public interface Constants {
+ "REFERENCES " + TABLE_MUSICS + "(" + TRACK_ID + ") "
+ "ON DELETE CASCADE"
+ ")";
String DELETE_DEAD = "DELETE FROM " + TABLE_MUSICS +
" WHERE "+TRACK_ID+" NOT IN (" +
" SELECT " + TABLE_PLAYLIST_TRACKS + "." + TRACK_ID +
" FROM " + TABLE_PLAYLIST_TRACKS +
");";

String DROP_MUSICS = "DROP TABLE IF EXISTS " + TABLE_MUSICS;
String DROP_PLAYLIST = "DROP TABLE IF EXISTS " + TABLE_PLAYLIST;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
import com.vk.dto.music.MusicTrack;
import com.vk.dto.music.Playlist;

import ru.vtosters.lite.music.cache.DatabaseAccess;
import ru.vtosters.lite.music.cache.db.old.OldMusicCacheDb;
import ru.vtosters.lite.music.cache.db.old.OldPlaylistCacheDb;
import ru.vtosters.lite.music.cache.helpers.PlaylistHelper;
import ru.vtosters.lite.music.cache.playlists.MusicCacheDb;
import ru.vtosters.lite.music.cache.playlists.SqlPlaylists;
import ru.vtosters.lite.music.interfaces.IPlaylist;
import ru.vtosters.lite.utils.AccountManagerUtils;
import ru.vtosters.lite.utils.AndroidUtils;
Expand All @@ -34,7 +35,6 @@ public void onCreate(SQLiteDatabase db) {
db.execSQL(Constants.CREATE_TABLE_MUSICS);
db.execSQL(Constants.CREATE_TABLE_PLAYLISTS);
db.execSQL(Constants.CREATE_TABLE_PLAYLIST_TRACKS);

}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ru.vtosters.lite.music.cache;
package ru.vtosters.lite.music.cache.db;

import android.database.sqlite.SQLiteDatabase;

Expand Down
Loading

0 comments on commit 502ccca

Please sign in to comment.