From 35407bf2892a59f3ab6e0e456eccb70f7113c45f Mon Sep 17 00:00:00 2001 From: M66B Date: Fri, 7 Dec 2018 15:23:17 +0100 Subject: [PATCH] Set contact info in download phase --- app/src/main/java/eu/faircode/email/ActivityView.java | 4 ++-- app/src/main/java/eu/faircode/email/EntityMessage.java | 6 +++++- app/src/main/java/eu/faircode/email/FragmentCompose.java | 2 +- app/src/main/java/eu/faircode/email/Helper.java | 2 +- .../main/java/eu/faircode/email/ServiceSynchronize.java | 9 +++------ 5 files changed, 12 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/ActivityView.java b/app/src/main/java/eu/faircode/email/ActivityView.java index f0e7f0c937..2a7e63a5c3 100644 --- a/app/src/main/java/eu/faircode/email/ActivityView.java +++ b/app/src/main/java/eu/faircode/email/ActivityView.java @@ -565,7 +565,7 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB draft.subject = context.getString(R.string.app_name) + " " + BuildConfig.VERSION_NAME + " crash log"; draft.content = true; draft.received = new Date().getTime(); - draft.getAvatar(context); + draft.setContactInfo(context); draft.id = db.message().insertMessage(draft); draft.write(context, body); @@ -871,7 +871,7 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB draft.subject = context.getString(R.string.app_name) + " " + BuildConfig.VERSION_NAME + " debug info"; draft.content = true; draft.received = new Date().getTime(); - draft.getAvatar(context); + draft.setContactInfo(context); draft.id = db.message().insertMessage(draft); draft.write(context, body); diff --git a/app/src/main/java/eu/faircode/email/EntityMessage.java b/app/src/main/java/eu/faircode/email/EntityMessage.java index f5c86db012..45292a6974 100644 --- a/app/src/main/java/eu/faircode/email/EntityMessage.java +++ b/app/src/main/java/eu/faircode/email/EntityMessage.java @@ -201,7 +201,7 @@ public class EntityMessage implements Serializable { } } - void getAvatar(Context context) { + boolean setContactInfo(Context context) { if (ContextCompat.checkSelfPermission(context, Manifest.permission.READ_CONTACTS) == PackageManager.PERMISSION_GRANTED) { this.avatar = null; @@ -234,6 +234,8 @@ public class EntityMessage implements Serializable { if (!TextUtils.isEmpty(displayName)) ((InternetAddress) this.from[i]).setPersonal(displayName); + + return true; } } finally { if (cursor != null) @@ -244,6 +246,8 @@ public class EntityMessage implements Serializable { Log.e(Helper.TAG, ex + "\n" + Log.getStackTraceString(ex)); } } + + return false; } static String getQuote(Context context, long id) throws IOException { diff --git a/app/src/main/java/eu/faircode/email/FragmentCompose.java b/app/src/main/java/eu/faircode/email/FragmentCompose.java index 327da86476..50aa504f5f 100644 --- a/app/src/main/java/eu/faircode/email/FragmentCompose.java +++ b/app/src/main/java/eu/faircode/email/FragmentCompose.java @@ -1202,7 +1202,7 @@ public class FragmentCompose extends FragmentEx { result.draft.content = true; result.draft.received = new Date().getTime(); - result.draft.getAvatar(context); + result.draft.setContactInfo(context); result.draft.id = db.message().insertMessage(result.draft); result.draft.write(context, body == null ? "" : body); diff --git a/app/src/main/java/eu/faircode/email/Helper.java b/app/src/main/java/eu/faircode/email/Helper.java index b54f97f723..18a63d09e5 100644 --- a/app/src/main/java/eu/faircode/email/Helper.java +++ b/app/src/main/java/eu/faircode/email/Helper.java @@ -215,7 +215,7 @@ public class Helper { draft.subject = context.getString(R.string.app_name) + " " + BuildConfig.VERSION_NAME + " crash log"; draft.content = true; draft.received = new Date().getTime(); - draft.getAvatar(context); + draft.setContactInfo(context); draft.id = db.message().insertMessage(draft); draft.write(context, body); diff --git a/app/src/main/java/eu/faircode/email/ServiceSynchronize.java b/app/src/main/java/eu/faircode/email/ServiceSynchronize.java index 730fc47dce..8423e377a9 100644 --- a/app/src/main/java/eu/faircode/email/ServiceSynchronize.java +++ b/app/src/main/java/eu/faircode/email/ServiceSynchronize.java @@ -2193,7 +2193,6 @@ public class ServiceSynchronize extends LifecycleService { message.ui_found = false; message.ui_ignored = false; message.ui_browsed = browsed; - message.getAvatar(context); message.id = db.message().insertMessage(message); @@ -2249,11 +2248,6 @@ public class ServiceSynchronize extends LifecycleService { Log.i(Helper.TAG, folder.name + " updated id=" + message.id + " uid=" + message.uid + " unhide"); } - boolean noavatar = TextUtils.isEmpty(message.avatar); - message.getAvatar(context); - if (noavatar != TextUtils.isEmpty(message.avatar)) - update = true; - if (update) db.message().updateMessage(message); } @@ -2287,6 +2281,9 @@ public class ServiceSynchronize extends LifecycleService { List attachments = db.attachment().getAttachments(message.id); MessageHelper helper = new MessageHelper(imessage); + if (message.setContactInfo(context)) + db.message().updateMessage(message); + boolean fetch = false; if (!message.content) if (!metered || (message.size != null && message.size < download))