feat(ui): общие блоки — ServerRow, empty-state, кнопка «назад»

- ServerRow: единая строка-сервер для списка настроек и листа на
  главном (аватар, тона active/inactive, semantics, два трейлинга)
- EmptyServersState: один пустой список на всё приложение
- SettingsRowIcon: параметры container/tint под danger-строки
- SettingsBackButton: общая кнопка «назад» settings-флоу
This commit is contained in:
samosvalishe committed 2026-06-10 16:07:04 +03:00
1 parent 8379eb46e1
commit 30d931230d
2 files changed
+189 -7

No files matched your search

@@ -0,0 +1,164 @@
@file:OptIn(androidx.compose.material3.ExperimentalMaterial3ExpressiveApi::class)
package com.freeturn.app.ui.components
import androidx.compose.foundation.background
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.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.shape.CircleShape
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialShapes
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.material3.toShape
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.Shape
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.semantics.contentDescription
import androidx.compose.ui.semantics.selected
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import com.freeturn.app.R
import com.freeturn.app.ui.HapticUtil
import com.freeturn.app.ui.util.hapticClickable
/**
* Общая строка-сервер сегментированной группы: аватар, имя/подзаголовок, опциональный
* trailing. Используется списком «Настройки → Серверы» и нижним листом на главном.
* Выбранность несёт тон контейнера (secondaryContainer, как у selected-элементов M3)
* + насыщенный аватар; для TalkBack — selected + бейдж «Активный» в contentDescription.
*/
@Composable
fun ServerRow(
name: String,
subtitle: String,
isActive: Boolean,
shape: Shape,
onClick: () -> Unit,
// Лист на главном сам лежит на surfaceContainerLow — ему нужен контейнер потемнее.
inactiveContainer: Color = MaterialTheme.colorScheme.surfaceContainerLow,
/** Простой иконко-трейлинг (шеврон навигации) — тинт согласован с подзаголовком. */
trailingIconRes: Int? = null,
/** Интерактивный трейлинг (IconButton) — у него свой тач-таргет, край прижимается. */
trailing: (@Composable () -> Unit)? = null
) {
val container = if (isActive) MaterialTheme.colorScheme.secondaryContainer
else inactiveContainer
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
val activeBadge = stringResource(R.string.profile_active_badge)
val rowDesc = if (isActive) "$name, $activeBadge" else name
Surface(shape = shape, color = container, modifier = Modifier.fillMaxWidth()) {
Row(
modifier = Modifier
.fillMaxWidth()
.hapticClickable(HapticUtil.Pattern.CLICK, onClick = onClick)
.semantics {
selected = isActive
contentDescription = rowDesc
}
.padding(
start = 16.dp,
// У trailing-кнопки собственный тач-таргет — прижимаем её к краю.
end = if (trailing != null) 4.dp else 16.dp,
top = 12.dp,
bottom = 12.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(
name,
style = MaterialTheme.typography.bodyLarge,
color = titleColor,
maxLines = 1,
overflow = TextOverflow.Ellipsis
)
Text(
subtitle,
style = MaterialTheme.typography.bodyMedium,
color = subColor,
maxLines = 1,
overflow = TextOverflow.Ellipsis
)
}
if (trailingIconRes != null) {
Icon(
painterResource(trailingIconRes),
contentDescription = null,
tint = subColor
)
}
if (trailing != null) trailing()
}
}
}
/** Пустой список серверов: Cookie9Sided-плашка + общая строка. Один вид на всё приложение. */
@Composable
fun EmptyServersState(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(104.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
)
}
}
@@ -16,6 +16,7 @@ import androidx.compose.foundation.shape.CornerSize
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.HorizontalDivider
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.MaterialShapes
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
@@ -29,6 +30,7 @@ import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.Shape
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.semantics.Role
import androidx.compose.ui.semantics.heading
import androidx.compose.ui.semantics.semantics
@@ -197,24 +199,29 @@ fun SettingsSwitchRow(
}
}
/** Тональная иконка-кружок (Sunny) строки настроек. Один источник формы/размера. */
/**
* Тональная иконка-кружок (Sunny) строки настроек. Один источник формы/размера.
* Цвета параметризованы под особые строки (danger → errorContainer).
*/
@Composable
fun SettingsRowIcon(iconRes: Int, enabled: Boolean = true) {
fun SettingsRowIcon(
iconRes: Int,
enabled: Boolean = true,
container: Color = MaterialTheme.colorScheme.secondaryContainer,
tint: Color = MaterialTheme.colorScheme.onSecondaryContainer
) {
// Disabled: гасим контейнер и тинт вместе с заголовком — строка не выглядит наполовину живой.
val alpha = if (enabled) 1f else 0.38f
Box(
modifier = Modifier
.size(40.dp)
.background(
MaterialTheme.colorScheme.secondaryContainer.copy(alpha = alpha),
MaterialShapes.Sunny.toShape()
),
.background(container.copy(alpha = alpha), MaterialShapes.Sunny.toShape()),
contentAlignment = Alignment.Center
) {
Icon(
painterResource(iconRes),
contentDescription = null,
tint = MaterialTheme.colorScheme.onSecondaryContainer.copy(alpha = alpha),
tint = tint.copy(alpha = alpha),
modifier = Modifier.size(22.dp)
)
}
@@ -270,6 +277,17 @@ fun SettingsEntryRow(
}
}
/** Кнопка «назад» в шапке экранов настроек — один источник для всего settings-флоу. */
@Composable
fun SettingsBackButton(onBack: () -> Unit) {
IconButton(onClick = onBack) {
Icon(
painterResource(R.drawable.arrow_back_24px),
contentDescription = stringResource(R.string.back)
)
}
}
/** Inset-разделитель между строками карточки (отступ под иконку). */
@Composable
fun SettingsRowDivider() {