feat: Implement account info update handling in MainScreen for reactive UI updates
This commit is contained in:
@@ -306,6 +306,37 @@ class MainActivity : ComponentActivity() {
|
||||
.disconnect()
|
||||
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,
|
||||
isDarkTheme: Boolean = true,
|
||||
onToggleTheme: () -> Unit = {},
|
||||
onLogout: () -> Unit = {}
|
||||
onLogout: () -> Unit = {},
|
||||
onAccountInfoUpdated: suspend () -> Unit = {}
|
||||
) {
|
||||
// Reactive state for account name and username
|
||||
var accountName by remember { mutableStateOf(account?.name ?: "Account") }
|
||||
@@ -476,6 +508,9 @@ fun MainScreen(
|
||||
// ProfileViewModel для логов
|
||||
val profileViewModel: com.rosetta.messenger.ui.settings.ProfileViewModel = androidx.lifecycle.viewmodel.compose.viewModel()
|
||||
val profileState by profileViewModel.state.collectAsState()
|
||||
|
||||
// Coroutine scope for profile updates
|
||||
val mainScreenScope = rememberCoroutineScope()
|
||||
|
||||
// 🔥 Простая навигация с fade-in анимацией
|
||||
Box(modifier = Modifier.fillMaxSize()) {
|
||||
@@ -716,8 +751,10 @@ fun MainScreen(
|
||||
// 3. This callback updates UI state immediately
|
||||
accountName = name
|
||||
accountUsername = username
|
||||
// Don't reload from DB immediately - it's async and may not be ready yet
|
||||
// The values are already updated above and DB is updated in ProfileScreen
|
||||
// Reload account list so auth screen shows updated name
|
||||
mainScreenScope.launch {
|
||||
onAccountInfoUpdated()
|
||||
}
|
||||
Log.d("MainActivity", "Profile saved: name=$name, username=$username, UI updated")
|
||||
},
|
||||
onLogout = onLogout,
|
||||
|
||||
Reference in New Issue
Block a user