From d3880b906c4073705cc11770073eb8a1005868b4 Mon Sep 17 00:00:00 2001 From: M66B Date: Sun, 6 Jun 2021 12:10:43 +0200 Subject: [PATCH] Allow selecting to show email addresses only --- .../eu/faircode/email/AdapterMessage.java | 30 +++++++++++++------ app/src/main/java/eu/faircode/email/Core.java | 10 +++---- .../eu/faircode/email/FragmentCompose.java | 6 ++-- .../eu/faircode/email/FragmentOptions.java | 2 +- .../email/FragmentOptionsDisplay.java | 20 ++++++++----- .../java/eu/faircode/email/MessageHelper.java | 22 ++++++++++++-- .../res/layout/fragment_options_display.xml | 22 ++++++++++---- app/src/main/res/values/strings.xml | 8 ++++- 8 files changed, 87 insertions(+), 33 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/AdapterMessage.java b/app/src/main/java/eu/faircode/email/AdapterMessage.java index c0ae828837..97a3052233 100644 --- a/app/src/main/java/eu/faircode/email/AdapterMessage.java +++ b/app/src/main/java/eu/faircode/email/AdapterMessage.java @@ -245,7 +245,7 @@ public class AdapterMessage extends RecyclerView.Adapter 0 ? View.VISIBLE : View.GONE); - if (show_recipients && recipients != null && recipients.length > 0) + + MessageHelper.AddressFormat format = email_format; + if (junk) + format = MessageHelper.AddressFormat.NAME_EMAIL; + + if (show_recipients && recipients != null && recipients.length > 0) { tvFrom.setText(context.getString(outgoing && viewType != ViewType.THREAD && compact ? R.string.title_to_from : R.string.title_from_to, - MessageHelper.formatAddresses(senders, name_email || junk, false), - MessageHelper.formatAddresses(recipients, name_email || junk, false))); - else - tvFrom.setText(MessageHelper.formatAddresses(senders, name_email || junk, false)); + MessageHelper.formatAddresses(senders, format, false), + MessageHelper.formatAddresses(recipients, format, false))); + } else + tvFrom.setText(MessageHelper.formatAddresses(senders, format, false)); + tvFrom.setPaintFlags(tvFrom.getPaintFlags() & ~Paint.UNDERLINE_TEXT_FLAG); tvSize.setText(message.totalSize == null ? null : Helper.humanReadableByteCount(message.totalSize)); tvSize.setVisibility( @@ -1855,7 +1861,9 @@ public class AdapterMessage extends RecyclerView.Adapter").append(Html.escapeHtml(from)).append(""); if (!TextUtils.isEmpty(message.subject)) sb.append(": ").append(Html.escapeHtml(message.subject)); @@ -4316,8 +4316,8 @@ class Core { if (notify_messaging) { // https://developer.android.com/training/cars/messaging - String meName = MessageHelper.formatAddresses(message.to, name_email, false); - String youName = MessageHelper.formatAddresses(message.from, name_email, false); + String meName = MessageHelper.formatAddresses(message.to, email_format, false); + String youName = MessageHelper.formatAddresses(message.from, email_format, false); // Names cannot be empty if (TextUtils.isEmpty(meName)) @@ -4357,7 +4357,7 @@ class Core { setLightAndSound(mbuilder, light, sound); Address[] afrom = messageFrom.get(message.id); - String from = MessageHelper.formatAddresses(afrom, name_email, false); + String from = MessageHelper.formatAddresses(afrom, email_format, false); mbuilder.setContentTitle(from); if (notify_subtext) if (message.folderUnified && !EntityFolder.INBOX.equals(message.folderType)) diff --git a/app/src/main/java/eu/faircode/email/FragmentCompose.java b/app/src/main/java/eu/faircode/email/FragmentCompose.java index 6d01d90188..88787127c2 100644 --- a/app/src/main/java/eu/faircode/email/FragmentCompose.java +++ b/app/src/main/java/eu/faircode/email/FragmentCompose.java @@ -6197,7 +6197,7 @@ public class FragmentCompose extends FragmentBase { final int send_delayed = prefs.getInt("send_delayed", 0); final boolean send_dialog = prefs.getBoolean("send_dialog", true); final boolean send_archive = prefs.getBoolean("send_archive", false); - final boolean name_email = prefs.getBoolean("name_email", false); + final MessageHelper.AddressFormat email_format = MessageHelper.getAddressFormat(getContext()); final int[] encryptValues = getResources().getIntArray(R.array.encryptValues); final int[] sendDelayedValues = getResources().getIntArray(R.array.sendDelayedValues); @@ -6507,10 +6507,10 @@ public class FragmentCompose extends FragmentBase { Address[] tos = t.toArray(new Address[0]); if (extra == 0) - tvTo.setText(MessageHelper.formatAddresses(tos, name_email, false)); + tvTo.setText(MessageHelper.formatAddresses(tos, email_format, false)); else tvTo.setText(getString(R.string.title_name_plus, - MessageHelper.formatAddresses(tos, name_email, false), extra)); + MessageHelper.formatAddresses(tos, email_format, false), extra)); tvTo.setTextColor(Helper.resolveColor(context, to + extra > RECIPIENTS_WARNING ? R.attr.colorWarning : android.R.attr.textColorPrimary)); if (draft.identityColor != null && draft.identityColor != Color.TRANSPARENT) diff --git a/app/src/main/java/eu/faircode/email/FragmentOptions.java b/app/src/main/java/eu/faircode/email/FragmentOptions.java index 45600ea75a..0c5698ea8f 100644 --- a/app/src/main/java/eu/faircode/email/FragmentOptions.java +++ b/app/src/main/java/eu/faircode/email/FragmentOptions.java @@ -87,7 +87,7 @@ public class FragmentOptions extends FragmentBase { "indentation", "date", "date_bold", "threading", "threading_unread", "highlight_unread", "highlight_color", "color_stripe", "avatars", "gravatars", "favicons", "generated_icons", "identicons", "circular", "saturation", "brightness", "threshold", - "name_email", "prefer_contact", "only_contact", "distinguish_contacts", "show_recipients", "authentication", + "email_format", "prefer_contact", "only_contact", "distinguish_contacts", "show_recipients", "authentication", "subject_top", "font_size_sender", "font_size_subject", "subject_italic", "highlight_subject", "subject_ellipsize", "keywords_header", "labels_header", "flags", "flags_background", "preview", "preview_italic", "preview_lines", "message_zoom", "overview_mode", "addresses", "button_extra", "attachments_alt", "thumbnails", diff --git a/app/src/main/java/eu/faircode/email/FragmentOptionsDisplay.java b/app/src/main/java/eu/faircode/email/FragmentOptionsDisplay.java index 7e76bffa58..10c7bc9f64 100644 --- a/app/src/main/java/eu/faircode/email/FragmentOptionsDisplay.java +++ b/app/src/main/java/eu/faircode/email/FragmentOptionsDisplay.java @@ -98,7 +98,7 @@ public class FragmentOptionsDisplay extends FragmentBase implements SharedPrefer private SeekBar sbBrightness; private TextView tvThreshold; private SeekBar sbThreshold; - private SwitchCompat swNameEmail; + private Spinner spNameEmail; private SwitchCompat swPreferContact; private SwitchCompat swOnlyContact; private SwitchCompat swDistinguishContacts; @@ -148,7 +148,7 @@ public class FragmentOptionsDisplay extends FragmentBase implements SharedPrefer "threading", "threading_unread", "indentation", "seekbar", "actionbar", "actionbar_color", "highlight_unread", "highlight_color", "color_stripe", "avatars", "gravatars", "favicons", "generated_icons", "identicons", "circular", "saturation", "brightness", "threshold", - "name_email", "prefer_contact", "only_contact", "distinguish_contacts", "show_recipients", + "email_format", "prefer_contact", "only_contact", "distinguish_contacts", "show_recipients", "subject_top", "font_size_sender", "font_size_subject", "subject_italic", "highlight_subject", "subject_ellipsize", "keywords_header", "labels_header", "flags", "flags_background", "preview", "preview_italic", "preview_lines", @@ -207,7 +207,7 @@ public class FragmentOptionsDisplay extends FragmentBase implements SharedPrefer sbBrightness = view.findViewById(R.id.sbBrightness); tvThreshold = view.findViewById(R.id.tvThreshold); sbThreshold = view.findViewById(R.id.sbThreshold); - swNameEmail = view.findViewById(R.id.swNameEmail); + spNameEmail = view.findViewById(R.id.spNameEmail); swPreferContact = view.findViewById(R.id.swPreferContact); swOnlyContact = view.findViewById(R.id.swOnlyContact); swDistinguishContacts = view.findViewById(R.id.swDistinguishContacts); @@ -555,10 +555,15 @@ public class FragmentOptionsDisplay extends FragmentBase implements SharedPrefer } }); - swNameEmail.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + spNameEmail.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override - public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { - prefs.edit().putBoolean("name_email", checked).apply(); + public void onItemSelected(AdapterView adapterView, View view, int position, long id) { + prefs.edit().putInt("email_format", position).apply(); + } + + @Override + public void onNothingSelected(AdapterView parent) { + prefs.edit().remove("email_format").apply(); } }); @@ -976,7 +981,8 @@ public class FragmentOptionsDisplay extends FragmentBase implements SharedPrefer sbThreshold.setProgress(threshold); sbThreshold.setEnabled(swGeneratedIcons.isChecked()); - swNameEmail.setChecked(prefs.getBoolean("name_email", false)); + MessageHelper.AddressFormat email_format = MessageHelper.getAddressFormat(getContext()); + spNameEmail.setSelection(email_format.ordinal()); swPreferContact.setChecked(prefs.getBoolean("prefer_contact", false)); swOnlyContact.setChecked(prefs.getBoolean("only_contact", false)); swDistinguishContacts.setChecked(prefs.getBoolean("distinguish_contacts", false)); diff --git a/app/src/main/java/eu/faircode/email/MessageHelper.java b/app/src/main/java/eu/faircode/email/MessageHelper.java index 9f716c13c2..51e406d5aa 100644 --- a/app/src/main/java/eu/faircode/email/MessageHelper.java +++ b/app/src/main/java/eu/faircode/email/MessageHelper.java @@ -1499,6 +1499,20 @@ public class MessageHelper { } } + enum AddressFormat {NAME_ONLY, EMAIL_ONLY, NAME_EMAIL} + + static AddressFormat getAddressFormat(Context context) { + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); + boolean name_email = prefs.getBoolean("name_email", false); + int email_format = prefs.getInt("email_format", name_email + ? MessageHelper.AddressFormat.NAME_EMAIL.ordinal() + : MessageHelper.AddressFormat.NAME_ONLY.ordinal()); + if (email_format < MessageHelper.AddressFormat.values().length) + return MessageHelper.AddressFormat.values()[email_format]; + else + return MessageHelper.AddressFormat.NAME_ONLY; + } + static String formatAddresses(Address[] addresses) { return formatAddresses(addresses, true, false); } @@ -1515,6 +1529,10 @@ public class MessageHelper { } static String formatAddresses(Address[] addresses, boolean full, boolean compose) { + return formatAddresses(addresses, full ? AddressFormat.NAME_EMAIL : AddressFormat.NAME_ONLY, compose); + } + + static String formatAddresses(Address[] addresses, AddressFormat format, boolean compose) { if (addresses == null || addresses.length == 0) return ""; @@ -1534,7 +1552,7 @@ public class MessageHelper { String email = address.getAddress(); String personal = address.getPersonal(); - if (TextUtils.isEmpty(personal)) + if (TextUtils.isEmpty(personal) || format == AddressFormat.EMAIL_ONLY) formatted.add(email); else { if (compose) { @@ -1550,7 +1568,7 @@ public class MessageHelper { personal = "\"" + personal + "\""; } - if (full) + if (format == AddressFormat.NAME_EMAIL) formatted.add(personal + " <" + email + ">"); else formatted.add(personal); diff --git a/app/src/main/res/layout/fragment_options_display.xml b/app/src/main/res/layout/fragment_options_display.xml index f5f3ca4819..921a00ca88 100644 --- a/app/src/main/res/layout/fragment_options_display.xml +++ b/app/src/main/res/layout/fragment_options_display.xml @@ -659,28 +659,40 @@ app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/tvThreshold" /> - + app:layout_constraintTop_toBottomOf="@id/sbThreshold" /> + + + app:layout_constraintTop_toBottomOf="@id/spNameEmail" /> Group messages related to each other The accent color of the theme will be used for highlighting There might be a privacy risk - When disabled only names will be shown when available + Names will only be shown when available Only available when message text has been downloaded Maximum %s characters in total Scrolling can be slow due to a bug in some Android versions when the number of lines is more than one @@ -1908,6 +1908,12 @@ comic sans + + Name only + Email only + Name and email + + 17BA15C1AF55D925F98B99CEA4375D4CDF4C174B MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAtFbxEbzL8u5accPGgBw/XdyiSS5BBE6ZQ9ELpKyJ/OQN+kdYniCAOw3lsQ/GuJScy4Y2HobqbBgLL8GLHG+Yu2EHC9dLjA3v2Mc25vvnfn86BsrpQvz1poN2n+roTBdq09FWbtebJ8m0hDBVmtfRi7RhTKIL4No3kodLhksdnucKjcFheubebWKgpmvbmw7NwuELhaZmyhw8WTtnQ4rZPMhjY1JJZgzwNExXgD7zzg4pJPkuQlfkuRkkvBpHpi3C7VDnYjrBlLHngI4wv3wxQBVwJqlvAT9PmX8dOVnTsWWdJdLQBZVWphuqVY54kjBIovN+o8w03WjsV9QiOQq+XwIDAQAB