Merge pull request #3789 from k9mail/fix-3787

Fix assigning account number when Account is first saved (fixes #3787)
This commit is contained in:
cketti 2018-12-03 17:09:21 +01:00 committed by GitHub
commit 5aa157d3c1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 8 deletions

View file

@ -102,6 +102,7 @@ public class Account implements BaseAccount, StoreConfig {
public static final SortType DEFAULT_SORT_TYPE = SortType.SORT_DATE;
public static final boolean DEFAULT_SORT_ASCENDING = false;
public static final long NO_OPENPGP_KEY = 0;
public static final int UNASSIGNED_ACCOUNT_NUMBER = -1;
private DeletePolicy deletePolicy = DeletePolicy.NEVER;

View file

@ -93,7 +93,7 @@ class AccountPreferenceSerializer(
autoExpandFolder = storage.getString("$accountUuid.autoExpandFolderName", INBOX)
accountNumber = storage.getInt("$accountUuid.accountNumber", 0)
accountNumber = storage.getInt("$accountUuid.accountNumber", UNASSIGNED_ACCOUNT_NUMBER)
chipColor = storage.getInt("$accountUuid.chipColor", FALLBACK_ACCOUNT_COLOR)
@ -503,7 +503,7 @@ class AccountPreferenceSerializer(
idleRefreshMinutes = 24
isPushPollOnConnect = true
displayCount = K9.DEFAULT_VISIBLE_LIMIT
accountNumber = -1
accountNumber = UNASSIGNED_ACCOUNT_NUMBER
isNotifyNewMail = true
folderNotifyNewMailMode = FolderMode.ALL
isNotifySync = true

View file

@ -203,14 +203,18 @@ public class Preferences {
public void saveAccount(Account account) {
StorageEditor editor = storage.edit();
if (!accounts.containsKey(account.getUuid())) {
int accountNumber = generateAccountNumber();
account.setAccountNumber(accountNumber);
ensureAssignedAccountNumber(account);
processChangedValues(account);
accountPreferenceSerializer.save(storage, editor, account);
}
private void ensureAssignedAccountNumber(Account account) {
if (account.getAccountNumber() != Account.UNASSIGNED_ACCOUNT_NUMBER) {
return;
}
processChangedValues(account);
accountPreferenceSerializer.save(storage, editor, account);
int accountNumber = generateAccountNumber();
account.setAccountNumber(accountNumber);
}
private void processChangedValues(Account account) {