chore: 修复预览不可用
This commit is contained in:
parent
895e6a8e55
commit
6a538508c0
|
|
@ -302,8 +302,43 @@ class App : Application(), IApp, SketchFactory {
|
||||||
}
|
}
|
||||||
|
|
||||||
object ThemeDelegate : ThemeSwitcher {
|
object ThemeDelegate : ThemeSwitcher {
|
||||||
|
private fun getDefaultColorResId(attrId: Int): Int {
|
||||||
|
return when (attrId) {
|
||||||
|
R.attr.colorPrimary -> R.color.default_color_primary
|
||||||
|
R.attr.colorNewPrimary -> R.color.default_color_primary
|
||||||
|
R.attr.colorAccent -> R.color.default_color_accent
|
||||||
|
R.attr.colorOnAccent -> R.color.default_color_on_accent
|
||||||
|
R.attr.colorToolbar -> R.color.default_color_toolbar
|
||||||
|
R.attr.colorToolbarItem -> R.color.default_color_toolbar_item
|
||||||
|
R.attr.colorToolbarItemSecondary -> R.color.default_color_toolbar_item_secondary
|
||||||
|
R.attr.colorToolbarItemActive -> R.color.default_color_toolbar_item_active
|
||||||
|
R.attr.colorToolbarSurface -> R.color.default_color_toolbar_bar
|
||||||
|
R.attr.colorOnToolbarSurface -> R.color.default_color_on_toolbar_bar
|
||||||
|
R.attr.colorText -> R.color.default_color_text
|
||||||
|
R.attr.colorTextSecondary -> R.color.default_color_text_secondary
|
||||||
|
R.attr.colorTextOnPrimary -> R.color.default_color_text_on_primary
|
||||||
|
R.attr.color_text_disabled -> R.color.default_color_text_disabled
|
||||||
|
R.attr.colorBackground -> R.color.default_color_background
|
||||||
|
R.attr.colorWindowBackground -> R.color.default_color_window_background
|
||||||
|
R.attr.colorChip -> R.color.default_color_chip
|
||||||
|
R.attr.colorOnChip -> R.color.default_color_on_chip
|
||||||
|
R.attr.colorUnselected -> R.color.default_color_unselected
|
||||||
|
R.attr.colorNavBar -> R.color.default_color_nav
|
||||||
|
R.attr.colorNavBarSurface -> R.color.default_color_nav_bar_surface
|
||||||
|
R.attr.colorOnNavBarSurface -> R.color.default_color_on_nav_bar_surface
|
||||||
|
R.attr.colorCard -> R.color.default_color_card
|
||||||
|
R.attr.colorFloorCard -> R.color.default_color_floor_card
|
||||||
|
R.attr.colorDivider -> R.color.default_color_divider
|
||||||
|
R.attr.shadow_color -> R.color.default_color_shadow
|
||||||
|
R.attr.colorIndicator -> R.color.default_color_swipe_refresh_view_background
|
||||||
|
R.attr.colorPlaceholder -> R.color.default_color_placeholder
|
||||||
|
else -> R.color.transparent
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@SuppressLint("DiscouragedApi")
|
@SuppressLint("DiscouragedApi")
|
||||||
fun getColorByAttr(context: Context, attrId: Int, theme: String): Int {
|
fun getColorByAttr(context: Context, attrId: Int, theme: String): Int {
|
||||||
|
if (!isInitialized) return context.getColorCompat(getDefaultColorResId(attrId))
|
||||||
val resources = context.resources
|
val resources = context.resources
|
||||||
when (attrId) {
|
when (attrId) {
|
||||||
R.attr.colorPrimary -> {
|
R.attr.colorPrimary -> {
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@ import androidx.compose.runtime.getValue
|
||||||
import androidx.compose.runtime.remember
|
import androidx.compose.runtime.remember
|
||||||
import androidx.compose.runtime.staticCompositionLocalOf
|
import androidx.compose.runtime.staticCompositionLocalOf
|
||||||
import androidx.compose.ui.graphics.Color
|
import androidx.compose.ui.graphics.Color
|
||||||
|
import androidx.compose.ui.platform.LocalContext
|
||||||
import com.huanchengfly.tieba.post.App
|
import com.huanchengfly.tieba.post.App
|
||||||
import com.huanchengfly.tieba.post.R
|
import com.huanchengfly.tieba.post.R
|
||||||
import com.huanchengfly.tieba.post.utils.ThemeUtil
|
import com.huanchengfly.tieba.post.utils.ThemeUtil
|
||||||
|
|
@ -53,7 +54,10 @@ data class ExtendedColors(
|
||||||
)
|
)
|
||||||
|
|
||||||
val LocalExtendedColors = staticCompositionLocalOf {
|
val LocalExtendedColors = staticCompositionLocalOf {
|
||||||
ExtendedColors("", false)
|
ExtendedColors(
|
||||||
|
ThemeUtil.THEME_DEFAULT,
|
||||||
|
false,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressLint("ConflictingOnColor")
|
@SuppressLint("ConflictingOnColor")
|
||||||
|
|
@ -90,71 +94,72 @@ fun getColorPalette(
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
private fun getThemeColorForTheme(theme: String): ExtendedColors {
|
private fun getThemeColorForTheme(theme: String): ExtendedColors {
|
||||||
|
val context = LocalContext.current
|
||||||
val nowTheme = ThemeUtil.getThemeTranslucent(theme)
|
val nowTheme = ThemeUtil.getThemeTranslucent(theme)
|
||||||
val textColor =
|
val textColor =
|
||||||
Color(App.ThemeDelegate.getColorByAttr(App.INSTANCE, R.attr.colorText, nowTheme))
|
Color(App.ThemeDelegate.getColorByAttr(context, R.attr.colorText, nowTheme))
|
||||||
val bottomBarColor =
|
val bottomBarColor =
|
||||||
Color(App.ThemeDelegate.getColorByAttr(App.INSTANCE, R.attr.colorNavBar, nowTheme))
|
Color(App.ThemeDelegate.getColorByAttr(context, R.attr.colorNavBar, nowTheme))
|
||||||
return ExtendedColors(
|
return ExtendedColors(
|
||||||
nowTheme,
|
nowTheme,
|
||||||
ThemeUtil.isNightMode(nowTheme),
|
ThemeUtil.isNightMode(nowTheme),
|
||||||
Color(App.ThemeDelegate.getColorByAttr(App.INSTANCE, R.attr.colorNewPrimary, nowTheme)),
|
Color(App.ThemeDelegate.getColorByAttr(context, R.attr.colorNewPrimary, nowTheme)),
|
||||||
Color(App.ThemeDelegate.getColorByAttr(App.INSTANCE, R.attr.colorPrimary, nowTheme)),
|
Color(App.ThemeDelegate.getColorByAttr(context, R.attr.colorPrimary, nowTheme)),
|
||||||
Color(App.ThemeDelegate.getColorByAttr(App.INSTANCE, R.attr.colorOnAccent, nowTheme)),
|
Color(App.ThemeDelegate.getColorByAttr(context, R.attr.colorOnAccent, nowTheme)),
|
||||||
Color(App.ThemeDelegate.getColorByAttr(App.INSTANCE, R.attr.colorToolbar, nowTheme)),
|
Color(App.ThemeDelegate.getColorByAttr(context, R.attr.colorToolbar, nowTheme)),
|
||||||
Color(App.ThemeDelegate.getColorByAttr(App.INSTANCE, R.attr.colorToolbarItem, nowTheme)),
|
Color(App.ThemeDelegate.getColorByAttr(context, R.attr.colorToolbarItem, nowTheme)),
|
||||||
Color(
|
Color(
|
||||||
App.ThemeDelegate.getColorByAttr(
|
App.ThemeDelegate.getColorByAttr(
|
||||||
App.INSTANCE,
|
context,
|
||||||
R.attr.colorToolbarItemSecondary,
|
R.attr.colorToolbarItemSecondary,
|
||||||
nowTheme
|
nowTheme
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
Color(
|
Color(
|
||||||
App.ThemeDelegate.getColorByAttr(
|
App.ThemeDelegate.getColorByAttr(
|
||||||
App.INSTANCE,
|
context,
|
||||||
R.attr.colorToolbarItemActive,
|
R.attr.colorToolbarItemActive,
|
||||||
nowTheme
|
nowTheme
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
Color(App.ThemeDelegate.getColorByAttr(App.INSTANCE, R.attr.colorToolbarSurface, nowTheme)),
|
Color(App.ThemeDelegate.getColorByAttr(context, R.attr.colorToolbarSurface, nowTheme)),
|
||||||
Color(
|
Color(
|
||||||
App.ThemeDelegate.getColorByAttr(
|
App.ThemeDelegate.getColorByAttr(
|
||||||
App.INSTANCE,
|
context,
|
||||||
R.attr.colorOnToolbarSurface,
|
R.attr.colorOnToolbarSurface,
|
||||||
nowTheme
|
nowTheme
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
bottomBarColor,
|
bottomBarColor,
|
||||||
Color(App.ThemeDelegate.getColorByAttr(App.INSTANCE, R.attr.colorNavBarSurface, nowTheme)),
|
Color(App.ThemeDelegate.getColorByAttr(context, R.attr.colorNavBarSurface, nowTheme)),
|
||||||
Color(
|
Color(
|
||||||
App.ThemeDelegate.getColorByAttr(
|
App.ThemeDelegate.getColorByAttr(
|
||||||
App.INSTANCE,
|
context,
|
||||||
R.attr.colorOnNavBarSurface,
|
R.attr.colorOnNavBarSurface,
|
||||||
nowTheme
|
nowTheme
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
textColor.copy(alpha = ContentAlpha.high),
|
textColor.copy(alpha = ContentAlpha.high),
|
||||||
textColor.copy(alpha = ContentAlpha.medium),
|
textColor.copy(alpha = ContentAlpha.medium),
|
||||||
Color(App.ThemeDelegate.getColorByAttr(App.INSTANCE, R.attr.colorOnAccent, nowTheme)),
|
Color(App.ThemeDelegate.getColorByAttr(context, R.attr.colorOnAccent, nowTheme)),
|
||||||
Color(App.ThemeDelegate.getColorByAttr(App.INSTANCE, R.attr.color_text_disabled, nowTheme)),
|
Color(App.ThemeDelegate.getColorByAttr(context, R.attr.color_text_disabled, nowTheme)),
|
||||||
Color(App.ThemeDelegate.getColorByAttr(App.INSTANCE, R.attr.colorBackground, nowTheme)),
|
Color(App.ThemeDelegate.getColorByAttr(context, R.attr.colorBackground, nowTheme)),
|
||||||
Color(App.ThemeDelegate.getColorByAttr(App.INSTANCE, R.attr.colorChip, nowTheme)),
|
Color(App.ThemeDelegate.getColorByAttr(context, R.attr.colorChip, nowTheme)),
|
||||||
Color(App.ThemeDelegate.getColorByAttr(App.INSTANCE, R.attr.colorOnChip, nowTheme)),
|
Color(App.ThemeDelegate.getColorByAttr(context, R.attr.colorOnChip, nowTheme)),
|
||||||
Color(App.ThemeDelegate.getColorByAttr(App.INSTANCE, R.attr.colorUnselected, nowTheme)),
|
Color(App.ThemeDelegate.getColorByAttr(context, R.attr.colorUnselected, nowTheme)),
|
||||||
Color(App.ThemeDelegate.getColorByAttr(App.INSTANCE, R.attr.colorCard, nowTheme)),
|
Color(App.ThemeDelegate.getColorByAttr(context, R.attr.colorCard, nowTheme)),
|
||||||
Color(App.ThemeDelegate.getColorByAttr(App.INSTANCE, R.attr.colorFloorCard, nowTheme)),
|
Color(App.ThemeDelegate.getColorByAttr(context, R.attr.colorFloorCard, nowTheme)),
|
||||||
Color(App.ThemeDelegate.getColorByAttr(App.INSTANCE, R.attr.colorDivider, nowTheme)),
|
Color(App.ThemeDelegate.getColorByAttr(context, R.attr.colorDivider, nowTheme)),
|
||||||
Color(App.ThemeDelegate.getColorByAttr(App.INSTANCE, R.attr.shadow_color, nowTheme)),
|
Color(App.ThemeDelegate.getColorByAttr(context, R.attr.shadow_color, nowTheme)),
|
||||||
Color(App.ThemeDelegate.getColorByAttr(App.INSTANCE, R.attr.colorIndicator, nowTheme)),
|
Color(App.ThemeDelegate.getColorByAttr(context, R.attr.colorIndicator, nowTheme)),
|
||||||
Color(
|
Color(
|
||||||
App.ThemeDelegate.getColorByAttr(
|
App.ThemeDelegate.getColorByAttr(
|
||||||
App.INSTANCE,
|
context,
|
||||||
R.attr.colorWindowBackground,
|
R.attr.colorWindowBackground,
|
||||||
nowTheme
|
nowTheme
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
Color(App.ThemeDelegate.getColorByAttr(App.INSTANCE, R.attr.colorPlaceholder, nowTheme)),
|
Color(App.ThemeDelegate.getColorByAttr(context, R.attr.colorPlaceholder, nowTheme)),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -70,6 +70,8 @@
|
||||||
<color name="default_color_shadow">#FEE9E9E9</color>
|
<color name="default_color_shadow">#FEE9E9E9</color>
|
||||||
<color name="default_color_swipe_refresh_view_background">#FFFFFFFF</color>
|
<color name="default_color_swipe_refresh_view_background">#FFFFFFFF</color>
|
||||||
<color name="default_color_chip">#FFF8F8F8</color>
|
<color name="default_color_chip">#FFF8F8F8</color>
|
||||||
|
<color name="default_color_on_chip">#FF808080</color>
|
||||||
|
<color name="default_color_placeholder">#FFF0F0F0</color>
|
||||||
|
|
||||||
<color name="theme_color_primary_white">@color/tieba</color>
|
<color name="theme_color_primary_white">@color/tieba</color>
|
||||||
<color name="theme_color_primary_tieba">@color/tieba</color>
|
<color name="theme_color_primary_tieba">@color/tieba</color>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue