Android: dark theme by default; the app's night mode told to Android
Some checks are pending
CI / macos-build (push) Waiting to run
CI / check (push) Waiting to run
CI / windows-build (push) Waiting to run

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
vrubelroman 2026-10-28 01:25:39 +03:00
parent 42828e900c
commit 9bcb753bb5
4 changed files with 20 additions and 1 deletions

View file

@ -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

View file

@ -24,6 +24,7 @@
<!-- One task: a file opened from another app comes to the app already open. -->
<activity
android:name=".MainActivity"
android:configChanges="uiMode"
android:exported="true"
android:launchMode="singleTask">
<intent-filter>

View file

@ -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) {

View file

@ -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,