feat(ui): M3 Expressive - connected button group, меню с выбором, морф кнопок и иконок
Общие ConnectedChoiceRow и OptionDropdown вместо SegmentedButton и пяти копий меню; иконки на бегунке свитча, строка поиска, пружины motionScheme.
This commit is contained in:
1 parent
66fb675bd2
commit
deb37d6c2b
20 files changed
+418
-212
No files matched your search
@@ -4,6 +4,7 @@ import androidx.compose.foundation.layout.Arrangement
|
|||||||
import androidx.compose.foundation.layout.Column
|
import androidx.compose.foundation.layout.Column
|
||||||
import androidx.compose.foundation.text.KeyboardOptions
|
import androidx.compose.foundation.text.KeyboardOptions
|
||||||
import androidx.compose.material3.AlertDialog
|
import androidx.compose.material3.AlertDialog
|
||||||
|
import androidx.compose.material3.ButtonDefaults
|
||||||
import androidx.compose.material3.OutlinedTextField
|
import androidx.compose.material3.OutlinedTextField
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.material3.TextButton
|
import androidx.compose.material3.TextButton
|
||||||
@@ -82,7 +83,7 @@ fun BackupPasswordDialog(
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
confirmButton = {
|
confirmButton = {
|
||||||
TextButton(onClick = {
|
TextButton(shapes = ButtonDefaults.shapes(), onClick = {
|
||||||
when {
|
when {
|
||||||
password.isEmpty() -> error = emptyMsg
|
password.isEmpty() -> error = emptyMsg
|
||||||
requireConfirmation && password != repeat -> error = mismatchMsg
|
requireConfirmation && password != repeat -> error = mismatchMsg
|
||||||
@@ -91,7 +92,7 @@ fun BackupPasswordDialog(
|
|||||||
}) { Text(confirmLabel) }
|
}) { Text(confirmLabel) }
|
||||||
},
|
},
|
||||||
dismissButton = {
|
dismissButton = {
|
||||||
TextButton(onClick = onDismiss) { Text(stringResource(R.string.cancel)) }
|
TextButton(shapes = ButtonDefaults.shapes(), onClick = onDismiss) { Text(stringResource(R.string.cancel)) }
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,89 @@
|
|||||||
|
@file:OptIn(androidx.compose.material3.ExperimentalMaterial3ExpressiveApi::class)
|
||||||
|
|
||||||
|
package com.freeturn.app.ui.components
|
||||||
|
|
||||||
|
import androidx.annotation.DrawableRes
|
||||||
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
|
import androidx.compose.foundation.layout.Row
|
||||||
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
|
import androidx.compose.material3.ButtonGroupDefaults
|
||||||
|
import androidx.compose.material3.Icon
|
||||||
|
import androidx.compose.material3.MaterialTheme
|
||||||
|
import androidx.compose.material3.Text
|
||||||
|
import androidx.compose.material3.ToggleButton
|
||||||
|
import androidx.compose.material3.ToggleButtonDefaults
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.platform.LocalContext
|
||||||
|
import androidx.compose.ui.res.painterResource
|
||||||
|
import androidx.compose.ui.semantics.Role
|
||||||
|
import androidx.compose.ui.semantics.role
|
||||||
|
import androidx.compose.ui.semantics.selectableGroup
|
||||||
|
import androidx.compose.ui.semantics.semantics
|
||||||
|
import androidx.compose.ui.semantics.stateDescription
|
||||||
|
import androidx.compose.ui.text.style.TextOverflow
|
||||||
|
import com.freeturn.app.ui.util.HapticUtil
|
||||||
|
|
||||||
|
/** Вариант выбора; [disabledReason] гасит только его и уходит в stateDescription. */
|
||||||
|
data class ChoiceOption<T>(
|
||||||
|
val value: T,
|
||||||
|
val label: String,
|
||||||
|
@DrawableRes val iconRes: Int? = null,
|
||||||
|
val disabledReason: String? = null
|
||||||
|
)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Одиночный выбор - connected button group (в M3 Expressive заменяет SegmentedButton).
|
||||||
|
* Тап по уже выбранному ничего не шлёт; хаптик внутри.
|
||||||
|
*/
|
||||||
|
@Composable
|
||||||
|
fun <T> ConnectedChoiceRow(
|
||||||
|
options: List<ChoiceOption<T>>,
|
||||||
|
selected: T,
|
||||||
|
onSelect: (T) -> Unit,
|
||||||
|
modifier: Modifier = Modifier,
|
||||||
|
enabled: Boolean = true
|
||||||
|
) {
|
||||||
|
val context = LocalContext.current
|
||||||
|
// Карточки настроек - surfaceContainerLow: дефолтный surfaceContainer с ними сливается.
|
||||||
|
val colors = ToggleButtonDefaults.colors(
|
||||||
|
containerColor = MaterialTheme.colorScheme.surfaceContainerHighest
|
||||||
|
)
|
||||||
|
Row(
|
||||||
|
modifier = modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.semantics { selectableGroup() },
|
||||||
|
horizontalArrangement = Arrangement.spacedBy(ButtonGroupDefaults.ConnectedSpaceBetween)
|
||||||
|
) {
|
||||||
|
options.forEachIndexed { i, option ->
|
||||||
|
val checked = option.value == selected
|
||||||
|
ToggleButton(
|
||||||
|
checked = checked,
|
||||||
|
onCheckedChange = {
|
||||||
|
if (!checked) {
|
||||||
|
HapticUtil.perform(context, HapticUtil.Pattern.TOGGLE_ON)
|
||||||
|
onSelect(option.value)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
enabled = enabled && option.disabledReason == null,
|
||||||
|
icon = option.iconRes?.let { res ->
|
||||||
|
@Composable { Icon(painterResource(res), contentDescription = null) }
|
||||||
|
},
|
||||||
|
shapes = when (i) {
|
||||||
|
0 -> ButtonGroupDefaults.connectedLeadingButtonShapes()
|
||||||
|
options.lastIndex -> ButtonGroupDefaults.connectedTrailingButtonShapes()
|
||||||
|
else -> ButtonGroupDefaults.connectedMiddleButtonShapes()
|
||||||
|
},
|
||||||
|
colors = colors,
|
||||||
|
modifier = Modifier
|
||||||
|
.weight(1f)
|
||||||
|
.semantics {
|
||||||
|
role = Role.RadioButton
|
||||||
|
option.disabledReason?.let { stateDescription = it }
|
||||||
|
}
|
||||||
|
) {
|
||||||
|
Text(option.label, maxLines = 1, overflow = TextOverflow.Ellipsis)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -12,6 +12,7 @@ import androidx.compose.foundation.layout.height
|
|||||||
import androidx.compose.foundation.layout.padding
|
import androidx.compose.foundation.layout.padding
|
||||||
import androidx.compose.foundation.layout.size
|
import androidx.compose.foundation.layout.size
|
||||||
import androidx.compose.material3.Button
|
import androidx.compose.material3.Button
|
||||||
|
import androidx.compose.material3.ButtonDefaults
|
||||||
import androidx.compose.material3.Icon
|
import androidx.compose.material3.Icon
|
||||||
import androidx.compose.material3.MaterialShapes
|
import androidx.compose.material3.MaterialShapes
|
||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
||||||
@@ -69,7 +70,7 @@ fun EmptyState(
|
|||||||
)
|
)
|
||||||
if (actionLabel != null && onAction != null) {
|
if (actionLabel != null && onAction != null) {
|
||||||
Spacer(Modifier.height(24.dp))
|
Spacer(Modifier.height(24.dp))
|
||||||
Button(onClick = onAction) { Text(actionLabel) }
|
Button(shapes = ButtonDefaults.shapes(), onClick = onAction) { Text(actionLabel) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
package com.freeturn.app.ui.components
|
||||||
|
|
||||||
|
import androidx.compose.ui.geometry.Size
|
||||||
|
import androidx.compose.ui.graphics.Matrix
|
||||||
|
import androidx.compose.ui.graphics.Outline
|
||||||
|
import androidx.compose.ui.graphics.Shape
|
||||||
|
import androidx.compose.ui.graphics.asComposePath
|
||||||
|
import androidx.compose.ui.unit.Density
|
||||||
|
import androidx.compose.ui.unit.LayoutDirection
|
||||||
|
import androidx.graphics.shapes.Morph
|
||||||
|
import androidx.graphics.shapes.toPath
|
||||||
|
|
||||||
|
internal class MorphProgressShape(private val morph: Morph, private val progress: Float) : Shape {
|
||||||
|
override fun createOutline(size: Size, layoutDirection: LayoutDirection, density: Density): Outline {
|
||||||
|
val path = morph.toPath(progress.coerceIn(0f, 1f)).asComposePath()
|
||||||
|
path.transform(Matrix().apply { scale(size.width, size.height) })
|
||||||
|
return Outline.Generic(path)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun equals(other: Any?): Boolean =
|
||||||
|
other is MorphProgressShape && other.morph === morph && other.progress == progress
|
||||||
|
|
||||||
|
override fun hashCode(): Int = 31 * System.identityHashCode(morph) + progress.hashCode()
|
||||||
|
}
|
||||||
@@ -0,0 +1,103 @@
|
|||||||
|
@file:OptIn(
|
||||||
|
androidx.compose.material3.ExperimentalMaterial3Api::class,
|
||||||
|
androidx.compose.material3.ExperimentalMaterial3ExpressiveApi::class
|
||||||
|
)
|
||||||
|
|
||||||
|
package com.freeturn.app.ui.components
|
||||||
|
|
||||||
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
|
import androidx.compose.foundation.layout.size
|
||||||
|
import androidx.compose.material3.ExposedDropdownMenu
|
||||||
|
import androidx.compose.material3.ExposedDropdownMenuAnchorType
|
||||||
|
import androidx.compose.material3.ExposedDropdownMenuBox
|
||||||
|
import androidx.compose.material3.ExposedDropdownMenuDefaults
|
||||||
|
import androidx.compose.material3.Icon
|
||||||
|
import androidx.compose.material3.MaterialTheme
|
||||||
|
import androidx.compose.material3.MenuDefaults
|
||||||
|
import androidx.compose.material3.OutlinedTextField
|
||||||
|
import androidx.compose.material3.SelectableDropdownMenuItem
|
||||||
|
import androidx.compose.material3.Text
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.getValue
|
||||||
|
import androidx.compose.runtime.mutableStateOf
|
||||||
|
import androidx.compose.runtime.remember
|
||||||
|
import androidx.compose.runtime.setValue
|
||||||
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.platform.LocalContext
|
||||||
|
import androidx.compose.ui.res.painterResource
|
||||||
|
import androidx.compose.ui.res.stringResource
|
||||||
|
import com.freeturn.app.R
|
||||||
|
import com.freeturn.app.data.config.ObfProfile
|
||||||
|
import com.freeturn.app.ui.util.HapticUtil
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun <T> OptionDropdown(
|
||||||
|
label: String,
|
||||||
|
options: List<ChoiceOption<T>>,
|
||||||
|
selected: T,
|
||||||
|
onSelect: (T) -> Unit,
|
||||||
|
modifier: Modifier = Modifier,
|
||||||
|
enabled: Boolean = true,
|
||||||
|
minLines: Int = 1
|
||||||
|
) {
|
||||||
|
val context = LocalContext.current
|
||||||
|
var expanded by remember { mutableStateOf(false) }
|
||||||
|
ExposedDropdownMenuBox(
|
||||||
|
expanded = expanded,
|
||||||
|
onExpandedChange = { if (enabled) expanded = it },
|
||||||
|
modifier = modifier
|
||||||
|
) {
|
||||||
|
OutlinedTextField(
|
||||||
|
value = options.firstOrNull { it.value == selected }?.label.orEmpty(),
|
||||||
|
onValueChange = {},
|
||||||
|
readOnly = true,
|
||||||
|
enabled = enabled,
|
||||||
|
singleLine = minLines == 1,
|
||||||
|
minLines = minLines,
|
||||||
|
label = { Text(label) },
|
||||||
|
trailingIcon = { ExposedDropdownMenuDefaults.TrailingIcon(expanded = expanded) },
|
||||||
|
modifier = Modifier
|
||||||
|
.menuAnchor(ExposedDropdownMenuAnchorType.PrimaryNotEditable, enabled)
|
||||||
|
.fillMaxWidth()
|
||||||
|
)
|
||||||
|
ExposedDropdownMenu(
|
||||||
|
expanded = expanded,
|
||||||
|
onDismissRequest = { expanded = false },
|
||||||
|
containerColor = MenuDefaults.groupStandardContainerColor,
|
||||||
|
shape = MenuDefaults.standaloneGroupShape
|
||||||
|
) {
|
||||||
|
options.forEachIndexed { i, option ->
|
||||||
|
SelectableDropdownMenuItem(
|
||||||
|
selected = option.value == selected,
|
||||||
|
onClick = {
|
||||||
|
expanded = false
|
||||||
|
if (option.value != selected) {
|
||||||
|
HapticUtil.perform(context, HapticUtil.Pattern.SELECTION)
|
||||||
|
onSelect(option.value)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
text = { Text(option.label, style = MaterialTheme.typography.bodyLarge) },
|
||||||
|
shapes = MenuDefaults.itemShape(i, options.size),
|
||||||
|
enabled = option.disabledReason == null,
|
||||||
|
selectedLeadingIcon = {
|
||||||
|
Icon(
|
||||||
|
painterResource(R.drawable.check_24px),
|
||||||
|
contentDescription = null,
|
||||||
|
modifier = Modifier.size(MenuDefaults.LeadingIconSize)
|
||||||
|
)
|
||||||
|
},
|
||||||
|
contentPadding = ExposedDropdownMenuDefaults.ItemContentPadding
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun obfProfileLabel(value: String): String = when (value) {
|
||||||
|
ObfProfile.NONE -> stringResource(R.string.obf_none)
|
||||||
|
ObfProfile.RTPOPUS -> stringResource(R.string.obf_rtpopus)
|
||||||
|
ObfProfile.RTPOPUS2 -> stringResource(R.string.obf_rtpopus2)
|
||||||
|
ObfProfile.RTPOPUS3 -> stringResource(R.string.obf_rtpopus3)
|
||||||
|
else -> value
|
||||||
|
}
|
||||||
@@ -2,7 +2,12 @@
|
|||||||
|
|
||||||
package com.freeturn.app.ui.components
|
package com.freeturn.app.ui.components
|
||||||
|
|
||||||
|
import androidx.compose.animation.core.animateFloatAsState
|
||||||
|
import androidx.compose.foundation.LocalIndication
|
||||||
import androidx.compose.foundation.background
|
import androidx.compose.foundation.background
|
||||||
|
import androidx.compose.foundation.interaction.InteractionSource
|
||||||
|
import androidx.compose.foundation.interaction.MutableInteractionSource
|
||||||
|
import androidx.compose.foundation.interaction.collectIsPressedAsState
|
||||||
import androidx.compose.foundation.layout.Arrangement
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
import androidx.compose.foundation.layout.Box
|
import androidx.compose.foundation.layout.Box
|
||||||
import androidx.compose.foundation.layout.Column
|
import androidx.compose.foundation.layout.Column
|
||||||
@@ -15,10 +20,12 @@ import androidx.compose.material3.Icon
|
|||||||
import androidx.compose.material3.MaterialShapes
|
import androidx.compose.material3.MaterialShapes
|
||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
||||||
import androidx.compose.material3.Slider
|
import androidx.compose.material3.Slider
|
||||||
|
import androidx.compose.material3.SliderState
|
||||||
import androidx.compose.material3.Switch
|
import androidx.compose.material3.Switch
|
||||||
|
import androidx.compose.material3.SwitchDefaults
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.material3.toShape
|
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.SideEffect
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
import androidx.compose.runtime.mutableIntStateOf
|
import androidx.compose.runtime.mutableIntStateOf
|
||||||
import androidx.compose.runtime.remember
|
import androidx.compose.runtime.remember
|
||||||
@@ -30,7 +37,9 @@ import androidx.compose.ui.platform.LocalContext
|
|||||||
import androidx.compose.ui.res.painterResource
|
import androidx.compose.ui.res.painterResource
|
||||||
import androidx.compose.ui.semantics.Role
|
import androidx.compose.ui.semantics.Role
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
|
import androidx.graphics.shapes.Morph
|
||||||
import com.freeturn.app.R
|
import com.freeturn.app.R
|
||||||
|
import com.freeturn.app.ui.theme.LocalReducedMotion
|
||||||
import com.freeturn.app.ui.theme.Spacing
|
import com.freeturn.app.ui.theme.Spacing
|
||||||
import com.freeturn.app.ui.util.HapticUtil
|
import com.freeturn.app.ui.util.HapticUtil
|
||||||
import com.freeturn.app.ui.util.hapticClickable
|
import com.freeturn.app.ui.util.hapticClickable
|
||||||
@@ -50,9 +59,12 @@ fun SettingsSliderRow(
|
|||||||
hint: String? = null
|
hint: String? = null
|
||||||
) {
|
) {
|
||||||
var lastInt by remember { mutableIntStateOf(value.roundToInt()) }
|
var lastInt by remember { mutableIntStateOf(value.roundToInt()) }
|
||||||
|
val state = remember(valueRange) { SliderState(value = value, trackRange = valueRange) }
|
||||||
|
// Источник правды - value снаружи (правку может откатить coerce родителя).
|
||||||
|
SideEffect { state.value = value }
|
||||||
SettingsControlLabel(title = valueLabel, desc = hint)
|
SettingsControlLabel(title = valueLabel, desc = hint)
|
||||||
Slider(
|
Slider(
|
||||||
value = value,
|
state = state,
|
||||||
onValueChange = {
|
onValueChange = {
|
||||||
val newInt = it.roundToInt()
|
val newInt = it.roundToInt()
|
||||||
if (newInt != lastInt) {
|
if (newInt != lastInt) {
|
||||||
@@ -61,7 +73,6 @@ fun SettingsSliderRow(
|
|||||||
}
|
}
|
||||||
onValueChange(it)
|
onValueChange(it)
|
||||||
},
|
},
|
||||||
valueRange = valueRange,
|
|
||||||
modifier = Modifier.fillMaxWidth()
|
modifier = Modifier.fillMaxWidth()
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -80,11 +91,14 @@ fun SettingsSwitchRow(
|
|||||||
else MaterialTheme.colorScheme.onSurface.copy(alpha = 0.38f)
|
else MaterialTheme.colorScheme.onSurface.copy(alpha = 0.38f)
|
||||||
val subtitleColor = if (enabled) MaterialTheme.colorScheme.onSurfaceVariant
|
val subtitleColor = if (enabled) MaterialTheme.colorScheme.onSurfaceVariant
|
||||||
else MaterialTheme.colorScheme.onSurfaceVariant.copy(alpha = 0.38f)
|
else MaterialTheme.colorScheme.onSurfaceVariant.copy(alpha = 0.38f)
|
||||||
|
val interactionSource = remember { MutableInteractionSource() }
|
||||||
Row(
|
Row(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
.toggleable(
|
.toggleable(
|
||||||
value = checked,
|
value = checked,
|
||||||
|
interactionSource = interactionSource,
|
||||||
|
indication = LocalIndication.current,
|
||||||
enabled = enabled,
|
enabled = enabled,
|
||||||
role = Role.Switch,
|
role = Role.Switch,
|
||||||
onValueChange = { v ->
|
onValueChange = { v ->
|
||||||
@@ -99,7 +113,7 @@ fun SettingsSwitchRow(
|
|||||||
verticalAlignment = Alignment.CenterVertically,
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
horizontalArrangement = Arrangement.spacedBy(Spacing.lg)
|
horizontalArrangement = Arrangement.spacedBy(Spacing.lg)
|
||||||
) {
|
) {
|
||||||
if (iconRes != null) SettingsRowIcon(iconRes, enabled = enabled)
|
if (iconRes != null) SettingsRowIcon(iconRes, enabled = enabled, interactionSource = interactionSource)
|
||||||
Column(modifier = Modifier.weight(1f)) {
|
Column(modifier = Modifier.weight(1f)) {
|
||||||
Text(title, style = MaterialTheme.typography.bodyLarge, color = titleColor)
|
Text(title, style = MaterialTheme.typography.bodyLarge, color = titleColor)
|
||||||
if (subtitle != null) {
|
if (subtitle != null) {
|
||||||
@@ -107,22 +121,48 @@ fun SettingsSwitchRow(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// null = display-only: клики и семантику несёт строка (один haptic, один фокус).
|
// null = display-only: клики и семантику несёт строка (один haptic, один фокус).
|
||||||
Switch(checked = checked, onCheckedChange = null, enabled = enabled)
|
Switch(
|
||||||
|
checked = checked,
|
||||||
|
onCheckedChange = null,
|
||||||
|
enabled = enabled,
|
||||||
|
thumbContent = { SwitchThumbIcon(checked) }
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Галочка/крестик на бегунке: состояние читается не только по цвету. */
|
||||||
|
@Composable
|
||||||
|
fun SwitchThumbIcon(checked: Boolean) {
|
||||||
|
Icon(
|
||||||
|
painterResource(if (checked) R.drawable.check_24px else R.drawable.close_24px),
|
||||||
|
contentDescription = null,
|
||||||
|
modifier = Modifier.size(SwitchDefaults.IconSize)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
private val iconPressMorph = Morph(MaterialShapes.Sunny, MaterialShapes.Cookie9Sided)
|
||||||
|
|
||||||
|
/** Иконка строки в Sunny; при нажатии строки ([interactionSource]) морфится в Cookie. */
|
||||||
@Composable
|
@Composable
|
||||||
fun SettingsRowIcon(
|
fun SettingsRowIcon(
|
||||||
iconRes: Int,
|
iconRes: Int,
|
||||||
enabled: Boolean = true,
|
enabled: Boolean = true,
|
||||||
container: Color = MaterialTheme.colorScheme.secondaryContainer,
|
container: Color = MaterialTheme.colorScheme.secondaryContainer,
|
||||||
tint: Color = MaterialTheme.colorScheme.onSecondaryContainer
|
tint: Color = MaterialTheme.colorScheme.onSecondaryContainer,
|
||||||
|
interactionSource: InteractionSource? = null
|
||||||
) {
|
) {
|
||||||
val alpha = if (enabled) 1f else 0.38f
|
val alpha = if (enabled) 1f else 0.38f
|
||||||
|
val pressed = interactionSource?.collectIsPressedAsState()?.value == true
|
||||||
|
val reducedMotion = LocalReducedMotion.current
|
||||||
|
val progress by animateFloatAsState(
|
||||||
|
targetValue = if (pressed && !reducedMotion) 1f else 0f,
|
||||||
|
animationSpec = MaterialTheme.motionScheme.fastSpatialSpec(),
|
||||||
|
label = "rowIconMorph"
|
||||||
|
)
|
||||||
Box(
|
Box(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.size(40.dp)
|
.size(40.dp)
|
||||||
.background(container.copy(alpha = alpha), MaterialShapes.Sunny.toShape()),
|
.background(container.copy(alpha = alpha), MorphProgressShape(iconPressMorph, progress)),
|
||||||
contentAlignment = Alignment.Center
|
contentAlignment = Alignment.Center
|
||||||
) {
|
) {
|
||||||
Icon(
|
Icon(
|
||||||
@@ -152,15 +192,27 @@ fun SettingsEntryRow(
|
|||||||
else MaterialTheme.colorScheme.onSurface.copy(alpha = 0.38f)
|
else MaterialTheme.colorScheme.onSurface.copy(alpha = 0.38f)
|
||||||
val subtitleColor = if (enabled) MaterialTheme.colorScheme.onSurfaceVariant
|
val subtitleColor = if (enabled) MaterialTheme.colorScheme.onSurfaceVariant
|
||||||
else MaterialTheme.colorScheme.onSurfaceVariant.copy(alpha = 0.38f)
|
else MaterialTheme.colorScheme.onSurfaceVariant.copy(alpha = 0.38f)
|
||||||
|
val interactionSource = remember { MutableInteractionSource() }
|
||||||
Row(
|
Row(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
.hapticClickable(HapticUtil.Pattern.CLICK, enabled = enabled, onClick = onClick)
|
.hapticClickable(
|
||||||
|
HapticUtil.Pattern.CLICK,
|
||||||
|
enabled = enabled,
|
||||||
|
interactionSource = interactionSource,
|
||||||
|
onClick = onClick
|
||||||
|
)
|
||||||
.padding(horizontal = Spacing.lg, vertical = Spacing.lg),
|
.padding(horizontal = Spacing.lg, vertical = Spacing.lg),
|
||||||
verticalAlignment = Alignment.CenterVertically,
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
horizontalArrangement = Arrangement.spacedBy(Spacing.lg)
|
horizontalArrangement = Arrangement.spacedBy(Spacing.lg)
|
||||||
) {
|
) {
|
||||||
SettingsRowIcon(iconRes, enabled = enabled, container = iconContainer, tint = iconTint)
|
SettingsRowIcon(
|
||||||
|
iconRes,
|
||||||
|
enabled = enabled,
|
||||||
|
container = iconContainer,
|
||||||
|
tint = iconTint,
|
||||||
|
interactionSource = interactionSource
|
||||||
|
)
|
||||||
Column(modifier = Modifier.weight(1f)) {
|
Column(modifier = Modifier.weight(1f)) {
|
||||||
Text(title, style = MaterialTheme.typography.bodyLarge, color = titleColor)
|
Text(title, style = MaterialTheme.typography.bodyLarge, color = titleColor)
|
||||||
if (subtitle != null) {
|
if (subtitle != null) {
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ import androidx.compose.foundation.layout.ColumnScope
|
|||||||
import androidx.compose.foundation.layout.fillMaxWidth
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
import androidx.compose.foundation.layout.padding
|
import androidx.compose.foundation.layout.padding
|
||||||
import androidx.compose.material3.HorizontalDivider
|
import androidx.compose.material3.HorizontalDivider
|
||||||
|
import androidx.compose.material3.IconButtonDefaults
|
||||||
|
import androidx.compose.material3.ButtonDefaults
|
||||||
import androidx.compose.material3.Icon
|
import androidx.compose.material3.Icon
|
||||||
import androidx.compose.material3.IconButton
|
import androidx.compose.material3.IconButton
|
||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
||||||
@@ -80,7 +82,7 @@ fun SettingsControlLabel(title: String, desc: String? = null) {
|
|||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun SettingsBackButton(onBack: () -> Unit) {
|
fun SettingsBackButton(onBack: () -> Unit) {
|
||||||
IconButton(onClick = onBack) {
|
IconButton(shapes = IconButtonDefaults.shapes(), onClick = onBack) {
|
||||||
Icon(
|
Icon(
|
||||||
painterResource(R.drawable.arrow_back_24px),
|
painterResource(R.drawable.arrow_back_24px),
|
||||||
contentDescription = stringResource(R.string.back)
|
contentDescription = stringResource(R.string.back)
|
||||||
|
|||||||
@@ -2,15 +2,14 @@
|
|||||||
|
|
||||||
package com.freeturn.app.ui.components
|
package com.freeturn.app.ui.components
|
||||||
|
|
||||||
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
|
import androidx.compose.foundation.layout.Column
|
||||||
import androidx.compose.foundation.layout.fillMaxWidth
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
import androidx.compose.foundation.layout.heightIn
|
import androidx.compose.foundation.layout.heightIn
|
||||||
import androidx.compose.foundation.text.KeyboardOptions
|
import androidx.compose.foundation.text.KeyboardOptions
|
||||||
import androidx.compose.material3.DropdownMenuItem
|
|
||||||
import androidx.compose.material3.ExposedDropdownMenu
|
|
||||||
import androidx.compose.material3.ExposedDropdownMenuAnchorType
|
|
||||||
import androidx.compose.material3.ExposedDropdownMenuBox
|
|
||||||
import androidx.compose.material3.ExposedDropdownMenuDefaults
|
|
||||||
import androidx.compose.material3.Icon
|
import androidx.compose.material3.Icon
|
||||||
|
import androidx.compose.material3.IconButtonDefaults
|
||||||
|
import androidx.compose.material3.ButtonDefaults
|
||||||
import androidx.compose.material3.IconButton
|
import androidx.compose.material3.IconButton
|
||||||
import androidx.compose.material3.OutlinedTextField
|
import androidx.compose.material3.OutlinedTextField
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
@@ -30,6 +29,7 @@ import androidx.compose.ui.text.input.VisualTransformation
|
|||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import com.freeturn.app.R
|
import com.freeturn.app.R
|
||||||
import com.freeturn.app.data.config.SshConfig
|
import com.freeturn.app.data.config.SshConfig
|
||||||
|
import com.freeturn.app.ui.theme.Spacing
|
||||||
import com.freeturn.app.ui.util.HapticUtil
|
import com.freeturn.app.ui.util.HapticUtil
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
@@ -95,7 +95,7 @@ fun SshFormFields(
|
|||||||
}
|
}
|
||||||
SettingsRowDivider()
|
SettingsRowDivider()
|
||||||
SettingsFieldSlot {
|
SettingsFieldSlot {
|
||||||
AuthMethodDropdown(
|
AuthMethodChoice(
|
||||||
authType = authType,
|
authType = authType,
|
||||||
onAuthTypeChange = onAuthTypeChange
|
onAuthTypeChange = onAuthTypeChange
|
||||||
)
|
)
|
||||||
@@ -115,7 +115,7 @@ fun SshFormFields(
|
|||||||
} else null,
|
} else null,
|
||||||
visualTransformation = if (showPassword) VisualTransformation.None else PasswordVisualTransformation(),
|
visualTransformation = if (showPassword) VisualTransformation.None else PasswordVisualTransformation(),
|
||||||
trailingIcon = {
|
trailingIcon = {
|
||||||
IconButton(onClick = {
|
IconButton(shapes = IconButtonDefaults.shapes(), onClick = {
|
||||||
HapticUtil.perform(context, HapticUtil.Pattern.SELECTION)
|
HapticUtil.perform(context, HapticUtil.Pattern.SELECTION)
|
||||||
showPassword = !showPassword
|
showPassword = !showPassword
|
||||||
}) {
|
}) {
|
||||||
@@ -159,7 +159,7 @@ fun SshFormFields(
|
|||||||
singleLine = true,
|
singleLine = true,
|
||||||
visualTransformation = if (showSudoPw) VisualTransformation.None else PasswordVisualTransformation(),
|
visualTransformation = if (showSudoPw) VisualTransformation.None else PasswordVisualTransformation(),
|
||||||
trailingIcon = {
|
trailingIcon = {
|
||||||
IconButton(onClick = {
|
IconButton(shapes = IconButtonDefaults.shapes(), onClick = {
|
||||||
HapticUtil.perform(context, HapticUtil.Pattern.SELECTION)
|
HapticUtil.perform(context, HapticUtil.Pattern.SELECTION)
|
||||||
showSudoPw = !showSudoPw
|
showSudoPw = !showSudoPw
|
||||||
}) {
|
}) {
|
||||||
@@ -180,47 +180,19 @@ fun SshFormFields(
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
private fun AuthMethodDropdown(
|
private fun AuthMethodChoice(
|
||||||
authType: String,
|
authType: String,
|
||||||
onAuthTypeChange: (String) -> Unit
|
onAuthTypeChange: (String) -> Unit
|
||||||
) {
|
) {
|
||||||
val context = LocalContext.current
|
Column(verticalArrangement = Arrangement.spacedBy(Spacing.sm)) {
|
||||||
var expanded by remember { mutableStateOf(false) }
|
SettingsControlLabel(stringResource(R.string.auth_method_label))
|
||||||
val options = listOf(
|
ConnectedChoiceRow(
|
||||||
SshConfig.AUTH_PASSWORD to stringResource(R.string.password),
|
options = listOf(
|
||||||
SshConfig.AUTH_SSH_KEY to stringResource(R.string.private_key)
|
ChoiceOption(SshConfig.AUTH_PASSWORD, stringResource(R.string.password)),
|
||||||
)
|
ChoiceOption(SshConfig.AUTH_SSH_KEY, stringResource(R.string.private_key))
|
||||||
val current = options.firstOrNull { it.first == authType }?.second.orEmpty()
|
),
|
||||||
|
selected = authType,
|
||||||
ExposedDropdownMenuBox(
|
onSelect = onAuthTypeChange
|
||||||
expanded = expanded,
|
|
||||||
onExpandedChange = { expanded = !expanded },
|
|
||||||
modifier = Modifier.fillMaxWidth()
|
|
||||||
) {
|
|
||||||
OutlinedTextField(
|
|
||||||
value = current,
|
|
||||||
onValueChange = {},
|
|
||||||
readOnly = true,
|
|
||||||
singleLine = true,
|
|
||||||
label = { Text(stringResource(R.string.auth_method_label)) },
|
|
||||||
trailingIcon = { ExposedDropdownMenuDefaults.TrailingIcon(expanded = expanded) },
|
|
||||||
modifier = Modifier
|
|
||||||
.menuAnchor(ExposedDropdownMenuAnchorType.PrimaryNotEditable)
|
|
||||||
.fillMaxWidth()
|
|
||||||
)
|
|
||||||
ExposedDropdownMenu(expanded = expanded, onDismissRequest = { expanded = false }) {
|
|
||||||
options.forEach { (value, label) ->
|
|
||||||
DropdownMenuItem(
|
|
||||||
text = { Text(label) },
|
|
||||||
onClick = {
|
|
||||||
expanded = false
|
|
||||||
if (value != authType) {
|
|
||||||
HapticUtil.perform(context, HapticUtil.Pattern.SELECTION)
|
|
||||||
onAuthTypeChange(value)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -2,26 +2,14 @@ package com.freeturn.app.ui.components
|
|||||||
|
|
||||||
import androidx.compose.foundation.layout.Arrangement
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
import androidx.compose.foundation.layout.Column
|
import androidx.compose.foundation.layout.Column
|
||||||
import androidx.compose.foundation.layout.fillMaxWidth
|
|
||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
||||||
import androidx.compose.material3.SegmentedButton
|
|
||||||
import androidx.compose.material3.SegmentedButtonDefaults
|
|
||||||
import androidx.compose.material3.SingleChoiceSegmentedButtonRow
|
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.platform.LocalContext
|
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
import androidx.compose.ui.semantics.semantics
|
|
||||||
import androidx.compose.ui.semantics.stateDescription
|
|
||||||
import com.freeturn.app.R
|
import com.freeturn.app.R
|
||||||
import com.freeturn.app.ui.util.HapticUtil
|
|
||||||
import com.freeturn.app.ui.theme.Spacing
|
import com.freeturn.app.ui.theme.Spacing
|
||||||
|
|
||||||
/**
|
|
||||||
* Выбор проброса UDP/TCP. [label] обязателен - без него сегменты озвучиваются как "1 из 2"
|
|
||||||
* без предмета выбора; [tcpDisabledReason] уходит и под группу, и в stateDescription.
|
|
||||||
*/
|
|
||||||
@Composable
|
@Composable
|
||||||
fun UdpTcpSegmented(
|
fun UdpTcpSegmented(
|
||||||
tcp: Boolean,
|
tcp: Boolean,
|
||||||
@@ -30,30 +18,16 @@ fun UdpTcpSegmented(
|
|||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
tcpDisabledReason: String? = null
|
tcpDisabledReason: String? = null
|
||||||
) {
|
) {
|
||||||
val context = LocalContext.current
|
|
||||||
fun pick(value: Boolean) {
|
|
||||||
if (value == tcp) return
|
|
||||||
HapticUtil.perform(context, HapticUtil.Pattern.TOGGLE_ON)
|
|
||||||
onTcp(value)
|
|
||||||
}
|
|
||||||
|
|
||||||
Column(modifier = modifier, verticalArrangement = Arrangement.spacedBy(Spacing.sm)) {
|
Column(modifier = modifier, verticalArrangement = Arrangement.spacedBy(Spacing.sm)) {
|
||||||
SettingsControlLabel(label)
|
SettingsControlLabel(label)
|
||||||
SingleChoiceSegmentedButtonRow(modifier = Modifier.fillMaxWidth()) {
|
ConnectedChoiceRow(
|
||||||
SegmentedButton(
|
options = listOf(
|
||||||
selected = !tcp,
|
ChoiceOption(false, stringResource(R.string.udp)),
|
||||||
onClick = { pick(false) },
|
ChoiceOption(true, stringResource(R.string.tcp), disabledReason = tcpDisabledReason)
|
||||||
shape = SegmentedButtonDefaults.itemShape(index = 0, count = 2)
|
),
|
||||||
) { Text(stringResource(R.string.udp)) }
|
|
||||||
SegmentedButton(
|
|
||||||
selected = tcp,
|
selected = tcp,
|
||||||
onClick = { pick(true) },
|
onSelect = onTcp
|
||||||
enabled = tcpDisabledReason == null,
|
)
|
||||||
shape = SegmentedButtonDefaults.itemShape(index = 1, count = 2),
|
|
||||||
modifier = if (tcpDisabledReason == null) Modifier
|
|
||||||
else Modifier.semantics { stateDescription = tcpDisabledReason }
|
|
||||||
) { Text(stringResource(R.string.tcp)) }
|
|
||||||
}
|
|
||||||
if (tcpDisabledReason != null) {
|
if (tcpDisabledReason != null) {
|
||||||
Text(
|
Text(
|
||||||
tcpDisabledReason,
|
tcpDisabledReason,
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package com.freeturn.app.ui.screens.addserver
|
|||||||
|
|
||||||
import androidx.compose.foundation.layout.fillMaxWidth
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
import androidx.compose.material3.AlertDialog
|
import androidx.compose.material3.AlertDialog
|
||||||
|
import androidx.compose.material3.ButtonDefaults
|
||||||
import androidx.compose.material3.OutlinedTextField
|
import androidx.compose.material3.OutlinedTextField
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.material3.TextButton
|
import androidx.compose.material3.TextButton
|
||||||
@@ -38,6 +39,7 @@ internal fun ManualNameDialog(
|
|||||||
},
|
},
|
||||||
confirmButton = {
|
confirmButton = {
|
||||||
TextButton(
|
TextButton(
|
||||||
|
shapes = ButtonDefaults.shapes(),
|
||||||
onClick = {
|
onClick = {
|
||||||
HapticUtil.perform(context, HapticUtil.Pattern.CLICK)
|
HapticUtil.perform(context, HapticUtil.Pattern.CLICK)
|
||||||
onCreate(name)
|
onCreate(name)
|
||||||
@@ -46,7 +48,7 @@ internal fun ManualNameDialog(
|
|||||||
) { Text(stringResource(R.string.add_manual_create)) }
|
) { Text(stringResource(R.string.add_manual_create)) }
|
||||||
},
|
},
|
||||||
dismissButton = {
|
dismissButton = {
|
||||||
TextButton(onClick = onDismiss) { Text(stringResource(R.string.cancel)) }
|
TextButton(shapes = ButtonDefaults.shapes(), onClick = onDismiss) { Text(stringResource(R.string.cancel)) }
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -6,6 +6,7 @@ import androidx.compose.foundation.layout.fillMaxWidth
|
|||||||
import androidx.compose.foundation.layout.padding
|
import androidx.compose.foundation.layout.padding
|
||||||
import androidx.compose.foundation.shape.CircleShape
|
import androidx.compose.foundation.shape.CircleShape
|
||||||
import androidx.compose.material3.Button
|
import androidx.compose.material3.Button
|
||||||
|
import androidx.compose.material3.ButtonDefaults
|
||||||
import androidx.compose.material3.Icon
|
import androidx.compose.material3.Icon
|
||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
||||||
import androidx.compose.material3.Surface
|
import androidx.compose.material3.Surface
|
||||||
@@ -48,7 +49,7 @@ internal fun PasteLinkField(onPaste: () -> Unit) {
|
|||||||
overflow = TextOverflow.Ellipsis,
|
overflow = TextOverflow.Ellipsis,
|
||||||
modifier = Modifier.weight(1f)
|
modifier = Modifier.weight(1f)
|
||||||
)
|
)
|
||||||
Button(onClick = {
|
Button(shapes = ButtonDefaults.shapes(), onClick = {
|
||||||
HapticUtil.perform(context, HapticUtil.Pattern.CLICK)
|
HapticUtil.perform(context, HapticUtil.Pattern.CLICK)
|
||||||
onPaste()
|
onPaste()
|
||||||
}) {
|
}) {
|
||||||
|
|||||||
+17
-23
@@ -20,13 +20,12 @@ import androidx.compose.foundation.layout.widthIn
|
|||||||
import androidx.compose.foundation.rememberScrollState
|
import androidx.compose.foundation.rememberScrollState
|
||||||
import androidx.compose.foundation.verticalScroll
|
import androidx.compose.foundation.verticalScroll
|
||||||
import androidx.compose.material3.Icon
|
import androidx.compose.material3.Icon
|
||||||
|
import androidx.compose.material3.IconButtonDefaults
|
||||||
|
import androidx.compose.material3.ButtonDefaults
|
||||||
import androidx.compose.material3.IconButton
|
import androidx.compose.material3.IconButton
|
||||||
import androidx.compose.material3.LargeFlexibleTopAppBar
|
import androidx.compose.material3.LargeFlexibleTopAppBar
|
||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
||||||
import androidx.compose.material3.Scaffold
|
import androidx.compose.material3.Scaffold
|
||||||
import androidx.compose.material3.SegmentedButton
|
|
||||||
import androidx.compose.material3.SegmentedButtonDefaults
|
|
||||||
import androidx.compose.material3.SingleChoiceSegmentedButtonRow
|
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.material3.TopAppBarDefaults
|
import androidx.compose.material3.TopAppBarDefaults
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
@@ -53,6 +52,8 @@ import com.freeturn.app.data.config.TunnelTransport
|
|||||||
import com.freeturn.app.data.server.ServerOpts
|
import com.freeturn.app.data.server.ServerOpts
|
||||||
import com.freeturn.app.ui.util.HapticUtil
|
import com.freeturn.app.ui.util.HapticUtil
|
||||||
import com.freeturn.app.ui.components.ApplyFab
|
import com.freeturn.app.ui.components.ApplyFab
|
||||||
|
import com.freeturn.app.ui.components.ChoiceOption
|
||||||
|
import com.freeturn.app.ui.components.ConnectedChoiceRow
|
||||||
import com.freeturn.app.ui.components.FabClearance
|
import com.freeturn.app.ui.components.FabClearance
|
||||||
import com.freeturn.app.ui.components.InlineNoticeCard
|
import com.freeturn.app.ui.components.InlineNoticeCard
|
||||||
import com.freeturn.app.ui.components.SectionLabel
|
import com.freeturn.app.ui.components.SectionLabel
|
||||||
@@ -97,7 +98,7 @@ fun ConnectionModeScreen(
|
|||||||
val context = LocalContext.current
|
val context = LocalContext.current
|
||||||
val scope = rememberCoroutineScope()
|
val scope = rememberCoroutineScope()
|
||||||
|
|
||||||
// userPickedVpn сохраняет выбор на время сессии (чтобы сегмент не мигал).
|
// userPickedVpn сохраняет выбор на время сессии (чтобы выбор не мигал).
|
||||||
var userPickedVpn by remember(serverId, saved.tunnelTransport) { mutableStateOf<Boolean?>(null) }
|
var userPickedVpn by remember(serverId, saved.tunnelTransport) { mutableStateOf<Boolean?>(null) }
|
||||||
val isVpn = userPickedVpn ?: (saved.tunnelTransport == TunnelTransport.WIREGUARD)
|
val isVpn = userPickedVpn ?: (saved.tunnelTransport == TunnelTransport.WIREGUARD)
|
||||||
|
|
||||||
@@ -181,7 +182,7 @@ fun ConnectionModeScreen(
|
|||||||
title = { Text(stringResource(R.string.connection_mode_title)) },
|
title = { Text(stringResource(R.string.connection_mode_title)) },
|
||||||
navigationIcon = {
|
navigationIcon = {
|
||||||
if (onBack != null) {
|
if (onBack != null) {
|
||||||
IconButton(onClick = onBack) {
|
IconButton(shapes = IconButtonDefaults.shapes(), onClick = onBack) {
|
||||||
Icon(
|
Icon(
|
||||||
painterResource(R.drawable.arrow_back_24px),
|
painterResource(R.drawable.arrow_back_24px),
|
||||||
contentDescription = stringResource(R.string.back)
|
contentDescription = stringResource(R.string.back)
|
||||||
@@ -212,30 +213,23 @@ fun ConnectionModeScreen(
|
|||||||
.padding(horizontal = Spacing.lg, vertical = Spacing.md),
|
.padding(horizontal = Spacing.lg, vertical = Spacing.md),
|
||||||
verticalArrangement = Arrangement.spacedBy(Spacing.lg)
|
verticalArrangement = Arrangement.spacedBy(Spacing.lg)
|
||||||
) {
|
) {
|
||||||
SingleChoiceSegmentedButtonRow(modifier = Modifier.fillMaxWidth()) {
|
ConnectedChoiceRow(
|
||||||
SegmentedButton(
|
options = listOf(
|
||||||
selected = !isVpn,
|
ChoiceOption(false, stringResource(R.string.mode_proxy)),
|
||||||
onClick = {
|
ChoiceOption(true, stringResource(R.string.mode_vpn))
|
||||||
HapticUtil.perform(context, HapticUtil.Pattern.TOGGLE_ON)
|
),
|
||||||
userPickedVpn = false
|
|
||||||
persistWg(vpn = false)
|
|
||||||
},
|
|
||||||
shape = SegmentedButtonDefaults.itemShape(index = 0, count = 2)
|
|
||||||
) { Text(stringResource(R.string.mode_proxy)) }
|
|
||||||
SegmentedButton(
|
|
||||||
selected = isVpn,
|
selected = isVpn,
|
||||||
onClick = {
|
onSelect = { vpn ->
|
||||||
HapticUtil.perform(context, HapticUtil.Pattern.TOGGLE_ON)
|
userPickedVpn = vpn
|
||||||
userPickedVpn = true
|
persistWg(vpn = vpn)
|
||||||
persistWg(vpn = true)
|
if (vpn) {
|
||||||
// Встроенный туннель живёт только поверх udp: иначе сервер
|
// Встроенный туннель живёт только поверх udp: иначе сервер
|
||||||
// остался бы поднят в tcp и отклонял бы наши сессии.
|
// остался бы поднят в tcp и отклонял бы наши сессии.
|
||||||
isTcp = false
|
isTcp = false
|
||||||
if (savedOpts.tcpMode) serverConfigViewModel.setProxyMode(serverId, ProxyMode.UDP)
|
if (savedOpts.tcpMode) serverConfigViewModel.setProxyMode(serverId, ProxyMode.UDP)
|
||||||
},
|
|
||||||
shape = SegmentedButtonDefaults.itemShape(index = 1, count = 2)
|
|
||||||
) { Text(stringResource(R.string.mode_vpn)) }
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
Text(
|
Text(
|
||||||
stringResource(if (isVpn) R.string.mode_vpn_desc else R.string.mode_proxy_desc),
|
stringResource(if (isVpn) R.string.mode_vpn_desc else R.string.mode_proxy_desc),
|
||||||
|
|||||||
@@ -3,28 +3,22 @@
|
|||||||
package com.freeturn.app.ui.screens.connectionmode
|
package com.freeturn.app.ui.screens.connectionmode
|
||||||
|
|
||||||
import androidx.annotation.StringRes
|
import androidx.annotation.StringRes
|
||||||
import androidx.compose.foundation.layout.fillMaxWidth
|
|
||||||
import androidx.compose.foundation.text.KeyboardOptions
|
import androidx.compose.foundation.text.KeyboardOptions
|
||||||
import androidx.compose.material3.DropdownMenuItem
|
|
||||||
import androidx.compose.material3.ExposedDropdownMenu
|
|
||||||
import androidx.compose.material3.ExposedDropdownMenuAnchorType
|
|
||||||
import androidx.compose.material3.ExposedDropdownMenuBox
|
|
||||||
import androidx.compose.material3.ExposedDropdownMenuDefaults
|
|
||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
||||||
import androidx.compose.material3.OutlinedTextField
|
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
import androidx.compose.runtime.mutableStateOf
|
import androidx.compose.runtime.mutableStateOf
|
||||||
import androidx.compose.runtime.remember
|
import androidx.compose.runtime.remember
|
||||||
import androidx.compose.runtime.setValue
|
import androidx.compose.runtime.setValue
|
||||||
import androidx.compose.ui.Modifier
|
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
import androidx.compose.ui.text.input.KeyboardType
|
import androidx.compose.ui.text.input.KeyboardType
|
||||||
import com.freeturn.app.R
|
import com.freeturn.app.R
|
||||||
import com.freeturn.app.data.config.KcpPreset
|
import com.freeturn.app.data.config.KcpPreset
|
||||||
import com.freeturn.app.data.config.KcpProfile
|
import com.freeturn.app.data.config.KcpProfile
|
||||||
|
import com.freeturn.app.ui.components.ChoiceOption
|
||||||
import com.freeturn.app.ui.components.LabeledTextField
|
import com.freeturn.app.ui.components.LabeledTextField
|
||||||
|
import com.freeturn.app.ui.components.OptionDropdown
|
||||||
import com.freeturn.app.ui.components.SectionLabel
|
import com.freeturn.app.ui.components.SectionLabel
|
||||||
import com.freeturn.app.ui.components.SettingsCard
|
import com.freeturn.app.ui.components.SettingsCard
|
||||||
import com.freeturn.app.ui.components.SettingsFieldSlot
|
import com.freeturn.app.ui.components.SettingsFieldSlot
|
||||||
@@ -107,34 +101,12 @@ internal fun KcpCard(profile: KcpProfile, onProfile: (KcpProfile) -> Unit) {
|
|||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
private fun PresetDropdown(preset: String, onPreset: (String) -> Unit) {
|
private fun PresetDropdown(preset: String, onPreset: (String) -> Unit) {
|
||||||
var expanded by remember { mutableStateOf(false) }
|
OptionDropdown(
|
||||||
|
label = stringResource(R.string.kcp_preset_label),
|
||||||
ExposedDropdownMenuBox(
|
options = KcpPreset.VALUES.map { ChoiceOption(it, stringResource(presetLabelRes(it))) },
|
||||||
expanded = expanded,
|
selected = preset,
|
||||||
onExpandedChange = { expanded = !expanded }
|
onSelect = onPreset
|
||||||
) {
|
|
||||||
OutlinedTextField(
|
|
||||||
value = stringResource(presetLabelRes(preset)),
|
|
||||||
onValueChange = {},
|
|
||||||
readOnly = true,
|
|
||||||
label = { Text(stringResource(R.string.kcp_preset_label)) },
|
|
||||||
trailingIcon = { ExposedDropdownMenuDefaults.TrailingIcon(expanded = expanded) },
|
|
||||||
modifier = Modifier
|
|
||||||
.menuAnchor(ExposedDropdownMenuAnchorType.PrimaryNotEditable, true)
|
|
||||||
.fillMaxWidth()
|
|
||||||
)
|
)
|
||||||
ExposedDropdownMenu(expanded = expanded, onDismissRequest = { expanded = false }) {
|
|
||||||
KcpPreset.VALUES.forEach { value ->
|
|
||||||
DropdownMenuItem(
|
|
||||||
text = { Text(stringResource(presetLabelRes(value))) },
|
|
||||||
onClick = {
|
|
||||||
expanded = false
|
|
||||||
onPreset(value)
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@StringRes
|
@StringRes
|
||||||
|
|||||||
@@ -97,6 +97,7 @@ internal fun HomeEmptyState(
|
|||||||
)
|
)
|
||||||
Spacer(Modifier.height(24.dp))
|
Spacer(Modifier.height(24.dp))
|
||||||
Button(
|
Button(
|
||||||
|
shapes = ButtonDefaults.shapes(),
|
||||||
onClick = onAddServer,
|
onClick = onAddServer,
|
||||||
contentPadding = ButtonDefaults.ButtonWithIconContentPadding
|
contentPadding = ButtonDefaults.ButtonWithIconContentPadding
|
||||||
) {
|
) {
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import androidx.compose.foundation.layout.Spacer
|
|||||||
import androidx.compose.foundation.layout.fillMaxWidth
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
import androidx.compose.foundation.layout.height
|
import androidx.compose.foundation.layout.height
|
||||||
import androidx.compose.material3.AlertDialog
|
import androidx.compose.material3.AlertDialog
|
||||||
|
import androidx.compose.material3.ButtonDefaults
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.material3.TextButton
|
import androidx.compose.material3.TextButton
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
@@ -47,14 +48,14 @@ internal fun UpdateDialogs(
|
|||||||
title = { Text(stringResource(R.string.update_available_title)) },
|
title = { Text(stringResource(R.string.update_available_title)) },
|
||||||
text = { Text(stringResource(R.string.update_available, state.version)) },
|
text = { Text(stringResource(R.string.update_available, state.version)) },
|
||||||
confirmButton = {
|
confirmButton = {
|
||||||
TextButton(onClick = {
|
TextButton(shapes = ButtonDefaults.shapes(), onClick = {
|
||||||
HapticUtil.perform(context, HapticUtil.Pattern.CLICK)
|
HapticUtil.perform(context, HapticUtil.Pattern.CLICK)
|
||||||
dismissedVersion = state.version
|
dismissedVersion = state.version
|
||||||
onDownload()
|
onDownload()
|
||||||
}) { Text(stringResource(R.string.update_download)) }
|
}) { Text(stringResource(R.string.update_download)) }
|
||||||
},
|
},
|
||||||
dismissButton = {
|
dismissButton = {
|
||||||
TextButton(onClick = { dismissedVersion = state.version }) {
|
TextButton(shapes = ButtonDefaults.shapes(), onClick = { dismissedVersion = state.version }) {
|
||||||
Text(stringResource(R.string.cancel))
|
Text(stringResource(R.string.cancel))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -82,13 +83,13 @@ internal fun UpdateDialogs(
|
|||||||
title = { Text(stringResource(R.string.update_ready_title)) },
|
title = { Text(stringResource(R.string.update_ready_title)) },
|
||||||
text = { Text(stringResource(R.string.update_ready_desc)) },
|
text = { Text(stringResource(R.string.update_ready_desc)) },
|
||||||
confirmButton = {
|
confirmButton = {
|
||||||
TextButton(onClick = {
|
TextButton(shapes = ButtonDefaults.shapes(), onClick = {
|
||||||
HapticUtil.perform(context, HapticUtil.Pattern.CLICK)
|
HapticUtil.perform(context, HapticUtil.Pattern.CLICK)
|
||||||
onInstall()
|
onInstall()
|
||||||
}) { Text(stringResource(R.string.update_install)) }
|
}) { Text(stringResource(R.string.update_install)) }
|
||||||
},
|
},
|
||||||
dismissButton = {
|
dismissButton = {
|
||||||
TextButton(onClick = onReset) {
|
TextButton(shapes = ButtonDefaults.shapes(), onClick = onReset) {
|
||||||
Text(stringResource(R.string.cancel))
|
Text(stringResource(R.string.cancel))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,26 +1,12 @@
|
|||||||
@file:OptIn(androidx.compose.material3.ExperimentalMaterial3Api::class)
|
|
||||||
|
|
||||||
package com.freeturn.app.ui.screens.splittunnel
|
package com.freeturn.app.ui.screens.splittunnel
|
||||||
|
|
||||||
import androidx.compose.foundation.layout.fillMaxWidth
|
|
||||||
import androidx.compose.material3.DropdownMenuItem
|
|
||||||
import androidx.compose.material3.ExposedDropdownMenu
|
|
||||||
import androidx.compose.material3.ExposedDropdownMenuAnchorType
|
|
||||||
import androidx.compose.material3.ExposedDropdownMenuBox
|
|
||||||
import androidx.compose.material3.ExposedDropdownMenuDefaults
|
|
||||||
import androidx.compose.material3.OutlinedTextField
|
|
||||||
import androidx.compose.material3.Text
|
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.getValue
|
|
||||||
import androidx.compose.runtime.mutableStateOf
|
|
||||||
import androidx.compose.runtime.remember
|
|
||||||
import androidx.compose.runtime.setValue
|
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.platform.LocalContext
|
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
import com.freeturn.app.R
|
import com.freeturn.app.R
|
||||||
import com.freeturn.app.data.config.SplitTunnelMode
|
import com.freeturn.app.data.config.SplitTunnelMode
|
||||||
import com.freeturn.app.ui.util.HapticUtil
|
import com.freeturn.app.ui.components.ChoiceOption
|
||||||
|
import com.freeturn.app.ui.components.OptionDropdown
|
||||||
|
|
||||||
/** Выбор режима split-tunnel: include / exclude. */
|
/** Выбор режима split-tunnel: include / exclude. */
|
||||||
@Composable
|
@Composable
|
||||||
@@ -30,42 +16,16 @@ internal fun ModeDropdown(
|
|||||||
onSelect: (String) -> Unit,
|
onSelect: (String) -> Unit,
|
||||||
modifier: Modifier = Modifier
|
modifier: Modifier = Modifier
|
||||||
) {
|
) {
|
||||||
val context = LocalContext.current
|
OptionDropdown(
|
||||||
var expanded by remember { mutableStateOf(false) }
|
label = stringResource(R.string.split_tunnel_mode_label),
|
||||||
val options = listOf(
|
options = listOf(
|
||||||
SplitTunnelMode.INCLUDE to stringResource(R.string.split_tunnel_mode_include),
|
ChoiceOption(SplitTunnelMode.INCLUDE, stringResource(R.string.split_tunnel_mode_include)),
|
||||||
SplitTunnelMode.EXCLUDE to stringResource(R.string.split_tunnel_mode_exclude)
|
ChoiceOption(SplitTunnelMode.EXCLUDE, stringResource(R.string.split_tunnel_mode_exclude))
|
||||||
)
|
),
|
||||||
val current = options.firstOrNull { it.first == mode }?.second.orEmpty()
|
selected = mode,
|
||||||
|
onSelect = onSelect,
|
||||||
ExposedDropdownMenuBox(
|
modifier = modifier,
|
||||||
expanded = expanded,
|
|
||||||
onExpandedChange = { if (enabled) expanded = !expanded },
|
|
||||||
modifier = modifier
|
|
||||||
) {
|
|
||||||
OutlinedTextField(
|
|
||||||
value = current,
|
|
||||||
onValueChange = {},
|
|
||||||
readOnly = true,
|
|
||||||
enabled = enabled,
|
enabled = enabled,
|
||||||
minLines = 2,
|
minLines = 2
|
||||||
label = { Text(stringResource(R.string.split_tunnel_mode_label)) },
|
|
||||||
trailingIcon = { ExposedDropdownMenuDefaults.TrailingIcon(expanded = expanded) },
|
|
||||||
modifier = Modifier
|
|
||||||
.menuAnchor(ExposedDropdownMenuAnchorType.PrimaryNotEditable, enabled)
|
|
||||||
.fillMaxWidth()
|
|
||||||
)
|
|
||||||
ExposedDropdownMenu(expanded = expanded, onDismissRequest = { expanded = false }) {
|
|
||||||
options.forEach { (value, label) ->
|
|
||||||
DropdownMenuItem(
|
|
||||||
text = { Text(label) },
|
|
||||||
onClick = {
|
|
||||||
HapticUtil.perform(context, HapticUtil.Pattern.SELECTION)
|
|
||||||
expanded = false
|
|
||||||
onSelect(value)
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -13,13 +13,19 @@ import androidx.compose.foundation.layout.fillMaxWidth
|
|||||||
import androidx.compose.foundation.layout.height
|
import androidx.compose.foundation.layout.height
|
||||||
import androidx.compose.foundation.layout.navigationBarsPadding
|
import androidx.compose.foundation.layout.navigationBarsPadding
|
||||||
import androidx.compose.foundation.layout.padding
|
import androidx.compose.foundation.layout.padding
|
||||||
|
import androidx.compose.foundation.text.KeyboardOptions
|
||||||
import androidx.compose.material3.BottomSheetDefaults
|
import androidx.compose.material3.BottomSheetDefaults
|
||||||
import androidx.compose.material3.Icon
|
import androidx.compose.material3.Icon
|
||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
||||||
import androidx.compose.material3.ModalBottomSheet
|
import androidx.compose.material3.ModalBottomSheet
|
||||||
import androidx.compose.material3.OutlinedTextField
|
import androidx.compose.material3.IconButton
|
||||||
|
import androidx.compose.material3.IconButtonDefaults
|
||||||
|
import androidx.compose.material3.SearchBarDefaults
|
||||||
|
import androidx.compose.material3.TextField
|
||||||
|
import androidx.compose.material3.TextFieldDefaults
|
||||||
import androidx.compose.material3.SheetValue
|
import androidx.compose.material3.SheetValue
|
||||||
import androidx.compose.material3.Switch
|
import androidx.compose.material3.Switch
|
||||||
|
import com.freeturn.app.ui.components.SwitchThumbIcon
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.material3.rememberBottomSheetState
|
import androidx.compose.material3.rememberBottomSheetState
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
@@ -34,6 +40,7 @@ import androidx.compose.ui.graphics.Color
|
|||||||
import androidx.compose.ui.platform.LocalContext
|
import androidx.compose.ui.platform.LocalContext
|
||||||
import androidx.compose.ui.res.painterResource
|
import androidx.compose.ui.res.painterResource
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
|
import androidx.compose.ui.text.input.ImeAction
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import com.freeturn.app.R
|
import com.freeturn.app.R
|
||||||
import com.freeturn.app.data.config.SplitTunnelMode
|
import com.freeturn.app.data.config.SplitTunnelMode
|
||||||
@@ -123,6 +130,7 @@ fun SplitTunnelSheetContent(
|
|||||||
Switch(
|
Switch(
|
||||||
checked = splitOn,
|
checked = splitOn,
|
||||||
enabled = !locked,
|
enabled = !locked,
|
||||||
|
thumbContent = { SwitchThumbIcon(splitOn) },
|
||||||
onCheckedChange = { on ->
|
onCheckedChange = { on ->
|
||||||
HapticUtil.perform(context, HapticUtil.Pattern.SELECTION)
|
HapticUtil.perform(context, HapticUtil.Pattern.SELECTION)
|
||||||
onModeChange(if (on) modeChoice else SplitTunnelMode.ALL)
|
onModeChange(if (on) modeChoice else SplitTunnelMode.ALL)
|
||||||
@@ -156,17 +164,38 @@ fun SplitTunnelSheetContent(
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
OutlinedTextField(
|
val searchContainer = MaterialTheme.colorScheme.surfaceContainerHighest
|
||||||
|
TextField(
|
||||||
value = query,
|
value = query,
|
||||||
onValueChange = { query = it },
|
onValueChange = { query = it },
|
||||||
enabled = controlsEnabled,
|
enabled = controlsEnabled,
|
||||||
singleLine = true,
|
singleLine = true,
|
||||||
|
shape = SearchBarDefaults.inputFieldShape,
|
||||||
|
colors = TextFieldDefaults.colors(
|
||||||
|
focusedContainerColor = searchContainer,
|
||||||
|
unfocusedContainerColor = searchContainer,
|
||||||
|
disabledContainerColor = searchContainer,
|
||||||
|
focusedIndicatorColor = Color.Transparent,
|
||||||
|
unfocusedIndicatorColor = Color.Transparent,
|
||||||
|
disabledIndicatorColor = Color.Transparent
|
||||||
|
),
|
||||||
|
keyboardOptions = KeyboardOptions(imeAction = ImeAction.Search),
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
.padding(horizontal = HorizontalPadding),
|
.padding(horizontal = HorizontalPadding),
|
||||||
label = { Text(stringResource(R.string.split_tunnel_search)) },
|
placeholder = { Text(stringResource(R.string.split_tunnel_search)) },
|
||||||
leadingIcon = {
|
leadingIcon = {
|
||||||
Icon(painterResource(R.drawable.search_24px), null)
|
Icon(painterResource(R.drawable.search_24px), null)
|
||||||
|
},
|
||||||
|
trailingIcon = {
|
||||||
|
if (query.isNotEmpty()) {
|
||||||
|
IconButton(shapes = IconButtonDefaults.shapes(), onClick = { query = "" }) {
|
||||||
|
Icon(
|
||||||
|
painterResource(R.drawable.close_24px),
|
||||||
|
contentDescription = stringResource(R.string.clear)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
package com.freeturn.app.ui.util
|
package com.freeturn.app.ui.util
|
||||||
|
|
||||||
|
import androidx.compose.foundation.LocalIndication
|
||||||
import androidx.compose.foundation.clickable
|
import androidx.compose.foundation.clickable
|
||||||
|
import androidx.compose.foundation.interaction.MutableInteractionSource
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.platform.LocalContext
|
import androidx.compose.ui.platform.LocalContext
|
||||||
@@ -8,15 +10,21 @@ import androidx.compose.ui.platform.LocalContext
|
|||||||
/**
|
/**
|
||||||
* Кликабельность с тактильным откликом. Унифицирует haptic feedback для всех
|
* Кликабельность с тактильным откликом. Унифицирует haptic feedback для всех
|
||||||
* интерактивных элементов вне Material-компонентов (которые могут иметь свой).
|
* интерактивных элементов вне Material-компонентов (которые могут иметь свой).
|
||||||
|
* [interactionSource] - чтобы дочерние элементы реагировали на нажатие строки.
|
||||||
*/
|
*/
|
||||||
@Composable
|
@Composable
|
||||||
fun Modifier.hapticClickable(
|
fun Modifier.hapticClickable(
|
||||||
pattern: HapticUtil.Pattern = HapticUtil.Pattern.CLICK,
|
pattern: HapticUtil.Pattern = HapticUtil.Pattern.CLICK,
|
||||||
enabled: Boolean = true,
|
enabled: Boolean = true,
|
||||||
|
interactionSource: MutableInteractionSource? = null,
|
||||||
onClick: () -> Unit
|
onClick: () -> Unit
|
||||||
): Modifier {
|
): Modifier {
|
||||||
val context = LocalContext.current
|
val context = LocalContext.current
|
||||||
return clickable(enabled = enabled) {
|
return clickable(
|
||||||
|
interactionSource = interactionSource,
|
||||||
|
indication = LocalIndication.current,
|
||||||
|
enabled = enabled
|
||||||
|
) {
|
||||||
HapticUtil.perform(context, pattern)
|
HapticUtil.perform(context, pattern)
|
||||||
onClick()
|
onClick()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,10 @@
|
|||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="24dp"
|
||||||
|
android:height="24dp"
|
||||||
|
android:viewportWidth="960"
|
||||||
|
android:viewportHeight="960"
|
||||||
|
android:tint="?attr/colorControlNormal">
|
||||||
|
<path
|
||||||
|
android:fillColor="@android:color/white"
|
||||||
|
android:pathData="M382,720L154,492L211,435L382,606L749,239L806,296L382,720Z"/>
|
||||||
|
</vector>
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="24dp"
|
||||||
|
android:height="24dp"
|
||||||
|
android:viewportWidth="960"
|
||||||
|
android:viewportHeight="960"
|
||||||
|
android:tint="?attr/colorControlNormal">
|
||||||
|
<path
|
||||||
|
android:fillColor="@android:color/white"
|
||||||
|
android:pathData="M256,760L200,704L424,480L200,256L256,200L480,424L704,200L760,256L536,480L760,704L704,760L480,536L256,760Z"/>
|
||||||
|
</vector>
|
||||||
Reference in new issue
Block a user