Added option to prefer contact names

pull/174/head
M66B 5 years ago
parent da1afe95b1
commit b62c9b4ab8

@ -205,6 +205,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
private boolean avatars;
private boolean color_stripe;
private boolean name_email;
private boolean prefer_contact;
private boolean distinguish_contacts;
private Float font_size_sender;
private Float font_size_subject;
@ -1222,7 +1223,8 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
addresses != null && addresses.length == 1) {
String email = ((InternetAddress) addresses[0]).getAddress();
String personal = ((InternetAddress) addresses[0]).getPersonal();
if (TextUtils.isEmpty(personal))
if (TextUtils.isEmpty(personal) ||
(prefer_contact && !personal.equals(displayName)))
try {
InternetAddress a = new InternetAddress(email, displayName, StandardCharsets.UTF_8.name());
tvFrom.setText(MessageHelper.formatAddresses(new Address[]{a}, name_email, false));
@ -4176,6 +4178,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
this.avatars = (contacts && avatars) || generated;
this.color_stripe = prefs.getBoolean("color_stripe", true);
this.name_email = prefs.getBoolean("name_email", false);
this.prefer_contact = prefs.getBoolean("prefer_contact", false);
this.distinguish_contacts = prefs.getBoolean("distinguish_contacts", false);
this.subject_top = prefs.getBoolean("subject_top", false);

@ -45,7 +45,7 @@ public class FragmentOptions extends FragmentBase {
"subscriptions",
"landscape", "landscape3", "startup", "cards", "indentation", "date", "threading", "highlight_unread", "color_stripe",
"avatars", "gravatars", "generated_icons", "identicons", "circular", "saturation", "brightness", "threshold",
"name_email", "distinguish_contacts", "authentication",
"name_email", "prefer_contact", "distinguish_contacts", "authentication",
"subject_top", "font_size_sender", "font_size_subject", "subject_italic", "subject_ellipsize", "keywords_header",
"flags", "flags_background", "preview", "preview_italic", "preview_lines",
"addresses", "attachments_alt",

@ -75,6 +75,7 @@ public class FragmentOptionsDisplay extends FragmentBase implements SharedPrefer
private SeekBar sbBrightness;
private SeekBar sbThreshold;
private SwitchCompat swNameEmail;
private SwitchCompat swPreferContact;
private SwitchCompat swDistinguishContacts;
private SwitchCompat swAuthentication;
private SwitchCompat swSubjectTop;
@ -102,7 +103,7 @@ public class FragmentOptionsDisplay extends FragmentBase implements SharedPrefer
private final static String[] RESET_OPTIONS = new String[]{
"theme", "landscape", "landscape3", "startup", "cards", "indentation", "date", "threading", "highlight_unread", "color_stripe",
"avatars", "gravatars", "generated_icons", "identicons", "circular", "saturation", "brightness", "threshold",
"name_email", "distinguish_contacts", "authentication",
"name_email", "prefer_contact", "distinguish_contacts", "authentication",
"subject_top", "font_size_sender", "font_size_subject", "subject_italic", "subject_ellipsize", "keywords_header",
"flags", "flags_background", "preview", "preview_italic", "preview_lines", "addresses", "attachments_alt",
"contrast", "monospaced", "text_color",
@ -142,6 +143,7 @@ public class FragmentOptionsDisplay extends FragmentBase implements SharedPrefer
sbBrightness = view.findViewById(R.id.sbBrightness);
sbThreshold = view.findViewById(R.id.sbThreshold);
swNameEmail = view.findViewById(R.id.swNameEmail);
swPreferContact = view.findViewById(R.id.swPreferContact);
swDistinguishContacts = view.findViewById(R.id.swDistinguishContacts);
swAuthentication = view.findViewById(R.id.swAuthentication);
swSubjectTop = view.findViewById(R.id.swSubjectTop);
@ -367,6 +369,13 @@ public class FragmentOptionsDisplay extends FragmentBase implements SharedPrefer
}
});
swPreferContact.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
prefs.edit().putBoolean("prefer_contact", checked).apply();
}
});
swDistinguishContacts.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
@ -632,6 +641,7 @@ public class FragmentOptionsDisplay extends FragmentBase implements SharedPrefer
sbThreshold.setEnabled(swGeneratedIcons.isChecked());
swNameEmail.setChecked(prefs.getBoolean("name_email", false));
swPreferContact.setChecked(prefs.getBoolean("prefer_contact", false));
swDistinguishContacts.setChecked(prefs.getBoolean("distinguish_contacts", false));
swAuthentication.setChecked(prefs.getBoolean("authentication", true));

@ -370,6 +370,18 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swNameEmail" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swPreferContact"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:checked="true"
android:text="@string/title_advanced_replace_name"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvNameEmailHint"
app:switchPadding="12dp" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swDistinguishContacts"
android:layout_width="0dp"
@ -379,7 +391,7 @@
android:text="@string/title_advanced_distinguish_contacts"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvNameEmailHint"
app:layout_constraintTop_toBottomOf="@id/swPreferContact"
app:switchPadding="12dp" />
<ImageView

@ -297,7 +297,6 @@
<string name="title_advanced_threading">Conversation threading</string>
<string name="title_advanced_indentation">Left/right indent received/sent messages in conversations</string>
<string name="title_advanced_highlight_unread">Highlight unread messages</string>
<string name="title_advanced_distinguish_contacts">Underline the sender when the sender is known as local \'to\' contact</string>
<string name="title_advanced_color_stripe">Show color stripe</string>
<string name="title_advanced_avatars">Show contact photos</string>
<string name="title_advanced_gravatars">Show Gravatars</string>
@ -308,6 +307,8 @@
<string name="title_advanced_color_value">Brightness</string>
<string name="title_advanced_color_threshold">Threshold letter color</string>
<string name="title_advanced_name_email">Show names and email addresses</string>
<string name="title_advanced_replace_name">Prefer the name of the contact over the sent name</string>
<string name="title_advanced_distinguish_contacts">Underline the sender when the sender is known as local \'to\' contact</string>
<string name="title_advanced_authentication">Show a warning when the receiving server could not authenticate the message</string>
<string name="title_advanced_font_size_sender">Font size sender</string>
<string name="title_advanced_font_size_subject">Font size subject</string>

Loading…
Cancel
Save