fix(i18n): make the language picker actually apply on device
The in-app language picker silently did nothing: AppCompatDelegate.set ApplicationLocales only syncs to the system from an AppCompatActivity, but MainActivity was a plain ComponentActivity (with a platform theme). Switch MainActivity to AppCompatActivity and base Theme.Calendula on Theme.AppCompat.DayNight.NoActionBar. Changing the locale recreates the activity; set android:windowBackground to a DayNight colour matching the Compose background (light #FBFCFE / dark #101316) so the recreation no longer flashes a contrasting backdrop. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -3,9 +3,9 @@ package de.jeanlucmakiola.calendula
|
|||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import androidx.activity.ComponentActivity
|
|
||||||
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.compose.foundation.isSystemInDarkTheme
|
import androidx.compose.foundation.isSystemInDarkTheme
|
||||||
import androidx.compose.foundation.layout.fillMaxSize
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
@@ -24,7 +24,7 @@ import de.jeanlucmakiola.calendula.ui.theme.CalendulaTheme
|
|||||||
import kotlinx.datetime.LocalDate
|
import kotlinx.datetime.LocalDate
|
||||||
|
|
||||||
@AndroidEntryPoint
|
@AndroidEntryPoint
|
||||||
class MainActivity : ComponentActivity() {
|
class MainActivity : AppCompatActivity() {
|
||||||
|
|
||||||
// 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
|
||||||
|
|||||||
6
app/src/main/res/values-night/colors.xml
Normal file
6
app/src/main/res/values-night/colors.xml
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
<resources>
|
||||||
|
<!-- Dark-scheme window backdrop, matching the Compose dark background/surface
|
||||||
|
(#101316) so activity recreation (e.g. language switch) doesn't flash a
|
||||||
|
lighter grey. See values/colors.xml. -->
|
||||||
|
<color name="window_background">#FF101316</color>
|
||||||
|
</resources>
|
||||||
@@ -3,4 +3,8 @@
|
|||||||
<color name="seed">#FF5C6B7A</color>
|
<color name="seed">#FF5C6B7A</color>
|
||||||
<!-- Adaptive icon background -->
|
<!-- Adaptive icon background -->
|
||||||
<color name="ic_launcher_background">#FF5C6B7A</color>
|
<color name="ic_launcher_background">#FF5C6B7A</color>
|
||||||
|
<!-- Window backdrop shown during activity recreation (e.g. on a language
|
||||||
|
switch). Matches the Compose light scheme background/surface so the
|
||||||
|
recreation is seamless; overridden for dark in values-night. -->
|
||||||
|
<color name="window_background">#FFFBFCFE</color>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
@@ -1,5 +1,10 @@
|
|||||||
<resources xmlns:tools="http://schemas.android.com/tools">
|
<resources xmlns:tools="http://schemas.android.com/tools">
|
||||||
<style name="Theme.Calendula" parent="android:Theme.Material.Light.NoActionBar">
|
<!-- AppCompat (DayNight) parent so MainActivity can be an AppCompatActivity,
|
||||||
|
which is required for AppCompatDelegate.setApplicationLocales (the in-app
|
||||||
|
language picker) to sync to the system. Actual colours are driven by the
|
||||||
|
Compose theme; this is essentially the launch/backdrop theme. -->
|
||||||
|
<style name="Theme.Calendula" parent="Theme.AppCompat.DayNight.NoActionBar">
|
||||||
|
<item name="android:windowBackground">@color/window_background</item>
|
||||||
<item name="android:statusBarColor">@android:color/transparent</item>
|
<item name="android:statusBarColor">@android:color/transparent</item>
|
||||||
<item name="android:navigationBarColor">@android:color/transparent</item>
|
<item name="android:navigationBarColor">@android:color/transparent</item>
|
||||||
<item name="android:windowLightStatusBar">true</item>
|
<item name="android:windowLightStatusBar">true</item>
|
||||||
|
|||||||
Reference in New Issue
Block a user