Code cleanup
This commit is contained in:
parent
6714a7ec5a
commit
d791770154
1 changed files with 27 additions and 27 deletions
|
@ -321,24 +321,8 @@ public class StorageImporter {
|
||||||
uuid = UUID.randomUUID().toString();
|
uuid = UUID.randomUUID().toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<String, String> validatedSettings =
|
// Make sure the account name is unique
|
||||||
AccountSettings.validate(account.settings.settings, !mergeImportedAccount);
|
String accountName = (account.name != null) ? account.name : "Imported";
|
||||||
|
|
||||||
Map<String, String> writeSettings;
|
|
||||||
if (mergeImportedAccount) {
|
|
||||||
writeSettings = new HashMap<String, String>(
|
|
||||||
AccountSettings.getAccountSettings(prefs.getPreferences(), uuid));
|
|
||||||
writeSettings.putAll(validatedSettings);
|
|
||||||
} else {
|
|
||||||
writeSettings = new HashMap<String, String>(validatedSettings);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//TODO: validate account name
|
|
||||||
//TODO: validate server settings
|
|
||||||
|
|
||||||
|
|
||||||
String accountName = account.name;
|
|
||||||
if (isAccountNameUsed(accountName, accounts)) {
|
if (isAccountNameUsed(accountName, accounts)) {
|
||||||
// Account name is already in use. So generate a new one by appending " (x)", where x
|
// Account name is already in use. So generate a new one by appending " (x)", where x
|
||||||
// is the first number >= 1 that results in an unused account name.
|
// is the first number >= 1 that results in an unused account name.
|
||||||
|
@ -350,6 +334,7 @@ public class StorageImporter {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Write account name
|
||||||
String accountKeyPrefix = uuid + ".";
|
String accountKeyPrefix = uuid + ".";
|
||||||
putString(editor, accountKeyPrefix + Account.ACCOUNT_DESCRIPTION_KEY, accountName);
|
putString(editor, accountKeyPrefix + Account.ACCOUNT_DESCRIPTION_KEY, accountName);
|
||||||
|
|
||||||
|
@ -363,6 +348,20 @@ public class StorageImporter {
|
||||||
String transportUri = Transport.createTransportUri(outgoing);
|
String transportUri = Transport.createTransportUri(outgoing);
|
||||||
putString(editor, accountKeyPrefix + Account.TRANSPORT_URI_KEY, Utility.base64Encode(transportUri));
|
putString(editor, accountKeyPrefix + Account.TRANSPORT_URI_KEY, Utility.base64Encode(transportUri));
|
||||||
|
|
||||||
|
// Validate account settings
|
||||||
|
Map<String, String> validatedSettings =
|
||||||
|
AccountSettings.validate(account.settings.settings, !mergeImportedAccount);
|
||||||
|
|
||||||
|
// Merge account settings if necessary
|
||||||
|
Map<String, String> writeSettings;
|
||||||
|
if (mergeImportedAccount) {
|
||||||
|
writeSettings = new HashMap<String, String>(
|
||||||
|
AccountSettings.getAccountSettings(prefs.getPreferences(), uuid));
|
||||||
|
writeSettings.putAll(validatedSettings);
|
||||||
|
} else {
|
||||||
|
writeSettings = validatedSettings;
|
||||||
|
}
|
||||||
|
|
||||||
// Write account settings
|
// Write account settings
|
||||||
for (Map.Entry<String, String> setting : writeSettings.entrySet()) {
|
for (Map.Entry<String, String> setting : writeSettings.entrySet()) {
|
||||||
String key = accountKeyPrefix + setting.getKey();
|
String key = accountKeyPrefix + setting.getKey();
|
||||||
|
@ -376,6 +375,7 @@ public class StorageImporter {
|
||||||
putString(editor, accountKeyPrefix + "accountNumber", Integer.toString(newAccountNumber));
|
putString(editor, accountKeyPrefix + "accountNumber", Integer.toString(newAccountNumber));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Write identities
|
||||||
if (account.identities != null) {
|
if (account.identities != null) {
|
||||||
importIdentities(editor, uuid, account, overwrite, existingAccount, prefs);
|
importIdentities(editor, uuid, account, overwrite, existingAccount, prefs);
|
||||||
}
|
}
|
||||||
|
@ -397,23 +397,23 @@ public class StorageImporter {
|
||||||
ImportedFolder folder, boolean overwrite, Preferences prefs) {
|
ImportedFolder folder, boolean overwrite, Preferences prefs) {
|
||||||
|
|
||||||
// Validate folder settings
|
// Validate folder settings
|
||||||
Map<String, String> validatedFolderSettings =
|
Map<String, String> validatedSettings =
|
||||||
FolderSettings.validate(folder.settings.settings, !overwrite);
|
FolderSettings.validate(folder.settings.settings, !overwrite);
|
||||||
|
|
||||||
// Merge folder settings if necessary
|
// Merge folder settings if necessary
|
||||||
Map<String, String> writeFolderSettings;
|
Map<String, String> writeSettings;
|
||||||
if (overwrite) {
|
if (overwrite) {
|
||||||
writeFolderSettings = FolderSettings.getFolderSettings(prefs.getPreferences(),
|
writeSettings = FolderSettings.getFolderSettings(prefs.getPreferences(),
|
||||||
uuid, folder.name);
|
uuid, folder.name);
|
||||||
writeFolderSettings.putAll(validatedFolderSettings);
|
writeSettings.putAll(validatedSettings);
|
||||||
} else {
|
} else {
|
||||||
writeFolderSettings = new HashMap<String, String>(validatedFolderSettings);
|
writeSettings = validatedSettings;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write folder settings
|
// Write folder settings
|
||||||
String folderKeyPrefix = uuid + "." + folder.name + ".";
|
String prefix = uuid + "." + folder.name + ".";
|
||||||
for (Map.Entry<String, String> setting : writeFolderSettings.entrySet()) {
|
for (Map.Entry<String, String> setting : writeSettings.entrySet()) {
|
||||||
String key = folderKeyPrefix + setting.getKey();
|
String key = prefix + setting.getKey();
|
||||||
String value = setting.getValue();
|
String value = setting.getValue();
|
||||||
putString(editor, key, value);
|
putString(editor, key, value);
|
||||||
}
|
}
|
||||||
|
@ -496,7 +496,7 @@ public class StorageImporter {
|
||||||
prefs.getPreferences(), uuid, writeIdentityIndex));
|
prefs.getPreferences(), uuid, writeIdentityIndex));
|
||||||
writeSettings.putAll(validatedSettings);
|
writeSettings.putAll(validatedSettings);
|
||||||
} else {
|
} else {
|
||||||
writeSettings = new HashMap<String, String>(validatedSettings);
|
writeSettings = validatedSettings;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write identity settings
|
// Write identity settings
|
||||||
|
|
Loading…
Reference in a new issue