From ee08ec259766458ecb25ab328b80f6cb813d539f Mon Sep 17 00:00:00 2001 From: M66B Date: Fri, 7 Sep 2018 06:52:19 +0000 Subject: [PATCH] Set first new account/identity primary only --- .../main/java/eu/faircode/email/DaoIdentity.java | 4 ++-- .../java/eu/faircode/email/FragmentAccount.java | 13 +++++++++++++ .../java/eu/faircode/email/FragmentIdentity.java | 13 +++++++++++++ 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/DaoIdentity.java b/app/src/main/java/eu/faircode/email/DaoIdentity.java index 78fd044f6b..556ce944a3 100644 --- a/app/src/main/java/eu/faircode/email/DaoIdentity.java +++ b/app/src/main/java/eu/faircode/email/DaoIdentity.java @@ -48,8 +48,8 @@ public interface DaoIdentity { @Query("SELECT * FROM identity WHERE id = :id") LiveData liveIdentity(long id); - @Query("SELECT * FROM identity WHERE account = :account AND `primary`") - EntityIdentity getPrimaryIdentity(long account); + @Query("SELECT COUNT(*) FROM identity WHERE synchronize") + int getSynchronizingIdentityCount(); @Insert long insertIdentity(EntityIdentity identity); diff --git a/app/src/main/java/eu/faircode/email/FragmentAccount.java b/app/src/main/java/eu/faircode/email/FragmentAccount.java index 8a6e4e425f..7f2d984511 100644 --- a/app/src/main/java/eu/faircode/email/FragmentAccount.java +++ b/app/src/main/java/eu/faircode/email/FragmentAccount.java @@ -751,6 +751,19 @@ public class FragmentAccount extends FragmentEx { cbSynchronize.setChecked(account == null ? true : account.synchronize); cbPrimary.setChecked(account == null ? true : account.primary); + + if (account == null) + new SimpleTask() { + @Override + protected Integer onLoad(Context context, Bundle args) { + return DB.getInstance(context).account().getSynchronizingAccountCount(); + } + + @Override + protected void onLoaded(Bundle args, Integer count) { + cbPrimary.setChecked(count == 0); + } + }.load(FragmentAccount.this, new Bundle()); } else { int provider = savedInstanceState.getInt("provider"); spProvider.setTag(provider); diff --git a/app/src/main/java/eu/faircode/email/FragmentIdentity.java b/app/src/main/java/eu/faircode/email/FragmentIdentity.java index bf94923a1d..cbea606c70 100644 --- a/app/src/main/java/eu/faircode/email/FragmentIdentity.java +++ b/app/src/main/java/eu/faircode/email/FragmentIdentity.java @@ -436,6 +436,19 @@ public class FragmentIdentity extends FragmentEx { cbStoreSent.setChecked(identity == null ? false : identity.store_sent); etName.requestFocus(); + + if (identity == null) + new SimpleTask() { + @Override + protected Integer onLoad(Context context, Bundle args) { + return DB.getInstance(context).identity().getSynchronizingIdentityCount(); + } + + @Override + protected void onLoaded(Bundle args, Integer count) { + cbPrimary.setChecked(count == 0); + } + }.load(FragmentIdentity.this, new Bundle()); } else { tilPassword.getEditText().setText(savedInstanceState.getString("password")); grpAdvanced.setVisibility(savedInstanceState.getInt("advanced"));