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

Commit a64f90cd authored by cketti's avatar cketti
Browse files

Read account colors from resource array

parent b7e8200f
Loading
Loading
Loading
Loading
+8 −21
Original line number Diff line number Diff line
package com.fsck.k9.account

import android.graphics.Color
import android.content.res.Resources
import com.fsck.k9.Account.DeletePolicy
import com.fsck.k9.Preferences
import com.fsck.k9.mail.ConnectionSecurity
import com.fsck.k9.preferences.Protocols
import com.fsck.k9.ui.R

/**
 * Deals with logic surrounding account creation.
 *
 * TODO Move much of the code from com.fsck.k9.activity.setup.* into here
 */
class AccountCreator(private val preferences: Preferences) {
    /*
     * https://developer.android.com/design/style/color.html
     * Note: Order does matter, it's the order in which they will be picked.
     */
    private val PREDEFINED_COLORS = listOf(
        Color.parseColor("#0099CC"),  // blue
        Color.parseColor("#669900"),  // green
        Color.parseColor("#FF8800"),  // orange
        Color.parseColor("#CC0000"),  // red
        Color.parseColor("#9933CC") // purple
    )
class AccountCreator(private val preferences: Preferences, private val resources: Resources) {

    fun getDefaultDeletePolicy(type: String): DeletePolicy {
        return when (type) {
@@ -61,14 +51,11 @@ class AccountCreator(private val preferences: Preferences) {

    fun pickColor(): Int {
        val accounts = preferences.accounts
        val usedAccountColors = accounts.map { it.chipColor }.toSet()
        val accountColors = resources.getIntArray(R.array.account_colors)

        val usedAccountColors = accounts.map { it.chipColor }
        val availableColors = PREDEFINED_COLORS - usedAccountColors
        return availableColors.firstOrNull() ?: getRandomColor()
    }

    private fun getRandomColor(): Int {
        //TODO: return random color
        return PREDEFINED_COLORS[4]
        return accountColors.asSequence()
            .filterNot { it in usedAccountColors }
            .firstOrNull() ?: accountColors.random()
    }
}
+1 −1
Original line number Diff line number Diff line
@@ -5,5 +5,5 @@ import org.koin.dsl.module
val accountModule = module {
    factory { AccountRemover(get(), get(), get()) }
    factory { BackgroundAccountRemover(get()) }
    factory { AccountCreator(get()) }
    factory { AccountCreator(get(), get()) }
}
+4 −1
Original line number Diff line number Diff line
package com.fsck.k9.account;


import android.content.res.Resources;

import com.fsck.k9.Account.DeletePolicy;
import com.fsck.k9.Preferences;
import com.fsck.k9.RobolectricTest;
@@ -20,7 +22,8 @@ public class AccountCreatorTest extends RobolectricTest {
    @Before
    public void setUp() {
        Preferences preferences = mock(Preferences.class);
        accountCreator = new AccountCreator(preferences);
        Resources resources = mock(Resources.class);
        accountCreator = new AccountCreator(preferences, resources);
    }

    @Test