feat: add haptic feedback throughout all screens
This commit is contained in:
1 parent
cc00883fb4
commit
2c157e43ec
4 files changed
+84
-15
No files matched your search
@@ -40,14 +40,17 @@ import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableFloatStateOf
|
||||
import androidx.compose.runtime.mutableIntStateOf
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.saveable.rememberSaveable
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||
import com.freeturn.app.data.ClientConfig
|
||||
import com.freeturn.app.ui.HapticUtil
|
||||
import com.freeturn.app.viewmodel.MainViewModel
|
||||
import kotlinx.coroutines.delay
|
||||
|
||||
@@ -67,6 +70,8 @@ fun ClientSetupScreen(
|
||||
val proxyListen by viewModel.proxyListen.collectAsStateWithLifecycle()
|
||||
val customKernelExists by viewModel.customKernelExists.collectAsStateWithLifecycle()
|
||||
|
||||
val context = LocalContext.current
|
||||
|
||||
val kernelPickerLauncher = rememberLauncherForActivityResult(
|
||||
ActivityResultContracts.OpenDocument()
|
||||
) { uri -> uri?.let { viewModel.setCustomKernel(it) } }
|
||||
@@ -78,6 +83,7 @@ fun ClientSetupScreen(
|
||||
var noDtls by rememberSaveable(saved.noDtls) { mutableStateOf(saved.noDtls) }
|
||||
var localPort by rememberSaveable(saved.localPort) { mutableStateOf(saved.localPort) }
|
||||
var showAdvanced by rememberSaveable { mutableStateOf(false) }
|
||||
var lastSliderInt by remember { mutableIntStateOf(saved.threads) }
|
||||
|
||||
// Автозаполнение адреса сервера из SSH-конфига если поле пустое
|
||||
LaunchedEffect(sshConfig.ip, proxyListen) {
|
||||
@@ -165,7 +171,14 @@ fun ClientSetupScreen(
|
||||
}
|
||||
Slider(
|
||||
value = threads,
|
||||
onValueChange = { threads = it },
|
||||
onValueChange = {
|
||||
val newInt = it.toInt()
|
||||
if (newInt != lastSliderInt) {
|
||||
HapticUtil.perform(context, HapticUtil.Pattern.SELECTION)
|
||||
lastSliderInt = newInt
|
||||
}
|
||||
threads = it
|
||||
},
|
||||
valueRange = 1f..8f,
|
||||
steps = 6,
|
||||
modifier = Modifier.fillMaxWidth()
|
||||
@@ -176,14 +189,20 @@ fun ClientSetupScreen(
|
||||
label = "UDP-режим",
|
||||
description = "Снижает задержки и повышает стабильность",
|
||||
checked = useUdp,
|
||||
onCheckedChange = { useUdp = it }
|
||||
onCheckedChange = {
|
||||
HapticUtil.perform(context, if (it) HapticUtil.Pattern.TOGGLE_ON else HapticUtil.Pattern.TOGGLE_OFF)
|
||||
useUdp = it
|
||||
}
|
||||
)
|
||||
|
||||
SwitchRow(
|
||||
label = "Без DTLS-шифрования",
|
||||
description = "Может ускорить соединение, повышает риск блокировки",
|
||||
checked = noDtls,
|
||||
onCheckedChange = { noDtls = it }
|
||||
onCheckedChange = {
|
||||
HapticUtil.perform(context, if (it) HapticUtil.Pattern.TOGGLE_ON else HapticUtil.Pattern.TOGGLE_OFF)
|
||||
noDtls = it
|
||||
}
|
||||
)
|
||||
|
||||
HorizontalDivider(Modifier, DividerDefaults.Thickness, DividerDefaults.color)
|
||||
@@ -194,7 +213,10 @@ fun ClientSetupScreen(
|
||||
colors = CardDefaults.cardColors(
|
||||
containerColor = MaterialTheme.colorScheme.surfaceVariant
|
||||
),
|
||||
onClick = { showAdvanced = !showAdvanced }
|
||||
onClick = {
|
||||
HapticUtil.perform(context, HapticUtil.Pattern.SELECTION)
|
||||
showAdvanced = !showAdvanced
|
||||
}
|
||||
) {
|
||||
Row(
|
||||
modifier = Modifier
|
||||
@@ -262,13 +284,19 @@ fun ClientSetupScreen(
|
||||
Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) {
|
||||
if (customKernelExists) {
|
||||
OutlinedButton(
|
||||
onClick = { viewModel.clearCustomKernel() },
|
||||
onClick = {
|
||||
HapticUtil.perform(context, HapticUtil.Pattern.CLICK)
|
||||
viewModel.clearCustomKernel()
|
||||
},
|
||||
colors = ButtonDefaults.outlinedButtonColors(
|
||||
contentColor = MaterialTheme.colorScheme.error
|
||||
)
|
||||
) { Text("Сбросить") }
|
||||
}
|
||||
Button(onClick = { kernelPickerLauncher.launch(arrayOf("*/*")) }) {
|
||||
Button(onClick = {
|
||||
HapticUtil.perform(context, HapticUtil.Pattern.CLICK)
|
||||
kernelPickerLauncher.launch(arrayOf("*/*"))
|
||||
}) {
|
||||
Text("Загрузить")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,14 +37,17 @@ import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.scale
|
||||
import androidx.compose.ui.graphics.Brush
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.text.style.TextAlign
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.freeturn.app.ui.HapticUtil
|
||||
|
||||
@Composable
|
||||
fun OnboardingScreen(
|
||||
onSetupServer: () -> Unit,
|
||||
onSkip: () -> Unit
|
||||
) {
|
||||
val context = LocalContext.current
|
||||
val infiniteTransition = rememberInfiniteTransition(label = "icon_pulse")
|
||||
val pulseScale by infiniteTransition.animateFloat(
|
||||
initialValue = 1f,
|
||||
@@ -147,7 +150,10 @@ fun OnboardingScreen(
|
||||
horizontalAlignment = Alignment.CenterHorizontally
|
||||
) {
|
||||
Button(
|
||||
onClick = onSetupServer,
|
||||
onClick = {
|
||||
HapticUtil.perform(context, HapticUtil.Pattern.CLICK)
|
||||
onSetupServer()
|
||||
},
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.height(56.dp),
|
||||
@@ -161,7 +167,10 @@ fun OnboardingScreen(
|
||||
|
||||
Spacer(Modifier.height(12.dp))
|
||||
|
||||
TextButton(onClick = onSkip) {
|
||||
TextButton(onClick = {
|
||||
HapticUtil.perform(context, HapticUtil.Pattern.SELECTION)
|
||||
onSkip()
|
||||
}) {
|
||||
Text("Пропустить настройки")
|
||||
}
|
||||
|
||||
|
||||
@@ -45,8 +45,10 @@ import androidx.compose.runtime.saveable.rememberSaveable
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||
import com.freeturn.app.ui.HapticUtil
|
||||
import com.freeturn.app.ui.theme.StatusGreen
|
||||
import com.freeturn.app.viewmodel.MainViewModel
|
||||
import com.freeturn.app.viewmodel.ServerState
|
||||
@@ -67,6 +69,7 @@ fun ServerManagementScreen(
|
||||
var proxyListen by rememberSaveable(savedListen) { mutableStateOf(savedListen) }
|
||||
var proxyConnect by rememberSaveable(savedConnect) { mutableStateOf(savedConnect) }
|
||||
|
||||
val context = LocalContext.current
|
||||
val snackbarHostState = remember { SnackbarHostState() }
|
||||
val isConnected = sshState is SshConnectionState.Connected
|
||||
val isWorking = serverState is ServerState.Working || serverState is ServerState.Checking
|
||||
@@ -158,6 +161,7 @@ fun ServerManagementScreen(
|
||||
// Action buttons
|
||||
FilledTonalButton(
|
||||
onClick = {
|
||||
HapticUtil.perform(context, HapticUtil.Pattern.CLICK)
|
||||
viewModel.saveProxyServerConfig(proxyListen, proxyConnect)
|
||||
viewModel.installServer()
|
||||
},
|
||||
@@ -174,6 +178,7 @@ fun ServerManagementScreen(
|
||||
|
||||
Button(
|
||||
onClick = {
|
||||
HapticUtil.perform(context, HapticUtil.Pattern.CLICK)
|
||||
viewModel.saveProxyServerConfig(proxyListen, proxyConnect)
|
||||
viewModel.startServer()
|
||||
},
|
||||
@@ -190,7 +195,10 @@ fun ServerManagementScreen(
|
||||
}
|
||||
|
||||
OutlinedButton(
|
||||
onClick = { viewModel.stopServer() },
|
||||
onClick = {
|
||||
HapticUtil.perform(context, HapticUtil.Pattern.CLICK)
|
||||
viewModel.stopServer()
|
||||
},
|
||||
enabled = isConnected && !isWorking && serverKnown?.running == true,
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
@@ -208,7 +216,10 @@ fun ServerManagementScreen(
|
||||
if (serverKnown?.running == true) {
|
||||
Spacer(Modifier.height(4.dp))
|
||||
Button(
|
||||
onClick = onContinue,
|
||||
onClick = {
|
||||
HapticUtil.perform(context, HapticUtil.Pattern.CLICK)
|
||||
onContinue()
|
||||
},
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.height(56.dp),
|
||||
|
||||
@@ -48,6 +48,7 @@ import androidx.compose.runtime.saveable.rememberSaveable
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.text.input.KeyboardType
|
||||
import androidx.compose.ui.text.input.PasswordVisualTransformation
|
||||
import androidx.compose.ui.text.input.VisualTransformation
|
||||
@@ -55,6 +56,7 @@ import androidx.compose.ui.text.style.TextAlign
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||
import com.freeturn.app.data.SshConfig
|
||||
import com.freeturn.app.ui.HapticUtil
|
||||
import com.freeturn.app.viewmodel.MainViewModel
|
||||
import com.freeturn.app.viewmodel.SshConnectionState
|
||||
|
||||
@@ -82,13 +84,17 @@ fun SshSetupScreen(
|
||||
}
|
||||
|
||||
val isConnecting = sshState is SshConnectionState.Connecting
|
||||
val context = LocalContext.current
|
||||
|
||||
Scaffold(
|
||||
topBar = {
|
||||
TopAppBar(
|
||||
title = { Text("Подключение к серверу") },
|
||||
navigationIcon = {
|
||||
IconButton(onClick = onBack) {
|
||||
IconButton(onClick = {
|
||||
HapticUtil.perform(context, HapticUtil.Pattern.SELECTION)
|
||||
onBack()
|
||||
}) {
|
||||
Icon(Icons.AutoMirrored.Filled.ArrowBack, contentDescription = "Назад")
|
||||
}
|
||||
}
|
||||
@@ -156,6 +162,7 @@ private fun FormSection(
|
||||
sshState: SshConnectionState,
|
||||
onConnect: () -> Unit
|
||||
) {
|
||||
val context = LocalContext.current
|
||||
Text("Данные сервера", style = MaterialTheme.typography.titleMedium)
|
||||
|
||||
OutlinedTextField(
|
||||
@@ -205,9 +212,17 @@ private fun FormSection(
|
||||
onDismissRequest = { onAuthDropdownChange(false) }
|
||||
) {
|
||||
DropdownMenuItem(text = { Text("Пароль") },
|
||||
onClick = { onAuthTypeChange("PASSWORD"); onAuthDropdownChange(false) })
|
||||
onClick = {
|
||||
HapticUtil.perform(context, HapticUtil.Pattern.SELECTION)
|
||||
onAuthTypeChange("PASSWORD")
|
||||
onAuthDropdownChange(false)
|
||||
})
|
||||
DropdownMenuItem(text = { Text("Приватный ключ") },
|
||||
onClick = { onAuthTypeChange("SSH_KEY"); onAuthDropdownChange(false) })
|
||||
onClick = {
|
||||
HapticUtil.perform(context, HapticUtil.Pattern.SELECTION)
|
||||
onAuthTypeChange("SSH_KEY")
|
||||
onAuthDropdownChange(false)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -220,7 +235,10 @@ private fun FormSection(
|
||||
singleLine = true,
|
||||
visualTransformation = if (showPassword) VisualTransformation.None else PasswordVisualTransformation(),
|
||||
trailingIcon = {
|
||||
IconButton(onClick = onTogglePassword) {
|
||||
IconButton(onClick = {
|
||||
HapticUtil.perform(context, HapticUtil.Pattern.SELECTION)
|
||||
onTogglePassword()
|
||||
}) {
|
||||
Icon(
|
||||
if (showPassword) Icons.Filled.VisibilityOff else Icons.Filled.Visibility,
|
||||
contentDescription = null
|
||||
@@ -259,7 +277,10 @@ private fun FormSection(
|
||||
}
|
||||
|
||||
Button(
|
||||
onClick = onConnect,
|
||||
onClick = {
|
||||
HapticUtil.perform(context, HapticUtil.Pattern.CLICK)
|
||||
onConnect()
|
||||
},
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.height(56.dp),
|
||||
|
||||
Reference in new issue
Block a user