diff --git a/app/src/main/java/eu/faircode/email/FragmentAccount.java b/app/src/main/java/eu/faircode/email/FragmentAccount.java index 9cf46cbe2f..1f77d551c9 100644 --- a/app/src/main/java/eu/faircode/email/FragmentAccount.java +++ b/app/src/main/java/eu/faircode/email/FragmentAccount.java @@ -63,6 +63,7 @@ import androidx.annotation.Nullable; import androidx.constraintlayout.widget.ConstraintLayout; import androidx.constraintlayout.widget.Group; import androidx.fragment.app.FragmentTransaction; +import androidx.localbroadcastmanager.content.LocalBroadcastManager; import com.android.colorpicker.ColorPickerDialog; import com.android.colorpicker.ColorPickerSwatch; @@ -134,6 +135,7 @@ public class FragmentAccount extends FragmentBase { private Spinner spLeft; private Spinner spRight; + private CheckBox cbIdentity; private Button btnSave; private ContentLoadingProgressBar pbSave; private TextView tvError; @@ -211,6 +213,7 @@ public class FragmentAccount extends FragmentBase { spLeft = view.findViewById(R.id.spLeft); spRight = view.findViewById(R.id.spRight); + cbIdentity = view.findViewById(R.id.cbIdentity); btnSave = view.findViewById(R.id.btnSave); pbSave = view.findViewById(R.id.pbSave); tvError = view.findViewById(R.id.tvError); @@ -264,6 +267,7 @@ public class FragmentAccount extends FragmentBase { etPrefix.setText(provider.prefix); grpFolders.setVisibility(View.GONE); + cbIdentity.setVisibility(View.GONE); btnSave.setVisibility(View.GONE); } @@ -457,6 +461,7 @@ public class FragmentAccount extends FragmentBase { btnCheck.setVisibility(View.GONE); pbCheck.setVisibility(View.GONE); + cbIdentity.setVisibility(View.GONE); btnSave.setVisibility(View.GONE); pbSave.setVisibility(View.GONE); tvError.setVisibility(View.GONE); @@ -703,6 +708,7 @@ public class FragmentAccount extends FragmentBase { @Override protected void onException(Bundle args, Throwable ex) { grpFolders.setVisibility(View.GONE); + cbIdentity.setVisibility(View.GONE); btnSave.setVisibility(View.GONE); if (ex instanceof IllegalArgumentException) @@ -775,7 +781,7 @@ public class FragmentAccount extends FragmentBase { args.putSerializable("left", left); args.putSerializable("right", right); - new SimpleTask() { + new SimpleTask() { @Override protected void onPreExecute(Bundle args) { saving = true; @@ -794,7 +800,7 @@ public class FragmentAccount extends FragmentBase { } @Override - protected Void onExecute(Context context, Bundle args) throws Throwable { + protected Long onExecute(Context context, Bundle args) throws Throwable { long id = args.getLong("id"); int auth_type = args.getInt("auth_type"); @@ -1053,12 +1059,18 @@ public class FragmentAccount extends FragmentBase { nm.cancel("receive", account.id.intValue()); } - return null; + return account.id; } @Override - protected void onExecuted(Bundle args, Void data) { + protected void onExecuted(Bundle args, Long id) { getFragmentManager().popBackStack(); + if (cbIdentity.isChecked()) { + LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(getContext()); + lbm.sendBroadcast( + new Intent(ActivitySetup.ACTION_EDIT_IDENTITY) + .putExtra("account", id)); + } } @Override @@ -1155,6 +1167,8 @@ public class FragmentAccount extends FragmentBase { cbBrowse.setChecked(account == null ? true : account.browse); etInterval.setText(account == null ? "" : Long.toString(account.poll_interval)); + cbIdentity.setChecked(account == null); + color = (account == null || account.color == null ? Color.TRANSPARENT : account.color); new SimpleTask() { @@ -1451,6 +1465,7 @@ public class FragmentAccount extends FragmentBase { } grpFolders.setVisibility(folders.size() > 1 ? View.VISIBLE : View.GONE); + cbIdentity.setVisibility(folders.size() > 1 ? View.VISIBLE : View.GONE); btnSave.setVisibility(folders.size() > 1 ? View.VISIBLE : View.GONE); } diff --git a/app/src/main/java/eu/faircode/email/FragmentIdentity.java b/app/src/main/java/eu/faircode/email/FragmentIdentity.java index d1e57fc0b7..22707f6f87 100644 --- a/app/src/main/java/eu/faircode/email/FragmentIdentity.java +++ b/app/src/main/java/eu/faircode/email/FragmentIdentity.java @@ -121,6 +121,7 @@ public class FragmentIdentity extends FragmentBase { private Group grpAdvanced; private long id = -1; + private long account = -1; private boolean saving = false; private int auth_type = Helper.AUTH_TYPE_PASSWORD; private int color = Color.TRANSPARENT; @@ -133,6 +134,7 @@ public class FragmentIdentity extends FragmentBase { // Get arguments Bundle args = getArguments(); id = args.getLong("id", -1); + account = args.getLong("account", -1); } @Override @@ -879,7 +881,7 @@ public class FragmentIdentity extends FragmentBase { spAccount.setSelection(0); for (int pos = 0; pos < accounts.size(); pos++) { EntityAccount account = accounts.get(pos); - if (account.id.equals((identity == null ? -1 : identity.account))) { + if (account.id.equals(identity == null ? FragmentIdentity.this.account : identity.account)) { spAccount.setTag(pos); spAccount.setSelection(pos); // OAuth token could be updated diff --git a/app/src/main/res/layout/fragment_account.xml b/app/src/main/res/layout/fragment_account.xml index 98e09b4923..fdb92a1e57 100644 --- a/app/src/main/res/layout/fragment_account.xml +++ b/app/src/main/res/layout/fragment_account.xml @@ -672,6 +672,15 @@ + +