feat(settings): разделы «Приложение» и «О проекте», редизайн SSH-лога
- «Приложение»: приватный режим, динамическая тема, карточка обновлений (статус + действие во всю ширину), сброс настроек - «О проекте»: лого, версия, описание, ссылки (контент инфо-шита с главного переезжает в настройки) - SSH-лог: терминальная панель на тональных ролях схемы, счётчик строк, промпт с курсором, действия отдельным рядом — шапка больше не переполняется на узких экранах
This commit is contained in:
1 parent
30d931230d
commit
a5c053629e
8 files changed
+701
-166
No files matched your search
@@ -45,7 +45,9 @@ import androidx.navigation.compose.rememberNavController
|
||||
import com.freeturn.app.ui.HapticUtil
|
||||
import com.freeturn.app.ui.theme.LocalReducedMotion
|
||||
import com.freeturn.app.ui.screens.CaptchaWebViewDialog
|
||||
import com.freeturn.app.ui.screens.AboutScreen
|
||||
import com.freeturn.app.ui.screens.AdvancedScreen
|
||||
import com.freeturn.app.ui.screens.AppScreen
|
||||
import com.freeturn.app.ui.screens.ClientSetupScreen
|
||||
import com.freeturn.app.ui.screens.ConnectionModeScreen
|
||||
import com.freeturn.app.ui.screens.HomeScreen
|
||||
@@ -80,6 +82,8 @@ object Routes {
|
||||
|
||||
// Settings-флоу: Настройки → Серверы → [сервер] → подключение / сервер
|
||||
const val SETTINGS = "settings"
|
||||
const val APP_SETTINGS = "app_settings"
|
||||
const val ABOUT = "about"
|
||||
const val ADVANCED = "advanced"
|
||||
const val SERVERS_LIST = "servers_list"
|
||||
const val SERVER_DETAIL = "server_detail/{profileId}"
|
||||
@@ -310,7 +314,10 @@ private fun AppNavHost(
|
||||
HomeScreen(
|
||||
settingsViewModel = settingsViewModel,
|
||||
proxyViewModel = proxyViewModel,
|
||||
onOpenLogs = { navController.navigate(Routes.LOGS) }
|
||||
onOpenLogs = { navController.navigate(Routes.LOGS) },
|
||||
// Хаб сервера живёт в графе настроек — нижний бар подсветит «Настройки»,
|
||||
// системный «назад» вернёт на главную.
|
||||
onOpenServerSettings = { id -> navController.navigate(Routes.serverDetail(id)) }
|
||||
)
|
||||
}
|
||||
composable(Routes.LOGS) {
|
||||
@@ -323,10 +330,23 @@ private fun AppNavHost(
|
||||
composable(Routes.SETTINGS) {
|
||||
SettingsScreen(
|
||||
onOpenServers = { navController.navigate(Routes.SERVERS_LIST) },
|
||||
onOpenAdvanced = { navController.navigate(Routes.ADVANCED) }
|
||||
onOpenApp = { navController.navigate(Routes.APP_SETTINGS) },
|
||||
onOpenAdvanced = { navController.navigate(Routes.ADVANCED) },
|
||||
onOpenAbout = { navController.navigate(Routes.ABOUT) }
|
||||
)
|
||||
}
|
||||
|
||||
composable(Routes.APP_SETTINGS) {
|
||||
AppScreen(
|
||||
settingsViewModel = settingsViewModel,
|
||||
onBack = { navController.popBackStack() }
|
||||
)
|
||||
}
|
||||
|
||||
composable(Routes.ABOUT) {
|
||||
AboutScreen(onBack = { navController.popBackStack() })
|
||||
}
|
||||
|
||||
composable(Routes.ADVANCED) {
|
||||
AdvancedScreen(
|
||||
settingsViewModel = settingsViewModel,
|
||||
|
||||
@@ -0,0 +1,446 @@
|
||||
@file:OptIn(
|
||||
androidx.compose.material3.ExperimentalMaterial3Api::class,
|
||||
androidx.compose.material3.ExperimentalMaterial3ExpressiveApi::class
|
||||
)
|
||||
|
||||
package com.freeturn.app.ui.screens
|
||||
|
||||
import androidx.compose.animation.AnimatedContent
|
||||
import androidx.compose.animation.fadeIn
|
||||
import androidx.compose.animation.fadeOut
|
||||
import androidx.compose.animation.togetherWith
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.WindowInsets
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.layout.widthIn
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.foundation.shape.CircleShape
|
||||
import androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.material3.AlertDialog
|
||||
import androidx.compose.material3.ButtonDefaults
|
||||
import androidx.compose.material3.FilledTonalButton
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.LargeFlexibleTopAppBar
|
||||
import androidx.compose.material3.LinearWavyProgressIndicator
|
||||
import androidx.compose.material3.LoadingIndicator
|
||||
import androidx.compose.material3.MaterialShapes
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Scaffold
|
||||
import androidx.compose.material3.Surface
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TextButton
|
||||
import androidx.compose.material3.TopAppBarDefaults
|
||||
import androidx.compose.material3.toShape
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
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.input.nestedscroll.nestedScroll
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.platform.LocalUriHandler
|
||||
import androidx.compose.ui.res.painterResource
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.font.FontFamily
|
||||
import androidx.compose.ui.text.style.TextAlign
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||
import com.freeturn.app.R
|
||||
import com.freeturn.app.ui.HapticUtil
|
||||
import com.freeturn.app.ui.components.SectionLabel
|
||||
import com.freeturn.app.ui.components.SettingsBackButton
|
||||
import com.freeturn.app.ui.components.SettingsCard
|
||||
import com.freeturn.app.ui.components.SettingsContentMaxWidth
|
||||
import com.freeturn.app.ui.components.SettingsEntryRow
|
||||
import com.freeturn.app.ui.components.SettingsGroup
|
||||
import com.freeturn.app.ui.components.SettingsGroupItem
|
||||
import com.freeturn.app.ui.components.SettingsRowIcon
|
||||
import com.freeturn.app.ui.components.SettingsSwitchRow
|
||||
import com.freeturn.app.ui.util.hapticClickable
|
||||
import com.freeturn.app.viewmodel.SettingsViewModel
|
||||
import com.freeturn.app.viewmodel.UpdateState
|
||||
|
||||
// Экраны «Приложение» и «О проекте» — бывшее содержимое инфо-шита главного экрана,
|
||||
// разложенное по разделам настроек на общих settings-блоках.
|
||||
|
||||
/** Версия приложения из PackageManager; "—" если недоступна. */
|
||||
@Composable
|
||||
private fun rememberAppVersion(): String {
|
||||
val context = LocalContext.current
|
||||
return remember {
|
||||
try {
|
||||
context.packageManager.getPackageInfo(context.packageName, 0).versionName ?: "—"
|
||||
} catch (_: Exception) {
|
||||
"—"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** «Приложение»: интерфейсные тоггл-настройки, обновление и сброс. */
|
||||
@Suppress("AssignedValueIsNeverRead") // showResetDialog пишется в лямбдах диалога
|
||||
@Composable
|
||||
fun AppScreen(
|
||||
settingsViewModel: SettingsViewModel,
|
||||
onBack: () -> Unit
|
||||
) {
|
||||
val context = LocalContext.current
|
||||
val privacyMode by settingsViewModel.privacyMode.collectAsStateWithLifecycle()
|
||||
val dynamicTheme by settingsViewModel.dynamicTheme.collectAsStateWithLifecycle()
|
||||
val updateState by settingsViewModel.updateState.collectAsStateWithLifecycle()
|
||||
val appVersion = rememberAppVersion()
|
||||
var showResetDialog by rememberSaveable { mutableStateOf(false) }
|
||||
val scrollBehavior = TopAppBarDefaults.exitUntilCollapsedScrollBehavior()
|
||||
|
||||
Scaffold(
|
||||
modifier = Modifier.nestedScroll(scrollBehavior.nestedScrollConnection),
|
||||
topBar = {
|
||||
LargeFlexibleTopAppBar(
|
||||
title = { Text(stringResource(R.string.settings_app)) },
|
||||
navigationIcon = { SettingsBackButton(onBack) },
|
||||
scrollBehavior = scrollBehavior
|
||||
)
|
||||
},
|
||||
contentWindowInsets = WindowInsets(0, 0, 0, 0)
|
||||
) { padding ->
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.padding(padding)
|
||||
.verticalScroll(rememberScrollState()),
|
||||
horizontalAlignment = Alignment.CenterHorizontally
|
||||
) {
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.widthIn(max = SettingsContentMaxWidth)
|
||||
.fillMaxWidth()
|
||||
.padding(horizontal = 16.dp, vertical = 12.dp),
|
||||
verticalArrangement = Arrangement.spacedBy(16.dp)
|
||||
) {
|
||||
SectionLabel(stringResource(R.string.app_section_interface))
|
||||
SettingsGroup {
|
||||
SettingsGroupItem(0, 2) {
|
||||
SettingsSwitchRow(
|
||||
title = stringResource(R.string.privacy_mode_title),
|
||||
subtitle = stringResource(R.string.privacy_mode_desc),
|
||||
iconRes = R.drawable.visibility_off_24px,
|
||||
checked = privacyMode,
|
||||
onCheckedChange = { settingsViewModel.setPrivacyMode(it) }
|
||||
)
|
||||
}
|
||||
SettingsGroupItem(1, 2) {
|
||||
SettingsSwitchRow(
|
||||
title = stringResource(R.string.dynamic_theme_title),
|
||||
subtitle = stringResource(R.string.dynamic_theme_desc),
|
||||
iconRes = R.drawable.palette_24px,
|
||||
checked = dynamicTheme,
|
||||
onCheckedChange = { settingsViewModel.setDynamicTheme(it) }
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
SectionLabel(stringResource(R.string.app_section_updates))
|
||||
UpdateCard(
|
||||
state = updateState,
|
||||
appVersion = appVersion,
|
||||
onCheck = {
|
||||
HapticUtil.perform(context, HapticUtil.Pattern.CLICK)
|
||||
settingsViewModel.checkForUpdate()
|
||||
},
|
||||
onDownload = {
|
||||
HapticUtil.perform(context, HapticUtil.Pattern.CLICK)
|
||||
settingsViewModel.downloadUpdate()
|
||||
},
|
||||
onInstall = {
|
||||
HapticUtil.perform(context, HapticUtil.Pattern.CLICK)
|
||||
settingsViewModel.installUpdate()
|
||||
}
|
||||
)
|
||||
|
||||
SectionLabel(stringResource(R.string.app_section_reset))
|
||||
SettingsCard {
|
||||
ResetRow(onClick = { showResetDialog = true })
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (showResetDialog) {
|
||||
AlertDialog(
|
||||
onDismissRequest = { showResetDialog = false },
|
||||
title = { Text(stringResource(R.string.reset_all_settings_title)) },
|
||||
text = { Text(stringResource(R.string.reset_all_settings_desc)) },
|
||||
confirmButton = {
|
||||
TextButton(
|
||||
onClick = {
|
||||
showResetDialog = false
|
||||
settingsViewModel.resetAllSettings()
|
||||
},
|
||||
colors = ButtonDefaults.textButtonColors(
|
||||
contentColor = MaterialTheme.colorScheme.error
|
||||
)
|
||||
) { Text(stringResource(R.string.reset)) }
|
||||
},
|
||||
dismissButton = {
|
||||
TextButton(onClick = { showResetDialog = false }) {
|
||||
Text(stringResource(R.string.cancel))
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Карточка обновления. Двухэтажная (как SshLogCard): шапка — иконка, заголовок и статус
|
||||
* (анимированная смена), под ней действие во всю ширину — кнопка по состоянию либо
|
||||
* wavy-прогресс загрузки. В одну строку всё это не влезает на узких экранах.
|
||||
*/
|
||||
@Composable
|
||||
private fun UpdateCard(
|
||||
state: UpdateState,
|
||||
appVersion: String,
|
||||
onCheck: () -> Unit,
|
||||
onDownload: () -> Unit,
|
||||
onInstall: () -> Unit
|
||||
) {
|
||||
val statusText = when (state) {
|
||||
is UpdateState.Idle -> stringResource(R.string.update_current_version, "v$appVersion")
|
||||
is UpdateState.Checking -> stringResource(R.string.update_checking)
|
||||
is UpdateState.Available -> stringResource(R.string.update_available, state.version)
|
||||
is UpdateState.Downloading -> stringResource(R.string.update_downloading, state.progress)
|
||||
is UpdateState.ReadyToInstall -> stringResource(R.string.update_ready_desc_short)
|
||||
is UpdateState.NoUpdate -> stringResource(R.string.update_no_update)
|
||||
is UpdateState.Error -> stringResource(R.string.update_error, state.message)
|
||||
}
|
||||
|
||||
SettingsCard {
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(16.dp),
|
||||
verticalArrangement = Arrangement.spacedBy(12.dp)
|
||||
) {
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
horizontalArrangement = Arrangement.spacedBy(16.dp),
|
||||
modifier = Modifier.fillMaxWidth()
|
||||
) {
|
||||
SettingsRowIcon(R.drawable.cloud_download_24px)
|
||||
Column(modifier = Modifier.weight(1f)) {
|
||||
Text(stringResource(R.string.update_title), style = MaterialTheme.typography.bodyLarge)
|
||||
AnimatedContent(
|
||||
targetState = statusText,
|
||||
transitionSpec = { fadeIn() togetherWith fadeOut() },
|
||||
label = "update_status"
|
||||
) { text ->
|
||||
Text(
|
||||
text,
|
||||
style = MaterialTheme.typography.bodyMedium,
|
||||
color = if (state is UpdateState.Error) MaterialTheme.colorScheme.error
|
||||
else MaterialTheme.colorScheme.onSurfaceVariant
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
if (state is UpdateState.Downloading) {
|
||||
LinearWavyProgressIndicator(
|
||||
progress = { state.progress / 100f },
|
||||
modifier = Modifier.fillMaxWidth()
|
||||
)
|
||||
} else {
|
||||
val action = when (state) {
|
||||
is UpdateState.Available -> onDownload
|
||||
is UpdateState.ReadyToInstall -> onInstall
|
||||
else -> onCheck
|
||||
}
|
||||
FilledTonalButton(
|
||||
onClick = action,
|
||||
enabled = state !is UpdateState.Checking,
|
||||
modifier = Modifier.fillMaxWidth()
|
||||
) {
|
||||
if (state is UpdateState.Checking) {
|
||||
LoadingIndicator(modifier = Modifier.size(22.dp))
|
||||
} else {
|
||||
Text(
|
||||
when (state) {
|
||||
is UpdateState.Available -> stringResource(R.string.update_download)
|
||||
is UpdateState.ReadyToInstall -> stringResource(R.string.update_install)
|
||||
else -> stringResource(R.string.update_check)
|
||||
},
|
||||
maxLines = 1
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Опасная строка сброса: error-тинт иконки и заголовка, без trailing-шеврона. */
|
||||
@Composable
|
||||
private fun ResetRow(onClick: () -> Unit) {
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.hapticClickable(HapticUtil.Pattern.CLICK, onClick = onClick)
|
||||
.padding(horizontal = 16.dp, vertical = 14.dp),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
horizontalArrangement = Arrangement.spacedBy(16.dp)
|
||||
) {
|
||||
SettingsRowIcon(
|
||||
R.drawable.delete_24px,
|
||||
container = MaterialTheme.colorScheme.errorContainer,
|
||||
tint = MaterialTheme.colorScheme.onErrorContainer
|
||||
)
|
||||
Column(modifier = Modifier.weight(1f)) {
|
||||
Text(
|
||||
stringResource(R.string.reset_settings),
|
||||
style = MaterialTheme.typography.bodyLarge,
|
||||
color = MaterialTheme.colorScheme.error
|
||||
)
|
||||
Text(
|
||||
stringResource(R.string.app_reset_desc),
|
||||
style = MaterialTheme.typography.bodyMedium,
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** «О проекте»: hero с лого в expressive-форме, версия, описание и ссылки. */
|
||||
@Composable
|
||||
fun AboutScreen(onBack: () -> Unit) {
|
||||
val context = LocalContext.current
|
||||
val uriHandler = LocalUriHandler.current
|
||||
val appVersion = rememberAppVersion()
|
||||
val scrollBehavior = TopAppBarDefaults.exitUntilCollapsedScrollBehavior()
|
||||
|
||||
fun open(url: String) {
|
||||
HapticUtil.perform(context, HapticUtil.Pattern.SELECTION)
|
||||
uriHandler.openUri(url)
|
||||
}
|
||||
|
||||
Scaffold(
|
||||
modifier = Modifier.nestedScroll(scrollBehavior.nestedScrollConnection),
|
||||
topBar = {
|
||||
LargeFlexibleTopAppBar(
|
||||
title = { Text(stringResource(R.string.settings_about)) },
|
||||
navigationIcon = { SettingsBackButton(onBack) },
|
||||
scrollBehavior = scrollBehavior
|
||||
)
|
||||
},
|
||||
contentWindowInsets = WindowInsets(0, 0, 0, 0)
|
||||
) { padding ->
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.padding(padding)
|
||||
.verticalScroll(rememberScrollState()),
|
||||
horizontalAlignment = Alignment.CenterHorizontally
|
||||
) {
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.widthIn(max = SettingsContentMaxWidth)
|
||||
.fillMaxWidth()
|
||||
.padding(horizontal = 16.dp, vertical = 12.dp),
|
||||
verticalArrangement = Arrangement.spacedBy(16.dp)
|
||||
) {
|
||||
AboutHero(appVersion)
|
||||
|
||||
SectionLabel(stringResource(R.string.about_links))
|
||||
SettingsGroup {
|
||||
SettingsGroupItem(0, 3) {
|
||||
SettingsEntryRow(
|
||||
iconRes = R.drawable.code_24px,
|
||||
title = stringResource(R.string.android_client),
|
||||
subtitle = "samosvalishe/turn-proxy-android",
|
||||
trailingRes = R.drawable.open_in_new_24px,
|
||||
trailingTint = MaterialTheme.colorScheme.primary,
|
||||
onClick = { open("https://github.com/samosvalishe/turn-proxy-android") }
|
||||
)
|
||||
}
|
||||
SettingsGroupItem(1, 3) {
|
||||
SettingsEntryRow(
|
||||
iconRes = R.drawable.terminal_24px,
|
||||
title = stringResource(R.string.proxy_core),
|
||||
subtitle = "samosvalishe/free-turn-proxy",
|
||||
trailingRes = R.drawable.open_in_new_24px,
|
||||
trailingTint = MaterialTheme.colorScheme.primary,
|
||||
onClick = { open("https://github.com/samosvalishe/free-turn-proxy") }
|
||||
)
|
||||
}
|
||||
SettingsGroupItem(2, 3) {
|
||||
SettingsEntryRow(
|
||||
iconRes = R.drawable.public_24px,
|
||||
title = stringResource(R.string.tg_channel),
|
||||
trailingRes = R.drawable.open_in_new_24px,
|
||||
trailingTint = MaterialTheme.colorScheme.primary,
|
||||
onClick = { open("https://t.me/+53nh4UNiSv5lNTgy") }
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Hero «О проекте»: ромб-лого в 9-гранной cookie (как пустой список серверов), имя, версия-пилюля, описание. */
|
||||
@Composable
|
||||
private fun AboutHero(appVersion: String) {
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(top = 12.dp, bottom = 4.dp),
|
||||
horizontalAlignment = Alignment.CenterHorizontally
|
||||
) {
|
||||
Surface(
|
||||
shape = MaterialShapes.Cookie9Sided.toShape(),
|
||||
color = MaterialTheme.colorScheme.primaryContainer,
|
||||
modifier = Modifier.size(112.dp)
|
||||
) {
|
||||
Box(contentAlignment = Alignment.Center, modifier = Modifier.fillMaxSize()) {
|
||||
Icon(
|
||||
painterResource(R.drawable.logo_diamond_24px),
|
||||
contentDescription = null,
|
||||
tint = MaterialTheme.colorScheme.onPrimaryContainer,
|
||||
modifier = Modifier.size(52.dp)
|
||||
)
|
||||
}
|
||||
}
|
||||
Spacer(Modifier.height(16.dp))
|
||||
Text(
|
||||
stringResource(R.string.turn_proxy_title),
|
||||
style = MaterialTheme.typography.headlineSmall
|
||||
)
|
||||
Spacer(Modifier.height(8.dp))
|
||||
Surface(
|
||||
shape = CircleShape,
|
||||
color = MaterialTheme.colorScheme.secondaryContainer
|
||||
) {
|
||||
Text(
|
||||
"v$appVersion",
|
||||
style = MaterialTheme.typography.labelMedium.copy(fontFamily = FontFamily.Monospace),
|
||||
color = MaterialTheme.colorScheme.onSecondaryContainer,
|
||||
modifier = Modifier.padding(horizontal = 12.dp, vertical = 4.dp)
|
||||
)
|
||||
}
|
||||
Spacer(Modifier.height(16.dp))
|
||||
Text(
|
||||
stringResource(R.string.about_description),
|
||||
style = MaterialTheme.typography.bodyMedium,
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
textAlign = TextAlign.Center,
|
||||
modifier = Modifier.padding(horizontal = 8.dp)
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -40,16 +40,16 @@ import androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.material3.AlertDialog
|
||||
import androidx.compose.material3.Button
|
||||
import androidx.compose.material3.ButtonDefaults
|
||||
import androidx.compose.material3.CircularProgressIndicator
|
||||
import androidx.compose.material3.DropdownMenu
|
||||
import androidx.compose.material3.DropdownMenuItem
|
||||
import androidx.compose.material3.FilledTonalButton
|
||||
import androidx.compose.material3.FilledTonalIconButton
|
||||
import androidx.compose.material3.LoadingIndicator
|
||||
import androidx.compose.material3.HorizontalDivider
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.IconButton
|
||||
import androidx.compose.material3.LargeFlexibleTopAppBar
|
||||
import androidx.compose.material3.LinearWavyProgressIndicator
|
||||
import androidx.compose.material3.MaterialShapes
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.OutlinedTextField
|
||||
import androidx.compose.material3.Scaffold
|
||||
@@ -57,7 +57,6 @@ import androidx.compose.material3.Surface
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TextButton
|
||||
import androidx.compose.material3.TopAppBarDefaults
|
||||
import androidx.compose.material3.toShape
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.getValue
|
||||
@@ -91,7 +90,10 @@ import com.freeturn.app.data.Profile
|
||||
import com.freeturn.app.domain.server.ServerCommand
|
||||
import com.freeturn.app.domain.server.ServerOptions
|
||||
import com.freeturn.app.ui.HapticUtil
|
||||
import com.freeturn.app.ui.components.EmptyServersState
|
||||
import com.freeturn.app.ui.components.SectionLabel
|
||||
import com.freeturn.app.ui.components.ServerRow
|
||||
import com.freeturn.app.ui.components.SettingsBackButton
|
||||
import com.freeturn.app.ui.components.SettingsCard
|
||||
import com.freeturn.app.ui.components.SettingsContentMaxWidth
|
||||
import com.freeturn.app.ui.components.SettingsEntryRow
|
||||
@@ -101,7 +103,6 @@ import com.freeturn.app.ui.components.SettingsSwitchRow
|
||||
import com.freeturn.app.ui.components.settingsItemShape
|
||||
import com.freeturn.app.ui.theme.LocalReducedMotion
|
||||
import com.freeturn.app.ui.theme.extendedColorScheme
|
||||
import com.freeturn.app.ui.util.hapticClickable
|
||||
import com.freeturn.app.viewmodel.ServerHubStatus
|
||||
import com.freeturn.app.viewmodel.ServerViewModel
|
||||
import com.freeturn.app.viewmodel.SettingsViewModel
|
||||
@@ -109,11 +110,13 @@ import com.freeturn.app.viewmodel.SshConnectionState
|
||||
import com.freeturn.app.viewmodel.serverSettingsAvailable
|
||||
|
||||
|
||||
/** Корневой экран настроек (нижнее меню). Пока единственный пункт — «Серверы». */
|
||||
/** Корневой экран настроек (нижнее меню): серверы, приложение, продвинутые, о проекте. */
|
||||
@Composable
|
||||
fun SettingsScreen(
|
||||
onOpenServers: () -> Unit,
|
||||
onOpenAdvanced: () -> Unit
|
||||
onOpenApp: () -> Unit,
|
||||
onOpenAdvanced: () -> Unit,
|
||||
onOpenAbout: () -> Unit
|
||||
) {
|
||||
val scrollBehavior = TopAppBarDefaults.exitUntilCollapsedScrollBehavior()
|
||||
Scaffold(
|
||||
@@ -145,7 +148,7 @@ fun SettingsScreen(
|
||||
// наружные углы большие. Новые пункты добавляются строкой в группу,
|
||||
// при разрастании — разбиение на группы с SectionLabel.
|
||||
SettingsGroup {
|
||||
SettingsGroupItem(0, 2) {
|
||||
SettingsGroupItem(0, 4) {
|
||||
SettingsEntryRow(
|
||||
iconRes = R.drawable.database_24px,
|
||||
title = stringResource(R.string.settings_servers),
|
||||
@@ -153,7 +156,15 @@ fun SettingsScreen(
|
||||
onClick = onOpenServers
|
||||
)
|
||||
}
|
||||
SettingsGroupItem(1, 2) {
|
||||
SettingsGroupItem(1, 4) {
|
||||
SettingsEntryRow(
|
||||
iconRes = R.drawable.mobile_24px,
|
||||
title = stringResource(R.string.settings_app),
|
||||
subtitle = stringResource(R.string.settings_app_desc),
|
||||
onClick = onOpenApp
|
||||
)
|
||||
}
|
||||
SettingsGroupItem(2, 4) {
|
||||
SettingsEntryRow(
|
||||
iconRes = R.drawable.tune_24px,
|
||||
title = stringResource(R.string.settings_advanced),
|
||||
@@ -161,6 +172,14 @@ fun SettingsScreen(
|
||||
onClick = onOpenAdvanced
|
||||
)
|
||||
}
|
||||
SettingsGroupItem(3, 4) {
|
||||
SettingsEntryRow(
|
||||
iconRes = R.drawable.info_24px,
|
||||
title = stringResource(R.string.settings_about),
|
||||
subtitle = stringResource(R.string.settings_about_desc),
|
||||
onClick = onOpenAbout
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -184,7 +203,7 @@ fun AdvancedScreen(
|
||||
topBar = {
|
||||
LargeFlexibleTopAppBar(
|
||||
title = { Text(stringResource(R.string.settings_advanced)) },
|
||||
navigationIcon = { BackButton(onBack) },
|
||||
navigationIcon = { SettingsBackButton(onBack) },
|
||||
scrollBehavior = scrollBehavior
|
||||
)
|
||||
},
|
||||
@@ -234,7 +253,7 @@ fun ServersListScreen(
|
||||
topBar = {
|
||||
LargeFlexibleTopAppBar(
|
||||
title = { Text(stringResource(R.string.settings_servers)) },
|
||||
navigationIcon = { BackButton(onBack) },
|
||||
navigationIcon = { SettingsBackButton(onBack) },
|
||||
scrollBehavior = scrollBehavior
|
||||
)
|
||||
},
|
||||
@@ -242,7 +261,7 @@ fun ServersListScreen(
|
||||
contentWindowInsets = WindowInsets(0, 0, 0, 0)
|
||||
) { padding ->
|
||||
if (snapshot.loaded && snapshot.list.isEmpty()) {
|
||||
EmptyServers(modifier = Modifier.fillMaxSize().padding(padding))
|
||||
EmptyServersState(modifier = Modifier.fillMaxSize().padding(padding))
|
||||
return@Scaffold
|
||||
}
|
||||
Column(
|
||||
@@ -292,71 +311,14 @@ private fun ServerListRow(
|
||||
profile.client.serverAddress.takeIf { it.isNotBlank() }?.redact(privacyMode),
|
||||
stringResource(R.string.profile_has_ssh).takeIf { profile.ssh.ip.isNotBlank() }
|
||||
).joinToString(" · ").ifBlank { "—" }
|
||||
|
||||
// «Активный» = выбранный профиль (а не статус SSH-подключения). Текстового бейджа нет —
|
||||
// он сжимал заголовок на узких экранах; выбранность несёт тон контейнера
|
||||
// (secondaryContainer, как у selected-элементов M3) + насыщенный аватар.
|
||||
// Для TalkBack статус остаётся в contentDescription.
|
||||
val activeBadge = stringResource(R.string.profile_active_badge)
|
||||
val rowDesc = if (isActive) "${profile.name}, $activeBadge" else profile.name
|
||||
|
||||
val container = if (isActive) MaterialTheme.colorScheme.secondaryContainer
|
||||
else MaterialTheme.colorScheme.surfaceContainerLow
|
||||
val titleColor = if (isActive) MaterialTheme.colorScheme.onSecondaryContainer
|
||||
else MaterialTheme.colorScheme.onSurface
|
||||
val subColor = if (isActive) MaterialTheme.colorScheme.onSecondaryContainer.copy(alpha = 0.8f)
|
||||
else MaterialTheme.colorScheme.onSurfaceVariant
|
||||
val iconContainer = if (isActive) MaterialTheme.colorScheme.primary
|
||||
else MaterialTheme.colorScheme.surfaceContainerHighest
|
||||
val iconTint = if (isActive) MaterialTheme.colorScheme.onPrimary
|
||||
else MaterialTheme.colorScheme.onSurfaceVariant
|
||||
|
||||
Surface(shape = shape, color = container, modifier = Modifier.fillMaxWidth()) {
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.hapticClickable(HapticUtil.Pattern.CLICK, onClick = onClick)
|
||||
.semantics { contentDescription = rowDesc }
|
||||
.padding(horizontal = 16.dp, vertical = 14.dp),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
horizontalArrangement = Arrangement.spacedBy(16.dp)
|
||||
) {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.size(44.dp)
|
||||
.background(iconContainer, CircleShape),
|
||||
contentAlignment = Alignment.Center
|
||||
) {
|
||||
Icon(
|
||||
painterResource(R.drawable.database_24px),
|
||||
contentDescription = null,
|
||||
tint = iconTint,
|
||||
modifier = Modifier.size(22.dp)
|
||||
)
|
||||
}
|
||||
Column(modifier = Modifier.weight(1f)) {
|
||||
Text(
|
||||
profile.name,
|
||||
style = MaterialTheme.typography.bodyLarge,
|
||||
color = titleColor,
|
||||
maxLines = 1,
|
||||
overflow = TextOverflow.Ellipsis
|
||||
)
|
||||
Text(
|
||||
sub,
|
||||
style = MaterialTheme.typography.bodyMedium,
|
||||
color = subColor,
|
||||
maxLines = 1,
|
||||
overflow = TextOverflow.Ellipsis
|
||||
)
|
||||
}
|
||||
Icon(
|
||||
painterResource(R.drawable.chevron_right_24px),
|
||||
contentDescription = null,
|
||||
tint = subColor
|
||||
)
|
||||
}
|
||||
}
|
||||
ServerRow(
|
||||
name = profile.name,
|
||||
subtitle = sub,
|
||||
isActive = isActive,
|
||||
shape = shape,
|
||||
onClick = onClick,
|
||||
trailingIconRes = R.drawable.chevron_right_24px
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -435,7 +397,7 @@ fun ServerDetailScreen(
|
||||
subtitle = headerSubtitle?.let { sub ->
|
||||
{ Text(sub, maxLines = 1, overflow = TextOverflow.Ellipsis) }
|
||||
},
|
||||
navigationIcon = { BackButton(onBack) },
|
||||
navigationIcon = { SettingsBackButton(onBack) },
|
||||
scrollBehavior = scrollBehavior,
|
||||
actions = {
|
||||
Box {
|
||||
@@ -949,7 +911,7 @@ fun NerdScreen(
|
||||
topBar = {
|
||||
LargeFlexibleTopAppBar(
|
||||
title = { Text(stringResource(R.string.nerd_section_title)) },
|
||||
navigationIcon = { BackButton(onBack) },
|
||||
navigationIcon = { SettingsBackButton(onBack) },
|
||||
scrollBehavior = scrollBehavior
|
||||
)
|
||||
},
|
||||
@@ -1206,7 +1168,11 @@ private fun LogPane(text: String, color: Color = MaterialTheme.colorScheme.onSur
|
||||
|
||||
/**
|
||||
* Единый SSH-лог: весь вывод команд сопряжения/управления + server.log (тянется кнопкой
|
||||
* «Журнал сервера») — всё идёт сюда через runCmd. Автопрокрутка к свежим строкам.
|
||||
* «Журнал сервера») — всё идёт сюда через runCmd.
|
||||
*
|
||||
* Раскладка трёхэтажная, чтобы ничего не толкалось в одной строке: шапка (заголовок +
|
||||
* счётчик строк), терминал, ряд действий во всю ширину. Терминал на inverseSurface —
|
||||
* настоящая тёмная консоль в светлой теме, с приглашением «❯» и мигающим курсором.
|
||||
*/
|
||||
@Composable
|
||||
private fun SshLogCard(
|
||||
@@ -1221,7 +1187,10 @@ private fun SshLogCard(
|
||||
color = MaterialTheme.colorScheme.surfaceContainerLow,
|
||||
modifier = Modifier.fillMaxWidth()
|
||||
) {
|
||||
Column(modifier = Modifier.padding(20.dp)) {
|
||||
Column(
|
||||
modifier = Modifier.padding(20.dp),
|
||||
verticalArrangement = Arrangement.spacedBy(12.dp)
|
||||
) {
|
||||
Row(verticalAlignment = Alignment.CenterVertically, modifier = Modifier.fillMaxWidth()) {
|
||||
Text(
|
||||
stringResource(R.string.ssh_log_title),
|
||||
@@ -1229,83 +1198,142 @@ private fun SshLogCard(
|
||||
modifier = Modifier.weight(1f)
|
||||
)
|
||||
if (lines.isNotEmpty()) {
|
||||
IconButton(onClick = onClear) {
|
||||
Icon(
|
||||
painterResource(R.drawable.delete_24px),
|
||||
contentDescription = stringResource(R.string.clear)
|
||||
)
|
||||
}
|
||||
}
|
||||
if (canFetchJournal) {
|
||||
FilledTonalButton(onClick = onFetchJournal, enabled = !journalLoading) {
|
||||
if (journalLoading) {
|
||||
CircularProgressIndicator(
|
||||
modifier = Modifier.size(18.dp),
|
||||
strokeWidth = 2.dp
|
||||
)
|
||||
} else {
|
||||
Icon(
|
||||
painterResource(R.drawable.cloud_download_24px),
|
||||
contentDescription = null,
|
||||
modifier = Modifier.size(18.dp)
|
||||
AnimatedContent(
|
||||
targetState = lines.size,
|
||||
transitionSpec = {
|
||||
(fadeIn() togetherWith fadeOut()).using(SizeTransform(clip = false))
|
||||
},
|
||||
label = "ssh_log_count"
|
||||
) { count ->
|
||||
Surface(
|
||||
shape = CircleShape,
|
||||
color = MaterialTheme.colorScheme.secondaryContainer
|
||||
) {
|
||||
Text(
|
||||
"$count",
|
||||
style = MaterialTheme.typography.labelMedium.copy(fontFamily = FontFamily.Monospace),
|
||||
color = MaterialTheme.colorScheme.onSecondaryContainer,
|
||||
modifier = Modifier.padding(horizontal = 10.dp, vertical = 4.dp)
|
||||
)
|
||||
}
|
||||
Spacer(Modifier.width(8.dp))
|
||||
Text(stringResource(R.string.ssh_log_fetch_journal))
|
||||
}
|
||||
}
|
||||
}
|
||||
Spacer(Modifier.height(12.dp))
|
||||
|
||||
SshTerminalPane(lines)
|
||||
|
||||
// Действия отдельным рядом во всю ширину — в шапке им тесно на узких экранах.
|
||||
if (canFetchJournal || lines.isNotEmpty()) {
|
||||
Row(
|
||||
horizontalArrangement = Arrangement.spacedBy(8.dp),
|
||||
modifier = Modifier.fillMaxWidth()
|
||||
) {
|
||||
if (canFetchJournal) {
|
||||
FilledTonalButton(
|
||||
onClick = onFetchJournal,
|
||||
enabled = !journalLoading,
|
||||
modifier = Modifier.weight(1f)
|
||||
) {
|
||||
if (journalLoading) {
|
||||
LoadingIndicator(modifier = Modifier.size(22.dp))
|
||||
} else {
|
||||
Icon(
|
||||
painterResource(R.drawable.cloud_download_24px),
|
||||
contentDescription = null,
|
||||
modifier = Modifier.size(18.dp)
|
||||
)
|
||||
}
|
||||
Spacer(Modifier.width(8.dp))
|
||||
Text(stringResource(R.string.ssh_log_fetch_journal), maxLines = 1)
|
||||
}
|
||||
}
|
||||
if (lines.isNotEmpty()) {
|
||||
if (canFetchJournal) {
|
||||
FilledTonalIconButton(onClick = onClear) {
|
||||
Icon(
|
||||
painterResource(R.drawable.delete_24px),
|
||||
contentDescription = stringResource(R.string.clear)
|
||||
)
|
||||
}
|
||||
} else {
|
||||
// Оффлайн: журнал не потянуть, очистка — единственное действие.
|
||||
FilledTonalButton(onClick = onClear, modifier = Modifier.weight(1f)) {
|
||||
Icon(
|
||||
painterResource(R.drawable.delete_24px),
|
||||
contentDescription = null,
|
||||
modifier = Modifier.size(18.dp)
|
||||
)
|
||||
Spacer(Modifier.width(8.dp))
|
||||
Text(stringResource(R.string.clear))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Консоль SSH-лога: тёмная (inverseSurface) моноширинная панель с приглашением «❯» и
|
||||
* мигающим курсором в конце — пустой лог выглядит как ждущий терминал, а не дырка.
|
||||
* Автопрокрутка к свежим строкам.
|
||||
*/
|
||||
@Composable
|
||||
private fun SshTerminalPane(lines: List<String>) {
|
||||
// Тональные роли M3 — как у LogPane соседних карточек: панель живёт в теме
|
||||
// (light/dark/dynamic color), консольность несут моно-шрифт, промпт и курсор.
|
||||
val fg = MaterialTheme.colorScheme.onSurfaceVariant
|
||||
val accent = MaterialTheme.colorScheme.primary
|
||||
Surface(
|
||||
shape = MaterialTheme.shapes.medium,
|
||||
color = MaterialTheme.colorScheme.surfaceContainerHighest,
|
||||
modifier = Modifier.fillMaxWidth()
|
||||
) {
|
||||
val scroll = rememberScrollState()
|
||||
LaunchedEffect(lines.size) { scroll.scrollTo(scroll.maxValue) }
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.heightIn(min = 88.dp, max = 400.dp)
|
||||
.verticalScroll(scroll)
|
||||
.padding(horizontal = 12.dp, vertical = 10.dp)
|
||||
) {
|
||||
val mono = MaterialTheme.typography.bodySmall.copy(fontFamily = FontFamily.Monospace)
|
||||
if (lines.isEmpty()) {
|
||||
Text(
|
||||
stringResource(R.string.ssh_log_empty),
|
||||
style = MaterialTheme.typography.bodyMedium,
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant
|
||||
"# ${stringResource(R.string.ssh_log_empty)}",
|
||||
style = mono,
|
||||
color = fg.copy(alpha = 0.55f)
|
||||
)
|
||||
} else {
|
||||
LogPane(lines.joinToString("\n"), autoScroll = true)
|
||||
// Склейка дорогая (кап 500 строк) — кэшируем по содержимому лога.
|
||||
val text = remember(lines) { lines.joinToString("\n") }
|
||||
Text(text, style = mono, color = fg)
|
||||
}
|
||||
Row {
|
||||
Text("❯ ", style = mono, color = accent)
|
||||
if (LocalReducedMotion.current) {
|
||||
Text("▍", style = mono, color = accent)
|
||||
} else {
|
||||
// Альфа в draw-фазе через graphicsLayer: чтение анимации в композиции
|
||||
// рекомпозило бы строку на каждом кадре мигания.
|
||||
val blink = rememberInfiniteTransition(label = "ssh_cursor")
|
||||
.animateFloat(
|
||||
initialValue = 1f,
|
||||
targetValue = 0.1f,
|
||||
animationSpec = infiniteRepeatable(tween(600), RepeatMode.Reverse),
|
||||
label = "ssh_cursor_alpha"
|
||||
)
|
||||
Text(
|
||||
"▍",
|
||||
style = mono,
|
||||
color = accent,
|
||||
modifier = Modifier.graphicsLayer { alpha = blink.value }
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun BackButton(onBack: () -> Unit) {
|
||||
IconButton(onClick = onBack) {
|
||||
Icon(
|
||||
painterResource(R.drawable.arrow_back_24px),
|
||||
contentDescription = stringResource(R.string.back)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun EmptyServers(modifier: Modifier = Modifier) {
|
||||
Column(
|
||||
modifier = modifier.padding(horizontal = 32.dp),
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
verticalArrangement = Arrangement.Center
|
||||
) {
|
||||
Surface(
|
||||
shape = MaterialShapes.Cookie9Sided.toShape(),
|
||||
color = MaterialTheme.colorScheme.primaryContainer,
|
||||
modifier = Modifier.size(112.dp)
|
||||
) {
|
||||
Box(contentAlignment = Alignment.Center, modifier = Modifier.fillMaxSize()) {
|
||||
Icon(
|
||||
painterResource(R.drawable.database_outlined_24px),
|
||||
contentDescription = null,
|
||||
tint = MaterialTheme.colorScheme.onPrimaryContainer,
|
||||
modifier = Modifier.size(48.dp)
|
||||
)
|
||||
}
|
||||
}
|
||||
Spacer(Modifier.height(16.dp))
|
||||
Text(
|
||||
stringResource(R.string.settings_empty_servers),
|
||||
style = MaterialTheme.typography.bodyMedium,
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
textAlign = TextAlign.Center
|
||||
)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user