Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 72d76029 authored by ByteHamster's avatar ByteHamster Committed by cketti
Browse files

Use account color as accent color in drawer

Use slightly different dark theme highlight colors
Chose the colors so they have WCAG AA contrast on #333333 background
parent 6b91f608
Loading
Loading
Loading
Loading
+4 −3
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<resources>

    <!-- Must be kept in sync with arrays_drawer.xml/drawer_account_accent_color_dark_theme -->
    <integer-array name="account_colors">
        <item>0xFFFFB300</item> <!-- Amber 600 -->
        <item>0xFFFB8C00</item> <!-- Orange 600 -->
+27 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<resources>

    <!-- Must be kept in sync with arrays_account_settings_values.xml/account_colors -->
    <integer-array name="drawer_account_accent_color_dark_theme">
        <item>0xFFFFB300</item> <!-- Amber 600 -->
        <item>0xFFFF9800</item> <!-- Orange 500 -->
        <item>0xFFFF7043</item> <!-- Deep orange 400 -->
        <item>0xFFEF5350</item> <!-- Red 400 -->

        <item>0xFFC0CA33</item> <!-- Lime 600 -->
        <item>0xFF7CB342</item> <!-- Light green 600 -->
        <item>0xFF4CAF50</item> <!-- Green 500 -->
        <item>0xFF4DB6AC</item> <!-- Teal 300 -->

        <item>0xFF00ACC1</item> <!-- Cyan 600 -->
        <item>0xFF03A9F4</item> <!-- Light blue 500 -->
        <item>0xFF42A5F5</item> <!-- Blue 400 -->
        <item>0xFF9FA8DA</item> <!-- Indigo 200 -->

        <item>0xFFF48FB1</item> <!-- Pink 200 -->
        <item>0xFFCE93D8</item> <!-- Purple 200 -->
        <item>0xFFB39DDB</item> <!-- Deep purple 200 -->
        <item>0xFF90A4AE</item> <!-- Blue gray 300 -->
    </integer-array>

</resources>
+34 −0
Original line number Diff line number Diff line
package com.fsck.k9.ui

import android.content.res.Resources
import android.graphics.Color
import android.graphics.PorterDuff
import android.net.Uri
@@ -45,6 +46,8 @@ import org.koin.core.inject
class K9Drawer(private val parent: MessageList, savedInstanceState: Bundle?) : KoinComponent {
    private val folderNameFormatter: FolderNameFormatter by inject()
    private val preferences: Preferences by inject()
    private val themeManager: ThemeManager by inject()
    private val resources: Resources by inject()

    private val drawer: Drawer
    private val accountHeader: AccountHeader
@@ -53,6 +56,8 @@ class K9Drawer(private val parent: MessageList, savedInstanceState: Bundle?) : K

    private val userFolderDrawerIds = ArrayList<Long>()
    private var unifiedInboxSelected: Boolean = false
    private var accentColor: Int = 0
    private var selectedColor: Int = 0
    private var openedFolderServerId: String? = null

    private var foldersLiveData: FoldersLiveData? = null
@@ -178,6 +183,11 @@ class K9Drawer(private val parent: MessageList, savedInstanceState: Bundle?) : K
            selectUnifiedInbox()
        } else {
            unifiedInboxSelected = false
            with (getDrawerColorsForAccount(account)) {
                accentColor = first
                selectedColor = second
            }

            accountHeader.setActiveProfile((account.accountNumber + 1 shl DRAWER_ACCOUNT_SHIFT).toLong())
            accountHeader.headerBackgroundView.setColorFilter(account.chipColor, PorterDuff.Mode.MULTIPLY)
            val viewModelProvider = ViewModelProviders.of(parent, MessageListViewModelFactory())
@@ -231,6 +241,8 @@ class K9Drawer(private val parent: MessageList, savedInstanceState: Bundle?) : K
                    .withIcon(folderIconProvider.getFolderIcon(folder.type))
                    .withIdentifier(drawerId)
                    .withTag(folder)
                    .withSelectedColor(selectedColor)
                    .withSelectedTextColor(accentColor)
                    .withName(getFolderDisplayName(folder))

            val unreadCount = displayFolder.unreadCount
@@ -281,12 +293,34 @@ class K9Drawer(private val parent: MessageList, savedInstanceState: Bundle?) : K
    fun selectUnifiedInbox() {
        unifiedInboxSelected = true
        openedFolderServerId = null
        accentColor = 0 // Unified inbox does not have folders, so color does not matter
        selectedColor = 0
        accountHeader.setActiveProfile(DRAWER_ID_UNIFIED_INBOX)
        accountHeader.headerBackgroundView.setColorFilter(0xFFFFFFFFL.toInt(), PorterDuff.Mode.MULTIPLY)
        clearUserFolders()
        updateFolderSettingsItem()
    }

    private fun getDrawerColorsForAccount(account: Account) : Pair<Int, Int> {
        val baseColor = if (themeManager.appTheme == Theme.DARK) {
            getDarkThemeAccentColor(account.chipColor)
        } else {
            account.chipColor
        }
        return Pair(baseColor, baseColor.and(0xffffff).or(0x22000000))
    }

    private fun getDarkThemeAccentColor(color: Int) : Int {
        val lightColors = resources.getIntArray(R.array.account_colors)
        val darkColors = resources.getIntArray(R.array.drawer_account_accent_color_dark_theme)
        val idx = lightColors.indexOf(color)
        return if (idx == -1) {
            color
        } else {
            darkColors[idx]
        }
    }

    fun open() {
        drawer.openDrawer()
    }
+19 −0
Original line number Diff line number Diff line
package com.fsck.k9.ui;

import android.content.res.Resources;
import com.fsck.k9.RobolectricTest;
import org.junit.Test;
import org.robolectric.RuntimeEnvironment;

import static junit.framework.Assert.assertEquals;

public class K9DrawerTest extends RobolectricTest {

    @Test
    public void testAccountColorLengthEqualsDrawerColorLength() {
        Resources res = RuntimeEnvironment.application.getResources();
        int[] lightColors = res.getIntArray(R.array.account_colors);
        int[] darkColors = res.getIntArray(R.array.drawer_account_accent_color_dark_theme);
        assertEquals(lightColors.length, darkColors.length);
    }
}