mirror of
https://github.com/moparisthebest/k-9
synced 2024-12-17 21:32:26 -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:
parent
0625e13380
commit
be2aac52a8
@ -215,7 +215,6 @@ public class SettingsImporter {
|
|||||||
|
|
||||||
if (accountUuids != null && accountUuids.size() > 0) {
|
if (accountUuids != null && accountUuids.size() > 0) {
|
||||||
if (imported.accounts != null) {
|
if (imported.accounts != null) {
|
||||||
List<String> newUuids = new ArrayList<String>();
|
|
||||||
for (String accountUuid : accountUuids) {
|
for (String accountUuid : accountUuids) {
|
||||||
if (imported.accounts.containsKey(accountUuid)) {
|
if (imported.accounts.containsKey(accountUuid)) {
|
||||||
ImportedAccount account = imported.accounts.get(accountUuid);
|
ImportedAccount account = imported.accounts.get(accountUuid);
|
||||||
@ -225,16 +224,33 @@ public class SettingsImporter {
|
|||||||
AccountDescriptionPair importResult = importAccount(context,
|
AccountDescriptionPair importResult = importAccount(context,
|
||||||
editor, imported.contentVersion, account, overwrite);
|
editor, imported.contentVersion, account, overwrite);
|
||||||
|
|
||||||
String newUuid = importResult.imported.uuid;
|
|
||||||
if (!importResult.overwritten) {
|
|
||||||
newUuids.add(newUuid);
|
|
||||||
}
|
|
||||||
if (editor.commit()) {
|
if (editor.commit()) {
|
||||||
if (K9.DEBUG) {
|
if (K9.DEBUG) {
|
||||||
Log.v(K9.LOG_TAG, "Committed settings for account \"" +
|
Log.v(K9.LOG_TAG, "Committed settings for account \"" +
|
||||||
importResult.imported.name +
|
importResult.imported.name +
|
||||||
"\" to the settings database.");
|
"\" 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);
|
importedAccounts.add(importResult);
|
||||||
} else {
|
} else {
|
||||||
if (K9.DEBUG) {
|
if (K9.DEBUG) {
|
||||||
@ -263,16 +279,6 @@ public class SettingsImporter {
|
|||||||
|
|
||||||
SharedPreferences.Editor editor = storage.edit();
|
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);
|
String defaultAccountUuid = storage.getString("defaultAccountUuid", null);
|
||||||
if (defaultAccountUuid == null) {
|
if (defaultAccountUuid == null) {
|
||||||
putString(editor, "defaultAccountUuid", accountUuids.get(0));
|
putString(editor, "defaultAccountUuid", accountUuids.get(0));
|
||||||
|
Loading…
Reference in New Issue
Block a user