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