Allow selecting to show email addresses only

This commit is contained in:
M66B 2021-06-06 12:10:43 +02:00
parent 8c6a656567
commit d3880b906c
8 changed files with 87 additions and 33 deletions

View File

@ -245,7 +245,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
private boolean indentation;
private boolean avatars;
private boolean color_stripe;
private boolean name_email;
private MessageHelper.AddressFormat email_format;
private boolean prefer_contact;
private boolean only_contact;
private boolean distinguish_contacts;
@ -1050,14 +1050,20 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
else
ivSigned.clearColorFilter();
ivEncrypted.setVisibility(message.encrypted > 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<AdapterMessage.ViewHold
private void bindAddresses(TupleMessageEx message) {
boolean show_addresses = properties.getValue("addresses", message.id);
boolean full = (show_addresses || name_email || EntityFolder.JUNK.equals(message.folderType));
boolean full = (show_addresses ||
email_format == MessageHelper.AddressFormat.NAME_EMAIL ||
EntityFolder.JUNK.equals(message.folderType));
int froms = (message.from == null ? 0 : message.from.length);
int tos = (message.to == null ? 0 : message.to.length);
@ -5434,7 +5442,11 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
boolean junk = EntityFolder.JUNK.equals(message.folderType);
Address[] addresses = (EntityFolder.isOutgoing(message.folderType) &&
(viewType != ViewType.THREAD || !threading) ? message.to : message.senders);
String from = MessageHelper.formatAddresses(addresses, name_email || junk, false);
MessageHelper.AddressFormat format = email_format;
if (junk)
format = MessageHelper.AddressFormat.NAME_EMAIL;
String from = MessageHelper.formatAddresses(addresses, format, false);
// For a11y purpose subject is reported first when: user wishes so or this is a single outgoing message
if (subject_top || (outgoing && message.visible == 1)) {
result.add(message.subject); // Don't want to ellipsize for a11y
@ -5564,7 +5576,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
this.avatars = (contacts && avatars) || (gravatars || favicons || generated);
this.color_stripe = prefs.getBoolean("color_stripe", true);
this.name_email = prefs.getBoolean("name_email", false);
this.email_format = MessageHelper.getAddressFormat(context);
this.prefer_contact = prefs.getBoolean("prefer_contact", false);
this.only_contact = prefs.getBoolean("only_contact", false);
this.distinguish_contacts = prefs.getBoolean("distinguish_contacts", false);

View File

@ -4075,7 +4075,7 @@ class Core {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean notify_newest_first = prefs.getBoolean("notify_newest_first", false);
boolean name_email = prefs.getBoolean("name_email", false);
MessageHelper.AddressFormat email_format = MessageHelper.getAddressFormat(context);
boolean prefer_contact = prefs.getBoolean("prefer_contact", false);
boolean flags = prefs.getBoolean("flags", true);
boolean notify_messaging = prefs.getBoolean("notify_messaging", false);
@ -4215,7 +4215,7 @@ class Core {
StringBuilder sb = new StringBuilder();
for (EntityMessage message : messages) {
Address[] afrom = messageFrom.get(message.id);
String from = MessageHelper.formatAddresses(afrom, name_email, false);
String from = MessageHelper.formatAddresses(afrom, email_format, false);
sb.append("<strong>").append(Html.escapeHtml(from)).append("</strong>");
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))

View File

@ -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)

View File

@ -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",

View File

@ -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));

View File

@ -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);

View File

@ -659,28 +659,40 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvThreshold" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swNameEmail"
<eu.faircode.email.FixedTextView
android:id="@+id/tvNameEmail"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:layout_marginEnd="48dp"
android:text="@string/title_advanced_name_email"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
android:textColor="?android:attr/textColorPrimary"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/sbThreshold"
app:switchPadding="12dp" />
app:layout_constraintTop_toBottomOf="@id/sbThreshold" />
<Spinner
android:id="@+id/spNameEmail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="6dp"
android:entries="@array/addressFormatNames"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvNameEmail" />
<eu.faircode.email.FixedTextView
android:id="@+id/tvNameEmailHint"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="6dp"
android:layout_marginEnd="48dp"
android:text="@string/title_advanced_name_email_hint"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
android:textStyle="italic"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swNameEmail" />
app:layout_constraintTop_toBottomOf="@id/spNameEmail" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swPreferContact"

View File

@ -617,7 +617,7 @@
<string name="title_advanced_threading_hint">Group messages related to each other</string>
<string name="title_advanced_highlight_hint">The accent color of the theme will be used for highlighting</string>
<string name="title_advanced_gravatars_hint">There might be a privacy risk</string>
<string name="title_advanced_name_email_hint">When disabled only names will be shown when available</string>
<string name="title_advanced_name_email_hint">Names will only be shown when available</string>
<string name="title_advanced_preview_hint">Only available when message text has been downloaded</string>
<string name="title_advanced_preview_lines_hint">Maximum %s characters in total</string>
<string name="title_advanced_preview_issue">Scrolling can be slow due to a bug in some Android versions when the number of lines is more than one</string>
@ -1908,6 +1908,12 @@
<item>comic sans</item>
</string-array>
<string-array name="addressFormatNames">
<item>Name only</item>
<item>Email only</item>
<item>Name and email</item>
</string-array>
<string name="fingerprint" translatable="false">17BA15C1AF55D925F98B99CEA4375D4CDF4C174B</string>
<string name="public_key" translatable="false">MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAtFbxEbzL8u5accPGgBw/XdyiSS5BBE6ZQ9ELpKyJ/OQN+kdYniCAOw3lsQ/GuJScy4Y2HobqbBgLL8GLHG+Yu2EHC9dLjA3v2Mc25vvnfn86BsrpQvz1poN2n+roTBdq09FWbtebJ8m0hDBVmtfRi7RhTKIL4No3kodLhksdnucKjcFheubebWKgpmvbmw7NwuELhaZmyhw8WTtnQ4rZPMhjY1JJZgzwNExXgD7zzg4pJPkuQlfkuRkkvBpHpi3C7VDnYjrBlLHngI4wv3wxQBVwJqlvAT9PmX8dOVnTsWWdJdLQBZVWphuqVY54kjBIovN+o8w03WjsV9QiOQq+XwIDAQAB</string>
</resources>