diff --git a/app/build.gradle.kts b/app/build.gradle.kts index eec4b1ca..a0299775 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -262,6 +262,7 @@ dependencies { implementation(libs.slf4j) implementation(libs.timber) implementation(libs.tinypinyin) + implementation(libs.superlyricapi) debugImplementation(libs.leakcanary) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 6892174c..2a049be8 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,6 +1,6 @@ - + @@ -31,6 +31,8 @@ + + { + SuperLyricLine( + lyrics.currentLine.content, + Array(lyrics.currentLine.words.size) { index -> + val word = lyrics.currentLine.words[index] + if (index != lyrics.currentLine.words.size - 1) { + val nextWord = lyrics.currentLine.words[index + 1] + SuperLyricWord( + word.content, + word.time, + nextWord.time + ) + } else { + SuperLyricWord( + word.content, + word.time, + lyrics.nextLine?.time ?: (progress.duration + offset) + ) + } + }, + lyrics.currentLine.time, + lyrics.nextLine?.time ?: (progress.duration + offset) + ) + } + + else -> { + SuperLyricLine( + lyrics.currentLine.content, + lyrics.currentLine.time, + lyrics.nextLine?.time ?: (progress.duration + offset) + ) + } + } + + SuperLyricHelper.sendLyric( + SuperLyricData() + .setTitle(song.title) + .setArtist(song.artist) + .setAlbum(song.album) + .setLyric(superLine) + .setTranslation(SuperLyricLine(lyrics.currentLine.translation ?: "")) + ) + } + } + } + } else { + SuperLyricHelper.sendStop( + SuperLyricData() + ) + } + } + private val updateMutex = Mutex() private var updateLyricsJob: Job? = null private var updateProgressJob: Job? = null diff --git a/app/src/main/java/remix/myplayer/ui/screen/setting/SettingScreen.kt b/app/src/main/java/remix/myplayer/ui/screen/setting/SettingScreen.kt index c56d8d7f..e4a85a6f 100644 --- a/app/src/main/java/remix/myplayer/ui/screen/setting/SettingScreen.kt +++ b/app/src/main/java/remix/myplayer/ui/screen/setting/SettingScreen.kt @@ -41,6 +41,7 @@ import remix.myplayer.ui.screen.setting.logic.library.LibraryLogic import remix.myplayer.ui.screen.setting.logic.lyric.DesktopLyricLogic import remix.myplayer.ui.screen.setting.logic.lyric.LyricPriorityLogic import remix.myplayer.ui.screen.setting.logic.lyric.StatusBarLyricLogic +import remix.myplayer.ui.screen.setting.logic.lyric.SuperLyricApiLogic import remix.myplayer.ui.screen.setting.logic.notification.ClassicNotifyLogic import remix.myplayer.ui.screen.setting.logic.notification.NotifyBackgroundLogic import remix.myplayer.ui.screen.setting.logic.other.ClearCacheLogic @@ -262,6 +263,8 @@ private fun LyricPreferenceItems() { StatusBarLyricLogic() + SuperLyricApiLogic() + LyricPriorityLogic() } diff --git a/app/src/main/java/remix/myplayer/ui/screen/setting/logic/lyric/SuperLyricApiLogic.kt b/app/src/main/java/remix/myplayer/ui/screen/setting/logic/lyric/SuperLyricApiLogic.kt new file mode 100644 index 00000000..d4eccfcb --- /dev/null +++ b/app/src/main/java/remix/myplayer/ui/screen/setting/logic/lyric/SuperLyricApiLogic.kt @@ -0,0 +1,26 @@ +package remix.myplayer.ui.screen.setting.logic.lyric + +import androidx.compose.runtime.Composable +import androidx.compose.runtime.getValue +import androidx.lifecycle.compose.collectAsStateWithLifecycle +import com.hchen.superlyricapi.SuperLyricHelper +import remix.myplayer.ui.screen.setting.SwitchPreference +import remix.myplayer.viewmodel.settingViewModel + +@Composable +fun SuperLyricApiLogic() { + if (!SuperLyricHelper.isAvailable()) { + return + } + + val settingVM = settingViewModel + val settingState by settingVM.settingsState.collectAsStateWithLifecycle() + + SwitchPreference( + title = "SuperLyricApi", + content = "API version: ${SuperLyricHelper.getApiVersion()}", + checked = settingState.lyric.superLyricApiEnabled + ) { + settingVM.setSuperLyricApiEnabled(it) + } +} \ No newline at end of file diff --git a/app/src/main/java/remix/myplayer/viewmodel/settings/SettingState.kt b/app/src/main/java/remix/myplayer/viewmodel/settings/SettingState.kt index d8c03226..f72c8f09 100644 --- a/app/src/main/java/remix/myplayer/viewmodel/settings/SettingState.kt +++ b/app/src/main/java/remix/myplayer/viewmodel/settings/SettingState.kt @@ -75,6 +75,7 @@ data class CoverSettings( data class LyricSettings( val desktopLyricEnabled: Boolean, val statusBarLyricEnabled: Boolean, + val superLyricApiEnabled: Boolean, val fontScale: Float, val generalLyricOrder: List, ) diff --git a/app/src/main/java/remix/myplayer/viewmodel/settings/SettingViewModel.kt b/app/src/main/java/remix/myplayer/viewmodel/settings/SettingViewModel.kt index 8eea9672..891b1bba 100644 --- a/app/src/main/java/remix/myplayer/viewmodel/settings/SettingViewModel.kt +++ b/app/src/main/java/remix/myplayer/viewmodel/settings/SettingViewModel.kt @@ -125,6 +125,7 @@ class SettingViewModel @Inject constructor( lyric = LyricSettings( desktopLyricEnabled = lyricPrefs.desktopLyricEnabled, statusBarLyricEnabled = lyricPrefs.statusBarLyricEnabled, + superLyricApiEnabled = lyricPrefs.superLyricApiEnabled, fontScale = lyricPrefs.fontScale, generalLyricOrder = lyricPrefs.generalLyricOrderList ), @@ -358,6 +359,11 @@ class SettingViewModel @Inject constructor( _settingsState.update { it.copy(lyric = it.lyric.copy(statusBarLyricEnabled = enabled)) } } + fun setSuperLyricApiEnabled(enabled: Boolean) { + lyricManager.isSuperLyricApiEnabled = enabled + _settingsState.update { it.copy(lyric = it.lyric.copy(superLyricApiEnabled = enabled)) } + } + fun setLyricFontScale(scale: Float) { lyricPrefs.fontScale = scale _settingsState.update { it.copy(lyric = it.lyric.copy(fontScale = scale)) } diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index e6632a20..c8042ecf 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -13,6 +13,7 @@ glideCompose = "1.0.0-beta01" retrofit = "3.0.0" retrofitKotlinxSerialization = "1.0.0" room = "2.7.2" +superlyricapi = "3.3" xxpermissions = "21.2" workRuntimeKtx = "2.10.4" activityCompose = "1.10.1" @@ -102,6 +103,7 @@ image-cropper = { module = "com.vanniktech:android-image-cropper", version.ref = bugly = { group = "com.tencent.bugly", name = "crashreport", version.ref = "bugly" } leakcanary = { group = "com.squareup.leakcanary", name = "leakcanary-android", version.ref = "leakcanary" } logback-android = { group = "com.github.tony19", name = "logback-android", version.ref = "logbackAndroid" } +superlyricapi = { module = "com.github.HChenX:SuperLyricApi", version.ref = "superlyricapi" } xxpermissions = { module = "com.github.getActivity:XXPermissions", version.ref = "xxpermissions" } sardine-android = { group = "com.github.thegrizzlylabs", name = "sardine-android", version.ref = "sardineAndroid" } smbj = { group = "com.hierynomus", name = "smbj", version.ref = "smbj" }