feat: Implement account info update handling in MainScreen for reactive UI updates

This commit is contained in:
k1ngsterr1
2026-01-22 01:21:36 +05:00
parent 9f0e29c4cd
commit c9cd3dc69b

View File

@@ -306,6 +306,37 @@ class MainActivity : ComponentActivity() {
.disconnect() .disconnect()
accountManager.logout() accountManager.logout()
} }
},
onAccountInfoUpdated = {
// Reload account list when profile is updated
val accounts = accountManager.getAllAccounts()
accountInfoList =
accounts.map { acc ->
val shortKey = acc.publicKey.take(7)
val displayName = acc.name ?: shortKey
val initials =
displayName
.trim()
.split(Regex("\\s+"))
.filter { it.isNotEmpty() }
.let { words ->
when {
words.isEmpty() -> "??"
words.size == 1 ->
words[0]
.take(2)
.uppercase()
else ->
"${words[0].first()}${words[1].first()}".uppercase()
}
}
AccountInfo(
id = acc.publicKey,
name = displayName,
initials = initials,
publicKey = acc.publicKey
)
}
} }
) )
} }
@@ -426,7 +457,8 @@ fun MainScreen(
account: DecryptedAccount? = null, account: DecryptedAccount? = null,
isDarkTheme: Boolean = true, isDarkTheme: Boolean = true,
onToggleTheme: () -> Unit = {}, onToggleTheme: () -> Unit = {},
onLogout: () -> Unit = {} onLogout: () -> Unit = {},
onAccountInfoUpdated: suspend () -> Unit = {}
) { ) {
// Reactive state for account name and username // Reactive state for account name and username
var accountName by remember { mutableStateOf(account?.name ?: "Account") } var accountName by remember { mutableStateOf(account?.name ?: "Account") }
@@ -477,6 +509,9 @@ fun MainScreen(
val profileViewModel: com.rosetta.messenger.ui.settings.ProfileViewModel = androidx.lifecycle.viewmodel.compose.viewModel() val profileViewModel: com.rosetta.messenger.ui.settings.ProfileViewModel = androidx.lifecycle.viewmodel.compose.viewModel()
val profileState by profileViewModel.state.collectAsState() val profileState by profileViewModel.state.collectAsState()
// Coroutine scope for profile updates
val mainScreenScope = rememberCoroutineScope()
// 🔥 Простая навигация с fade-in анимацией // 🔥 Простая навигация с fade-in анимацией
Box(modifier = Modifier.fillMaxSize()) { Box(modifier = Modifier.fillMaxSize()) {
// Base layer - chats list // Base layer - chats list
@@ -716,8 +751,10 @@ fun MainScreen(
// 3. This callback updates UI state immediately // 3. This callback updates UI state immediately
accountName = name accountName = name
accountUsername = username accountUsername = username
// Don't reload from DB immediately - it's async and may not be ready yet // Reload account list so auth screen shows updated name
// The values are already updated above and DB is updated in ProfileScreen mainScreenScope.launch {
onAccountInfoUpdated()
}
Log.d("MainActivity", "Profile saved: name=$name, username=$username, UI updated") Log.d("MainActivity", "Profile saved: name=$name, username=$username, UI updated")
}, },
onLogout = onLogout, onLogout = onLogout,