From 9f0e29c4cd88aae2fda12720acf28e20d943bd6d Mon Sep 17 00:00:00 2001 From: k1ngsterr1 Date: Thu, 22 Jan 2026 01:03:41 +0500 Subject: [PATCH] feat: Sync edited fields in ProfileScreen when account data changes --- .../messenger/ui/chats/ChatsListScreen.kt | 120 ++---------------- .../messenger/ui/settings/ProfileScreen.kt | 6 + 2 files changed, 14 insertions(+), 112 deletions(-) diff --git a/app/src/main/java/com/rosetta/messenger/ui/chats/ChatsListScreen.kt b/app/src/main/java/com/rosetta/messenger/ui/chats/ChatsListScreen.kt index 07c8939..fcf8b35 100644 --- a/app/src/main/java/com/rosetta/messenger/ui/chats/ChatsListScreen.kt +++ b/app/src/main/java/com/rosetta/messenger/ui/chats/ChatsListScreen.kt @@ -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 ) ) } diff --git a/app/src/main/java/com/rosetta/messenger/ui/settings/ProfileScreen.kt b/app/src/main/java/com/rosetta/messenger/ui/settings/ProfileScreen.kt index e727b8f..9b98a08 100644 --- a/app/src/main/java/com/rosetta/messenger/ui/settings/ProfileScreen.kt +++ b/app/src/main/java/com/rosetta/messenger/ui/settings/ProfileScreen.kt @@ -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()