From 1aab01ce4163a2059284da0d0680bed9c08eae45 Mon Sep 17 00:00:00 2001 From: cketti Date: Wed, 3 Mar 2021 20:04:35 +0100 Subject: [PATCH] Update drawer with new account color When the color of the currently selected account has changed update the drawer to reflect that change. --- .../src/main/java/com/fsck/k9/ui/K9Drawer.kt | 35 +++++++++++++------ 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/app/ui/legacy/src/main/java/com/fsck/k9/ui/K9Drawer.kt b/app/ui/legacy/src/main/java/com/fsck/k9/ui/K9Drawer.kt index f8d010feb..0bcc98855 100644 --- a/app/ui/legacy/src/main/java/com/fsck/k9/ui/K9Drawer.kt +++ b/app/ui/legacy/src/main/java/com/fsck/k9/ui/K9Drawer.kt @@ -142,6 +142,9 @@ class K9Drawer(private val parent: MessageList, savedInstanceState: Bundle?) : K private fun setAccounts(accounts: List) { val photoUris = mutableSetOf() + val selectedAccountUuid = (headerView.activeProfile?.tag as? Account)?.uuid + val oldSelectedBackgroundColor = selectedBackgroundColor + val accountItems = accounts.map { account -> val drawerId = (account.accountNumber + 1 shl DRAWER_ACCOUNT_SHIFT).toLong() @@ -173,11 +176,20 @@ class K9Drawer(private val parent: MessageList, savedInstanceState: Bundle?) : K } } + if (account.uuid == selectedAccountUuid) { + initializeWithAccountColor(account) + } + accountItem }.toTypedArray() headerView.clear() headerView.addProfiles(*accountItems) + + if (oldSelectedBackgroundColor != selectedBackgroundColor) { + // Recreate list of folders with updated account color + setUserFolders(foldersViewModel.getFolderListLiveData().value) + } } private fun addFooterItems() { @@ -215,17 +227,8 @@ class K9Drawer(private val parent: MessageList, savedInstanceState: Bundle?) : K fun updateUserAccountsAndFolders(account: Account?) { if (account != null) { - getDrawerColorsForAccount(account).let { drawerColors -> - selectedBackgroundColor = drawerColors.selectedColor - val selectedTextColor = drawerColors.accentColor.toSelectedColorStateList() - this.selectedTextColor = selectedTextColor - folderBadgeStyle = BadgeStyle().apply { - textColorStateList = selectedTextColor - } - } - + initializeWithAccountColor(account) headerView.setActiveProfile((account.accountNumber + 1 shl DRAWER_ACCOUNT_SHIFT).toLong()) - headerView.accountHeaderBackground.setColorFilter(account.chipColor, PorterDuff.Mode.MULTIPLY) foldersViewModel.loadFolders(account) } @@ -245,6 +248,18 @@ class K9Drawer(private val parent: MessageList, savedInstanceState: Bundle?) : K } } + private fun initializeWithAccountColor(account: Account) { + getDrawerColorsForAccount(account).let { drawerColors -> + selectedBackgroundColor = drawerColors.selectedColor + val selectedTextColor = drawerColors.accentColor.toSelectedColorStateList() + this.selectedTextColor = selectedTextColor + folderBadgeStyle = BadgeStyle().apply { + textColorStateList = selectedTextColor + } + } + headerView.accountHeaderBackground.setColorFilter(account.chipColor, PorterDuff.Mode.MULTIPLY) + } + private fun handleItemClickListener(drawerItem: IDrawerItem<*>) { when (drawerItem.identifier) { DRAWER_ID_PREFERENCES -> SettingsActivity.launch(parent)