From c02e5992ec27885100d4f5c2e56528a39f5edd17 Mon Sep 17 00:00:00 2001 From: M66B Date: Wed, 4 Dec 2019 13:28:28 +0100 Subject: [PATCH] Auto select certificate --- .../eu/faircode/email/FragmentCompose.java | 37 +++++++++++++++++-- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/FragmentCompose.java b/app/src/main/java/eu/faircode/email/FragmentCompose.java index 5f7e4f9b8e..2778524c64 100644 --- a/app/src/main/java/eu/faircode/email/FragmentCompose.java +++ b/app/src/main/java/eu/faircode/email/FragmentCompose.java @@ -1264,10 +1264,39 @@ public class FragmentCompose extends FragmentBase { args.putString("alias", alias); if (EntityMessage.SMIME_SIGNENCRYPT.equals(draft.encrypt)) { - FragmentDialogCertificate fragment = new FragmentDialogCertificate(); - fragment.setArguments(args); - fragment.setTargetFragment(FragmentCompose.this, REQUEST_CERTIFICATE); - fragment.show(getParentFragmentManager(), "compose:certificate"); + new SimpleTask() { + @Override + protected Long onExecute(Context context, Bundle args) throws Throwable { + String email = args.getString("email"); + if (email == null) + return null; + + DB db = DB.getInstance(context); + List certs = db.certificate().getCertificateByEmail(email); + if (certs == null || certs.size() != 1) + return null; + + return certs.get(0).id; + } + + @Override + protected void onExecuted(Bundle args, Long id) { + if (id == null) { + FragmentDialogCertificate fragment = new FragmentDialogCertificate(); + fragment.setArguments(args); + fragment.setTargetFragment(FragmentCompose.this, REQUEST_CERTIFICATE); + fragment.show(getParentFragmentManager(), "certificate:select"); + } else { + args.putLong("certificate", id); + onSmime(args); + } + } + + @Override + protected void onException(Bundle args, Throwable ex) { + Helper.unexpectedError(getParentFragmentManager(), ex); + } + }.execute(FragmentCompose.this, args, "certificate:find"); } else onSmime(args); } catch (Throwable ex) {