Skip to content
This repository has been archived by the owner on Feb 17, 2024. It is now read-only.

Commit

Permalink
fix: 启动时闪退
Browse files Browse the repository at this point in the history
  • Loading branch information
HuanCheng65 committed Oct 6, 2023
1 parent 2c7194c commit bd3f952
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
8 changes: 7 additions & 1 deletion app/src/main/java/com/huanchengfly/tieba/post/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -743,7 +743,13 @@ class App : Application(), IApp, SketchFactory {
}

override fun getColorByAttr(context: Context, attrId: Int): Int {
return getColorByAttr(context, attrId, ThemeUtil.getCurrentTheme())
return when (attrId) {
R.attr.colorPrimary, R.attr.colorNewPrimary, R.attr.colorAccent -> {
getColorByAttr(context, attrId, ThemeUtil.getCurrentTheme(checkDynamic = true))
}

else -> getColorByAttr(context, attrId, ThemeUtil.getCurrentTheme())
}
}

override fun getColorById(context: Context, colorId: Int): Int {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,10 @@ object ThemeUtil {
}

@JvmOverloads
fun getCurrentTheme(theme: String = getRawTheme()): String {
fun getCurrentTheme(
theme: String = getRawTheme(),
checkDynamic: Boolean = false,
): String {
var nowTheme = theme
if (isTranslucentTheme(nowTheme)) {
val colorTheme =
Expand All @@ -289,7 +292,7 @@ object ThemeUtil {
} else {
THEME_TRANSLUCENT_LIGHT
}
} else if (isUsingDynamicTheme() && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
} else if (checkDynamic && isUsingDynamicTheme() && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
nowTheme = "${nowTheme}_dynamic"
}
return nowTheme
Expand Down

0 comments on commit bd3f952

Please sign in to comment.