From 3cf2c89708ebdaecc5e4feb9ed2e987fc24c4d7e Mon Sep 17 00:00:00 2001 From: M66B Date: Sat, 19 Oct 2019 20:56:19 +0200 Subject: [PATCH] Add related identity --- .../eu/faircode/email/FragmentAccount.java | 30 ++++++++++++++++--- .../eu/faircode/email/FragmentIdentity.java | 8 +++-- app/src/main/res/layout/fragment_account.xml | 11 ++++++- app/src/main/res/values/strings.xml | 1 + 4 files changed, 43 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/FragmentAccount.java b/app/src/main/java/eu/faircode/email/FragmentAccount.java index 980bbdf44d..b40a4a5dfa 100644 --- a/app/src/main/java/eu/faircode/email/FragmentAccount.java +++ b/app/src/main/java/eu/faircode/email/FragmentAccount.java @@ -50,6 +50,7 @@ import android.widget.TextView; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.constraintlayout.widget.Group; +import androidx.fragment.app.FragmentTransaction; import androidx.lifecycle.Lifecycle; import com.google.android.material.snackbar.Snackbar; @@ -123,6 +124,7 @@ public class FragmentAccount extends FragmentBase { private Button btnSave; private ContentLoadingProgressBar pbSave; + private CheckBox cbIdentity; private TextView tvError; private Button btnHelp; private Button btnSupport; @@ -218,6 +220,7 @@ public class FragmentAccount extends FragmentBase { btnSave = view.findViewById(R.id.btnSave); pbSave = view.findViewById(R.id.pbSave); + cbIdentity = view.findViewById(R.id.cbIdentity); tvError = view.findViewById(R.id.tvError); btnHelp = view.findViewById(R.id.btnHelp); @@ -267,6 +270,7 @@ public class FragmentAccount extends FragmentBase { grpFolders.setVisibility(View.GONE); btnSave.setVisibility(View.GONE); + cbIdentity.setVisibility(View.GONE); } @Override @@ -422,6 +426,7 @@ public class FragmentAccount extends FragmentBase { btnSave.setVisibility(View.GONE); pbSave.setVisibility(View.GONE); + cbIdentity.setVisibility(View.GONE); tvError.setVisibility(View.GONE); btnHelp.setVisibility(View.GONE); @@ -636,7 +641,7 @@ public class FragmentAccount extends FragmentBase { new Handler().post(new Runnable() { @Override public void run() { - scroll.smoothScrollTo(0, btnSave.getBottom()); + scroll.smoothScrollTo(0, cbIdentity.getBottom()); } }); } @@ -645,6 +650,7 @@ public class FragmentAccount extends FragmentBase { protected void onException(Bundle args, Throwable ex) { grpFolders.setVisibility(View.GONE); btnSave.setVisibility(View.GONE); + cbIdentity.setVisibility(View.GONE); if (ex instanceof IllegalArgumentException) Snackbar.make(view, ex.getMessage(), Snackbar.LENGTH_LONG).show(); @@ -972,6 +978,8 @@ public class FragmentAccount extends FragmentBase { db.account().updateAccount(account); else account.id = db.account().insertAccount(account); + + args.putLong("account", account.id); EntityLog.log(context, (update ? "Updated" : "Added") + " account=" + account.name); // Make sure the channel exists on commit @@ -1082,8 +1090,20 @@ public class FragmentAccount extends FragmentBase { fragment.setArguments(aargs); fragment.setTargetFragment(FragmentAccount.this, REQUEST_SAVE); fragment.show(getParentFragmentManager(), "account:save"); - } else if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED)) + } else if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED)) { getParentFragmentManager().popBackStack(); + + if (cbIdentity.isChecked()) { + Bundle aargs = new Bundle(); + aargs.putLong("account", args.getLong("account")); + + FragmentIdentity fragment = new FragmentIdentity(); + fragment.setArguments(aargs); + FragmentTransaction fragmentTransaction = getParentFragmentManager().beginTransaction(); + fragmentTransaction.replace(R.id.content_frame, fragment).addToBackStack("identity"); + fragmentTransaction.commit(); + } + } } @Override @@ -1247,8 +1267,8 @@ public class FragmentAccount extends FragmentBase { // Consider previous check/save/delete as cancelled pbWait.setVisibility(View.GONE); - if (copy < 0) { - args.putLong("account", account == null ? -1 : account.id); + if (copy < 0 && account != null) { + args.putLong("account", account.id); new SimpleTask>() { @Override @@ -1481,6 +1501,8 @@ public class FragmentAccount extends FragmentBase { grpFolders.setVisibility(View.VISIBLE); btnSave.setVisibility(View.VISIBLE); + cbIdentity.setVisibility(View.VISIBLE); + cbIdentity.setChecked(account == null); } private class CheckResult { diff --git a/app/src/main/java/eu/faircode/email/FragmentIdentity.java b/app/src/main/java/eu/faircode/email/FragmentIdentity.java index 17ae1794d7..235ab1675c 100644 --- a/app/src/main/java/eu/faircode/email/FragmentIdentity.java +++ b/app/src/main/java/eu/faircode/email/FragmentIdentity.java @@ -123,6 +123,7 @@ public class FragmentIdentity extends FragmentBase { private long id = -1; private long copy = -1; + private long account = -1; private int auth = MailService.AUTH_TYPE_PASSWORD; private boolean saving = false; @@ -141,6 +142,8 @@ public class FragmentIdentity extends FragmentBase { copy = args.getLong("id", -1); else id = args.getLong("id", -1); + + account = args.getLong("account", -1); } @Override @@ -965,8 +968,9 @@ 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))) { - spAccount.setTag(pos); + if (account.id.equals(identity == null ? FragmentIdentity.this.account : identity.account)) { + if (identity != null) + spAccount.setTag(pos); spAccount.setSelection(pos); break; } diff --git a/app/src/main/res/layout/fragment_account.xml b/app/src/main/res/layout/fragment_account.xml index 2cd94e4f4b..6740265e8a 100644 --- a/app/src/main/res/layout/fragment_account.xml +++ b/app/src/main/res/layout/fragment_account.xml @@ -739,6 +739,15 @@ app:layout_constraintStart_toEndOf="@id/btnSave" app:layout_constraintTop_toTopOf="@id/btnSave" /> + + + app:layout_constraintTop_toBottomOf="@id/cbIdentity" />