feat: simplify color handling in ChatsListScreen and improve gesture callbacks in SwipeableDialogItem
This commit is contained in:
@@ -331,6 +331,56 @@ class MainActivity : FragmentActivity() {
|
||||
accountManager.logout()
|
||||
}
|
||||
},
|
||||
onDeleteAccount = {
|
||||
val publicKey = currentAccount?.publicKey ?: return@MainScreen
|
||||
scope.launch {
|
||||
try {
|
||||
val database = RosettaDatabase.getDatabase(this@MainActivity)
|
||||
// 1. Delete all messages
|
||||
database.messageDao().deleteAllByAccount(publicKey)
|
||||
// 2. Delete all dialogs
|
||||
database.dialogDao().deleteAllByAccount(publicKey)
|
||||
// 3. Delete blacklist
|
||||
database.blacklistDao().deleteAllByAccount(publicKey)
|
||||
// 4. Delete avatars from DB
|
||||
database.avatarDao().deleteAvatars(publicKey)
|
||||
// 5. Delete account from Room DB
|
||||
database.accountDao().deleteAccount(publicKey)
|
||||
// 6. Disconnect protocol
|
||||
com.rosetta.messenger.network.ProtocolManager.disconnect()
|
||||
// 7. Delete account from AccountManager DataStore (removes from accounts list + clears login)
|
||||
accountManager.deleteAccount(publicKey)
|
||||
// 8. Refresh accounts list
|
||||
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,
|
||||
username = acc.username ?: "",
|
||||
initials = initials,
|
||||
publicKey = acc.publicKey
|
||||
)
|
||||
}
|
||||
hasExistingAccount = accounts.isNotEmpty()
|
||||
// 8. Navigate away last
|
||||
currentAccount = null
|
||||
} catch (e: Exception) {
|
||||
android.util.Log.e("DeleteAccount", "Failed to delete account", e)
|
||||
}
|
||||
}
|
||||
},
|
||||
onAccountInfoUpdated = {
|
||||
// Reload account list when profile is updated
|
||||
val accounts = accountManager.getAllAccounts()
|
||||
@@ -509,6 +559,7 @@ fun MainScreen(
|
||||
onToggleTheme: () -> Unit = {},
|
||||
onThemeModeChange: (String) -> Unit = {},
|
||||
onLogout: () -> Unit = {},
|
||||
onDeleteAccount: () -> Unit = {},
|
||||
onAccountInfoUpdated: suspend () -> Unit = {}
|
||||
) {
|
||||
// Reactive state for account name and username
|
||||
@@ -758,7 +809,6 @@ fun MainScreen(
|
||||
onNavigateToAppearance = { pushScreen(Screen.Appearance) },
|
||||
onNavigateToSafety = { pushScreen(Screen.Safety) },
|
||||
onNavigateToLogs = { pushScreen(Screen.Logs) },
|
||||
onNavigateToCrashLogs = { pushScreen(Screen.CrashLogs) },
|
||||
onNavigateToBiometric = { pushScreen(Screen.Biometric) },
|
||||
viewModel = profileViewModel,
|
||||
avatarRepository = avatarRepository,
|
||||
@@ -770,13 +820,13 @@ fun MainScreen(
|
||||
// Other screens with swipe back
|
||||
SwipeBackContainer(
|
||||
isVisible = isBackupVisible,
|
||||
onBack = { navStack = navStack.filterNot { it is Screen.Backup } + Screen.Safety },
|
||||
onBack = { navStack = navStack.filterNot { it is Screen.Backup } },
|
||||
isDarkTheme = isDarkTheme
|
||||
) {
|
||||
BackupScreen(
|
||||
isDarkTheme = isDarkTheme,
|
||||
onBack = {
|
||||
navStack = navStack.filterNot { it is Screen.Backup } + Screen.Safety
|
||||
navStack = navStack.filterNot { it is Screen.Backup }
|
||||
},
|
||||
onVerifyPassword = { password ->
|
||||
// Verify password by trying to decrypt the private key
|
||||
@@ -824,11 +874,9 @@ fun MainScreen(
|
||||
accountPrivateKey = accountPrivateKey,
|
||||
onBack = { navStack = navStack.filterNot { it is Screen.Safety } },
|
||||
onBackupClick = {
|
||||
navStack = navStack.filterNot { it is Screen.Safety } + Screen.Backup
|
||||
navStack = navStack + Screen.Backup
|
||||
},
|
||||
onDeleteAccount = {
|
||||
// TODO: Implement account deletion
|
||||
}
|
||||
onDeleteAccount = onDeleteAccount
|
||||
)
|
||||
}
|
||||
|
||||
@@ -893,8 +941,13 @@ fun MainScreen(
|
||||
currentUserName = accountName,
|
||||
onBack = { popChatAndChildren() },
|
||||
onUserProfileClick = { user ->
|
||||
// Открываем профиль другого пользователя
|
||||
pushScreen(Screen.OtherProfile(user))
|
||||
if (user.publicKey == accountPublicKey) {
|
||||
// Свой профиль — открываем My Profile
|
||||
pushScreen(Screen.Profile)
|
||||
} else {
|
||||
// Открываем профиль другого пользователя
|
||||
pushScreen(Screen.OtherProfile(user))
|
||||
}
|
||||
},
|
||||
onNavigateToChat = { forwardUser ->
|
||||
// 📨 Forward: переход в выбранный чат с полными данными
|
||||
@@ -926,6 +979,9 @@ fun MainScreen(
|
||||
navStack =
|
||||
navStack.filterNot { it is Screen.Search } +
|
||||
Screen.ChatDetail(selectedSearchUser)
|
||||
},
|
||||
onNavigateToCrashLogs = {
|
||||
navStack = navStack.filterNot { it is Screen.Search } + Screen.CrashLogs
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user