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