From be2aac52a852dfc8a942d0e08895193ecf5273df Mon Sep 17 00:00:00 2001 From: cketti Date: Sat, 21 Jan 2012 03:10:40 +0100 Subject: [PATCH] Reload accounts after writing imported account settings to storage This makes sure that when the next account is imported it will see the account just imported. That's necessary e.g. when going though all accounts to find the next free account number, or when avoiding account name conflicts. --- .../fsck/k9/preferences/SettingsImporter.java | 36 +++++++++++-------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/src/com/fsck/k9/preferences/SettingsImporter.java b/src/com/fsck/k9/preferences/SettingsImporter.java index aa307ba66..a20059f47 100644 --- a/src/com/fsck/k9/preferences/SettingsImporter.java +++ b/src/com/fsck/k9/preferences/SettingsImporter.java @@ -215,7 +215,6 @@ public class SettingsImporter { if (accountUuids != null && accountUuids.size() > 0) { if (imported.accounts != null) { - List newUuids = new ArrayList(); for (String accountUuid : accountUuids) { if (imported.accounts.containsKey(accountUuid)) { ImportedAccount account = imported.accounts.get(accountUuid); @@ -225,16 +224,33 @@ public class SettingsImporter { AccountDescriptionPair importResult = importAccount(context, editor, imported.contentVersion, account, overwrite); - String newUuid = importResult.imported.uuid; - if (!importResult.overwritten) { - newUuids.add(newUuid); - } if (editor.commit()) { if (K9.DEBUG) { Log.v(K9.LOG_TAG, "Committed settings for account \"" + importResult.imported.name + "\" to the settings database."); } + + // Add UUID of the account we just imported to the list of + // account UUIDs + if (!importResult.overwritten) { + editor = storage.edit(); + + String newUuid = importResult.imported.uuid; + String oldAccountUuids = storage.getString("accountUuids", ""); + String newAccountUuids = (oldAccountUuids.length() > 0) ? + oldAccountUuids + "," + newUuid : newUuid; + + putString(editor, "accountUuids", newAccountUuids); + + if (!editor.commit()) { + throw new SettingsImportExportException("Failed to set account UUID list"); + } + } + + // Reload accounts + preferences.loadAccounts(); + importedAccounts.add(importResult); } else { if (K9.DEBUG) { @@ -263,16 +279,6 @@ public class SettingsImporter { SharedPreferences.Editor editor = storage.edit(); - if (newUuids.size() > 0) { - String oldAccountUuids = storage.getString("accountUuids", ""); - String appendUuids = Utility.combine(newUuids.toArray(new String[0]), ','); - String prefix = ""; - if (oldAccountUuids.length() > 0) { - prefix = oldAccountUuids + ","; - } - putString(editor, "accountUuids", prefix + appendUuids); - } - String defaultAccountUuid = storage.getString("defaultAccountUuid", null); if (defaultAccountUuid == null) { putString(editor, "defaultAccountUuid", accountUuids.get(0));