Added flag to use Material You Compat on Android 12+
Signed-off-by: Guillermo Villafuerte <gvillafu@comunidad.unam.mx>
This commit is contained in:
parent
f984f68b34
commit
706bd38731
@ -17,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.Preference
|
||||||
import de.mm20.launcher2.ui.component.preferences.PreferenceCategory
|
import de.mm20.launcher2.ui.component.preferences.PreferenceCategory
|
||||||
import de.mm20.launcher2.ui.component.preferences.PreferenceScreen
|
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.component.preferences.value
|
||||||
import de.mm20.launcher2.ui.locals.LocalNavController
|
import de.mm20.launcher2.ui.locals.LocalNavController
|
||||||
import de.mm20.launcher2.ui.theme.getTypography
|
import de.mm20.launcher2.ui.theme.getTypography
|
||||||
@ -51,6 +52,15 @@ fun AppearanceSettingsScreen() {
|
|||||||
navController?.navigate("settings/appearance/themes")
|
navController?.navigate("settings/appearance/themes")
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
val compatMode by viewModel.compatMode.collectAsState()
|
||||||
|
SwitchPreference(
|
||||||
|
title = stringResource(id = R.string.preference_force_compat_system_colors),
|
||||||
|
summary = stringResource(id = R.string.preference_force_compat_system_colors_summary),
|
||||||
|
value = compatMode,
|
||||||
|
onValueChanged = {
|
||||||
|
viewModel.setCompatMode(it)
|
||||||
|
}
|
||||||
|
)
|
||||||
val font by viewModel.font.collectAsState()
|
val font by viewModel.font.collectAsState()
|
||||||
ListPreference(
|
ListPreference(
|
||||||
title = stringResource(R.string.preference_font),
|
title = stringResource(R.string.preference_font),
|
||||||
|
|||||||
@ -47,6 +47,19 @@ class AppearanceSettingsScreenVM : ViewModel(), KoinComponent {
|
|||||||
}
|
}
|
||||||
.stateIn(viewModelScope, SharingStarted.WhileSubscribed(), null)
|
.stateIn(viewModelScope, SharingStarted.WhileSubscribed(), null)
|
||||||
|
|
||||||
|
val compatMode = dataStore.data.map {
|
||||||
|
it.appearance.forceCompatModeSystemColors
|
||||||
|
}.stateIn(viewModelScope, SharingStarted.WhileSubscribed(), false)
|
||||||
|
|
||||||
|
fun setCompatMode(enabled: Boolean) {
|
||||||
|
viewModelScope.launch {
|
||||||
|
dataStore.updateData {
|
||||||
|
it.toBuilder()
|
||||||
|
.setAppearance(it.appearance.toBuilder().setForceCompatModeSystemColors(enabled))
|
||||||
|
.build()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
val font = dataStore.data.map { it.appearance.font }
|
val font = dataStore.data.map { it.appearance.font }
|
||||||
.stateIn(viewModelScope, SharingStarted.WhileSubscribed(), null)
|
.stateIn(viewModelScope, SharingStarted.WhileSubscribed(), null)
|
||||||
|
|||||||
@ -3,11 +3,14 @@ package de.mm20.launcher2.ui.theme.colorscheme
|
|||||||
import android.os.Build
|
import android.os.Build
|
||||||
import androidx.compose.material3.ColorScheme
|
import androidx.compose.material3.ColorScheme
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.collectAsState
|
||||||
|
import androidx.compose.runtime.getValue
|
||||||
import androidx.compose.runtime.remember
|
import androidx.compose.runtime.remember
|
||||||
import androidx.compose.ui.graphics.Color
|
import androidx.compose.ui.graphics.Color
|
||||||
import androidx.compose.ui.graphics.toArgb
|
import androidx.compose.ui.graphics.toArgb
|
||||||
import androidx.compose.ui.platform.LocalContext
|
import androidx.compose.ui.platform.LocalContext
|
||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
|
import androidx.datastore.core.DataStore
|
||||||
import de.mm20.launcher2.preferences.Settings
|
import de.mm20.launcher2.preferences.Settings
|
||||||
import de.mm20.launcher2.themes.CorePalette
|
import de.mm20.launcher2.themes.CorePalette
|
||||||
import de.mm20.launcher2.themes.DefaultDarkColorScheme
|
import de.mm20.launcher2.themes.DefaultDarkColorScheme
|
||||||
@ -18,6 +21,8 @@ import de.mm20.launcher2.themes.Theme
|
|||||||
import de.mm20.launcher2.themes.get
|
import de.mm20.launcher2.themes.get
|
||||||
import de.mm20.launcher2.themes.merge
|
import de.mm20.launcher2.themes.merge
|
||||||
import de.mm20.launcher2.ui.locals.LocalWallpaperColors
|
import de.mm20.launcher2.ui.locals.LocalWallpaperColors
|
||||||
|
import kotlinx.coroutines.flow.map
|
||||||
|
import org.koin.androidx.compose.inject
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun lightColorSchemeOf(theme: Theme): ColorScheme {
|
fun lightColorSchemeOf(theme: Theme): ColorScheme {
|
||||||
@ -77,8 +82,13 @@ fun colorSchemeOf(colorScheme: FullColorScheme, corePalette: PartialCorePalette)
|
|||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun systemCorePalette(): CorePalette<Int> {
|
fun systemCorePalette(): CorePalette<Int> {
|
||||||
val context = LocalContext.current
|
val dataStore: DataStore<Settings> by inject()
|
||||||
if (Build.VERSION.SDK_INT >= 31) {
|
val compatMode by remember {
|
||||||
|
dataStore.data.map { it.appearance.forceCompatModeSystemColors }
|
||||||
|
}.collectAsState(false)
|
||||||
|
|
||||||
|
if (Build.VERSION.SDK_INT >= 31 && !compatMode) {
|
||||||
|
val context = LocalContext.current
|
||||||
return CorePalette(
|
return CorePalette(
|
||||||
primary = ContextCompat.getColor(context, android.R.color.system_accent1_500),
|
primary = ContextCompat.getColor(context, android.R.color.system_accent1_500),
|
||||||
secondary = ContextCompat.getColor(context, android.R.color.system_accent2_500),
|
secondary = ContextCompat.getColor(context, android.R.color.system_accent2_500),
|
||||||
|
|||||||
@ -447,6 +447,8 @@
|
|||||||
<string name="preference_colors_auto_generate">Generate from primary color</string>
|
<string name="preference_colors_auto_generate">Generate from primary color</string>
|
||||||
<string name="preference_category_custom_colors_light">Light color scheme</string>
|
<string name="preference_category_custom_colors_light">Light color scheme</string>
|
||||||
<string name="preference_category_custom_colors_dark">Dark color scheme</string>
|
<string name="preference_category_custom_colors_dark">Dark color scheme</string>
|
||||||
|
<string name="preference_force_compat_system_colors">Ignore system colors</string>
|
||||||
|
<string name="preference_force_compat_system_colors_summary">Request color scheme via Material You Compat, if available</string>
|
||||||
<string name="preference_font">Font</string>
|
<string name="preference_font">Font</string>
|
||||||
<string name="preference_font_system">System default</string>
|
<string name="preference_font_system">System default</string>
|
||||||
<string name="preference_screen_about">About</string>
|
<string name="preference_screen_about">About</string>
|
||||||
|
|||||||
@ -22,7 +22,7 @@ internal val Context.dataStore: LauncherDataStore by dataStore(
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
internal const val SchemaVersion = 18
|
internal const val SchemaVersion = 19
|
||||||
|
|
||||||
internal fun getMigrations(context: Context): List<DataMigration<Settings>> {
|
internal fun getMigrations(context: Context): List<DataMigration<Settings>> {
|
||||||
return listOf(
|
return listOf(
|
||||||
@ -44,5 +44,6 @@ internal fun getMigrations(context: Context): List<DataMigration<Settings>> {
|
|||||||
Migration_15_16(),
|
Migration_15_16(),
|
||||||
Migration_16_17(),
|
Migration_16_17(),
|
||||||
Migration_17_18(),
|
Migration_17_18(),
|
||||||
|
Migration_18_19(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -18,6 +18,7 @@ fun createFactorySettings(context: Context): Settings {
|
|||||||
.setBlurWallpaperRadius(32)
|
.setBlurWallpaperRadius(32)
|
||||||
.setThemeId(UUID(0L, 0L).toString())
|
.setThemeId(UUID(0L, 0L).toString())
|
||||||
.setFont(Settings.AppearanceSettings.Font.Outfit)
|
.setFont(Settings.AppearanceSettings.Font.Outfit)
|
||||||
|
.setForceCompatModeSystemColors(false)
|
||||||
.build()
|
.build()
|
||||||
)
|
)
|
||||||
.setWeather(
|
.setWeather(
|
||||||
|
|||||||
@ -0,0 +1,12 @@
|
|||||||
|
package de.mm20.launcher2.preferences.migrations
|
||||||
|
|
||||||
|
import de.mm20.launcher2.preferences.Settings
|
||||||
|
|
||||||
|
class Migration_18_19 : VersionedMigration(18, 19) {
|
||||||
|
override suspend fun applyMigrations(builder: Settings.Builder): Settings.Builder {
|
||||||
|
return builder
|
||||||
|
.setAppearance(builder.appearance.toBuilder()
|
||||||
|
.setForceCompatModeSystemColors(false)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -90,6 +90,8 @@ message Settings {
|
|||||||
// UUID of the selected theme
|
// UUID of the selected theme
|
||||||
string theme_id = 12;
|
string theme_id = 12;
|
||||||
uint32 blur_wallpaper_radius = 13;
|
uint32 blur_wallpaper_radius = 13;
|
||||||
|
|
||||||
|
bool force_compat_mode_system_colors = 14;
|
||||||
}
|
}
|
||||||
AppearanceSettings appearance = 2;
|
AppearanceSettings appearance = 2;
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user