Add preference to adjust wallpaper blur radius

This commit is contained in:
MM20 2023-09-30 14:49:35 +02:00
parent 8fb83f9729
commit 5a821eaabe
No known key found for this signature in database
GPG Key ID: 0B61A8F2DEAFA389
12 changed files with 58 additions and 12 deletions

View File

@ -121,10 +121,6 @@ fun AssistantScaffold(
}
}
WallpaperBlur {
true
}
LaunchedEffect(darkNavBarIcons, showNavBarScrim) {
if (showNavBarScrim) {
systemUiController.setNavigationBarColor(

View File

@ -122,6 +122,10 @@ class LauncherScaffoldVM : ViewModel(), KoinComponent {
val wallpaperBlur = dataStore.data.map { it.appearance.blurWallpaper }
.stateIn(viewModelScope, SharingStarted.WhileSubscribed(), true)
val wallpaperBlurRadius = dataStore.data.map { it.appearance.blurWallpaperRadius }
.stateIn(viewModelScope, SharingStarted.WhileSubscribed(), 32)
val fillClockHeight = dataStore.data.map { it.clockWidget.fillHeight }
.stateIn(viewModelScope, SharingStarted.WhileSubscribed(), true)
val searchBarColor = dataStore.data.map { it.searchBar.color }

View File

@ -217,6 +217,7 @@ fun PagerScaffold(
}
val blurEnabled by viewModel.wallpaperBlur.collectAsState()
val blurRadius by viewModel.wallpaperBlurRadius.collectAsState()
val blurWallpaper by remember {
derivedStateOf {
@ -225,7 +226,7 @@ fun PagerScaffold(
}
WallpaperBlur {
blurWallpaper
if (blurWallpaper) blurRadius else 0
}
val currentPage = pagerState.currentPage

View File

@ -211,6 +211,7 @@ fun PullDownScaffold(
val maxSearchBarOffset = with(density) { 128.dp.toPx() }
val blurEnabled by viewModel.wallpaperBlur.collectAsState()
val blurRadius by viewModel.wallpaperBlurRadius.collectAsState()
val blurWallpaper by remember {
derivedStateOf {
@ -219,7 +220,7 @@ fun PullDownScaffold(
}
WallpaperBlur {
blurWallpaper
if (blurWallpaper) blurRadius else 0
}

View File

@ -10,15 +10,15 @@ import androidx.compose.ui.unit.dp
import de.mm20.launcher2.ktx.isAtLeastApiLevel
@Composable
fun WallpaperBlur(blur: () -> Boolean) {
fun WallpaperBlur(blurRadius: () -> Int) {
val context = LocalContext.current
val density = LocalDensity.current
val blurWallpaper = blur()
LaunchedEffect(blurWallpaper) {
val radius = blurRadius()
LaunchedEffect(radius) {
if (!isAtLeastApiLevel(31)) return@LaunchedEffect
(context as Activity).window.attributes = context.window.attributes.also {
if (blurWallpaper) {
it.blurBehindRadius = with(density) { 32.dp.toPx().toInt() }
if (radius > 0) {
it.blurBehindRadius = with(density) { radius.dp.toPx().toInt() }
it.flags = it.flags or WindowManager.LayoutParams.FLAG_BLUR_BEHIND
} else {
it.blurBehindRadius = 0

View File

@ -34,6 +34,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.SliderPreference
import de.mm20.launcher2.ui.component.preferences.SwitchPreference
import de.mm20.launcher2.ui.locals.LocalNavController
import kotlinx.coroutines.delay
@ -57,6 +58,7 @@ fun HomescreenSettingsScreen() {
val lightStatusBar by viewModel.statusBarIcons.collectAsStateWithLifecycle(null)
val dimWallpaper by viewModel.dimWallpaper.collectAsStateWithLifecycle()
val blurWallpaper by viewModel.blurWallpaper.collectAsStateWithLifecycle()
val blurWallpaperRadius by viewModel.blurWallpaperRadius.collectAsStateWithLifecycle()
val lightNavBar by viewModel.navBarIcons.collectAsStateWithLifecycle(null)
val hideStatusBar by viewModel.hideStatusBar.collectAsStateWithLifecycle(null)
val hideNavBar by viewModel.hideNavBar.collectAsStateWithLifecycle(null)
@ -172,6 +174,18 @@ fun HomescreenSettingsScreen() {
},
enabled = isBlurSupported
)
AnimatedVisibility(blurWallpaper && isBlurSupported) {
SliderPreference(
title = stringResource(R.string.preference_blur_wallpaper_radius),
value = blurWallpaperRadius,
onValueChanged = {
viewModel.setBlurWallpaperRadius(it)
},
min = 4,
max = 64,
step = 4,
)
}
}
}
item {

View File

@ -52,6 +52,20 @@ class HomescreenSettingsScreenVM(
}
}
val blurWallpaperRadius = dataStore.data.map { it.appearance.blurWallpaperRadius }
.stateIn(viewModelScope, SharingStarted.WhileSubscribed(), 32)
fun setBlurWallpaperRadius(blurWallpaperRadius: Int) {
viewModelScope.launch {
dataStore.updateData {
it.toBuilder()
.setAppearance(
it.appearance.toBuilder()
.setBlurWallpaperRadius(blurWallpaperRadius)
).build()
}
}
}
fun openWallpaperChooser(context: AppCompatActivity) {
context.startActivity(Intent.createChooser(Intent(Intent.ACTION_SET_WALLPAPER), null))
}

View File

@ -532,6 +532,7 @@
<string name="preference_blur_wallpaper">Blur wallpaper</string>
<string name="preference_blur_wallpaper_summary">Use a blur effect on the wallpaper</string>
<string name="preference_blur_wallpaper_unsupported">Not supported on this device</string>
<string name="preference_blur_wallpaper_radius">Blur radius</string>
<string name="preference_wallpaper_summary">Choose a wallpaper</string>
<string name="preference_category_badges">Badges</string>
<string name="preference_screen_badges_summary">Configure icon badges</string>

View File

@ -22,7 +22,7 @@ internal val Context.dataStore: LauncherDataStore by dataStore(
}
)
internal const val SchemaVersion = 17
internal const val SchemaVersion = 18
internal fun getMigrations(context: Context): List<DataMigration<Settings>> {
return listOf(
@ -43,5 +43,6 @@ internal fun getMigrations(context: Context): List<DataMigration<Settings>> {
Migration_14_15(),
Migration_15_16(),
Migration_16_17(),
Migration_17_18(),
)
}

View File

@ -15,6 +15,7 @@ fun createFactorySettings(context: Context): Settings {
.setTheme(Settings.AppearanceSettings.Theme.System)
.setDimWallpaper(false)
.setBlurWallpaper(true)
.setBlurWallpaperRadius(32)
.setThemeId(UUID(0L, 0L).toString())
.setFont(Settings.AppearanceSettings.Font.Outfit)
.build()

View File

@ -0,0 +1,12 @@
package de.mm20.launcher2.preferences.migrations
import de.mm20.launcher2.preferences.Settings
class Migration_17_18 : VersionedMigration(17, 18) {
override suspend fun applyMigrations(builder: Settings.Builder): Settings.Builder {
return builder
.setAppearance(builder.appearance.toBuilder()
.setBlurWallpaperRadius(32)
)
}
}

View File

@ -89,6 +89,7 @@ message Settings {
bool blur_wallpaper = 11;
// UUID of the selected theme
string theme_id = 12;
uint32 blur_wallpaper_radius = 13;
}
AppearanceSettings appearance = 2;