From 64e0ab7401715dc0478e28d790599e485520311f Mon Sep 17 00:00:00 2001 From: M66B Date: Mon, 30 Mar 2020 17:58:41 +0200 Subject: [PATCH] Fail-safe --- .../eu/faircode/email/FragmentCompose.java | 51 ++++++++++--------- 1 file changed, 28 insertions(+), 23 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/FragmentCompose.java b/app/src/main/java/eu/faircode/email/FragmentCompose.java index f4a96f4ffb..b87b55fc7d 100644 --- a/app/src/main/java/eu/faircode/email/FragmentCompose.java +++ b/app/src/main/java/eu/faircode/email/FragmentCompose.java @@ -803,32 +803,37 @@ public class FragmentCompose extends FragmentBase { Collections.sort(items, new Comparator() { @Override public int compare(EntityContact i1, EntityContact i2) { - if (suggest_frequently) { - int t = -i1.times_contacted.compareTo(i2.times_contacted); - if (t != 0) - return t; + try { + if (suggest_frequently) { + int t = -i1.times_contacted.compareTo(i2.times_contacted); + if (t != 0) + return t; - int l = -i1.last_contacted.compareTo(i2.last_contacted); - if (l != 0) - return l; - } else { - int a = -Boolean.compare(i1.id == 0, i2.id == 0); - if (a != 0) - return a; - } + int l = -i1.last_contacted.compareTo(i2.last_contacted); + if (l != 0) + return l; + } else { + int a = -Boolean.compare(i1.id == 0, i2.id == 0); + if (a != 0) + return a; + } - if (TextUtils.isEmpty(i1.name) && TextUtils.isEmpty(i2.name)) + if (TextUtils.isEmpty(i1.name) && TextUtils.isEmpty(i2.name)) + return 0; + if (TextUtils.isEmpty(i1.name) && !TextUtils.isEmpty(i2.name)) + return 1; + if (!TextUtils.isEmpty(i1.name) && TextUtils.isEmpty(i2.name)) + return -1; + + int n = collator.compare(i1.name, i2.name); + if (n != 0) + return n; + + return collator.compare(i1.email, i2.email); + } catch (Throwable ex) { + Log.e(ex); return 0; - if (TextUtils.isEmpty(i1.name) && !TextUtils.isEmpty(i2.name)) - return 1; - if (!TextUtils.isEmpty(i1.name) && TextUtils.isEmpty(i2.name)) - return -1; - - int n = collator.compare(i1.name, i2.name); - if (n != 0) - return n; - - return collator.compare(i1.email, i2.email); + } } });