1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-12-25 00:58:50 -05:00

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.
This commit is contained in:
cketti 2012-01-21 03:10:40 +01:00
parent 45e7afc60e
commit 5b7cf15753

View File

@ -214,7 +214,6 @@ public class SettingsImporter {
if (accountUuids != null && accountUuids.size() > 0) {
if (imported.accounts != null) {
List<String> newUuids = new ArrayList<String>();
for (String accountUuid : accountUuids) {
if (imported.accounts.containsKey(accountUuid)) {
ImportedAccount account = imported.accounts.get(accountUuid);
@ -224,16 +223,33 @@ public class SettingsImporter {
AccountDescriptionPair importResult = importAccount(context,
editor, 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) {
@ -262,16 +278,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));