From 9bcb753bb5d0743f06dacaf5f4b5c16f5719f10b Mon Sep 17 00:00:00 2001 From: vrubelroman Date: Wed, 28 Oct 2026 01:25:39 +0300 Subject: [PATCH] Android: dark theme by default; the app's night mode told to Android Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 4 ++++ androidApp/app/src/main/AndroidManifest.xml | 1 + .../vrubelroman/chesspenguin/MainActivity.kt | 14 ++++++++++++++ .../vrubelroman/chesspenguin/data/Settings.kt | 2 +- 4 files changed, 20 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fb165aa..dc5ce3a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ All notable changes are listed here. Versions follow [Semantic Versioning](https ## [Unreleased] +- Android: the dark theme by default (it was the system's); a theme chosen before stays. + Android is told the app's own theme, so the window and the splash screen before the + app draws match it (no white flash before a dark app on a light phone). + - Game review marks brilliant moves (!!, a sound piece sacrifice) and great moves (!, the only good move that turns the game), next to inaccuracies, mistakes and blunders: in the report, the notation, the graph and on the board; written to the game as $3 and $1. The diff --git a/androidApp/app/src/main/AndroidManifest.xml b/androidApp/app/src/main/AndroidManifest.xml index ec66981..9f5c421 100644 --- a/androidApp/app/src/main/AndroidManifest.xml +++ b/androidApp/app/src/main/AndroidManifest.xml @@ -24,6 +24,7 @@ diff --git a/androidApp/app/src/main/java/io/github/vrubelroman/chesspenguin/MainActivity.kt b/androidApp/app/src/main/java/io/github/vrubelroman/chesspenguin/MainActivity.kt index 32e8b4e..500f4fd 100644 --- a/androidApp/app/src/main/java/io/github/vrubelroman/chesspenguin/MainActivity.kt +++ b/androidApp/app/src/main/java/io/github/vrubelroman/chesspenguin/MainActivity.kt @@ -1,6 +1,7 @@ package io.github.vrubelroman.chesspenguin import android.content.Context +import android.app.UiModeManager import android.content.Intent import androidx.lifecycle.Lifecycle import androidx.lifecycle.lifecycleScope @@ -19,6 +20,7 @@ import androidx.compose.material3.Surface import androidx.compose.ui.Modifier import androidx.compose.foundation.isSystemInDarkTheme import androidx.compose.runtime.DisposableEffect +import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.collectAsState import androidx.compose.runtime.getValue import io.github.vrubelroman.chesspenguin.data.Language @@ -60,6 +62,18 @@ class MainActivity : ComponentActivity() { Theme.Light -> false Theme.Dark -> true } + // Android keeps the app's own day or night (Android 12+): the window and the + // splash screen before Compose draws then match the theme chosen, not the + // system's (no white flash before a dark app). + LaunchedEffect(prefs.theme) { + getSystemService(UiModeManager::class.java)?.setApplicationNightMode( + when (prefs.theme) { + Theme.System -> UiModeManager.MODE_NIGHT_AUTO + Theme.Light -> UiModeManager.MODE_NIGHT_NO + Theme.Dark -> UiModeManager.MODE_NIGHT_YES + }, + ) + } // The system bars follow the theme chosen in the app, not the system's: light // icons over a dark app even when the phone itself is light, and back. DisposableEffect(dark) { diff --git a/androidApp/app/src/main/java/io/github/vrubelroman/chesspenguin/data/Settings.kt b/androidApp/app/src/main/java/io/github/vrubelroman/chesspenguin/data/Settings.kt index 5236d82..83f798f 100644 --- a/androidApp/app/src/main/java/io/github/vrubelroman/chesspenguin/data/Settings.kt +++ b/androidApp/app/src/main/java/io/github/vrubelroman/chesspenguin/data/Settings.kt @@ -15,7 +15,7 @@ enum class Notation { Latin, Figurines, Local } /// The user's choices (android-ui.md ยง9), applied at once and kept across starts. data class Prefs( - val theme: Theme = Theme.System, + val theme: Theme = Theme.Dark, val notation: Notation = Notation.Latin, val board: BoardTheme = BoardTheme.Green, val pieces: PieceSet = PieceSet.Merida,