Skip to content

Unofficial YouTube Music / Spotify Premium client for Android, built in Liquid Glass. Audio effects, Spotify Connect, listening history, 8 languages. Rust core on librespot.

Let the language be chosen, not inherited

Lelonio62a4e07ece97
diff --git a/app/.cxx/Debug/286k5v33/arm64-v8a/configure_fingerprint.bin b/app/.cxx/Debug/286k5v33/arm64-v8a/configure_fingerprint.bin
index 5d41b22..cb23c03 100644
--- a/app/.cxx/Debug/286k5v33/arm64-v8a/configure_fingerprint.bin
+++ b/app/.cxx/Debug/286k5v33/arm64-v8a/configure_fingerprint.bin
@@ -2,27 +2,27 @@ C/C++ Structured Logc
a
_/Users/emanuele/Progetto Spotify/app/.cxx/Debug/286k5v33/arm64-v8a/additional_project_files.txtC
A
-?com.android.build.gradle.internal.cxx.io.EncodedFileFingerPrint  ��IJ�3  ��߈�3`
+?com.android.build.gradle.internal.cxx.io.EncodedFileFingerPrint  ��ٲ�3  ��߈�3`
^
-\/Users/emanuele/Progetto Spotify/app/.cxx/Debug/286k5v33/arm64-v8a/android_gradle_build.json  ��IJ�3� ��߈�3e
+\/Users/emanuele/Progetto Spotify/app/.cxx/Debug/286k5v33/arm64-v8a/android_gradle_build.json  ��ٲ�3� ��߈�3e
c
-a/Users/emanuele/Progetto Spotify/app/.cxx/Debug/286k5v33/arm64-v8a/android_gradle_build_mini.json  ��IJ�3� ��߈�3R
+a/Users/emanuele/Progetto Spotify/app/.cxx/Debug/286k5v33/arm64-v8a/android_gradle_build_mini.json  ��ٲ�3� ��߈�3R
P
-N/Users/emanuele/Progetto Spotify/app/.cxx/Debug/286k5v33/arm64-v8a/build.ninja  ��IJ�3� ��߈�3V
+N/Users/emanuele/Progetto Spotify/app/.cxx/Debug/286k5v33/arm64-v8a/build.ninja  ��ٲ�3� ��߈�3V
T
-R/Users/emanuele/Progetto Spotify/app/.cxx/Debug/286k5v33/arm64-v8a/build.ninja.txt  ��IJ�3[
+R/Users/emanuele/Progetto Spotify/app/.cxx/Debug/286k5v33/arm64-v8a/build.ninja.txt  ��ٲ�3[
Y
-W/Users/emanuele/Progetto Spotify/app/.cxx/Debug/286k5v33/arm64-v8a/build_file_index.txt  ��IJ�3 @ ��߈�3\
+W/Users/emanuele/Progetto Spotify/app/.cxx/Debug/286k5v33/arm64-v8a/build_file_index.txt  ��ٲ�3 @ ��߈�3\
Z
-X/Users/emanuele/Progetto Spotify/app/.cxx/Debug/286k5v33/arm64-v8a/compile_commands.json  ��IJ�3֚ ��߈�3`
+X/Users/emanuele/Progetto Spotify/app/.cxx/Debug/286k5v33/arm64-v8a/compile_commands.json  ��ٲ�3֚ ��߈�3`
^
-\/Users/emanuele/Progetto Spotify/app/.cxx/Debug/286k5v33/arm64-v8a/compile_commands.json.bin  ��IJ�3 �" ��߈�3f
+\/Users/emanuele/Progetto Spotify/app/.cxx/Debug/286k5v33/arm64-v8a/compile_commands.json.bin  ��ٲ�3 �" ��߈�3f
d
-b/Users/emanuele/Progetto Spotify/app/.cxx/Debug/286k5v33/arm64-v8a/metadata_generation_command.txt  ��IJ�3
+b/Users/emanuele/Progetto Spotify/app/.cxx/Debug/286k5v33/arm64-v8a/metadata_generation_command.txt  ��ٲ�3
� ��߈�3Y
W
-U/Users/emanuele/Progetto Spotify/app/.cxx/Debug/286k5v33/arm64-v8a/prefab_config.json  ��IJ�3  ( ��߈�3^
+U/Users/emanuele/Progetto Spotify/app/.cxx/Debug/286k5v33/arm64-v8a/prefab_config.json  ��ٲ�3  ( ��߈�3^
\
-Z/Users/emanuele/Progetto Spotify/app/.cxx/Debug/286k5v33/arm64-v8a/symbol_folder_index.txt  ��IJ�3  Y ��߈�3D
+Z/Users/emanuele/Progetto Spotify/app/.cxx/Debug/286k5v33/arm64-v8a/symbol_folder_index.txt  ��ٲ�3  Y ��߈�3D
B
-@/Users/emanuele/Progetto Spotify/app/src/main/cpp/CMakeLists.txt  ��IJ�3 � �Ȅ��3
\ No newline at end of file
+@/Users/emanuele/Progetto Spotify/app/src/main/cpp/CMakeLists.txt  ��ٲ�3 � �Ȅ��3
\ No newline at end of file
diff --git a/app/src/main/java/dev/emanuele/spot/SpotApplication.kt b/app/src/main/java/dev/emanuele/spot/SpotApplication.kt
index 5fdfb3b..995f0d1 100644
--- a/app/src/main/java/dev/emanuele/spot/SpotApplication.kt
+++ b/app/src/main/java/dev/emanuele/spot/SpotApplication.kt
@@ -4,6 +4,7 @@ import android.app.Application
import dev.emanuele.spot.auth.TokenStore
import dev.emanuele.spot.auth.WebApiAccount
import dev.emanuele.spot.data.ContextCacheStore
+import dev.emanuele.spot.data.LanguageStore
import dev.emanuele.spot.data.PlaylistOrderStore
import dev.emanuele.spot.data.PreferencesStore
import dev.emanuele.spot.data.RecentStore
@@ -27,6 +28,9 @@ class SpotApplication : Application() {
val playlistOrder: PlaylistOrderStore by lazy { PlaylistOrderStore(this) }
val preferences: PreferencesStore by lazy { PreferencesStore(this) }
+ /** What language the app is read in, and what the engine asks Spotify for. */
+ val language: LanguageStore by lazy { LanguageStore(this) }
+
/** Track lists already resolved, so reopening a playlist is not a reload. */
val contextCache: ContextCacheStore by lazy { ContextCacheStore(this) }
diff --git a/app/src/main/java/dev/emanuele/spot/data/LanguageStore.kt b/app/src/main/java/dev/emanuele/spot/data/LanguageStore.kt
new file mode 100644
index 0000000..00bf0e3
--- /dev/null
+++ b/app/src/main/java/dev/emanuele/spot/data/LanguageStore.kt
@@ -0,0 +1,108 @@
+package dev.emanuele.spot.data
+
+import android.content.Context
+import android.content.res.Configuration
+import android.os.Build
+import android.os.LocaleList
+import java.util.Locale
+import kotlinx.coroutines.flow.MutableStateFlow
+import kotlinx.coroutines.flow.StateFlow
+import kotlinx.coroutines.flow.asStateFlow
+
+/**
+ * The language the app is read in.
+ *
+ * Android 13 has a per-app language picker of its own, and this writes to it on
+ * those versions so the two never disagree — a setting inside the app and a
+ * different one in the system settings would be a bug nobody could explain.
+ * Below 13 there is nothing to write to, so the choice is kept here and applied
+ * by wrapping the context every screen is built from.
+ *
+ * Stored as a language tag, empty meaning "whatever the phone is set to". It is
+ * also what the engine sends as `Accept-Language`, so the covers of Spotify's
+ * generated playlists come back in the same language as the app.
+ */
+class LanguageStore(context: Context) {
+
+ private val app = context.applicationContext
+ private val prefs = app.getSharedPreferences(FILE_NAME, Context.MODE_PRIVATE)
+
+ private val _tag = MutableStateFlow(prefs.getString(KEY_LANGUAGE, null).orEmpty())
+
+ /** The chosen tag, or empty for the system's. */
+ val tag: StateFlow<String> = _tag.asStateFlow()
+
+ /**
+ * The two-letter language actually in force, which is what the engine wants.
+ *
+ * Falls back to English rather than to Italian: an unknown phone language
+ * gets the same answer as the app's own base locale.
+ */
+ fun language(): String {
+ val chosen = _tag.value
+ if (chosen.isNotEmpty()) return chosen.substringBefore('-')
+ val locale = systemLocale()
+ return locale.language.takeIf { it.isNotEmpty() } ?: "en"
+ }
+
+ fun set(tag: String) {
+ _tag.value = tag
+ prefs.edit().putString(KEY_LANGUAGE, tag).apply()
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
+ val manager = app.getSystemService(android.app.LocaleManager::class.java)
+ manager?.applicationLocales =
+ if (tag.isEmpty()) LocaleList.getEmptyLocaleList()
+ else LocaleList.forLanguageTags(tag)
+ }
+ }
+
+ /**
+ * The same context, reading in the chosen language.
+ *
+ * Only needed below Android 13; above it the system has already applied the
+ * choice by the time anything is created, and wrapping again would be a
+ * second answer to a settled question.
+ */
+ fun wrap(base: Context): Context {
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) return base
+ val chosen = _tag.value
+ if (chosen.isEmpty()) return base
+ val locale = Locale.forLanguageTag(chosen)
+ Locale.setDefault(locale)
+ val configuration = Configuration(base.resources.configuration)
+ configuration.setLocale(locale)
+ configuration.setLocales(LocaleList(locale))
+ return base.createConfigurationContext(configuration)
+ }
+
+ private fun systemLocale(): Locale =
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
+ android.content.res.Resources.getSystem().configuration.locales[0]
+ } else {
+ @Suppress("DEPRECATION")
+ android.content.res.Resources.getSystem().configuration.locale
+ }
+
+ private companion object {
+ const val FILE_NAME = "spot_language"
+ const val KEY_LANGUAGE = "language"
+ }
+}
+
+/**
+ * The languages Square is translated into.
+ *
+ * Kept next to the store rather than in the screen that draws them: the same
+ * list has to match res/xml/locales_config.xml, and one list is easier to keep
+ * honest than two. Each name is written in its own language, which is how a
+ * language picker is read by the person who needs it.
+ */
+val AppLanguages: List<Pair<String, String>> = listOf(
+ "" to "",
+ "en" to "English",
+ "it" to "Italiano",
+ "es" to "Español",
+ "fr" to "Français",
+ "de" to "Deutsch",
+ "pt" to "Português",
+)
diff --git a/app/src/main/java/dev/emanuele/spot/playback/PlaybackService.kt b/app/src/main/java/dev/emanuele/spot/playback/PlaybackService.kt
index e35d443..0f937fc 100644
--- a/app/src/main/java/dev/emanuele/spot/playback/PlaybackService.kt
+++ b/app/src/main/java/dev/emanuele/spot/playback/PlaybackService.kt
@@ -361,5 +361,12 @@ class PlaybackService : MediaSessionService() {
* app is actually showing: today that is Italian for everyone, and the day it
* has more languages this keeps pointing at the one in use.
*/
+/**
+ * The language to ask Spotify to answer in.
+ *
+ * Read from the app's own setting rather than from this context's resources: a
+ * service is not re-created when the language changes, and its configuration
+ * would still be yesterday's.
+ */
private fun android.content.Context.appLanguage(): String =
- resources.configuration.locales[0]?.language?.takeIf { it.isNotEmpty() } ?: "it"
+ (applicationContext as dev.emanuele.spot.SpotApplication).language.language()
diff --git a/app/src/main/java/dev/emanuele/spot/ui/MainActivity.kt b/app/src/main/java/dev/emanuele/spot/ui/MainActivity.kt
index f49de14..85f867d 100644
--- a/app/src/main/java/dev/emanuele/spot/ui/MainActivity.kt
+++ b/app/src/main/java/dev/emanuele/spot/ui/MainActivity.kt
@@ -31,6 +31,15 @@ class MainActivity : ComponentActivity() {
private var controller by mutableStateOf<MediaController?>(null)
+ /**
+ * Below Android 13 nothing applies the chosen language for us, so every
+ * resource this activity reads has to come from a context that carries it.
+ */
+ override fun attachBaseContext(base: android.content.Context) {
+ val store = (base.applicationContext as dev.emanuele.spot.SpotApplication).language
+ super.attachBaseContext(store.wrap(base))
+ }
+
/**
* Bumped when something asks for the player to be open — the notification,
* for now.
diff --git a/app/src/main/java/dev/emanuele/spot/ui/SpotApp.kt b/app/src/main/java/dev/emanuele/spot/ui/SpotApp.kt
index 6768f33..f0eac3e 100644
--- a/app/src/main/java/dev/emanuele/spot/ui/SpotApp.kt
+++ b/app/src/main/java/dev/emanuele/spot/ui/SpotApp.kt
@@ -302,6 +302,23 @@ fun SpotApp(
lyricsLoading = false
}
+ // The language the app is read in. Changing it re-creates the activity,
+ // which is the only way a Compose tree already built out of one set of
+ // resources can be rebuilt out of another.
+ val context = LocalContext.current
+ val languageStore = remember(context) {
+ (context.applicationContext as dev.emanuele.spot.SpotApplication).language
+ }
+ val language by languageStore.tag.collectAsStateWithLifecycle()
+ val setLanguage: (String) -> Unit = remember(languageStore, context) {
+ { tag ->
+ if (tag != languageStore.tag.value) {
+ languageStore.set(tag)
+ (context as? android.app.Activity)?.recreate()
+ }
+ }
+ }
+
// Read once, up here: these travel with a play as plain text, and the rows
// that start one are not composables of their own.
val playAgainLabel = stringResource(R.string.play_again)
@@ -477,6 +494,8 @@ fun SpotApp(
onDisconnectWebApi = viewModel::disconnectWebApi,
onLogOut = viewModel::logOut,
onShowTutorial = { showTutorial = true },
+ language = language,
+ onLanguage = setLanguage,
onBack = { navController.popBackStack() },
)
}
@@ -731,6 +750,8 @@ fun SpotApp(
onLogIn = viewModel::logIn,
onClientIdChange = viewModel::onWebApiClientIdChange,
onConnectWebApi = { viewModel.connectWebApi() },
+ language = language,
+ onLanguage = setLanguage,
onFinish = {
showTutorial = false
viewModel.setOnboarded(true)
diff --git a/app/src/main/java/dev/emanuele/spot/ui/onboarding/OnboardingScreen.kt b/app/src/main/java/dev/emanuele/spot/ui/onboarding/OnboardingScreen.kt
index ec9213b..e7047c7 100644
--- a/app/src/main/java/dev/emanuele/spot/ui/onboarding/OnboardingScreen.kt
+++ b/app/src/main/java/dev/emanuele/spot/ui/onboarding/OnboardingScreen.kt
@@ -7,6 +7,8 @@ import androidx.compose.animation.fadeOut
import androidx.compose.animation.slideInHorizontally
import androidx.compose.animation.slideOutHorizontally
import androidx.compose.animation.togetherWith
+import dev.emanuele.spot.data.AppLanguages
+import androidx.compose.foundation.horizontalScroll
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
@@ -90,6 +92,9 @@ fun OnboardingScreen(
onLogIn: () -> Unit,
onClientIdChange: (String) -> Unit,
onConnectWebApi: () -> Unit,
+ /** The chosen language tag, empty for the phone's own. */
+ language: String,
+ onLanguage: (String) -> Unit,
onFinish: () -> Unit,
) {
var step by remember { mutableIntStateOf(0) }
@@ -155,7 +160,7 @@ fun OnboardingScreen(
.padding(horizontal = 26.dp),
) {
when (current) {
- 0 -> Welcome()
+ 0 -> Welcome(language, onLanguage)
1 -> LogIn(
loggedIn = loggedIn,
connecting = state is MainViewModel.UiState.Loading,
@@ -209,7 +214,7 @@ fun OnboardingScreen(
private const val STEP_COUNT = 5
@Composable
-private fun Welcome() {
+private fun Welcome(language: String, onLanguage: (String) -> Unit) {
Spacer(Modifier.height(24.dp))
AppIcon(104.dp)
Spacer(Modifier.height(22.dp))
@@ -217,6 +222,11 @@ private fun Welcome() {
Body(stringResource(R.string.onboarding_welcome_1))
Note(stringResource(R.string.onboarding_welcome_2))
Body(stringResource(R.string.onboarding_welcome_3))
+
+ // First screen, before a word of the setup: someone who cannot read this
+ // page is exactly the person who needs the picker, and asking them to
+ // finish the tutorial first to find it would be the wrong way round.
+ LanguageChips(language, onLanguage)
}
@Composable
@@ -350,6 +360,37 @@ private fun Done() {
Note(stringResource(R.string.onboarding_done_3))
}
+/**
+ * The languages, as a row of pills.
+ *
+ * Chips rather than the list the settings screen uses: this is one line of a
+ * page that is mostly prose, and a seven-row list here would read as the first
+ * task rather than as a choice already made for most people.
+ */
+@Composable
+private fun LanguageChips(language: String, onLanguage: (String) -> Unit) {
+ Row(
+ Modifier
+ .padding(top = 22.dp)
+ .horizontalScroll(rememberScrollState()),
+ horizontalArrangement = Arrangement.spacedBy(8.dp),
+ ) {
+ AppLanguages.forEach { (tag, name) ->
+ val selected = tag == language
+ Text(
+ name.ifEmpty { stringResource(R.string.system_language) },
+ style = MaterialTheme.typography.bodyMedium,
+ color = if (selected) Ink else InkDim,
+ modifier = Modifier
+ .clip(RoundedCornerShape(50))
+ .background(Ink.copy(alpha = if (selected) 0.18f else 0.07f))
+ .clickable { onLanguage(tag) }
+ .padding(horizontal = 14.dp, vertical = 8.dp),
+ )
+ }
+ }
+}
+
/* ---- pieces ---- */
@Composable
diff --git a/app/src/main/java/dev/emanuele/spot/ui/settings/SettingsScreen.kt b/app/src/main/java/dev/emanuele/spot/ui/settings/SettingsScreen.kt
index a0c471d..ac2dd1e 100644
--- a/app/src/main/java/dev/emanuele/spot/ui/settings/SettingsScreen.kt
+++ b/app/src/main/java/dev/emanuele/spot/ui/settings/SettingsScreen.kt
@@ -35,12 +35,14 @@ import androidx.compose.ui.unit.dp
import com.adamglin.PhosphorIcons
import com.adamglin.phosphoricons.Regular
import com.adamglin.phosphoricons.regular.ArrowLeft
+import com.adamglin.phosphoricons.regular.Check
import com.adamglin.phosphoricons.regular.ArrowUpRight
import com.adamglin.phosphoricons.regular.CaretDown
import com.adamglin.phosphoricons.regular.CaretUp
import com.kyant.backdrop.Backdrop
import dev.emanuele.spot.BuildConfig
import dev.emanuele.spot.R
+import dev.emanuele.spot.data.AppLanguages
import dev.emanuele.spot.ui.MainViewModel
import dev.emanuele.spot.ui.components.Artwork
import dev.emanuele.spot.ui.glass.LiquidButton
@@ -74,6 +76,9 @@ fun SettingsScreen(
onDisconnectWebApi: () -> Unit,
onLogOut: () -> Unit,
onShowTutorial: () -> Unit,
+ /** The chosen language tag, empty for the phone's own. */
+ language: String,
+ onLanguage: (String) -> Unit,
onBack: () -> Unit,
) {
val ready = state as? MainViewModel.UiState.Ready
@@ -176,6 +181,18 @@ fun SettingsScreen(
}
}
+ item("language") {
+ Section(stringResource(R.string.language)) {
+ AppLanguages.forEachIndexed { index, (tag, name) ->
+ if (index > 0) RowDivider()
+ ChoiceRow(
+ label = name.ifEmpty { stringResource(R.string.system_language) },
+ selected = tag == language,
+ ) { onLanguage(tag) }
+ }
+ }
+ }
+
item("permissions") {
Section(stringResource(R.string.permissions_asked)) {
Text(
@@ -349,6 +366,33 @@ private fun ActionRow(label: String, destructive: Boolean, onClick: () -> Unit)
)
}
+/** A row of a list where one is picked, with a tick on the one that is. */
+@Composable
+private fun ChoiceRow(label: String, selected: Boolean, onClick: () -> Unit) {
+ Row(
+ Modifier
+ .fillMaxWidth()
+ .clickable(onClick = onClick)
+ .padding(horizontal = 18.dp, vertical = 14.dp),
+ verticalAlignment = Alignment.CenterVertically,
+ ) {
+ Text(
+ label,
+ style = MaterialTheme.typography.bodyLarge,
+ color = if (selected) Ink else InkDim,
+ modifier = Modifier.weight(1f),
+ )
+ if (selected) {
+ Icon(
+ PhosphorIcons.Regular.Check,
+ contentDescription = null,
+ tint = MaterialTheme.colorScheme.primary,
+ modifier = Modifier.size(18.dp),
+ )
+ }
+ }
+}
+
@Composable
private fun RowDivider() {
Box(
diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml
index 7745af4..bcdb31e 100644
--- a/app/src/main/res/values-de/strings.xml
+++ b/app/src/main/res/values-de/strings.xml
@@ -165,4 +165,6 @@
<string name="onboarding_done_3">Diese Anleitung findest du wieder in den Einstellungen — tippe auf der Startseite auf dein Bild.</string>
<string name="browser_return">Du kannst zur App zurückgehen.</string>
+ <string name="language">Sprache</string>
+ <string name="system_language">Sprache des Telefons</string>
</resources>
diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml
index c087b49..528a891 100644
--- a/app/src/main/res/values-es/strings.xml
+++ b/app/src/main/res/values-es/strings.xml
@@ -165,4 +165,6 @@
<string name="onboarding_done_3">Puedes ver esta guía otra vez en Ajustes, tocando tu foto en inicio.</string>
<string name="browser_return">Ya puedes volver a la app.</string>
+ <string name="language">Idioma</string>
+ <string name="system_language">Idioma del teléfono</string>
</resources>
diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml
index c41786d..33284fe 100644
--- a/app/src/main/res/values-fr/strings.xml
+++ b/app/src/main/res/values-fr/strings.xml
@@ -165,4 +165,6 @@
<string name="onboarding_done_3">Vous pouvez revoir ce guide depuis les Réglages, en touchant votre photo sur l\'accueil.</string>
<string name="browser_return">Vous pouvez revenir à l\'app.</string>
+ <string name="language">Langue</string>
+ <string name="system_language">Langue du téléphone</string>
</resources>
diff --git a/app/src/main/res/values-it/strings.xml b/app/src/main/res/values-it/strings.xml
index 25c0748..ee72d68 100644
--- a/app/src/main/res/values-it/strings.xml
+++ b/app/src/main/res/values-it/strings.xml
@@ -166,4 +166,6 @@
<string name="onboarding_done_3">Puoi rivedere questa guida da Impostazioni, toccando la tua foto in home.</string>
<string name="browser_return">Puoi tornare all\'app.</string>
+ <string name="language">Lingua</string>
+ <string name="system_language">Lingua del telefono</string>
</resources>
diff --git a/app/src/main/res/values-pt/strings.xml b/app/src/main/res/values-pt/strings.xml
index d3ad539..1e1c0aa 100644
--- a/app/src/main/res/values-pt/strings.xml
+++ b/app/src/main/res/values-pt/strings.xml
@@ -165,4 +165,6 @@
<string name="onboarding_done_3">Dá para rever este guia nas Configurações, tocando na sua foto no início.</string>
<string name="browser_return">Você já pode voltar ao app.</string>
+ <string name="language">Idioma</string>
+ <string name="system_language">Idioma do telefone</string>
</resources>
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index c04d553..fd209a9 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -186,4 +186,6 @@
<!-- Auth -->
<string name="browser_return">You can go back to the app.</string>
+ <string name="language">Language</string>
+ <string name="system_language">Phone language</string>
</resources>