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) -
|
// Display name (above username)
|
||||||
// clickable для копирования
|
if (accountName.isNotEmpty()) {
|
||||||
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 ->
|
|
||||||
Text(
|
Text(
|
||||||
text =
|
text = accountName,
|
||||||
if (isCopied
|
|
||||||
)
|
|
||||||
"Copied!"
|
|
||||||
else
|
|
||||||
truncatedKey,
|
|
||||||
fontSize = 16.sp,
|
fontSize = 16.sp,
|
||||||
fontWeight =
|
fontWeight = FontWeight.SemiBold,
|
||||||
FontWeight
|
color = Color.White
|
||||||
.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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Автоматически возвращаем обратно
|
// Username display (below name)
|
||||||
// через 1.5 секунды
|
|
||||||
if (showCopiedToast) {
|
|
||||||
LaunchedEffect(Unit) {
|
|
||||||
kotlinx.coroutines
|
|
||||||
.delay(1500)
|
|
||||||
showCopiedToast =
|
|
||||||
false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Spacer(
|
|
||||||
modifier =
|
|
||||||
Modifier.height(
|
|
||||||
6.dp
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
// Username display
|
|
||||||
if (accountUsername.isNotEmpty()) {
|
if (accountUsername.isNotEmpty()) {
|
||||||
|
Spacer(modifier = Modifier.height(4.dp))
|
||||||
Text(
|
Text(
|
||||||
text =
|
text =
|
||||||
"@$accountUsername",
|
"@$accountUsername",
|
||||||
@@ -572,7 +468,7 @@ fun ChatsListScreen(
|
|||||||
Color.White
|
Color.White
|
||||||
.copy(
|
.copy(
|
||||||
alpha =
|
alpha =
|
||||||
0.85f
|
0.7f
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -144,6 +144,12 @@ fun ProfileScreen(
|
|||||||
var editedUsername by remember(accountUsername) { mutableStateOf(accountUsername) }
|
var editedUsername by remember(accountUsername) { mutableStateOf(accountUsername) }
|
||||||
var hasChanges by remember { mutableStateOf(false) }
|
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
|
// ViewModel state
|
||||||
val profileState by viewModel.state.collectAsState()
|
val profileState by viewModel.state.collectAsState()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user