feat: implemented new API getLyricsBySongId for retrieving (synced) song lyrics based on song ID

This commit is contained in:
CappielloAntonio 2024-02-17 23:43:02 +01:00
parent b9462d7374
commit 54be869081
11 changed files with 197 additions and 0 deletions

View file

@ -0,0 +1,41 @@
package com.cappielloantonio.tempo.util;
import com.cappielloantonio.tempo.subsonic.models.OpenSubsonicExtension;
import com.google.common.reflect.TypeToken;
import com.google.gson.Gson;
import java.util.List;
public class OpenSubsonicExtensionsUtil {
private static List<OpenSubsonicExtension> getOpenSubsonicExtensions() {
List<OpenSubsonicExtension> extensions = null;
if (Preferences.isOpenSubsonic() && Preferences.getOpenSubsonicExtensions() != null) {
extensions = new Gson().fromJson(
Preferences.getOpenSubsonicExtensions(),
new TypeToken<List<OpenSubsonicExtension>>() {
}.getType()
);
}
return extensions;
}
private static OpenSubsonicExtension getOpenSubsonicExtension(String extensionName) {
if (getOpenSubsonicExtensions() == null) return null;
return getOpenSubsonicExtensions().stream().filter(openSubsonicExtension -> openSubsonicExtension.getName().equals(extensionName)).findAny().orElse(null);
}
public static boolean isTranscodeOffsetExtensionAvailable() {
return getOpenSubsonicExtension("transcodeOffset") != null;
}
public static boolean isFormPostExtensionAvailable() {
return getOpenSubsonicExtension("formPost") != null;
}
public static boolean isSongLyricsExtensionAvailable() {
return getOpenSubsonicExtension("songLyrics") != null;
}
}

View file

@ -1,6 +1,11 @@
package com.cappielloantonio.tempo.util
import com.cappielloantonio.tempo.App
import com.cappielloantonio.tempo.subsonic.models.OpenSubsonicExtension
import com.google.gson.Gson
object Preferences {
const val THEME = "theme"
@ -12,6 +17,8 @@ object Preferences {
private const val LOW_SECURITY = "low_security"
private const val BATTERY_OPTIMIZATION = "battery_optimization"
private const val SERVER_ID = "server_id"
private const val OPEN_SUBSONIC = "open_subsonic"
private const val OPEN_SUBSONIC_EXTENSIONS = "open_subsonic_extensions"
private const val PLAYBACK_SPEED = "playback_speed"
private const val SKIP_SILENCE = "skip_silence"
private const val IMAGE_CACHE_SIZE = "image_cache_size"
@ -119,6 +126,26 @@ object Preferences {
App.getInstance().preferences.edit().putString(SERVER_ID, serverId).apply()
}
@JvmStatic
fun isOpenSubsonic(): Boolean {
return App.getInstance().preferences.getBoolean(OPEN_SUBSONIC, false)
}
@JvmStatic
fun setOpenSubsonic(isOpenSubsonic: Boolean) {
App.getInstance().preferences.edit().putBoolean(OPEN_SUBSONIC, isOpenSubsonic).apply()
}
@JvmStatic
fun getOpenSubsonicExtensions(): String? {
return App.getInstance().preferences.getString(OPEN_SUBSONIC_EXTENSIONS, null)
}
@JvmStatic
fun setOpenSubsonicExtensions(extension: List<OpenSubsonicExtension>) {
App.getInstance().preferences.edit().putString(OPEN_SUBSONIC_EXTENSIONS, Gson().toJson(extension)).apply()
}
@JvmStatic
fun askForOptimization(): Boolean {
return App.getInstance().preferences.getBoolean(BATTERY_OPTIMIZATION, true)