Added option to show preformatted text monospaced

pull/187/head
M66B 4 years ago
parent ff29268824
commit 629ea43e5f

@ -85,7 +85,7 @@ public class FragmentOptions extends FragmentBase {
"subject_top", "font_size_sender", "font_size_subject", "subject_italic", "highlight_subject", "subject_ellipsize", "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", "keywords_header", "labels_header", "flags", "flags_background", "preview", "preview_italic", "preview_lines",
"message_zoom", "overview_mode", "addresses", "attachments_alt", "thumbnails", "message_zoom", "overview_mode", "addresses", "attachments_alt", "thumbnails",
"contrast", "monospaced", "contrast", "monospaced", "monospaced_pre",
"text_color", "text_size", "text_font", "text_align", "text_separators", "text_color", "text_size", "text_font", "text_align", "text_separators",
"inline_images", "collapse_quotes", "seekbar", "actionbar", "actionbar_color", "navbar_colorize", "inline_images", "collapse_quotes", "seekbar", "actionbar", "actionbar_color", "navbar_colorize",
"autoscroll", "swipenav", "swipe_close", "swipe_move", "autoexpand", "autoclose", "onclose", "autoscroll", "swipenav", "swipe_close", "swipe_move", "autoexpand", "autoclose", "onclose",

@ -119,6 +119,7 @@ public class FragmentOptionsDisplay extends FragmentBase implements SharedPrefer
private SwitchCompat swContrast; private SwitchCompat swContrast;
private SwitchCompat swMonospaced; private SwitchCompat swMonospaced;
private SwitchCompat swMonospacedPre;
private SwitchCompat swTextColor; private SwitchCompat swTextColor;
private SwitchCompat swTextSize; private SwitchCompat swTextSize;
private SwitchCompat swTextFont; private SwitchCompat swTextFont;
@ -142,7 +143,7 @@ public class FragmentOptionsDisplay extends FragmentBase implements SharedPrefer
"keywords_header", "labels_header", "flags", "flags_background", "keywords_header", "labels_header", "flags", "flags_background",
"preview", "preview_italic", "preview_lines", "preview", "preview_italic", "preview_lines",
"addresses", "addresses",
"message_zoom", "overview_mode", "contrast", "monospaced", "message_zoom", "overview_mode", "contrast", "monospaced", "monospaced_pre",
"text_color", "text_size", "text_font", "text_align", "text_separators", "text_color", "text_size", "text_font", "text_align", "text_separators",
"inline_images", "collapse_quotes", "attachments_alt", "thumbnails", "inline_images", "collapse_quotes", "attachments_alt", "thumbnails",
"parse_classes", "authentication" "parse_classes", "authentication"
@ -213,6 +214,7 @@ public class FragmentOptionsDisplay extends FragmentBase implements SharedPrefer
swOverviewMode = view.findViewById(R.id.swOverviewMode); swOverviewMode = view.findViewById(R.id.swOverviewMode);
swContrast = view.findViewById(R.id.swContrast); swContrast = view.findViewById(R.id.swContrast);
swMonospaced = view.findViewById(R.id.swMonospaced); swMonospaced = view.findViewById(R.id.swMonospaced);
swMonospacedPre = view.findViewById(R.id.swMonospacedPre);
swTextColor = view.findViewById(R.id.swTextColor); swTextColor = view.findViewById(R.id.swTextColor);
swTextSize = view.findViewById(R.id.swTextSize); swTextSize = view.findViewById(R.id.swTextSize);
swTextFont = view.findViewById(R.id.swTextFont); swTextFont = view.findViewById(R.id.swTextFont);
@ -716,6 +718,13 @@ public class FragmentOptionsDisplay extends FragmentBase implements SharedPrefer
} }
}); });
swMonospacedPre.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
prefs.edit().putBoolean("monospaced_pre", checked).apply();
}
});
swTextColor.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { swTextColor.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override @Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
@ -952,6 +961,7 @@ public class FragmentOptionsDisplay extends FragmentBase implements SharedPrefer
swContrast.setChecked(prefs.getBoolean("contrast", false)); swContrast.setChecked(prefs.getBoolean("contrast", false));
swMonospaced.setChecked(prefs.getBoolean("monospaced", false)); swMonospaced.setChecked(prefs.getBoolean("monospaced", false));
swMonospacedPre.setChecked(prefs.getBoolean("monospaced_pre", false));
swTextColor.setChecked(prefs.getBoolean("text_color", true)); swTextColor.setChecked(prefs.getBoolean("text_color", true));
swTextSize.setChecked(prefs.getBoolean("text_size", true)); swTextSize.setChecked(prefs.getBoolean("text_size", true));
swTextFont.setChecked(prefs.getBoolean("text_font", true)); swTextFont.setChecked(prefs.getBoolean("text_font", true));

@ -1897,6 +1897,7 @@ public class HtmlHelper {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean debug = prefs.getBoolean("debug", false); boolean debug = prefs.getBoolean("debug", false);
boolean text_separators = prefs.getBoolean("text_separators", false); boolean text_separators = prefs.getBoolean("text_separators", false);
boolean monospaced_pre = prefs.getBoolean("monospaced_pre", false);
final int colorPrimary = Helper.resolveColor(context, R.attr.colorPrimary); final int colorPrimary = Helper.resolveColor(context, R.attr.colorPrimary);
final int colorAccent = Helper.resolveColor(context, R.attr.colorAccent); final int colorAccent = Helper.resolveColor(context, R.attr.colorAccent);
@ -2043,7 +2044,12 @@ public class HtmlHelper {
ssb.append("[" + element.tagName() + ":" + element.attr("style") + "]"); ssb.append("[" + element.tagName() + ":" + element.attr("style") + "]");
} else if (node instanceof TextNode) { } else if (node instanceof TextNode) {
tnode = (TextNode) node; tnode = (TextNode) node;
ssb.append(tnode.getWholeText()); String text = tnode.getWholeText();
ssb.append(text);
if (monospaced_pre &&
node.parent() instanceof Element &&
"true".equals(((Element) node.parent()).attr("x-plain")))
setSpan(ssb, new TypefaceSpan("monospace"), ssb.length() - text.length(), ssb.length());
} }
} }

@ -925,6 +925,17 @@
app:layout_constraintTop_toBottomOf="@id/swContrast" app:layout_constraintTop_toBottomOf="@id/swContrast"
app:switchPadding="12dp" /> app:switchPadding="12dp" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swMonospacedPre"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="@string/title_advanced_monospaced_pre"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swMonospaced"
app:switchPadding="12dp" />
<androidx.appcompat.widget.SwitchCompat <androidx.appcompat.widget.SwitchCompat
android:id="@+id/swTextColor" android:id="@+id/swTextColor"
android:layout_width="0dp" android:layout_width="0dp"
@ -934,7 +945,7 @@
android:text="@string/title_advanced_text_color" android:text="@string/title_advanced_text_color"
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/swMonospaced" app:layout_constraintTop_toBottomOf="@id/swMonospacedPre"
app:switchPadding="12dp" /> app:switchPadding="12dp" />
<androidx.appcompat.widget.SwitchCompat <androidx.appcompat.widget.SwitchCompat

@ -385,6 +385,7 @@
<string name="title_advanced_overview_mode">Zoom original messages to fit the screen</string> <string name="title_advanced_overview_mode">Zoom original messages to fit the screen</string>
<string name="title_advanced_contrast">Use high contrast for message text</string> <string name="title_advanced_contrast">Use high contrast for message text</string>
<string name="title_advanced_monospaced">Use monospaced font for message text by default</string> <string name="title_advanced_monospaced">Use monospaced font for message text by default</string>
<string name="title_advanced_monospaced_pre">Use monospaced font for preformatted text</string>
<string name="title_advanced_text_color">Use text colors</string> <string name="title_advanced_text_color">Use text colors</string>
<string name="title_advanced_text_size">Use text sizes</string> <string name="title_advanced_text_size">Use text sizes</string>
<string name="title_advanced_text_font">Use fonts</string> <string name="title_advanced_text_font">Use fonts</string>

Loading…
Cancel
Save