Merge pull request #5186 from k9mail/drawer_account_color
Update drawer with new account color
This commit is contained in:
commit
2ec7443326
1 changed files with 25 additions and 10 deletions
|
@ -142,6 +142,9 @@ class K9Drawer(private val parent: MessageList, savedInstanceState: Bundle?) : K
|
|||
private fun setAccounts(accounts: List<Account>) {
|
||||
val photoUris = mutableSetOf<Uri>()
|
||||
|
||||
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)
|
||||
|
|
Loading…
Reference in a new issue