Android: dark theme by default; the app's night mode told to Android
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
42828e900c
commit
9bcb753bb5
4 changed files with 20 additions and 1 deletions
|
|
@ -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>
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue