diff --git a/k9mail/src/main/java/com/fsck/k9/Account.java b/k9mail/src/main/java/com/fsck/k9/Account.java index 8e6d0fe96..c4df1aad7 100644 --- a/k9mail/src/main/java/com/fsck/k9/Account.java +++ b/k9mail/src/main/java/com/fsck/k9/Account.java @@ -16,7 +16,6 @@ import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; import android.content.Context; -import android.graphics.Color; import android.net.Uri; import com.fsck.k9.activity.setup.AccountSetupCheckSettings.CheckDirection; @@ -110,18 +109,6 @@ public class Account implements BaseAccount, StoreConfig { public static final String IDENTITY_EMAIL_KEY = "email"; public static final String IDENTITY_DESCRIPTION_KEY = "description"; - /* - * https://developer.android.com/design/style/color.html - * Note: Order does matter, it's the order in which they will be picked. - */ - private static final Integer[] PREDEFINED_COLORS = new Integer[] { - Color.parseColor("#0099CC"), // blue - Color.parseColor("#669900"), // green - Color.parseColor("#FF8800"), // orange - Color.parseColor("#CC0000"), // red - Color.parseColor("#9933CC") // purple - }; - public enum SortType { SORT_DATE(R.string.sort_earliest_first, R.string.sort_latest_first, false), SORT_ARRIVAL(R.string.sort_earliest_first, R.string.sort_latest_first, false), @@ -296,7 +283,6 @@ public class Account implements BaseAccount, StoreConfig { autoExpandFolder = INBOX; inboxFolder = INBOX; maxPushFolders = 10; - chipColor = pickColor(context); goToUnreadMessageSearch = false; subscribedFoldersOnly = false; maximumPolledMessageAge = -1; @@ -339,28 +325,6 @@ public class Account implements BaseAccount, StoreConfig { cacheChips(); } - /* - * Pick a nice Android guidelines color if we haven't used them all yet. - */ - private int pickColor(Context context) { - List accounts = Preferences.getPreferences(context).getAccounts(); - - List availableColors = new ArrayList<>(PREDEFINED_COLORS.length); - Collections.addAll(availableColors, PREDEFINED_COLORS); - - for (Account account : accounts) { - Integer color = account.getChipColor(); - if (availableColors.contains(color)) { - availableColors.remove(color); - if (availableColors.isEmpty()) { - break; - } - } - } - - return (availableColors.isEmpty()) ? ColorPicker.getRandomColor() : availableColors.get(0); - } - protected Account(Preferences preferences, String uuid) { this.accountUuid = uuid; loadAccount(preferences); diff --git a/k9mail/src/main/java/com/fsck/k9/account/AccountCreator.java b/k9mail/src/main/java/com/fsck/k9/account/AccountCreator.java index d591ccddb..799ceb642 100644 --- a/k9mail/src/main/java/com/fsck/k9/account/AccountCreator.java +++ b/k9mail/src/main/java/com/fsck/k9/account/AccountCreator.java @@ -1,9 +1,19 @@ package com.fsck.k9.account; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import android.content.Context; +import android.graphics.Color; + +import com.fsck.k9.Account; import com.fsck.k9.Account.DeletePolicy; +import com.fsck.k9.Preferences; import com.fsck.k9.mail.ConnectionSecurity; import com.fsck.k9.mail.ServerSettings.Type; +import com.larswerkman.colorpicker.ColorPicker; /** @@ -12,6 +22,18 @@ import com.fsck.k9.mail.ServerSettings.Type; * TODO Move much of the code from com.fsck.k9.activity.setup.* into here */ public class AccountCreator { + /* + * https://developer.android.com/design/style/color.html + * Note: Order does matter, it's the order in which they will be picked. + */ + private static final Integer[] PREDEFINED_COLORS = new Integer[] { + Color.parseColor("#0099CC"), // blue + Color.parseColor("#669900"), // green + Color.parseColor("#FF8800"), // orange + Color.parseColor("#CC0000"), // red + Color.parseColor("#9933CC") // purple + }; + public static DeletePolicy getDefaultDeletePolicy(Type type) { switch (type) { @@ -45,4 +67,26 @@ public class AccountCreator { throw new AssertionError("Unhandled ConnectionSecurity type encountered: " + securityType); } + + /* + * Pick a nice Android guidelines color if we haven't used them all yet. + */ + public static int pickColor(Context context) { + List accounts = Preferences.getPreferences(context).getAccounts(); + + List availableColors = new ArrayList<>(PREDEFINED_COLORS.length); + Collections.addAll(availableColors, PREDEFINED_COLORS); + + for (Account account : accounts) { + Integer color = account.getChipColor(); + if (availableColors.contains(color)) { + availableColors.remove(color); + if (availableColors.isEmpty()) { + break; + } + } + } + + return (availableColors.isEmpty()) ? ColorPicker.getRandomColor() : availableColors.get(0); + } } diff --git a/k9mail/src/main/java/com/fsck/k9/activity/setup/AccountSetupBasics.java b/k9mail/src/main/java/com/fsck/k9/activity/setup/AccountSetupBasics.java index 79cf29ed7..e7c425a15 100644 --- a/k9mail/src/main/java/com/fsck/k9/activity/setup/AccountSetupBasics.java +++ b/k9mail/src/main/java/com/fsck/k9/activity/setup/AccountSetupBasics.java @@ -314,6 +314,7 @@ public class AccountSetupBasics extends K9Activity } if (mAccount == null) { mAccount = Preferences.getPreferences(this).newAccount(); + mAccount.setChipColor(AccountCreator.pickColor(this)); } mAccount.setName(getOwnerName()); mAccount.setEmail(email); @@ -400,6 +401,7 @@ public class AccountSetupBasics extends K9Activity if (mAccount == null) { mAccount = Preferences.getPreferences(this).newAccount(); + mAccount.setChipColor(AccountCreator.pickColor(this)); } mAccount.setName(getOwnerName()); mAccount.setEmail(email); diff --git a/k9mail/src/test/java/com/fsck/k9/account/AccountCreatorTest.java b/k9mail/src/test/java/com/fsck/k9/account/AccountCreatorTest.java index 8df85758c..c0c6a1649 100644 --- a/k9mail/src/test/java/com/fsck/k9/account/AccountCreatorTest.java +++ b/k9mail/src/test/java/com/fsck/k9/account/AccountCreatorTest.java @@ -5,10 +5,13 @@ import com.fsck.k9.Account.DeletePolicy; import com.fsck.k9.mail.ConnectionSecurity; import com.fsck.k9.mail.ServerSettings.Type; import org.junit.Test; +import org.junit.runner.RunWith; +import org.robolectric.RobolectricTestRunner; import static org.junit.Assert.assertEquals; +@RunWith(RobolectricTestRunner.class) public class AccountCreatorTest { @Test