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 app be light or dark whatever the phone is

Leloniod804efa5be3c
diff --git a/app/src/main/java/dev/lelonio/square/data/PreferencesStore.kt b/app/src/main/java/dev/lelonio/square/data/PreferencesStore.kt
index 6a8d4ad..3963e2a 100644
--- a/app/src/main/java/dev/lelonio/square/data/PreferencesStore.kt
+++ b/app/src/main/java/dev/lelonio/square/data/PreferencesStore.kt
@@ -174,6 +174,27 @@ class PreferencesStore(context: Context) {
prefs.edit().putBoolean(KEY_SYSTEM_FONT, value).apply()
}
+ /** Light, dark, or whichever the phone is set to; see [themeMode]. */
+ enum class ThemeMode { SYSTEM, LIGHT, DARK }
+
+ private val _themeMode = MutableStateFlow(
+ ThemeMode.entries.firstOrNull { it.name == prefs.getString(KEY_THEME_MODE, null) } ?: ThemeMode.SYSTEM,
+ )
+
+ /**
+ * The app's own light or dark, independent of the phone's.
+ *
+ * Asked for by listeners who keep the phone light and want the app dark,
+ * and the other way round. The phone's setting is the default, as it was
+ * before this existed.
+ */
+ val themeMode: StateFlow<ThemeMode> = _themeMode.asStateFlow()
+
+ fun setThemeMode(value: ThemeMode) {
+ _themeMode.value = value
+ prefs.edit().putString(KEY_THEME_MODE, value.name).apply()
+ }
+
/** Where the moving covers come from; see [animatedCoverSource]. */
enum class CoverSource { SPOTIFY, APPLE_MUSIC }
@@ -383,6 +404,7 @@ class PreferencesStore(context: Context) {
const val KEY_CANVAS = "canvas_enabled"
const val KEY_COVER_SOURCE = "animated_cover_source"
const val KEY_SYSTEM_FONT = "system_font"
+ const val KEY_THEME_MODE = "theme_mode"
const val KEY_YOUTUBE_QUALITY = "youtube_quality"
const val KEY_LYRICS_STYLE = "lyrics_style"
const val KEY_SPICY_LYRICS = "spicy_lyrics_key"
diff --git a/app/src/main/java/dev/lelonio/square/ui/MainActivity.kt b/app/src/main/java/dev/lelonio/square/ui/MainActivity.kt
index 1865102..823bc0d 100644
--- a/app/src/main/java/dev/lelonio/square/ui/MainActivity.kt
+++ b/app/src/main/java/dev/lelonio/square/ui/MainActivity.kt
@@ -106,14 +106,16 @@ class MainActivity : ComponentActivity() {
}
setContent {
- SquareApp(
- player = controller,
- onPlay = ::play,
- onEnqueue = ::enqueue,
- onEnqueueAll = ::enqueueAll,
- openPlayer = openPlayer,
- link = link,
- )
+ dev.lelonio.square.ui.theme.ChosenTheme {
+ SquareApp(
+ player = controller,
+ onPlay = ::play,
+ onEnqueue = ::enqueue,
+ onEnqueueAll = ::enqueueAll,
+ openPlayer = openPlayer,
+ link = link,
+ )
+ }
}
}
diff --git a/app/src/main/java/dev/lelonio/square/ui/settings/SettingsScreen.kt b/app/src/main/java/dev/lelonio/square/ui/settings/SettingsScreen.kt
index 18d18c6..a4d89af 100644
--- a/app/src/main/java/dev/lelonio/square/ui/settings/SettingsScreen.kt
+++ b/app/src/main/java/dev/lelonio/square/ui/settings/SettingsScreen.kt
@@ -81,6 +81,8 @@ import androidx.compose.animation.fadeIn
import androidx.compose.animation.fadeOut
import androidx.compose.animation.core.tween
import com.adamglin.phosphoricons.regular.DeviceMobile
+import com.adamglin.phosphoricons.regular.Moon
+import com.adamglin.phosphoricons.regular.Sun
import com.adamglin.phosphoricons.regular.Package
import com.adamglin.phosphoricons.regular.FilmStrip
import com.adamglin.phosphoricons.regular.Repeat
@@ -642,6 +644,34 @@ fun SettingsScreen(
if (shown == SettingsPage.App) groupHeading(Group.APPEARANCE, open = "appearance" in openGroups) { toggleGroup("appearance") }
+ // Light or dark, whatever the phone is.
+ if (shown == SettingsPage.App && "appearance" in openGroups) groupItem("theme", Group.APPEARANCE) {
+ val store = remember(context) {
+ (context.applicationContext as dev.lelonio.square.SquareApplication).preferences
+ }
+ val mode by store.themeMode.collectAsStateWithLifecycle()
+ Section(stringResource(R.string.theme_title)) {
+ dev.lelonio.square.data.PreferencesStore.ThemeMode.entries.forEachIndexed { index, choice ->
+ if (index > 0) RowDivider()
+ ChoiceRow(
+ label = stringResource(
+ when (choice) {
+ dev.lelonio.square.data.PreferencesStore.ThemeMode.SYSTEM -> R.string.theme_system
+ dev.lelonio.square.data.PreferencesStore.ThemeMode.LIGHT -> R.string.theme_light
+ dev.lelonio.square.data.PreferencesStore.ThemeMode.DARK -> R.string.theme_dark
+ },
+ ),
+ selected = choice == mode,
+ icon = when (choice) {
+ dev.lelonio.square.data.PreferencesStore.ThemeMode.SYSTEM -> PhosphorIcons.Regular.DeviceMobile
+ dev.lelonio.square.data.PreferencesStore.ThemeMode.LIGHT -> PhosphorIcons.Regular.Sun
+ dev.lelonio.square.data.PreferencesStore.ThemeMode.DARK -> PhosphorIcons.Regular.Moon
+ },
+ ) { store.setThemeMode(choice) }
+ }
+ }
+ }
+
// What the bar does, which is behaviour rather than material: the glass
// page says what it is made of, this says how it acts.
if (shown == SettingsPage.App && "appearance" in openGroups) groupItem("bar", Group.APPEARANCE) {
diff --git a/app/src/main/java/dev/lelonio/square/ui/theme/Theme.kt b/app/src/main/java/dev/lelonio/square/ui/theme/Theme.kt
index 8b5626c..81f2e6f 100644
--- a/app/src/main/java/dev/lelonio/square/ui/theme/Theme.kt
+++ b/app/src/main/java/dev/lelonio/square/ui/theme/Theme.kt
@@ -296,3 +296,40 @@ private val SpotTypography = spotTypography(Inter, tracking = 1f)
* the letters of a large title together.
*/
private val SystemTypography = spotTypography(FontFamily.Default, tracking = 0.5f)
+
+/**
+ * The listener's light or dark, over the phone's; see PreferencesStore.themeMode.
+ *
+ * Put in as the configuration's own night mode rather than handed to the
+ * theme: `isSystemInDarkTheme` is read in the theme and in the glass
+ * components on their own, and every one of them reads it from here. Nothing
+ * else in the configuration is touched, and on "system" it is the phone's,
+ * untouched.
+ */
+@Composable
+fun ChosenTheme(content: @Composable () -> Unit) {
+ val context = androidx.compose.ui.platform.LocalContext.current
+ val mode by remember(context) {
+ (context.applicationContext as? dev.lelonio.square.SquareApplication)?.preferences?.themeMode
+ ?: kotlinx.coroutines.flow.MutableStateFlow(dev.lelonio.square.data.PreferencesStore.ThemeMode.SYSTEM)
+ }.collectAsState()
+ val base = androidx.compose.ui.platform.LocalConfiguration.current
+ val night = when (mode) {
+ dev.lelonio.square.data.PreferencesStore.ThemeMode.SYSTEM -> null
+ dev.lelonio.square.data.PreferencesStore.ThemeMode.LIGHT -> android.content.res.Configuration.UI_MODE_NIGHT_NO
+ dev.lelonio.square.data.PreferencesStore.ThemeMode.DARK -> android.content.res.Configuration.UI_MODE_NIGHT_YES
+ }
+ val configuration = remember(base, night) {
+ if (night == null) {
+ base
+ } else {
+ android.content.res.Configuration(base).apply {
+ uiMode = (uiMode and android.content.res.Configuration.UI_MODE_NIGHT_MASK.inv()) or night
+ }
+ }
+ }
+ CompositionLocalProvider(
+ androidx.compose.ui.platform.LocalConfiguration provides configuration,
+ content = content,
+ )
+}
diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml
index 4eb25bf..ec30e9b 100644
--- a/app/src/main/res/values-de/strings.xml
+++ b/app/src/main/res/values-de/strings.xml
@@ -566,6 +566,10 @@
<string name="animated_cover_source">Quelle</string>
<string name="animated_cover_spotify">Spotify (Canvas)</string>
<string name="animated_cover_apple">Apple Music</string>
+ <string name="theme_title">Design</string>
+ <string name="theme_system">Wie das Telefon</string>
+ <string name="theme_light">Hell</string>
+ <string name="theme_dark">Dunkel</string>
<string name="font_title">Schrift</string>
<string name="font_system">Schrift des Handys verwenden</string>
<string name="youtube_quality_auto">Automatisch: hoch im WLAN, niedrig mit mobilen Daten</string>
diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml
index 7aaee48..abff510 100644
--- a/app/src/main/res/values-es/strings.xml
+++ b/app/src/main/res/values-es/strings.xml
@@ -572,6 +572,10 @@
<string name="animated_cover_source">Fuente</string>
<string name="animated_cover_spotify">Spotify (Canvas)</string>
<string name="animated_cover_apple">Apple Music</string>
+ <string name="theme_title">Tema</string>
+ <string name="theme_system">Como el teléfono</string>
+ <string name="theme_light">Claro</string>
+ <string name="theme_dark">Oscuro</string>
<string name="font_title">Fuente</string>
<string name="font_system">Usar la fuente del teléfono</string>
<string name="youtube_quality_auto">Automática: alta con Wi-Fi, baja con datos móviles</string>
diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml
index 6c90b65..4d56590 100644
--- a/app/src/main/res/values-fr/strings.xml
+++ b/app/src/main/res/values-fr/strings.xml
@@ -566,6 +566,10 @@
<string name="animated_cover_source">Source</string>
<string name="animated_cover_spotify">Spotify (Canvas)</string>
<string name="animated_cover_apple">Apple Music</string>
+ <string name="theme_title">Thème</string>
+ <string name="theme_system">Comme le téléphone</string>
+ <string name="theme_light">Clair</string>
+ <string name="theme_dark">Sombre</string>
<string name="font_title">Police</string>
<string name="font_system">Utiliser la police du téléphone</string>
<string name="youtube_quality_auto">Automatique : haute en Wi-Fi, basse en données mobiles</string>
diff --git a/app/src/main/res/values-hi/strings.xml b/app/src/main/res/values-hi/strings.xml
index 3062f50..48a9746 100644
--- a/app/src/main/res/values-hi/strings.xml
+++ b/app/src/main/res/values-hi/strings.xml
@@ -581,6 +581,10 @@
<string name="animated_cover_source">स्रोत</string>
<string name="animated_cover_spotify">Spotify (Canvas)</string>
<string name="animated_cover_apple">Apple Music</string>
+ <string name="theme_title">थीम</string>
+ <string name="theme_system">फ़ोन के अनुसार</string>
+ <string name="theme_light">हल्की</string>
+ <string name="theme_dark">गहरी</string>
<string name="font_title">फ़ॉन्ट</string>
<string name="font_system">फ़ोन का फ़ॉन्ट इस्तेमाल करें</string>
<string name="youtube_quality_auto">अपने-आप: Wi-Fi पर ऊँची, मोबाइल डेटा पर कम</string>
diff --git a/app/src/main/res/values-it/strings.xml b/app/src/main/res/values-it/strings.xml
index f4a1b78..7337c36 100644
--- a/app/src/main/res/values-it/strings.xml
+++ b/app/src/main/res/values-it/strings.xml
@@ -603,6 +603,10 @@
<string name="animated_cover_source">Sorgente</string>
<string name="animated_cover_spotify">Spotify (Canvas)</string>
<string name="animated_cover_apple">Apple Music</string>
+ <string name="theme_title">Tema</string>
+ <string name="theme_system">Come il telefono</string>
+ <string name="theme_light">Chiaro</string>
+ <string name="theme_dark">Scuro</string>
<string name="font_title">Carattere</string>
<string name="font_system">Usa il carattere del telefono</string>
<string name="youtube_quality_auto">Automatica: alta su Wi-Fi, bassa con i dati mobili</string>
diff --git a/app/src/main/res/values-ja/strings.xml b/app/src/main/res/values-ja/strings.xml
index 0725757..64a3964 100644
--- a/app/src/main/res/values-ja/strings.xml
+++ b/app/src/main/res/values-ja/strings.xml
@@ -622,6 +622,10 @@
<string name="animated_cover_source">取得元</string>
<string name="animated_cover_spotify">Spotify(Canvas)</string>
<string name="animated_cover_apple">Apple Music</string>
+ <string name="theme_title">テーマ</string>
+ <string name="theme_system">端末の設定に従う</string>
+ <string name="theme_light">ライト</string>
+ <string name="theme_dark">ダーク</string>
<string name="font_title">フォント</string>
<string name="font_system">端末のフォントを使用</string>
<string name="youtube_quality_auto">自動:Wi‑Fiでは高音質、モバイルデータ通信では低音質</string>
diff --git a/app/src/main/res/values-ko/strings.xml b/app/src/main/res/values-ko/strings.xml
index 11034e9..d21c0a1 100644
--- a/app/src/main/res/values-ko/strings.xml
+++ b/app/src/main/res/values-ko/strings.xml
@@ -581,6 +581,10 @@
<string name="animated_cover_source">소스</string>
<string name="animated_cover_spotify">Spotify (Canvas)</string>
<string name="animated_cover_apple">Apple Music</string>
+ <string name="theme_title">테마</string>
+ <string name="theme_system">휴대전화 설정과 동일</string>
+ <string name="theme_light">라이트</string>
+ <string name="theme_dark">다크</string>
<string name="font_title">글꼴</string>
<string name="font_system">휴대폰 글꼴 사용</string>
<string name="youtube_quality_auto">자동: Wi-Fi에서는 높음, 모바일 데이터에서는 낮음</string>
diff --git a/app/src/main/res/values-pt/strings.xml b/app/src/main/res/values-pt/strings.xml
index b52e0a2..396d46b 100644
--- a/app/src/main/res/values-pt/strings.xml
+++ b/app/src/main/res/values-pt/strings.xml
@@ -566,6 +566,10 @@
<string name="animated_cover_source">Fonte</string>
<string name="animated_cover_spotify">Spotify (Canvas)</string>
<string name="animated_cover_apple">Apple Music</string>
+ <string name="theme_title">Tema</string>
+ <string name="theme_system">Igual ao telemóvel</string>
+ <string name="theme_light">Claro</string>
+ <string name="theme_dark">Escuro</string>
<string name="font_title">Fonte</string>
<string name="font_system">Usar a fonte do telefone</string>
<string name="youtube_quality_auto">Automática: alta no Wi-Fi, baixa nos dados móveis</string>
diff --git a/app/src/main/res/values-ru/strings.xml b/app/src/main/res/values-ru/strings.xml
index 5f98c30..a863b48 100644
--- a/app/src/main/res/values-ru/strings.xml
+++ b/app/src/main/res/values-ru/strings.xml
@@ -595,6 +595,10 @@
<string name="animated_cover_source">Источник</string>
<string name="animated_cover_spotify">Spotify (Canvas)</string>
<string name="animated_cover_apple">Apple Music</string>
+ <string name="theme_title">Тема</string>
+ <string name="theme_system">Как в телефоне</string>
+ <string name="theme_light">Светлая</string>
+ <string name="theme_dark">Тёмная</string>
<string name="font_title">Шрифт</string>
<string name="font_system">Использовать шрифт телефона</string>
<string name="youtube_quality_auto">Автоматически: высокое по Wi-Fi, низкое по мобильной сети</string>
diff --git a/app/src/main/res/values-tr/strings.xml b/app/src/main/res/values-tr/strings.xml
index 2447bd8..db022a0 100644
--- a/app/src/main/res/values-tr/strings.xml
+++ b/app/src/main/res/values-tr/strings.xml
@@ -579,6 +579,10 @@
<string name="animated_cover_source">Kaynak</string>
<string name="animated_cover_spotify">Spotify (Canvas)</string>
<string name="animated_cover_apple">Apple Music</string>
+ <string name="theme_title">Tema</string>
+ <string name="theme_system">Telefonla aynı</string>
+ <string name="theme_light">Açık</string>
+ <string name="theme_dark">Koyu</string>
<string name="font_title">Yazı tipi</string>
<string name="font_system">Telefonun yazı tipini kullan</string>
<string name="youtube_quality_auto">Otomatik: Wi-Fi’da yüksek, mobil veride düşük</string>
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index b8ac84d..4312f73 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -630,6 +630,10 @@
<string name="animated_cover_source">Source</string>
<string name="animated_cover_spotify">Spotify (Canvas)</string>
<string name="animated_cover_apple">Apple Music</string>
+ <string name="theme_title">Theme</string>
+ <string name="theme_system">Same as the phone</string>
+ <string name="theme_light">Light</string>
+ <string name="theme_dark">Dark</string>
<string name="font_title">Font</string>
<string name="font_system">Use the phone’s font</string>
<string name="youtube_quality_auto">Automatic: high on Wi-Fi, low on mobile data</string>