Merge pull request #652 from strongville/feat/materialYouCompat
Use Material You Compat on Android 12+ if flag is enabled
This commit is contained in:
+13
@@ -9,6 +9,7 @@ import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||
import androidx.lifecycle.viewmodel.compose.viewModel
|
||||
import de.mm20.launcher2.ktx.isAtLeastApiLevel
|
||||
import de.mm20.launcher2.preferences.ColorScheme
|
||||
import de.mm20.launcher2.preferences.Font
|
||||
import de.mm20.launcher2.ui.R
|
||||
@@ -16,6 +17,7 @@ import de.mm20.launcher2.ui.component.preferences.ListPreference
|
||||
import de.mm20.launcher2.ui.component.preferences.Preference
|
||||
import de.mm20.launcher2.ui.component.preferences.PreferenceCategory
|
||||
import de.mm20.launcher2.ui.component.preferences.PreferenceScreen
|
||||
import de.mm20.launcher2.ui.component.preferences.SwitchPreference
|
||||
import de.mm20.launcher2.ui.component.preferences.value
|
||||
import de.mm20.launcher2.ui.locals.LocalNavController
|
||||
import de.mm20.launcher2.ui.theme.getTypography
|
||||
@@ -50,6 +52,17 @@ fun AppearanceSettingsScreen() {
|
||||
navController?.navigate("settings/appearance/themes")
|
||||
}
|
||||
)
|
||||
if (isAtLeastApiLevel(31)) {
|
||||
val compatModeColors by viewModel.compatModeColors.collectAsState()
|
||||
SwitchPreference(
|
||||
title = stringResource(id = R.string.preference_force_compat_system_colors),
|
||||
summary = stringResource(id = R.string.preference_force_compat_system_colors_summary),
|
||||
value = compatModeColors,
|
||||
onValueChanged = {
|
||||
viewModel.setCompatModeColors(it)
|
||||
}
|
||||
)
|
||||
}
|
||||
val font by viewModel.font.collectAsState()
|
||||
ListPreference(
|
||||
title = stringResource(R.string.preference_font),
|
||||
|
||||
+6
@@ -33,6 +33,12 @@ class AppearanceSettingsScreenVM : ViewModel(), KoinComponent {
|
||||
}
|
||||
.stateIn(viewModelScope, SharingStarted.WhileSubscribed(), null)
|
||||
|
||||
val compatModeColors = uiSettings.compatModeColors
|
||||
.stateIn(viewModelScope, SharingStarted.WhileSubscribed(), false)
|
||||
|
||||
fun setCompatModeColors(enabled: Boolean) {
|
||||
uiSettings.setCompatModeColors(enabled)
|
||||
}
|
||||
|
||||
val font = uiSettings.font
|
||||
.stateIn(viewModelScope, SharingStarted.WhileSubscribed(), null)
|
||||
|
||||
@@ -3,12 +3,16 @@ package de.mm20.launcher2.ui.theme.colorscheme
|
||||
import android.os.Build
|
||||
import androidx.compose.material3.ColorScheme
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.collectAsState
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.graphics.toArgb
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.datastore.core.DataStore
|
||||
import de.mm20.launcher2.preferences.LegacySettings
|
||||
import de.mm20.launcher2.preferences.ui.UiSettings
|
||||
import de.mm20.launcher2.themes.CorePalette
|
||||
import de.mm20.launcher2.themes.DefaultDarkColorScheme
|
||||
import de.mm20.launcher2.themes.DefaultLightColorScheme
|
||||
@@ -18,6 +22,9 @@ import de.mm20.launcher2.themes.Theme
|
||||
import de.mm20.launcher2.themes.get
|
||||
import de.mm20.launcher2.themes.merge
|
||||
import de.mm20.launcher2.ui.locals.LocalWallpaperColors
|
||||
import kotlinx.coroutines.flow.map
|
||||
import org.koin.androidx.compose.inject
|
||||
import org.koin.core.component.inject
|
||||
|
||||
@Composable
|
||||
fun lightColorSchemeOf(theme: Theme): ColorScheme {
|
||||
@@ -77,8 +84,13 @@ fun colorSchemeOf(colorScheme: FullColorScheme, corePalette: PartialCorePalette)
|
||||
|
||||
@Composable
|
||||
fun systemCorePalette(): CorePalette<Int> {
|
||||
val context = LocalContext.current
|
||||
if (Build.VERSION.SDK_INT >= 31) {
|
||||
val uiSettings: UiSettings by inject()
|
||||
val compatModeColors by remember {
|
||||
uiSettings.compatModeColors
|
||||
}.collectAsState(false)
|
||||
|
||||
if (Build.VERSION.SDK_INT >= 31 && !compatModeColors) {
|
||||
val context = LocalContext.current
|
||||
return CorePalette(
|
||||
primary = ContextCompat.getColor(context, android.R.color.system_accent1_500),
|
||||
secondary = ContextCompat.getColor(context, android.R.color.system_accent2_500),
|
||||
|
||||
Reference in New Issue
Block a user