feat(ui): M3 Expressive - connected button group, меню с выбором, морф кнопок и иконок
Общие ConnectedChoiceRow и OptionDropdown вместо SegmentedButton и пяти копий меню; иконки на бегунке свитча, строка поиска, пружины motionScheme.
This commit is contained in:
1 parent
66fb675bd2
commit
deb37d6c2b
20 files changed
+423
-217
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.text.KeyboardOptions
|
||||
import androidx.compose.material3.AlertDialog
|
||||
import androidx.compose.material3.ButtonDefaults
|
||||
import androidx.compose.material3.OutlinedTextField
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TextButton
|
||||
@@ -82,7 +83,7 @@ fun BackupPasswordDialog(
|
||||
}
|
||||
},
|
||||
confirmButton = {
|
||||
TextButton(onClick = {
|
||||
TextButton(shapes = ButtonDefaults.shapes(), onClick = {
|
||||
when {
|
||||
password.isEmpty() -> error = emptyMsg
|
||||
requireConfirmation && password != repeat -> error = mismatchMsg
|
||||
@@ -91,7 +92,7 @@ fun BackupPasswordDialog(
|
||||
}) { Text(confirmLabel) }
|
||||
},
|
||||
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.size
|
||||
import androidx.compose.material3.Button
|
||||
import androidx.compose.material3.ButtonDefaults
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.MaterialShapes
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
@@ -69,7 +70,7 @@ fun EmptyState(
|
||||
)
|
||||
if (actionLabel != null && onAction != null) {
|
||||
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
|
||||
|
||||
import androidx.compose.animation.core.animateFloatAsState
|
||||
import androidx.compose.foundation.LocalIndication
|
||||
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.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
@@ -15,10 +20,12 @@ import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.MaterialShapes
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Slider
|
||||
import androidx.compose.material3.SliderState
|
||||
import androidx.compose.material3.Switch
|
||||
import androidx.compose.material3.SwitchDefaults
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.toShape
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.SideEffect
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableIntStateOf
|
||||
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.semantics.Role
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.graphics.shapes.Morph
|
||||
import com.freeturn.app.R
|
||||
import com.freeturn.app.ui.theme.LocalReducedMotion
|
||||
import com.freeturn.app.ui.theme.Spacing
|
||||
import com.freeturn.app.ui.util.HapticUtil
|
||||
import com.freeturn.app.ui.util.hapticClickable
|
||||
@@ -50,9 +59,12 @@ fun SettingsSliderRow(
|
||||
hint: String? = null
|
||||
) {
|
||||
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)
|
||||
Slider(
|
||||
value = value,
|
||||
state = state,
|
||||
onValueChange = {
|
||||
val newInt = it.roundToInt()
|
||||
if (newInt != lastInt) {
|
||||
@@ -61,7 +73,6 @@ fun SettingsSliderRow(
|
||||
}
|
||||
onValueChange(it)
|
||||
},
|
||||
valueRange = valueRange,
|
||||
modifier = Modifier.fillMaxWidth()
|
||||
)
|
||||
}
|
||||
@@ -80,11 +91,14 @@ fun SettingsSwitchRow(
|
||||
else MaterialTheme.colorScheme.onSurface.copy(alpha = 0.38f)
|
||||
val subtitleColor = if (enabled) MaterialTheme.colorScheme.onSurfaceVariant
|
||||
else MaterialTheme.colorScheme.onSurfaceVariant.copy(alpha = 0.38f)
|
||||
val interactionSource = remember { MutableInteractionSource() }
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.toggleable(
|
||||
value = checked,
|
||||
interactionSource = interactionSource,
|
||||
indication = LocalIndication.current,
|
||||
enabled = enabled,
|
||||
role = Role.Switch,
|
||||
onValueChange = { v ->
|
||||
@@ -99,7 +113,7 @@ fun SettingsSwitchRow(
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
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)) {
|
||||
Text(title, style = MaterialTheme.typography.bodyLarge, color = titleColor)
|
||||
if (subtitle != null) {
|
||||
@@ -107,22 +121,48 @@ fun SettingsSwitchRow(
|
||||
}
|
||||
}
|
||||
// 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
|
||||
fun SettingsRowIcon(
|
||||
iconRes: Int,
|
||||
enabled: Boolean = true,
|
||||
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 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(
|
||||
modifier = Modifier
|
||||
.size(40.dp)
|
||||
.background(container.copy(alpha = alpha), MaterialShapes.Sunny.toShape()),
|
||||
.background(container.copy(alpha = alpha), MorphProgressShape(iconPressMorph, progress)),
|
||||
contentAlignment = Alignment.Center
|
||||
) {
|
||||
Icon(
|
||||
@@ -152,15 +192,27 @@ fun SettingsEntryRow(
|
||||
else MaterialTheme.colorScheme.onSurface.copy(alpha = 0.38f)
|
||||
val subtitleColor = if (enabled) MaterialTheme.colorScheme.onSurfaceVariant
|
||||
else MaterialTheme.colorScheme.onSurfaceVariant.copy(alpha = 0.38f)
|
||||
val interactionSource = remember { MutableInteractionSource() }
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.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),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
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)) {
|
||||
Text(title, style = MaterialTheme.typography.bodyLarge, color = titleColor)
|
||||
if (subtitle != null) {
|
||||
|
||||
@@ -6,6 +6,8 @@ import androidx.compose.foundation.layout.ColumnScope
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.material3.HorizontalDivider
|
||||
import androidx.compose.material3.IconButtonDefaults
|
||||
import androidx.compose.material3.ButtonDefaults
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.IconButton
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
@@ -80,7 +82,7 @@ fun SettingsControlLabel(title: String, desc: String? = null) {
|
||||
|
||||
@Composable
|
||||
fun SettingsBackButton(onBack: () -> Unit) {
|
||||
IconButton(onClick = onBack) {
|
||||
IconButton(shapes = IconButtonDefaults.shapes(), onClick = onBack) {
|
||||
Icon(
|
||||
painterResource(R.drawable.arrow_back_24px),
|
||||
contentDescription = stringResource(R.string.back)
|
||||
|
||||
@@ -2,15 +2,14 @@
|
||||
|
||||
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.heightIn
|
||||
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.IconButtonDefaults
|
||||
import androidx.compose.material3.ButtonDefaults
|
||||
import androidx.compose.material3.IconButton
|
||||
import androidx.compose.material3.OutlinedTextField
|
||||
import androidx.compose.material3.Text
|
||||
@@ -30,6 +29,7 @@ import androidx.compose.ui.text.input.VisualTransformation
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.freeturn.app.R
|
||||
import com.freeturn.app.data.config.SshConfig
|
||||
import com.freeturn.app.ui.theme.Spacing
|
||||
import com.freeturn.app.ui.util.HapticUtil
|
||||
|
||||
@Composable
|
||||
@@ -95,7 +95,7 @@ fun SshFormFields(
|
||||
}
|
||||
SettingsRowDivider()
|
||||
SettingsFieldSlot {
|
||||
AuthMethodDropdown(
|
||||
AuthMethodChoice(
|
||||
authType = authType,
|
||||
onAuthTypeChange = onAuthTypeChange
|
||||
)
|
||||
@@ -115,7 +115,7 @@ fun SshFormFields(
|
||||
} else null,
|
||||
visualTransformation = if (showPassword) VisualTransformation.None else PasswordVisualTransformation(),
|
||||
trailingIcon = {
|
||||
IconButton(onClick = {
|
||||
IconButton(shapes = IconButtonDefaults.shapes(), onClick = {
|
||||
HapticUtil.perform(context, HapticUtil.Pattern.SELECTION)
|
||||
showPassword = !showPassword
|
||||
}) {
|
||||
@@ -159,7 +159,7 @@ fun SshFormFields(
|
||||
singleLine = true,
|
||||
visualTransformation = if (showSudoPw) VisualTransformation.None else PasswordVisualTransformation(),
|
||||
trailingIcon = {
|
||||
IconButton(onClick = {
|
||||
IconButton(shapes = IconButtonDefaults.shapes(), onClick = {
|
||||
HapticUtil.perform(context, HapticUtil.Pattern.SELECTION)
|
||||
showSudoPw = !showSudoPw
|
||||
}) {
|
||||
@@ -180,47 +180,19 @@ fun SshFormFields(
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun AuthMethodDropdown(
|
||||
private fun AuthMethodChoice(
|
||||
authType: String,
|
||||
onAuthTypeChange: (String) -> Unit
|
||||
) {
|
||||
val context = LocalContext.current
|
||||
var expanded by remember { mutableStateOf(false) }
|
||||
val options = listOf(
|
||||
SshConfig.AUTH_PASSWORD to stringResource(R.string.password),
|
||||
SshConfig.AUTH_SSH_KEY to stringResource(R.string.private_key)
|
||||
)
|
||||
val current = options.firstOrNull { it.first == authType }?.second.orEmpty()
|
||||
|
||||
ExposedDropdownMenuBox(
|
||||
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()
|
||||
Column(verticalArrangement = Arrangement.spacedBy(Spacing.sm)) {
|
||||
SettingsControlLabel(stringResource(R.string.auth_method_label))
|
||||
ConnectedChoiceRow(
|
||||
options = listOf(
|
||||
ChoiceOption(SshConfig.AUTH_PASSWORD, stringResource(R.string.password)),
|
||||
ChoiceOption(SshConfig.AUTH_SSH_KEY, stringResource(R.string.private_key))
|
||||
),
|
||||
selected = authType,
|
||||
onSelect = onAuthTypeChange
|
||||
)
|
||||
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.Column
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
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.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
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.ui.util.HapticUtil
|
||||
import com.freeturn.app.ui.theme.Spacing
|
||||
|
||||
/**
|
||||
* Выбор проброса UDP/TCP. [label] обязателен - без него сегменты озвучиваются как "1 из 2"
|
||||
* без предмета выбора; [tcpDisabledReason] уходит и под группу, и в stateDescription.
|
||||
*/
|
||||
@Composable
|
||||
fun UdpTcpSegmented(
|
||||
tcp: Boolean,
|
||||
@@ -30,30 +18,16 @@ fun UdpTcpSegmented(
|
||||
modifier: Modifier = Modifier,
|
||||
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)) {
|
||||
SettingsControlLabel(label)
|
||||
SingleChoiceSegmentedButtonRow(modifier = Modifier.fillMaxWidth()) {
|
||||
SegmentedButton(
|
||||
selected = !tcp,
|
||||
onClick = { pick(false) },
|
||||
shape = SegmentedButtonDefaults.itemShape(index = 0, count = 2)
|
||||
) { Text(stringResource(R.string.udp)) }
|
||||
SegmentedButton(
|
||||
selected = tcp,
|
||||
onClick = { pick(true) },
|
||||
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)) }
|
||||
}
|
||||
ConnectedChoiceRow(
|
||||
options = listOf(
|
||||
ChoiceOption(false, stringResource(R.string.udp)),
|
||||
ChoiceOption(true, stringResource(R.string.tcp), disabledReason = tcpDisabledReason)
|
||||
),
|
||||
selected = tcp,
|
||||
onSelect = onTcp
|
||||
)
|
||||
if (tcpDisabledReason != null) {
|
||||
Text(
|
||||
tcpDisabledReason,
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.freeturn.app.ui.screens.addserver
|
||||
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.material3.AlertDialog
|
||||
import androidx.compose.material3.ButtonDefaults
|
||||
import androidx.compose.material3.OutlinedTextField
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TextButton
|
||||
@@ -38,6 +39,7 @@ internal fun ManualNameDialog(
|
||||
},
|
||||
confirmButton = {
|
||||
TextButton(
|
||||
shapes = ButtonDefaults.shapes(),
|
||||
onClick = {
|
||||
HapticUtil.perform(context, HapticUtil.Pattern.CLICK)
|
||||
onCreate(name)
|
||||
@@ -46,7 +48,7 @@ internal fun ManualNameDialog(
|
||||
) { Text(stringResource(R.string.add_manual_create)) }
|
||||
},
|
||||
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.shape.CircleShape
|
||||
import androidx.compose.material3.Button
|
||||
import androidx.compose.material3.ButtonDefaults
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Surface
|
||||
@@ -48,7 +49,7 @@ internal fun PasteLinkField(onPaste: () -> Unit) {
|
||||
overflow = TextOverflow.Ellipsis,
|
||||
modifier = Modifier.weight(1f)
|
||||
)
|
||||
Button(onClick = {
|
||||
Button(shapes = ButtonDefaults.shapes(), onClick = {
|
||||
HapticUtil.perform(context, HapticUtil.Pattern.CLICK)
|
||||
onPaste()
|
||||
}) {
|
||||
|
||||
+19
-25
@@ -20,13 +20,12 @@ import androidx.compose.foundation.layout.widthIn
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.IconButtonDefaults
|
||||
import androidx.compose.material3.ButtonDefaults
|
||||
import androidx.compose.material3.IconButton
|
||||
import androidx.compose.material3.LargeFlexibleTopAppBar
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
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.TopAppBarDefaults
|
||||
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.ui.util.HapticUtil
|
||||
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.InlineNoticeCard
|
||||
import com.freeturn.app.ui.components.SectionLabel
|
||||
@@ -97,7 +98,7 @@ fun ConnectionModeScreen(
|
||||
val context = LocalContext.current
|
||||
val scope = rememberCoroutineScope()
|
||||
|
||||
// userPickedVpn сохраняет выбор на время сессии (чтобы сегмент не мигал).
|
||||
// userPickedVpn сохраняет выбор на время сессии (чтобы выбор не мигал).
|
||||
var userPickedVpn by remember(serverId, saved.tunnelTransport) { mutableStateOf<Boolean?>(null) }
|
||||
val isVpn = userPickedVpn ?: (saved.tunnelTransport == TunnelTransport.WIREGUARD)
|
||||
|
||||
@@ -181,7 +182,7 @@ fun ConnectionModeScreen(
|
||||
title = { Text(stringResource(R.string.connection_mode_title)) },
|
||||
navigationIcon = {
|
||||
if (onBack != null) {
|
||||
IconButton(onClick = onBack) {
|
||||
IconButton(shapes = IconButtonDefaults.shapes(), onClick = onBack) {
|
||||
Icon(
|
||||
painterResource(R.drawable.arrow_back_24px),
|
||||
contentDescription = stringResource(R.string.back)
|
||||
@@ -212,30 +213,23 @@ fun ConnectionModeScreen(
|
||||
.padding(horizontal = Spacing.lg, vertical = Spacing.md),
|
||||
verticalArrangement = Arrangement.spacedBy(Spacing.lg)
|
||||
) {
|
||||
SingleChoiceSegmentedButtonRow(modifier = Modifier.fillMaxWidth()) {
|
||||
SegmentedButton(
|
||||
selected = !isVpn,
|
||||
onClick = {
|
||||
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,
|
||||
onClick = {
|
||||
HapticUtil.perform(context, HapticUtil.Pattern.TOGGLE_ON)
|
||||
userPickedVpn = true
|
||||
persistWg(vpn = true)
|
||||
ConnectedChoiceRow(
|
||||
options = listOf(
|
||||
ChoiceOption(false, stringResource(R.string.mode_proxy)),
|
||||
ChoiceOption(true, stringResource(R.string.mode_vpn))
|
||||
),
|
||||
selected = isVpn,
|
||||
onSelect = { vpn ->
|
||||
userPickedVpn = vpn
|
||||
persistWg(vpn = vpn)
|
||||
if (vpn) {
|
||||
// Встроенный туннель живёт только поверх udp: иначе сервер
|
||||
// остался бы поднят в tcp и отклонял бы наши сессии.
|
||||
isTcp = false
|
||||
if (savedOpts.tcpMode) serverConfigViewModel.setProxyMode(serverId, ProxyMode.UDP)
|
||||
},
|
||||
shape = SegmentedButtonDefaults.itemShape(index = 1, count = 2)
|
||||
) { Text(stringResource(R.string.mode_vpn)) }
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
Text(
|
||||
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
|
||||
|
||||
import androidx.annotation.StringRes
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
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.OutlinedTextField
|
||||
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.res.stringResource
|
||||
import androidx.compose.ui.text.input.KeyboardType
|
||||
import com.freeturn.app.R
|
||||
import com.freeturn.app.data.config.KcpPreset
|
||||
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.OptionDropdown
|
||||
import com.freeturn.app.ui.components.SectionLabel
|
||||
import com.freeturn.app.ui.components.SettingsCard
|
||||
import com.freeturn.app.ui.components.SettingsFieldSlot
|
||||
@@ -107,34 +101,12 @@ internal fun KcpCard(profile: KcpProfile, onProfile: (KcpProfile) -> Unit) {
|
||||
|
||||
@Composable
|
||||
private fun PresetDropdown(preset: String, onPreset: (String) -> Unit) {
|
||||
var expanded by remember { mutableStateOf(false) }
|
||||
|
||||
ExposedDropdownMenuBox(
|
||||
expanded = expanded,
|
||||
onExpandedChange = { expanded = !expanded }
|
||||
) {
|
||||
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)
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
OptionDropdown(
|
||||
label = stringResource(R.string.kcp_preset_label),
|
||||
options = KcpPreset.VALUES.map { ChoiceOption(it, stringResource(presetLabelRes(it))) },
|
||||
selected = preset,
|
||||
onSelect = onPreset
|
||||
)
|
||||
}
|
||||
|
||||
@StringRes
|
||||
|
||||
@@ -97,6 +97,7 @@ internal fun HomeEmptyState(
|
||||
)
|
||||
Spacer(Modifier.height(24.dp))
|
||||
Button(
|
||||
shapes = ButtonDefaults.shapes(),
|
||||
onClick = onAddServer,
|
||||
contentPadding = ButtonDefaults.ButtonWithIconContentPadding
|
||||
) {
|
||||
|
||||
@@ -7,6 +7,7 @@ import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.material3.AlertDialog
|
||||
import androidx.compose.material3.ButtonDefaults
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TextButton
|
||||
import androidx.compose.runtime.Composable
|
||||
@@ -47,14 +48,14 @@ internal fun UpdateDialogs(
|
||||
title = { Text(stringResource(R.string.update_available_title)) },
|
||||
text = { Text(stringResource(R.string.update_available, state.version)) },
|
||||
confirmButton = {
|
||||
TextButton(onClick = {
|
||||
TextButton(shapes = ButtonDefaults.shapes(), onClick = {
|
||||
HapticUtil.perform(context, HapticUtil.Pattern.CLICK)
|
||||
dismissedVersion = state.version
|
||||
onDownload()
|
||||
}) { Text(stringResource(R.string.update_download)) }
|
||||
},
|
||||
dismissButton = {
|
||||
TextButton(onClick = { dismissedVersion = state.version }) {
|
||||
TextButton(shapes = ButtonDefaults.shapes(), onClick = { dismissedVersion = state.version }) {
|
||||
Text(stringResource(R.string.cancel))
|
||||
}
|
||||
}
|
||||
@@ -82,13 +83,13 @@ internal fun UpdateDialogs(
|
||||
title = { Text(stringResource(R.string.update_ready_title)) },
|
||||
text = { Text(stringResource(R.string.update_ready_desc)) },
|
||||
confirmButton = {
|
||||
TextButton(onClick = {
|
||||
TextButton(shapes = ButtonDefaults.shapes(), onClick = {
|
||||
HapticUtil.perform(context, HapticUtil.Pattern.CLICK)
|
||||
onInstall()
|
||||
}) { Text(stringResource(R.string.update_install)) }
|
||||
},
|
||||
dismissButton = {
|
||||
TextButton(onClick = onReset) {
|
||||
TextButton(shapes = ButtonDefaults.shapes(), onClick = onReset) {
|
||||
Text(stringResource(R.string.cancel))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,26 +1,12 @@
|
||||
@file:OptIn(androidx.compose.material3.ExperimentalMaterial3Api::class)
|
||||
|
||||
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.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.stringResource
|
||||
import com.freeturn.app.R
|
||||
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. */
|
||||
@Composable
|
||||
@@ -30,42 +16,16 @@ internal fun ModeDropdown(
|
||||
onSelect: (String) -> Unit,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
val context = LocalContext.current
|
||||
var expanded by remember { mutableStateOf(false) }
|
||||
val options = listOf(
|
||||
SplitTunnelMode.INCLUDE to stringResource(R.string.split_tunnel_mode_include),
|
||||
SplitTunnelMode.EXCLUDE to stringResource(R.string.split_tunnel_mode_exclude)
|
||||
OptionDropdown(
|
||||
label = stringResource(R.string.split_tunnel_mode_label),
|
||||
options = listOf(
|
||||
ChoiceOption(SplitTunnelMode.INCLUDE, stringResource(R.string.split_tunnel_mode_include)),
|
||||
ChoiceOption(SplitTunnelMode.EXCLUDE, stringResource(R.string.split_tunnel_mode_exclude))
|
||||
),
|
||||
selected = mode,
|
||||
onSelect = onSelect,
|
||||
modifier = modifier,
|
||||
enabled = enabled,
|
||||
minLines = 2
|
||||
)
|
||||
val current = options.firstOrNull { it.first == mode }?.second.orEmpty()
|
||||
|
||||
ExposedDropdownMenuBox(
|
||||
expanded = expanded,
|
||||
onExpandedChange = { if (enabled) expanded = !expanded },
|
||||
modifier = modifier
|
||||
) {
|
||||
OutlinedTextField(
|
||||
value = current,
|
||||
onValueChange = {},
|
||||
readOnly = true,
|
||||
enabled = enabled,
|
||||
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.navigationBarsPadding
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.text.KeyboardOptions
|
||||
import androidx.compose.material3.BottomSheetDefaults
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
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.Switch
|
||||
import com.freeturn.app.ui.components.SwitchThumbIcon
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.rememberBottomSheetState
|
||||
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.res.painterResource
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.input.ImeAction
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.freeturn.app.R
|
||||
import com.freeturn.app.data.config.SplitTunnelMode
|
||||
@@ -123,6 +130,7 @@ fun SplitTunnelSheetContent(
|
||||
Switch(
|
||||
checked = splitOn,
|
||||
enabled = !locked,
|
||||
thumbContent = { SwitchThumbIcon(splitOn) },
|
||||
onCheckedChange = { on ->
|
||||
HapticUtil.perform(context, HapticUtil.Pattern.SELECTION)
|
||||
onModeChange(if (on) modeChoice else SplitTunnelMode.ALL)
|
||||
@@ -156,17 +164,38 @@ fun SplitTunnelSheetContent(
|
||||
}
|
||||
)
|
||||
|
||||
OutlinedTextField(
|
||||
val searchContainer = MaterialTheme.colorScheme.surfaceContainerHighest
|
||||
TextField(
|
||||
value = query,
|
||||
onValueChange = { query = it },
|
||||
enabled = controlsEnabled,
|
||||
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
|
||||
.fillMaxWidth()
|
||||
.padding(horizontal = HorizontalPadding),
|
||||
label = { Text(stringResource(R.string.split_tunnel_search)) },
|
||||
placeholder = { Text(stringResource(R.string.split_tunnel_search)) },
|
||||
leadingIcon = {
|
||||
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
|
||||
|
||||
import androidx.compose.foundation.LocalIndication
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.interaction.MutableInteractionSource
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
@@ -8,15 +10,21 @@ import androidx.compose.ui.platform.LocalContext
|
||||
/**
|
||||
* Кликабельность с тактильным откликом. Унифицирует haptic feedback для всех
|
||||
* интерактивных элементов вне Material-компонентов (которые могут иметь свой).
|
||||
* [interactionSource] - чтобы дочерние элементы реагировали на нажатие строки.
|
||||
*/
|
||||
@Composable
|
||||
fun Modifier.hapticClickable(
|
||||
pattern: HapticUtil.Pattern = HapticUtil.Pattern.CLICK,
|
||||
enabled: Boolean = true,
|
||||
interactionSource: MutableInteractionSource? = null,
|
||||
onClick: () -> Unit
|
||||
): Modifier {
|
||||
val context = LocalContext.current
|
||||
return clickable(enabled = enabled) {
|
||||
return clickable(
|
||||
interactionSource = interactionSource,
|
||||
indication = LocalIndication.current,
|
||||
enabled = enabled
|
||||
) {
|
||||
HapticUtil.perform(context, pattern)
|
||||
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