From d91d9e5eca607e324e52ef07f37d8e81a7181ccf Mon Sep 17 00:00:00 2001 From: M66B Date: Thu, 2 Apr 2020 11:18:16 +0200 Subject: [PATCH] Small improvement --- .../main/java/eu/faircode/email/Helper.java | 56 +++++++++---------- 1 file changed, 27 insertions(+), 29 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/Helper.java b/app/src/main/java/eu/faircode/email/Helper.java index c444fa8aea..2c2b05b003 100644 --- a/app/src/main/java/eu/faircode/email/Helper.java +++ b/app/src/main/java/eu/faircode/email/Helper.java @@ -1194,13 +1194,7 @@ public class Helper { try { if (KeyChain.getPrivateKey(context, alias) != null) { Log.i("Private key available alias=" + alias); - handler.post(new Runnable() { - @Override - public void run() { - if (owner.getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED)) - intf.onSelected(alias); - } - }); + deliver(alias); return; } } catch (KeyChainException ex) { @@ -1216,34 +1210,38 @@ public class Helper { @Override public void alias(@Nullable final String alias) { Log.i("Selected key alias=" + alias); - handler.post(new Runnable() { - @Override - public void run() { - if (owner.getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED)) { - if (alias == null) - intf.onNothingSelected(); - else - intf.onSelected(alias); - } else { - owner.getLifecycle().addObserver(new LifecycleObserver() { - @OnLifecycleEvent(Lifecycle.Event.ON_START) - public void onStart() { - owner.getLifecycle().removeObserver(this); - if (alias == null) - intf.onNothingSelected(); - else - intf.onSelected(alias); - } - }); - } - } - }); + deliver(alias); } }, null, null, null, -1, alias); } }); } + + private void deliver(final String selected) { + handler.post(new Runnable() { + @Override + public void run() { + if (owner.getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED)) { + if (selected == null) + intf.onNothingSelected(); + else + intf.onSelected(selected); + } else { + owner.getLifecycle().addObserver(new LifecycleObserver() { + @OnLifecycleEvent(Lifecycle.Event.ON_START) + public void onStart() { + owner.getLifecycle().removeObserver(this); + if (selected == null) + intf.onNothingSelected(); + else + intf.onSelected(selected); + } + }); + } + } + }); + } }).start(); }