Add preference for corner shape
This commit is contained in:
parent
b866d54503
commit
6d5ad8cac2
@ -433,6 +433,9 @@
|
||||
<string name="preference_cards_corner_radius">Corner radius</string>
|
||||
<string name="preference_cards_stroke_width">Stroke width</string>
|
||||
<string name="preference_cards_opacity">Opacity</string>
|
||||
<string name="preference_cards_shape">Shape</string>
|
||||
<string name="preference_cards_shape_rounded">Rounded</string>
|
||||
<string name="preference_cards_shape_cut">Cut</string>
|
||||
<string name="preference_icon_shape">Shape</string>
|
||||
<string name="preference_icon_shape_platform">System default</string>
|
||||
<string name="preference_icon_shape_square">Square</string>
|
||||
|
||||
@ -233,6 +233,11 @@ message Settings {
|
||||
float opacity = 1;
|
||||
uint32 radius = 2;
|
||||
uint32 border_width = 3;
|
||||
Shape shape = 4;
|
||||
enum Shape {
|
||||
Rounded = 0;
|
||||
Cut = 1;
|
||||
}
|
||||
}
|
||||
CardSettings cards = 24;
|
||||
|
||||
|
||||
@ -18,8 +18,10 @@ import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.lifecycle.viewmodel.compose.viewModel
|
||||
import de.mm20.launcher2.preferences.Settings
|
||||
import de.mm20.launcher2.ui.R
|
||||
import de.mm20.launcher2.ui.component.LauncherCard
|
||||
import de.mm20.launcher2.ui.component.preferences.ListPreference
|
||||
import de.mm20.launcher2.ui.component.preferences.PreferenceCategory
|
||||
import de.mm20.launcher2.ui.component.preferences.PreferenceScreen
|
||||
import de.mm20.launcher2.ui.component.preferences.SliderPreference
|
||||
@ -29,9 +31,11 @@ fun CardsSettingsScreen() {
|
||||
val viewModel: CardsSettingsScreenVM = viewModel()
|
||||
PreferenceScreen(title = stringResource(R.string.preference_cards)) {
|
||||
item {
|
||||
Box(modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.background(MaterialTheme.colorScheme.secondary)) {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.background(MaterialTheme.colorScheme.secondary)
|
||||
) {
|
||||
LauncherCard(
|
||||
modifier = Modifier
|
||||
.height(200.dp)
|
||||
@ -42,17 +46,18 @@ fun CardsSettingsScreen() {
|
||||
}
|
||||
item {
|
||||
PreferenceCategory {
|
||||
val opacity by viewModel.opacity.observeAsState(0f)
|
||||
SliderPreference(
|
||||
title = stringResource(R.string.preference_cards_opacity),
|
||||
icon = Icons.Rounded.Opacity,
|
||||
value = opacity,
|
||||
min = 0f,
|
||||
max = 1f,
|
||||
val shape by viewModel.shape.observeAsState()
|
||||
ListPreference(
|
||||
icon = Icons.Rounded.BorderStyle,
|
||||
title = stringResource(R.string.preference_cards_shape),
|
||||
items = listOf(
|
||||
stringResource(R.string.preference_cards_shape_rounded) to Settings.CardSettings.Shape.Rounded,
|
||||
stringResource(R.string.preference_cards_shape_cut) to Settings.CardSettings.Shape.Cut,
|
||||
),
|
||||
value = shape,
|
||||
onValueChanged = {
|
||||
viewModel.setOpacity(it)
|
||||
}
|
||||
)
|
||||
if (it != null) viewModel.setShape(it)
|
||||
})
|
||||
val radius by viewModel.radius.observeAsState(0)
|
||||
SliderPreference(
|
||||
title = stringResource(R.string.preference_cards_corner_radius),
|
||||
@ -65,6 +70,17 @@ fun CardsSettingsScreen() {
|
||||
viewModel.setRadius(it)
|
||||
}
|
||||
)
|
||||
val opacity by viewModel.opacity.observeAsState(0f)
|
||||
SliderPreference(
|
||||
title = stringResource(R.string.preference_cards_opacity),
|
||||
icon = Icons.Rounded.Opacity,
|
||||
value = opacity,
|
||||
min = 0f,
|
||||
max = 1f,
|
||||
onValueChanged = {
|
||||
viewModel.setOpacity(it)
|
||||
}
|
||||
)
|
||||
val borderWidth by viewModel.borderWidth.observeAsState(0)
|
||||
SliderPreference(
|
||||
title = stringResource(R.string.preference_cards_stroke_width),
|
||||
|
||||
@ -4,6 +4,7 @@ import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.asLiveData
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import de.mm20.launcher2.preferences.LauncherDataStore
|
||||
import de.mm20.launcher2.preferences.Settings
|
||||
import kotlinx.coroutines.flow.map
|
||||
import kotlinx.coroutines.launch
|
||||
import org.koin.core.component.KoinComponent
|
||||
@ -47,4 +48,16 @@ class CardsSettingsScreenVM: ViewModel(), KoinComponent {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val shape = dataStore.data.map { it.cards.shape }.asLiveData()
|
||||
fun setShape(shape: Settings.CardSettings.Shape) {
|
||||
viewModelScope.launch {
|
||||
dataStore.updateData {
|
||||
it.toBuilder()
|
||||
.setCards(it.cards.toBuilder()
|
||||
.setShape(shape)
|
||||
).build()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -2,6 +2,8 @@ package de.mm20.launcher2.ui.theme
|
||||
|
||||
import android.os.Build
|
||||
import androidx.compose.foundation.isSystemInDarkTheme
|
||||
import androidx.compose.foundation.shape.CornerSize
|
||||
import androidx.compose.foundation.shape.CutCornerShape
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material3.*
|
||||
import androidx.compose.runtime.*
|
||||
@ -44,6 +46,15 @@ fun LauncherTheme(
|
||||
dataStore.data.map { it.cards.radius.dp }
|
||||
}.collectAsState(8.dp)
|
||||
|
||||
val baseShape by remember {
|
||||
dataStore.data.map {
|
||||
when(it.cards.shape) {
|
||||
Settings.CardSettings.Shape.Cut -> CutCornerShape(0f)
|
||||
else -> RoundedCornerShape(0f)
|
||||
}
|
||||
}
|
||||
}.collectAsState(RoundedCornerShape(0f))
|
||||
|
||||
val colorScheme by colorSchemeAsState(colorSchemePreference, darkTheme)
|
||||
|
||||
CompositionLocalProvider(
|
||||
@ -53,11 +64,11 @@ fun LauncherTheme(
|
||||
colorScheme = colorScheme,
|
||||
typography = DefaultTypography,
|
||||
shapes = Shapes(
|
||||
extraSmall = RoundedCornerShape(cornerRadius / 3f),
|
||||
small = RoundedCornerShape(cornerRadius / 3f * 2f),
|
||||
medium = RoundedCornerShape(cornerRadius),
|
||||
large = RoundedCornerShape(cornerRadius / 3f * 4f),
|
||||
extraLarge = RoundedCornerShape(cornerRadius / 3f * 7f),
|
||||
extraSmall = baseShape.copy(CornerSize(cornerRadius / 3f)),
|
||||
small = baseShape.copy(CornerSize(cornerRadius / 3f * 2f)),
|
||||
medium = baseShape.copy(CornerSize(cornerRadius)),
|
||||
large = baseShape.copy(CornerSize(cornerRadius / 3f * 4f)),
|
||||
extraLarge = baseShape.copy(CornerSize(cornerRadius / 3f * 7f)),
|
||||
),
|
||||
content = content
|
||||
)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user