fixes
This commit is contained in:
@@ -5,6 +5,7 @@ import static bruhcollective.itaysonlab.libvkx.client.LibVKXClient.getInstance;
|
||||
import static bruhcollective.itaysonlab.libvkx.client.LibVKXClient.isVkxInstalled;
|
||||
import static bruhcollective.itaysonlab.libvkx.client.LibVKXClient.lambdaplay;
|
||||
import static ru.vtosters.lite.music.cache.CacheDatabaseDelegate.isCached;
|
||||
import static ru.vtosters.lite.music.cache.CacheDatabaseDelegate.isVkxCached;
|
||||
import static ru.vtosters.lite.music.cache.CacheDatabaseDelegate.removeTrackFromCache;
|
||||
import static ru.vtosters.lite.utils.Preferences.milkshake;
|
||||
|
||||
@@ -31,6 +32,12 @@ public class MusicBottomSheetHook {
|
||||
actions.add(addToCacheTrackAction());
|
||||
}
|
||||
|
||||
if (isVkxCached(asId(musicTrack))){
|
||||
actions.add(getRemoveCacheTrackVkxAction());
|
||||
} else {
|
||||
actions.add(addToCacheTrackVkxAction());
|
||||
}
|
||||
|
||||
actions.add(downloadAsMp3Action());
|
||||
|
||||
return actions;
|
||||
@@ -42,6 +49,12 @@ public class MusicBottomSheetHook {
|
||||
|
||||
actions.add(downloadAsMp3Action());
|
||||
|
||||
if (isCached(playlist)){
|
||||
actions.add(getRemoveCacheTrackAction());
|
||||
} else {
|
||||
actions.add(addToCacheTrackAction());
|
||||
}
|
||||
|
||||
return actions;
|
||||
}
|
||||
|
||||
@@ -54,6 +67,17 @@ public class MusicBottomSheetHook {
|
||||
AndroidUtils.sendToast("remove_from_cache");
|
||||
return true;
|
||||
} else if (actionId == AndroidUtils.getIdentifier("add_to_cache", "id")) {
|
||||
// TODO make music caching
|
||||
AndroidUtils.sendToast("add_to_cache");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (actionId == AndroidUtils.getIdentifier("remove_from_cache", "id")) {
|
||||
removeTrackFromCache(track.D);
|
||||
AndroidUtils.sendToast("remove_from_cache");
|
||||
return true;
|
||||
} else if (actionId == AndroidUtils.getIdentifier("add_to_cache", "id")) {
|
||||
// TODO make music caching
|
||||
AndroidUtils.sendToast("add_to_cache");
|
||||
return true;
|
||||
}
|
||||
@@ -71,6 +95,16 @@ public class MusicBottomSheetHook {
|
||||
if (actionId == AndroidUtils.getIdentifier("play_in_vkx", "id"))
|
||||
return tryPlayInVKX(null, null, playlist);
|
||||
|
||||
if (actionId == AndroidUtils.getIdentifier("remove_from_cache_vkx", "id")) {
|
||||
|
||||
AndroidUtils.sendToast("remove_from_cache");
|
||||
return true;
|
||||
} else if (actionId == AndroidUtils.getIdentifier("add_to_cache_vkx", "id")) {
|
||||
|
||||
AndroidUtils.sendToast("add_to_cache");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (actionId == AndroidUtils.getIdentifier("download_mp3", "id")) {
|
||||
MP3Downloader.downloadPlaylist(playlist);
|
||||
AndroidUtils.sendToast("download_mp3");
|
||||
@@ -126,6 +160,28 @@ public class MusicBottomSheetHook {
|
||||
);
|
||||
}
|
||||
|
||||
private static MusicAction getRemoveCacheTrackVkxAction() {
|
||||
return new MusicAction(
|
||||
AndroidUtils.getIdentifier("remove_from_cache_vkx", "id"),
|
||||
milkshake() ? R.drawable.ic_delete_outline_28 : R.drawable.ic_delete_24,
|
||||
AndroidUtils.getIdentifier("remove_from_cache_vkx", "string"),
|
||||
R.color.caption_gray,
|
||||
R.string.music_talkback_empty,
|
||||
false
|
||||
);
|
||||
}
|
||||
|
||||
private static MusicAction addToCacheTrackVkxAction() {
|
||||
return new MusicAction(
|
||||
AndroidUtils.getIdentifier("add_to_cache_vkx", "id"),
|
||||
milkshake() ? R.drawable.ic_add_outline_28 : R.drawable.ic_add_24,
|
||||
AndroidUtils.getIdentifier("add_to_cache_vkx", "string"),
|
||||
R.color.caption_gray,
|
||||
R.string.music_talkback_empty,
|
||||
false
|
||||
);
|
||||
}
|
||||
|
||||
private static MusicAction downloadAsMp3Action() {
|
||||
return new MusicAction(
|
||||
AndroidUtils.getIdentifier("download_mp3", "id"),
|
||||
|
||||
@@ -13,6 +13,7 @@ import androidx.annotation.Nullable;
|
||||
|
||||
import com.vk.core.util.ToastUtils;
|
||||
import com.vk.dto.music.MusicTrack;
|
||||
import com.vk.dto.music.Playlist;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
@@ -221,8 +222,11 @@ public class CacheDatabaseDelegate {
|
||||
return list;
|
||||
}
|
||||
|
||||
public static boolean isCached(Playlist playlist){
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean isCached(String trackId) {
|
||||
if (!LibVKXClient.isIntegrationEnabled()) {
|
||||
var formula = String.format(
|
||||
"SELECT COUNT(%s) FROM %s WHERE %s = '%s'",
|
||||
COLUMN_ID,
|
||||
@@ -242,11 +246,12 @@ public class CacheDatabaseDelegate {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return LibVKXClient.getInstance().runOnServiceSync(new LibVKXClientImpl.LibVKXActionGeneric<Boolean>() {
|
||||
public static boolean isVkxCached(String trackId) {
|
||||
return LibVKXClient.getInstance().runOnServiceSync(new LibVKXClientImpl.LibVKXActionGeneric<>(){
|
||||
@Override
|
||||
public Boolean run(ILibVkxService service) {
|
||||
public Boolean run(ILibVkxService service){
|
||||
try {
|
||||
var splits = trackId.split("_");
|
||||
var id = Integer.parseInt(splits[0]);
|
||||
@@ -258,7 +263,7 @@ public class CacheDatabaseDelegate {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean defaultValue() {
|
||||
public Boolean defaultValue(){
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
@@ -3917,4 +3917,6 @@
|
||||
<item name="play_in_vkx" type="id" />
|
||||
<item name="add_to_cache" type="id" />
|
||||
<item name="download_mp3" type="id" />
|
||||
<item name="remove_from_cache_vkx" type="id" />
|
||||
<item name="add_to_cache_vkx" type="id" />
|
||||
</resources>
|
||||
|
||||
@@ -6090,6 +6090,9 @@ May look like a fake leaving the online"</string>
|
||||
<string name="remove_from_cache">Delete from cache</string>
|
||||
<string name="add_to_cache">Add to cache</string>
|
||||
|
||||
<string name="remove_from_cache_vkx">Delete from VKX cache</string>
|
||||
<string name="add_to_cache_vkx">Add to VKX cache</string>
|
||||
|
||||
<string name="play_in_vkx">Play the track in VK X</string>
|
||||
|
||||
<string name="thanksfordonate">Thank you for supporting the project!</string>
|
||||
|
||||
Reference in New Issue
Block a user