Skip to content

Commit 0fa150e

Browse files
committed
fix: App theme swatch
Signed-off-by: Hu Shenghao <dede.hu@qq.com>
1 parent 12f5922 commit 0fa150e

File tree

23 files changed

+465
-124
lines changed

23 files changed

+465
-124
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
### v3.2.1
44

5+
- Optimize the setting of theme logic
56
- Optimize APK file size
67

78
### v3.2.0 (2024-12-03)

CHANGELOG_zh.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
### v3.2.1
44

5+
- 优化设置主题逻辑
56
- 优化 APK 文件大小
67

78
### v3.2.0 (2024-12-03)

app/src/main/java/com/dede/android_eggs/startup/ApplicationInitializer.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,15 @@ import android.app.Application
44
import android.content.Context
55
import androidx.startup.Initializer
66
import com.dede.android_eggs.util.ActivityActionDispatcher
7+
import com.dede.android_eggs.views.settings.compose.prefs.ThemePrefUtil
78
import com.dede.basic.GlobalContext
89

910
class ApplicationInitializer : Initializer<Unit> {
1011

1112
override fun create(context: Context) {
1213
val application = context.applicationContext as Application
14+
// apply compat style
15+
ThemePrefUtil.apply(application)
1316
ActivityActionDispatcher.register(application)
1417
}
1518

app/src/main/java/com/dede/android_eggs/ui/composes/ThemedHashImageBitmap.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ fun rememberThemedHashImageBitmap(
2121
height: Int = 32
2222
): ImageBitmap {
2323
val context = LocalContext.current
24-
return remember(hash, ThemeUtils.isDarkMode(context.resources)) {
24+
return remember(hash, ThemeUtils.isDarkMode(context)) {
2525
var bitmap = checkNotNull(BlurHashDecoder.decode(hash, width, height)) {
2626
"BlurHash decode error! hash: ".format(hash)
2727
}
28-
if (ThemeUtils.isDarkMode(context.resources)) {
28+
if (ThemeUtils.isDarkMode(context)) {
2929
val nightMode =
3030
Bitmap.createBitmap(bitmap.width, bitmap.height, Bitmap.Config.ARGB_8888)
3131
val paint = Paint(Paint.ANTI_ALIAS_FLAG)

app/src/main/java/com/dede/android_eggs/util/actions/WarningDialogAction.kt

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ package com.dede.android_eggs.util.actions
22

33
import android.app.Activity
44
import android.view.ViewGroup
5-
import android.widget.TextView
65
import androidx.annotation.StringRes
6+
import androidx.appcompat.widget.AppCompatTextView
77
import androidx.compose.foundation.layout.Arrangement
88
import androidx.compose.foundation.layout.Row
99
import androidx.compose.foundation.layout.fillMaxWidth
@@ -35,7 +35,7 @@ import androidx.lifecycle.setViewTreeLifecycleOwner
3535
import androidx.savedstate.setViewTreeSavedStateRegistryOwner
3636
import com.dede.android_eggs.R
3737
import com.dede.android_eggs.util.ActivityActionDispatcher
38-
import com.dede.android_eggs.views.theme.AppTheme
38+
import com.dede.android_eggs.views.theme.EasterEggsTheme
3939
import com.dede.basic.androidLifecycleOwner
4040
import com.dede.basic.androidSavedStateOwner
4141
import com.dede.basic.getBoolean
@@ -83,7 +83,7 @@ class WarningDialogAction : ActivityActionDispatcher.ActivityAction {
8383
)
8484
}
8585
composeView.setContent {
86-
AppTheme {
86+
EasterEggsTheme {
8787
val context = LocalContext.current
8888
WarningDialog(
8989
info.title,
@@ -143,15 +143,17 @@ private fun WarningDialog(
143143
val messageSpanned = remember(messageText) {
144144
HtmlCompat.fromHtml(messageText, HtmlCompat.FROM_HTML_MODE_COMPACT)
145145
}
146-
val textColor = MaterialTheme.colorScheme.onPrimaryContainer.toArgb()
146+
val textStyle = MaterialTheme.typography.bodyMedium
147+
val textColor = MaterialTheme.colorScheme.onSurfaceVariant
147148
AndroidView(
148149
modifier = Modifier.fillMaxWidth(),
149150
factory = {
150-
TextView(it)
151+
AppCompatTextView(it)
151152
},
152153
update = {
153154
it.text = messageSpanned
154-
it.setTextColor(textColor)
155+
it.setTextColor(textColor.toArgb())
156+
it.textSize = textStyle.fontSize.value
155157
}
156158
)
157159
},

app/src/main/java/com/dede/android_eggs/views/main/EasterEggsActivity.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import android.content.Intent
77
import android.os.Build
88
import android.os.Bundle
99
import androidx.activity.compose.setContent
10+
import androidx.activity.enableEdgeToEdge
1011
import androidx.appcompat.app.AppCompatActivity
1112
import androidx.compose.foundation.layout.Box
1213
import androidx.compose.foundation.layout.WindowInsets
@@ -33,7 +34,6 @@ import com.dede.android_eggs.inject.FlavorFeatures
3334
import com.dede.android_eggs.ui.composes.ReverseModalNavigationDrawer
3435
import com.dede.android_eggs.util.LocalEvent
3536
import com.dede.android_eggs.util.OrientationAngleSensor
36-
import com.dede.android_eggs.util.ThemeUtils
3737
import com.dede.android_eggs.util.compose.end
3838
import com.dede.android_eggs.views.main.compose.AnimatorDisabledAlertDialog
3939
import com.dede.android_eggs.views.main.compose.BottomSearchBar
@@ -51,7 +51,7 @@ import com.dede.android_eggs.views.main.util.IntentHandler
5151
import com.dede.android_eggs.views.settings.SettingsScreen
5252
import com.dede.android_eggs.views.settings.compose.basic.SettingPrefUtil
5353
import com.dede.android_eggs.views.settings.compose.prefs.IconVisualEffectsPrefUtil
54-
import com.dede.android_eggs.views.theme.AppTheme
54+
import com.dede.android_eggs.views.theme.EasterEggsTheme
5555
import com.dede.basic.Utils
5656
import com.dede.basic.provider.BaseEasterEgg
5757
import com.dede.basic.provider.EasterEgg
@@ -78,7 +78,7 @@ class EasterEggsActivity : AppCompatActivity() {
7878
lateinit var sensor: EasterEggLogoSensorMatrixConvert
7979

8080
override fun onCreate(savedInstanceState: Bundle?) {
81-
ThemeUtils.enableEdgeToEdge(this)
81+
enableEdgeToEdge()
8282
super.onCreate(savedInstanceState)
8383

8484
setContent {
@@ -87,7 +87,7 @@ class EasterEggsActivity : AppCompatActivity() {
8787
LocalEasterEggLogoSensor provides sensor,
8888
LocalKonfettiState provides konfettiState
8989
) {
90-
AppTheme {
90+
EasterEggsTheme {
9191
val drawerState = rememberDrawerState(DrawerValue.Closed)
9292
ReverseModalNavigationDrawer(
9393
drawerContent = {

app/src/main/java/com/dede/android_eggs/views/settings/compose/prefs/ThemePref.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.dede.android_eggs.views.settings.compose.prefs
22

3+
import androidx.appcompat.app.AppCompatDelegate
34
import androidx.compose.foundation.layout.Spacer
45
import androidx.compose.foundation.layout.height
56
import androidx.compose.material.icons.Icons
@@ -37,8 +38,16 @@ import com.dede.android_eggs.views.theme.themeMode
3738
fun ThemePref() {
3839
var themeModeValue by rememberPrefIntState(KEY_NIGHT_MODE, FOLLOW_SYSTEM)
3940
val onOptionClick = click@{ mode: Int ->
41+
if (themeModeValue == mode) {
42+
return@click
43+
}
4044
themeModeValue = mode
4145
themeMode = themeModeValue
46+
var appCompatMode = mode
47+
if (appCompatMode == AMOLED) {
48+
appCompatMode = DARK
49+
}
50+
AppCompatDelegate.setDefaultNightMode(appCompatMode)
4251
LocalEvent.poster().post(ACTION_NIGHT_MODE_CHANGED)
4352
}
4453

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
- Optimize the setting of theme logic
12
- Optimize APK file size
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
- 优化设置主题逻辑
12
- 优化 APK 文件大小

feature/crash/src/main/java/com/dede/android_eggs/crash/CrashActivity.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import android.os.Build
77
import android.os.Bundle
88
import android.util.Log
99
import androidx.activity.compose.setContent
10+
import androidx.activity.enableEdgeToEdge
1011
import androidx.appcompat.app.AppCompatActivity
1112
import androidx.compose.animation.animateContentSize
1213
import androidx.compose.foundation.layout.Arrangement
@@ -58,8 +59,7 @@ import androidx.compose.ui.text.withStyle
5859
import androidx.compose.ui.tooling.preview.Preview
5960
import androidx.compose.ui.unit.dp
6061
import com.dede.android_eggs.util.AGPUtils
61-
import com.dede.android_eggs.util.ThemeUtils
62-
import com.dede.android_eggs.views.theme.AppTheme
62+
import com.dede.android_eggs.views.theme.EasterEggsTheme
6363
import com.dede.basic.Utils
6464
import com.dede.basic.copy
6565
import kotlin.system.exitProcess
@@ -70,7 +70,7 @@ import kotlin.system.exitProcess
7070
class CrashActivity : AppCompatActivity() {
7171

7272
override fun onCreate(savedInstanceState: Bundle?) {
73-
ThemeUtils.enableEdgeToEdge(this)
73+
enableEdgeToEdge()
7474
super.onCreate(savedInstanceState)
7575

7676
val tr: Throwable? = GlobalExceptionHandler.getUncaughtException(intent)
@@ -80,7 +80,7 @@ class CrashActivity : AppCompatActivity() {
8080
}
8181

8282
setContent {
83-
AppTheme {
83+
EasterEggsTheme {
8484
Surface {
8585
CrashScreen(tr)
8686
}

0 commit comments

Comments
 (0)