clean up settings and some other things
This commit is contained in:
@@ -22,7 +22,7 @@ import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.compositionLocalOf
|
||||
import androidx.compose.ui.graphics.luminance
|
||||
import com.meloda.app.fast.ui.theme.LocalIsDarkTheme
|
||||
import com.meloda.app.fast.ui.theme.LocalThemeConfig
|
||||
|
||||
/**
|
||||
* Default alpha levels used by Material components.
|
||||
@@ -79,7 +79,7 @@ object ContentAlpha {
|
||||
lowContrastAlpha: Float
|
||||
): Float {
|
||||
val contentColor = LocalContentColor.current
|
||||
return if (!LocalIsDarkTheme.current) {
|
||||
return if (!LocalThemeConfig.current.darkMode) {
|
||||
if (contentColor.luminance() > 0.5) highContrastAlpha else lowContrastAlpha
|
||||
} else {
|
||||
if (contentColor.luminance() < 0.5) highContrastAlpha else lowContrastAlpha
|
||||
|
||||
@@ -33,8 +33,8 @@ import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.window.DialogProperties
|
||||
import com.meloda.app.fast.common.UiText
|
||||
import com.meloda.app.fast.common.parseString
|
||||
import com.meloda.app.fast.common.model.UiText
|
||||
import com.meloda.app.fast.common.model.parseString
|
||||
import com.meloda.app.fast.ui.util.ImmutableList
|
||||
import com.meloda.app.fast.ui.util.ImmutableList.Companion.toImmutableList
|
||||
import com.meloda.app.fast.ui.util.getString
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
package com.meloda.app.fast.ui.model
|
||||
|
||||
data class ThemeConfig(
|
||||
val usingDarkStyle: Boolean,
|
||||
val usingDynamicColors: Boolean,
|
||||
val darkMode: Boolean,
|
||||
val dynamicColors: Boolean,
|
||||
val selectedColorScheme: Int,
|
||||
val usingAmoledBackground: Boolean,
|
||||
val usingBlur: Boolean,
|
||||
val isMultiline: Boolean,
|
||||
val amoledDark: Boolean,
|
||||
val enableBlur: Boolean,
|
||||
val enableMultiline: Boolean,
|
||||
val isDeviceCompact: Boolean
|
||||
)
|
||||
|
||||
@@ -9,7 +9,6 @@ import androidx.compose.material3.dynamicDarkColorScheme
|
||||
import androidx.compose.material3.dynamicLightColorScheme
|
||||
import androidx.compose.material3.lightColorScheme
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.CompositionLocalProvider
|
||||
import androidx.compose.runtime.SideEffect
|
||||
import androidx.compose.runtime.compositionLocalOf
|
||||
import androidx.compose.ui.graphics.Color
|
||||
@@ -104,20 +103,18 @@ private val robotoFonts = FontFamily(
|
||||
)
|
||||
)
|
||||
|
||||
val LocalTheme = compositionLocalOf {
|
||||
val LocalThemeConfig = compositionLocalOf {
|
||||
ThemeConfig(
|
||||
usingDarkStyle = false,
|
||||
usingDynamicColors = false,
|
||||
darkMode = false,
|
||||
dynamicColors = false,
|
||||
selectedColorScheme = 0,
|
||||
usingAmoledBackground = false,
|
||||
usingBlur = false,
|
||||
isMultiline = false,
|
||||
amoledDark = false,
|
||||
enableBlur = false,
|
||||
enableMultiline = false,
|
||||
isDeviceCompact = false
|
||||
)
|
||||
}
|
||||
|
||||
val LocalIsDarkTheme = compositionLocalOf { false }
|
||||
|
||||
val LocalHazeState = compositionLocalOf {
|
||||
HazeState()
|
||||
}
|
||||
@@ -181,11 +178,9 @@ fun AppTheme(
|
||||
}
|
||||
}
|
||||
|
||||
CompositionLocalProvider(LocalIsDarkTheme provides useDarkTheme) {
|
||||
MaterialTheme(
|
||||
colorScheme = predefinedColorScheme ?: colorScheme,
|
||||
typography = typography,
|
||||
content = content
|
||||
)
|
||||
}
|
||||
MaterialTheme(
|
||||
colorScheme = predefinedColorScheme ?: colorScheme,
|
||||
typography = typography,
|
||||
content = content
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.meloda.app.fast.ui.util
|
||||
|
||||
import android.content.res.Configuration
|
||||
import android.os.PowerManager
|
||||
import android.view.KeyEvent
|
||||
import androidx.compose.foundation.lazy.LazyListState
|
||||
import androidx.compose.runtime.Composable
|
||||
@@ -10,9 +12,12 @@ import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.input.key.onKeyEvent
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.res.pluralStringResource
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import com.meloda.app.fast.common.UiText
|
||||
import androidx.core.content.getSystemService
|
||||
import com.meloda.app.fast.common.model.DarkMode
|
||||
import com.meloda.app.fast.common.model.UiText
|
||||
|
||||
@Composable
|
||||
fun UiText?.getString(): String? {
|
||||
@@ -75,3 +80,19 @@ fun LazyListState.isScrollingUp(): Boolean {
|
||||
}
|
||||
}.value
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun isNeedToEnableDarkMode(darkMode: DarkMode): Boolean {
|
||||
val context = LocalContext.current
|
||||
|
||||
val appForceDarkMode = darkMode == DarkMode.ENABLED
|
||||
val appBatterySaver = darkMode == DarkMode.AUTO_BATTERY
|
||||
|
||||
val systemUiNightMode = context.resources.configuration.uiMode
|
||||
|
||||
val isSystemBatterySaver = context.getSystemService<PowerManager>()?.isPowerSaveMode == true
|
||||
val isSystemUsingDarkTheme =
|
||||
systemUiNightMode and Configuration.UI_MODE_NIGHT_MASK == Configuration.UI_MODE_NIGHT_YES
|
||||
|
||||
return appForceDarkMode || (appBatterySaver && isSystemBatterySaver) || (!appBatterySaver && isSystemUsingDarkTheme && darkMode == DarkMode.FOLLOW_SYSTEM)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user