feat: Sync edited fields in ProfileScreen when account data changes
This commit is contained in:
@@ -447,123 +447,19 @@ fun ChatsListScreen(
|
||||
)
|
||||
)
|
||||
|
||||
// Public key (username style) -
|
||||
// clickable для копирования
|
||||
val truncatedKey =
|
||||
if (accountPublicKey
|
||||
.length > 16
|
||||
) {
|
||||
"${accountPublicKey.take(8)}...${accountPublicKey.takeLast(6)}"
|
||||
} else accountPublicKey
|
||||
|
||||
val context =
|
||||
androidx.compose.ui.platform
|
||||
.LocalContext
|
||||
.current
|
||||
var showCopiedToast by remember {
|
||||
mutableStateOf(false)
|
||||
}
|
||||
|
||||
// Плавная замена текста -
|
||||
// ускоренная анимация
|
||||
AnimatedContent(
|
||||
targetState =
|
||||
showCopiedToast,
|
||||
transitionSpec = {
|
||||
fadeIn(
|
||||
animationSpec =
|
||||
tween(
|
||||
150
|
||||
)
|
||||
) togetherWith
|
||||
fadeOut(
|
||||
animationSpec =
|
||||
tween(
|
||||
150
|
||||
)
|
||||
)
|
||||
},
|
||||
label = "copiedAnimation"
|
||||
) { isCopied ->
|
||||
// Display name (above username)
|
||||
if (accountName.isNotEmpty()) {
|
||||
Text(
|
||||
text =
|
||||
if (isCopied
|
||||
)
|
||||
"Copied!"
|
||||
else
|
||||
truncatedKey,
|
||||
text = accountName,
|
||||
fontSize = 16.sp,
|
||||
fontWeight =
|
||||
FontWeight
|
||||
.SemiBold,
|
||||
color = Color.White,
|
||||
fontStyle =
|
||||
if (isCopied
|
||||
)
|
||||
androidx.compose
|
||||
.ui
|
||||
.text
|
||||
.font
|
||||
.FontStyle
|
||||
.Italic
|
||||
else
|
||||
androidx.compose
|
||||
.ui
|
||||
.text
|
||||
.font
|
||||
.FontStyle
|
||||
.Normal,
|
||||
modifier =
|
||||
Modifier
|
||||
.clickable {
|
||||
if (!showCopiedToast
|
||||
) {
|
||||
// Копируем публичный ключ
|
||||
val clipboard =
|
||||
context.getSystemService(
|
||||
android.content
|
||||
.Context
|
||||
.CLIPBOARD_SERVICE
|
||||
) as
|
||||
android.content.ClipboardManager
|
||||
val clip =
|
||||
android.content
|
||||
.ClipData
|
||||
.newPlainText(
|
||||
"Public Key",
|
||||
accountPublicKey
|
||||
)
|
||||
clipboard
|
||||
.setPrimaryClip(
|
||||
clip
|
||||
)
|
||||
showCopiedToast =
|
||||
true
|
||||
}
|
||||
}
|
||||
fontWeight = FontWeight.SemiBold,
|
||||
color = Color.White
|
||||
)
|
||||
}
|
||||
|
||||
// Автоматически возвращаем обратно
|
||||
// через 1.5 секунды
|
||||
if (showCopiedToast) {
|
||||
LaunchedEffect(Unit) {
|
||||
kotlinx.coroutines
|
||||
.delay(1500)
|
||||
showCopiedToast =
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
Spacer(
|
||||
modifier =
|
||||
Modifier.height(
|
||||
6.dp
|
||||
)
|
||||
)
|
||||
|
||||
// Username display
|
||||
// Username display (below name)
|
||||
if (accountUsername.isNotEmpty()) {
|
||||
Spacer(modifier = Modifier.height(4.dp))
|
||||
Text(
|
||||
text =
|
||||
"@$accountUsername",
|
||||
@@ -572,7 +468,7 @@ fun ChatsListScreen(
|
||||
Color.White
|
||||
.copy(
|
||||
alpha =
|
||||
0.85f
|
||||
0.7f
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
@@ -144,6 +144,12 @@ fun ProfileScreen(
|
||||
var editedUsername by remember(accountUsername) { mutableStateOf(accountUsername) }
|
||||
var hasChanges by remember { mutableStateOf(false) }
|
||||
|
||||
// Sync edited fields when account data changes from parent (after save)
|
||||
LaunchedEffect(accountName, accountUsername) {
|
||||
editedName = accountName
|
||||
editedUsername = accountUsername
|
||||
}
|
||||
|
||||
// ViewModel state
|
||||
val profileState by viewModel.state.collectAsState()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user