Loading app/ui/src/main/java/com/fsck/k9/account/AccountCreator.kt +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) { Loading Loading @@ -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() } } app/ui/src/main/java/com/fsck/k9/account/KoinModule.kt +1 −1 Original line number Diff line number Diff line Loading @@ -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()) } } app/ui/src/test/java/com/fsck/k9/account/AccountCreatorTest.java +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; Loading @@ -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 Loading Loading
app/ui/src/main/java/com/fsck/k9/account/AccountCreator.kt +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) { Loading Loading @@ -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() } }
app/ui/src/main/java/com/fsck/k9/account/KoinModule.kt +1 −1 Original line number Diff line number Diff line Loading @@ -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()) } }
app/ui/src/test/java/com/fsck/k9/account/AccountCreatorTest.java +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; Loading @@ -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 Loading