Added default compose font

pull/184/head
M66B 4 years ago
parent ce641d5cec
commit ac97b50b4a

@ -245,6 +245,7 @@ public class FragmentCompose extends FragmentBase {
private boolean prefix_once = false; private boolean prefix_once = false;
private boolean monospaced = false; private boolean monospaced = false;
private String compose_font;
private Integer encrypt = null; private Integer encrypt = null;
private boolean media = true; private boolean media = true;
private boolean compact = false; private boolean compact = false;
@ -292,6 +293,7 @@ public class FragmentCompose extends FragmentBase {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext()); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
prefix_once = prefs.getBoolean("prefix_once", true); prefix_once = prefs.getBoolean("prefix_once", true);
monospaced = prefs.getBoolean("monospaced", false); monospaced = prefs.getBoolean("monospaced", false);
compose_font = prefs.getString("compose_font", monospaced ? "monospace" : "sans-serif");
media = prefs.getBoolean("compose_media", true); media = prefs.getBoolean("compose_media", true);
compact = prefs.getBoolean("compose_compact", false); compact = prefs.getBoolean("compose_compact", false);
zoom = prefs.getInt("compose_zoom", compact ? 0 : 1); zoom = prefs.getInt("compose_zoom", compact ? 0 : 1);
@ -610,7 +612,7 @@ public class FragmentCompose extends FragmentBase {
} }
}); });
etBody.setTypeface(monospaced ? Typeface.MONOSPACE : Typeface.DEFAULT); etBody.setTypeface(Typeface.create(compose_font, Typeface.NORMAL));
tvReference.setTypeface(monospaced ? Typeface.MONOSPACE : Typeface.DEFAULT); tvReference.setTypeface(monospaced ? Typeface.MONOSPACE : Typeface.DEFAULT);
tvReference.setMovementMethod(LinkMovementMethod.getInstance()); tvReference.setMovementMethod(LinkMovementMethod.getInstance());

@ -50,6 +50,7 @@ public class FragmentOptionsSend extends FragmentBase implements SharedPreferenc
private SwitchCompat swSendReminders; private SwitchCompat swSendReminders;
private Spinner spSendDelayed; private Spinner spSendDelayed;
private Spinner spComposeFont;
private SwitchCompat swAutoList; private SwitchCompat swAutoList;
private SwitchCompat swPrefixOnce; private SwitchCompat swPrefixOnce;
private SwitchCompat swExtendedReply; private SwitchCompat swExtendedReply;
@ -71,7 +72,7 @@ public class FragmentOptionsSend extends FragmentBase implements SharedPreferenc
private final static String[] RESET_OPTIONS = new String[]{ private final static String[] RESET_OPTIONS = new String[]{
"keyboard", "suggest_sent", "suggested_received", "suggest_frequently", "keyboard", "suggest_sent", "suggested_received", "suggest_frequently",
"send_reminders", "send_delayed", "send_reminders", "send_delayed",
"autolist", "prefix_once", "extended_reply", "quote_reply", "resize_reply", "compose_font", "autolist", "prefix_once", "extended_reply", "quote_reply", "resize_reply",
"signature_location", "signature_reply", "signature_forward", "signature_location", "signature_reply", "signature_forward",
"discard_delete", "discard_delete",
"plain_only", "format_flowed", "usenet_signature", "remove_signatures", "plain_only", "format_flowed", "usenet_signature", "remove_signatures",
@ -95,6 +96,7 @@ public class FragmentOptionsSend extends FragmentBase implements SharedPreferenc
btnLocalContacts = view.findViewById(R.id.btnLocalContacts); btnLocalContacts = view.findViewById(R.id.btnLocalContacts);
swSendReminders = view.findViewById(R.id.swSendReminders); swSendReminders = view.findViewById(R.id.swSendReminders);
spSendDelayed = view.findViewById(R.id.spSendDelayed); spSendDelayed = view.findViewById(R.id.spSendDelayed);
spComposeFont = view.findViewById(R.id.spComposeFont);
swAutoList = view.findViewById(R.id.swAutoList); swAutoList = view.findViewById(R.id.swAutoList);
swPrefixOnce = view.findViewById(R.id.swPrefixOnce); swPrefixOnce = view.findViewById(R.id.swPrefixOnce);
@ -178,6 +180,24 @@ public class FragmentOptionsSend extends FragmentBase implements SharedPreferenc
} }
}); });
spComposeFont.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> adapterView, View view, int position, long id) {
String[] values = getResources().getStringArray(R.array.fontNameValues);
String value = values[position];
boolean monospaced = prefs.getBoolean("monospaced", false);
if (value.equals(monospaced ? "monospace" : "sans-serif"))
prefs.edit().remove("compose_font").apply();
else
prefs.edit().putString("compose_font", values[position]).apply();
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
prefs.edit().remove("compose_font").apply();
}
});
swAutoList.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { swAutoList.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override @Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
@ -361,6 +381,15 @@ public class FragmentOptionsSend extends FragmentBase implements SharedPreferenc
break; break;
} }
boolean monospaced = prefs.getBoolean("monospaced", false);
String compose_font = prefs.getString("compose_font", monospaced ? "monospace" : "sans-serif");
String[] fontNameValues = getResources().getStringArray(R.array.fontNameValues);
for (int pos = 0; pos < fontNameValues.length; pos++)
if (fontNameValues[pos].equals(compose_font)) {
spComposeFont.setSelection(pos);
break;
}
swAutoList.setChecked(prefs.getBoolean("autolist", true)); swAutoList.setChecked(prefs.getBoolean("autolist", true));
swPrefixOnce.setChecked(prefs.getBoolean("prefix_once", true)); swPrefixOnce.setChecked(prefs.getBoolean("prefix_once", true));
swExtendedReply.setChecked(prefs.getBoolean("extended_reply", false)); swExtendedReply.setChecked(prefs.getBoolean("extended_reply", false));

@ -547,6 +547,8 @@ public class MessageHelper {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean autolist = prefs.getBoolean("autolist", true); boolean autolist = prefs.getBoolean("autolist", true);
boolean format_flowed = prefs.getBoolean("format_flowed", false); boolean format_flowed = prefs.getBoolean("format_flowed", false);
boolean monospaced = prefs.getBoolean("monospaced", false);
String compose_font = prefs.getString("compose_font", monospaced ? "monospace" : "sans-serif");
// Build html body // Build html body
Document document = JsoupEx.parse(message.getFile(context)); Document document = JsoupEx.parse(message.getFile(context));
@ -557,6 +559,12 @@ public class MessageHelper {
HtmlHelper.convertLists(document); HtmlHelper.convertLists(document);
if (send) { if (send) {
for (Element child : document.body().children())
if (TextUtils.isEmpty(child.attr("fairemail"))) {
String style = HtmlHelper.mergeStyles(
"font-family:" + compose_font, child.attr("style"));
child.attr("style", style);
}
document.select("div[fairemail=signature]").removeAttr("fairemail"); document.select("div[fairemail=signature]").removeAttr("fairemail");
document.select("div[fairemail=reference]").removeAttr("fairemail"); document.select("div[fairemail=reference]").removeAttr("fairemail");
} }

@ -169,6 +169,28 @@
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/spSendDelayed" /> app:layout_constraintTop_toBottomOf="@+id/spSendDelayed" />
<eu.faircode.email.FixedTextView
android:id="@+id/tvComposeFont"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:layout_marginEnd="48dp"
android:text="@string/title_advanced_compose_font"
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/tvCaptionMessage" />
<Spinner
android:id="@+id/spComposeFont"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:entries="@array/fontNameNames"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvComposeFont" />
<androidx.appcompat.widget.SwitchCompat <androidx.appcompat.widget.SwitchCompat
android:id="@+id/swAutoList" android:id="@+id/swAutoList"
android:layout_width="0dp" android:layout_width="0dp"
@ -178,7 +200,7 @@
android:text="@string/title_advanced_auto_list" android:text="@string/title_advanced_auto_list"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvCaptionMessage" app:layout_constraintTop_toBottomOf="@id/spComposeFont"
app:switchPadding="12dp" /> app:switchPadding="12dp" />
<androidx.appcompat.widget.SwitchCompat <androidx.appcompat.widget.SwitchCompat

@ -291,6 +291,7 @@
<string name="title_advanced_suggest_sent">Suggest addresses found in sent messages</string> <string name="title_advanced_suggest_sent">Suggest addresses found in sent messages</string>
<string name="title_advanced_suggest_received">Suggest addresses found in received messages</string> <string name="title_advanced_suggest_received">Suggest addresses found in received messages</string>
<string name="title_advanced_suggest_frequently">Sort suggested addresses on frequency of use</string> <string name="title_advanced_suggest_frequently">Sort suggested addresses on frequency of use</string>
<string name="title_advanced_compose_font">Default font</string>
<string name="title_advanced_auto_list">Automatically create lists</string> <string name="title_advanced_auto_list">Automatically create lists</string>
<string name="title_advanced_prefix_once">Prefix subject only once on replying or forwarding</string> <string name="title_advanced_prefix_once">Prefix subject only once on replying or forwarding</string>
<string name="title_advanced_extended_reply">Use extended reply/forward header</string> <string name="title_advanced_extended_reply">Use extended reply/forward header</string>

Loading…
Cancel
Save