Drive the system bar icons from the in-app light/dark choice (#70) (#120)
All checks were successful
Release — F-Droid repo + Gitea/Codeberg release + Play / detect (push) Successful in 8s
Release — F-Droid repo + Gitea/Codeberg release + Play / release (push) Has been skipped
Release — F-Droid repo + Gitea/Codeberg release + Play / play (push) Has been skipped

Reviewed-on: https://codeberg.org/jlmakiola/calendula/pulls/120
This commit is contained in:
Jean-Luc Makiola
2026-07-31 20:31:50 +02:00
parent 34a8e91ea5
commit 3d62036d79

View File

@@ -2,9 +2,11 @@ package de.jeanlucmakiola.calendula
import android.content.Context import android.content.Context
import android.content.Intent import android.content.Intent
import android.content.res.Configuration
import android.net.Uri import android.net.Uri
import android.os.Bundle import android.os.Bundle
import android.provider.CalendarContract import android.provider.CalendarContract
import androidx.activity.SystemBarStyle
import androidx.activity.compose.setContent import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
@@ -12,6 +14,7 @@ import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.runtime.CompositionLocalProvider import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.getValue import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember import androidx.compose.runtime.remember
@@ -53,6 +56,11 @@ import kotlin.time.Instant
@AndroidEntryPoint @AndroidEntryPoint
class MainActivity : AppCompatActivity() { class MainActivity : AppCompatActivity() {
// Which of light/dark the system bars are drawn for. The styles installed
// in onCreate read this field live, so androidx's config-change replay
// picks up the in-app override instead of the night resource qualifier.
private var systemBarsDark = false
// The occurrence a reminder notification was tapped for (eventId, begin, // The occurrence a reminder notification was tapped for (eventId, begin,
// end — the detail screen's key shape). singleTop + onNewIntent route a // end — the detail screen's key shape). singleTop + onNewIntent route a
// tap into the running activity; CalendarHost consumes and clears it. // tap into the running activity; CalendarHost consumes and clears it.
@@ -96,7 +104,9 @@ class MainActivity : AppCompatActivity() {
return return
} }
enableEdgeToEdge() systemBarsDark = resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK ==
Configuration.UI_MODE_NIGHT_YES
applyEdgeToEdge()
requestedDetailKey = intent.detailKeyOrNull() ?: intent.viewEventKeyOrNull() requestedDetailKey = intent.detailKeyOrNull() ?: intent.viewEventKeyOrNull()
requestedNav = intent.navRequestOrNull() requestedNav = intent.navRequestOrNull()
requestedImportUri = intent.importUriOrNull() requestedImportUri = intent.importUriOrNull()
@@ -113,6 +123,14 @@ class MainActivity : AppCompatActivity() {
ThemeMode.LIGHT -> false ThemeMode.LIGHT -> false
ThemeMode.DARK -> true ThemeMode.DARK -> true
} }
// onCreate can only see the night resource qualifier, not the in-app
// override — re-apply from the resolved theme so the bar icons follow
// the app's light/dark choice.
DisposableEffect(darkTheme) {
systemBarsDark = darkTheme
applyEdgeToEdge()
onDispose {}
}
// The app-wide clock convention: the time-format preference resolved // The app-wide clock convention: the time-format preference resolved
// against the device's 24-hour system setting, provided once here so // against the device's 24-hour system setting, provided once here so
// every time label reads it via LocalUse24HourFormat. // every time label reads it via LocalUse24HourFormat.
@@ -181,6 +199,19 @@ class MainActivity : AppCompatActivity() {
} }
} }
/**
* Applies the transparent edge-to-edge bars for the current [systemBarsDark].
* Both scrims are transparent because API 29+ enforces its own contrast and
* ignores them anyway.
*/
private fun applyEdgeToEdge() {
val transparent = android.graphics.Color.TRANSPARENT
enableEdgeToEdge(
statusBarStyle = SystemBarStyle.auto(transparent, transparent) { systemBarsDark },
navigationBarStyle = SystemBarStyle.auto(transparent, transparent) { systemBarsDark },
)
}
override fun onResume() { override fun onResume() {
super.onResume() super.onResume()
// Reaching a running UI means startup succeeded; reset the loop trail. // Reaching a running UI means startup succeeded; reset the loop trail.