Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion androidApp/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -275,4 +275,8 @@ if (!isFullBuild) {
tasks.named { it.contains("injectSentryDebugMetaPropertiesIntoAssetsRelease") }.configureEach {
finalizedBy(cleanSentryMetaTask)
}
}
}

configurations.configureEach {
exclude(group = "com.charleskorn.kaml")
}
9 changes: 9 additions & 0 deletions androidApp/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,15 @@
<data android:mimeType="text/plain" />
</intent-filter>

<!-- Gemini & Google Assistant Voice / Media Search -->
<intent-filter>
<action android:name="android.media.action.MEDIA_PLAY_FROM_SEARCH" />
<action android:name="android.intent.action.MEDIA_SEARCH" />
<action android:name="android.intent.action.SEARCH" />

<category android:name="android.intent.category.DEFAULT" />
</intent-filter>

<meta-data
android:name="android.app.shortcuts"
android:resource="@xml/shortcuts" />
Expand Down
89 changes: 71 additions & 18 deletions androidApp/src/main/java/com/maxrave/simpmusic/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.maxrave.simpmusic

import android.Manifest
import android.app.SearchManager
import android.content.ComponentName
import android.content.Intent
import android.content.ServiceConnection
Expand All @@ -9,6 +10,7 @@ import android.os.Build
import android.os.Bundle
import android.os.IBinder
import android.os.SystemClock
import android.provider.MediaStore
import androidx.activity.SystemBarStyle
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
Expand Down Expand Up @@ -111,14 +113,8 @@ class MainActivity : AppCompatActivity() {

override fun onNewIntent(intent: Intent) {
super.onNewIntent(intent)
Logger.d("MainActivity", "onNewIntent: $intent")
viewModel.setIntent(
GenericIntent(
action = intent.action,
data = (intent.data ?: intent.getStringExtra(Intent.EXTRA_TEXT)?.toUri())?.toKmpUriOrNull(),
type = intent.type,
),
)
setIntent(intent)
handleIntent(intent)
}

@ExperimentalFoundationApi
Expand All @@ -140,16 +136,7 @@ class MainActivity : AppCompatActivity() {
startMusicService()
}
Logger.d("MainActivity", "onCreate: ")
val data = (intent?.data ?: intent?.getStringExtra(Intent.EXTRA_TEXT)?.toUri())?.toKmpUriOrNull()
if (data != null) {
viewModel.setIntent(
GenericIntent(
action = intent.action,
data = data,
type = intent.type,
),
)
}
handleIntent(intent)
Logger.d("Italy", "Key: ${Locale.ITALY.toLanguageTag()}")

// Check if the migration has already been done or not
Expand Down Expand Up @@ -338,6 +325,72 @@ class MainActivity : AppCompatActivity() {

private fun getString(key: String): String? = viewModel.getString(key)

private fun handleIntent(intent: Intent?) {
if (intent == null) return
Logger.d("MainActivity", "handleIntent: action=${intent.action}, data=${intent.data}")

// 1. Check for Media / Voice search actions from Gemini / Google Assistant
val action = intent.action
val isMediaPlayFromSearch = action == MediaStore.INTENT_ACTION_MEDIA_PLAY_FROM_SEARCH ||
action == "android.intent.action.MEDIA_SEARCH" ||
action == Intent.ACTION_SEARCH

if (isMediaPlayFromSearch) {
val query = intent.getStringExtra(SearchManager.QUERY)
?: intent.getStringExtra(Intent.EXTRA_TEXT)
?: intent.getStringExtra(MediaStore.EXTRA_MEDIA_TITLE)
?: intent.getStringExtra("query")

if (query.isNullOrBlank()) {
viewModel.playRecommendations()
} else {
val clean = query.trim().lowercase()
when {
clean.contains("recommandation") || clean.contains("recommendation") || clean.contains("pour moi") -> {
viewModel.playRecommendations()
}
clean.contains("hors ligne") || clean.contains("offline") || clean.contains("téléchargé") || clean.contains("telecharge") -> {
viewModel.playDownloaded()
}
clean.contains("favori") || clean.contains("favorite") || clean.contains("aimé") || clean.contains("liked") -> {
viewModel.playFavorites()
}
clean.contains("cache") -> {
viewModel.playCached()
}
clean.contains("pause") || clean.contains("stop") || clean.contains("arrête") || clean.contains("arrete") -> {
viewModel.pausePlayback()
}
clean.contains("reprend") || clean.contains("resume") || clean.contains("relance") || clean.contains("play") -> {
viewModel.resumePlayback()
}
clean.contains("suivant") || clean.contains("next") -> {
viewModel.skipNextTrack()
}
clean.contains("précédent") || clean.contains("precedent") || clean.contains("previous") -> {
viewModel.skipPreviousTrack()
}
else -> {
viewModel.searchAndPlay(query)
}
}
}
return
}

// 2. Generic and deep links
val data = (intent.data ?: intent.getStringExtra(Intent.EXTRA_TEXT)?.toUri())?.toKmpUriOrNull()
if (data != null) {
viewModel.setIntent(
GenericIntent(
action = intent.action,
data = data,
type = intent.type,
),
)
}
}

override fun onConfigurationChanged(newConfig: Configuration) {
super.onConfigurationChanged(newConfig)
viewModel.activityRecreate()
Expand Down
18 changes: 18 additions & 0 deletions composeApp/src/commonMain/composeResources/values-fr/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -992,4 +992,22 @@
<string name="comments_load_error">Impossible de charger les commentaires</string>
<string name="comment_post_error">Impossible de publier votre commentaire</string>
<string name="comments_need_channel">Créez une chaîne YouTube pour laisser un commentaire</string>
<string name="generate_subtitles">Générer les sous-titres</string>
<string name="generating_subtitles">Génération des sous-titres…</string>
<string name="translate_lyrics">Traduire les paroles</string>
<string name="translating_lyrics">Traduction des paroles…</string>
<string name="translation_failed">Échec de la traduction</string>
<string name="subtitles_not_found">Aucun sous-titre trouvé</string>
<string name="search_settings">Rechercher dans les paramètres…</string>
<string name="no_settings_found">Aucun paramètre trouvé</string>
<string name="system_default">Par défaut du système</string>
<string name="assistant_and_ai">Assistant &amp; Actions Gemini</string>
<string name="assistant_and_ai_description">Commandes vocales de l\'assistant et intégration AppFunctions</string>
<string name="play_recommendations_action">Lancer les recommandations</string>
<string name="play_recommendations_description">Démarrer la lecture de votre mix recommandé</string>
<string name="play_downloaded_action">Lire les musiques téléchargées</string>
<string name="play_downloaded_description">Écouter les titres enregistrés hors-ligne</string>
<string name="play_favorites_action">Lire les favoris</string>
<string name="play_favorites_description">Écouter vos titres aimés</string>
<string name="voice_commands_info">Intents vocaux supportés : « Joue de la musique sur SimpMusic », « Joue [titre/artiste] », AppFunctions et liens simpmusic://action/...</string>
</resources>
22 changes: 22 additions & 0 deletions composeApp/src/commonMain/composeResources/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,10 @@
<string name="romanization_belarusian" translatable="false">Belarusian</string>
<string name="romanization_kyrgyz" translatable="false">Kyrgyz</string>
<string name="romanization_macedonian" translatable="false">Macedonian</string>
<string name="romanization_kazakh" translatable="false">Kazakh</string>
<string name="romanization_mongolian" translatable="false">Mongolian</string>
<string name="romanization_greek" translatable="false">Greek</string>
<string name="romanization_georgian" translatable="false">Georgian</string>
<string name="romanization_japanese_dict_downloading">Downloading the Japanese dictionary…</string>
<string name="romanization_japanese_dict_ready">Japanese dictionary downloaded</string>
<string name="romanization_japanese_dict_failed">Couldn't download the Japanese dictionary. Check your connection and select Japanese again to retry.</string>
Expand Down Expand Up @@ -1151,4 +1155,22 @@
<string name="browser_login_rejected">Sign-in could not be verified. Check your connection, or sign in again in this browser profile and refresh.</string>
<string name="browser_login_refresh">Refresh browser profiles</string>
<string name="soundcloud_play_count_info">%1$s - song info</string>
<string name="generate_subtitles">Generate subtitles</string>
<string name="generating_subtitles">Generating subtitles…</string>
<string name="translate_lyrics">Translate lyrics</string>
<string name="translating_lyrics">Translating lyrics…</string>
<string name="translation_failed">Translation failed</string>
<string name="subtitles_not_found">No subtitles found</string>
<string name="search_settings">Search settings…</string>
<string name="no_settings_found">No settings found</string>
<string name="system_default">System default</string>
<string name="assistant_and_ai">Assistant &amp; Gemini Actions</string>
<string name="assistant_and_ai_description">Voice assistant commands and AppFunctions integration</string>
<string name="play_recommendations_action">Play recommendations</string>
<string name="play_recommendations_description">Start playing your recommended mix</string>
<string name="play_downloaded_action">Play downloaded music</string>
<string name="play_downloaded_description">Play music saved offline</string>
<string name="play_favorites_action">Play favorites</string>
<string name="play_favorites_description">Play your liked tracks</string>
<string name="voice_commands_info">Supported voice intents: \"Play music on SimpMusic\", \"Play [song/artist]\", AppFunctions, and custom scheme simpmusic://action/...</string>
</resources>
79 changes: 79 additions & 0 deletions composeApp/src/commonMain/kotlin/com/maxrave/simpmusic/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,85 @@ fun App(
}
}

// Actions & Assistant commands: simpmusic://recommendations, simpmusic://offline, etc.
"recommendations", "recommandations" -> {
viewModel.playRecommendations()
}

"downloaded", "offline", "horsligne" -> {
viewModel.playDownloaded()
}

"favorites", "favoris" -> {
viewModel.playFavorites()
}

"cached" -> {
viewModel.playCached()
}

"pause" -> {
viewModel.pausePlayback()
}

"resume" -> {
viewModel.resumePlayback()
}

"next" -> {
viewModel.skipNextTrack()
}

"previous" -> {
viewModel.skipPreviousTrack()
}

"play" -> {
val type = data.getQueryParameter("type")?.lowercase()
val q = data.getQueryParameter("q") ?: data.getQueryParameter("query")
val action = data.getQueryParameter("action")?.lowercase()
when {
type == "recommendations" || type == "recommandations" || action == "recommendations" -> {
viewModel.playRecommendations()
}
type == "downloaded" || type == "offline" || type == "horsligne" || action == "downloaded" || action == "offline" -> {
viewModel.playDownloaded()
}
type == "favorites" || type == "favoris" || action == "favorites" -> {
viewModel.playFavorites()
}
type == "cached" || action == "cached" -> {
viewModel.playCached()
}
!q.isNullOrBlank() -> {
viewModel.searchAndPlay(q)
}
else -> {
viewModel.resumePlayback()
}
}
}

"action" -> {
val type = data.getQueryParameter("type")?.lowercase()
when (type) {
"recommendations", "recommandations" -> viewModel.playRecommendations()
"downloaded", "offline", "horsligne" -> viewModel.playDownloaded()
"favorites", "favoris" -> viewModel.playFavorites()
"cached" -> viewModel.playCached()
"pause" -> viewModel.pausePlayback()
"resume" -> viewModel.resumePlayback()
"next" -> viewModel.skipNextTrack()
"previous" -> viewModel.skipPreviousTrack()
else -> {
val q = data.getQueryParameter("q") ?: data.getQueryParameter("query")
if (!q.isNullOrBlank()) {
viewModel.searchAndPlay(q)
}
}
}
}

else -> {
viewModel.makeToast(getString(Res.string.this_link_is_not_supported))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ import com.maxrave.simpmusic.ui.icon.MoreVert
import com.maxrave.simpmusic.ui.icon.PictureInPictureAlt
import com.maxrave.simpmusic.ui.icon.QueueMusic
import com.maxrave.simpmusic.ui.icon.Share
import com.maxrave.simpmusic.ui.icon.Translate
import com.maxrave.simpmusic.ui.icon.AvTimer
import com.maxrave.simpmusic.ui.icon.SimpIcons
import com.maxrave.simpmusic.ui.icon.VolumeOff
Expand Down Expand Up @@ -133,6 +134,7 @@ import org.jetbrains.compose.resources.stringResource
import simpmusic.composeapp.generated.resources.Res
import simpmusic.composeapp.generated.resources.crossfading
import simpmusic.composeapp.generated.resources.share_lyrics
import simpmusic.composeapp.generated.resources.translate_lyrics
import simpmusic.composeapp.generated.resources.unavailable
import kotlin.math.PI
import kotlin.math.cos
Expand Down Expand Up @@ -449,6 +451,15 @@ fun FullscreenLyricsContent(

// Share lyrics — only when there are lyrics to share.
if (screenDataState.lyricsData != null) {
IconButton(
onClick = { sharedViewModel.translateCurrentLyrics() },
) {
Icon(
imageVector = SimpIcons.Translate,
contentDescription = stringResource(Res.string.translate_lyrics),
tint = Color.White,
)
}
IconButton(
onClick = { showShareLyricsSheet = true },
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,18 @@ private fun buildSyncedTranslatedWordsByLineIndex(
val _bt = bestTs
}
}
// Fallback: If time-based matching produced nothing or missed most lines while line count matches closely,
// fallback to line-index matching so translations never get dropped on timing drift.
if (result.isEmpty() || result.size < originalLines.size / 3) {
for (i in originalLines.indices) {
if (!result.containsKey(i)) {
val fallbackWords = translatedLines.getOrNull(i)?.words
if (!fallbackWords.isNullOrBlank()) {
result[i] = fallbackWords
}
}
}
}
return result
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,8 @@ import com.maxrave.simpmusic.ui.icon.Speed
import com.maxrave.simpmusic.ui.icon.Sync
import com.maxrave.simpmusic.ui.icon.SyncDisabled
import com.maxrave.simpmusic.ui.icon.ThumbDownOutline
import com.maxrave.simpmusic.ui.icon.Translate
import com.maxrave.simpmusic.ui.icon.Subtitles
import com.maxrave.simpmusic.ui.icon.Tune
import com.maxrave.simpmusic.ui.icon.Update
import com.maxrave.simpmusic.ui.navigation.destination.list.AlbumDestination
Expand Down Expand Up @@ -216,6 +218,8 @@ import simpmusic.composeapp.generated.resources.can_not_be_empty
import simpmusic.composeapp.generated.resources.cancel
import simpmusic.composeapp.generated.resources.cancel_download
import simpmusic.composeapp.generated.resources.crop_cover
import simpmusic.composeapp.generated.resources.generate_subtitles
import simpmusic.composeapp.generated.resources.translate_lyrics
import simpmusic.composeapp.generated.resources.codec
import simpmusic.composeapp.generated.resources.copied_to_clipboard
import simpmusic.composeapp.generated.resources.create_new_queue_and_play
Expand Down Expand Up @@ -1372,6 +1376,10 @@ fun NowPlayingBottomSheet(
onRemoveFromCache: (() -> Unit)? = null,
/** Set while the song playing has no lyrics: adds Add lyrics under Main Lyrics Provider. */
onAddLyrics: (() -> Unit)? = null,
/** Triggered on demand to translate lyrics */
onTranslateLyrics: (() -> Unit)? = null,
/** Triggered on demand to generate or fetch subtitles */
onGenerateSubtitles: (() -> Unit)? = null,
/** Set when opened from a queue row: adds that row's move and delete actions at the top. */
queuePosition: QueuePosition? = null,
/**
Expand Down Expand Up @@ -1887,6 +1895,24 @@ fun NowPlayingBottomSheet(
onAddLyrics()
}
}
if (onTranslateLyrics != null) {
ActionButton(
icon = SimpIcons.Translate,
text = Res.string.translate_lyrics,
) {
hideModalBottomSheet()
onTranslateLyrics()
}
}
if (onGenerateSubtitles != null) {
ActionButton(
icon = SimpIcons.Subtitles,
text = Res.string.generate_subtitles,
) {
hideModalBottomSheet()
onGenerateSubtitles()
}
}
Crossfade(targetState = setSleepTimerEnable) {
val sleepTimerState = uiState.sleepTimer
if (it) {
Expand Down
Loading