Optionally show text colors

This commit is contained in:
M66B 2019-09-23 20:13:38 +02:00
parent 7b183675c3
commit 214774fa09
8 changed files with 65 additions and 32 deletions

View File

@ -139,7 +139,7 @@ public class ActivityEML extends ActivityBase {
result.html = parts.getHtml(context);
if (result.html != null) {
result.body = HtmlHelper.fromHtml(HtmlHelper.sanitize(context, result.html, false));
result.body = HtmlHelper.fromHtml(HtmlHelper.sanitize(context, result.html, false, false));
if (result.html.length() > 100 * 1024)
result.html = null;
}

View File

@ -2527,6 +2527,10 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
boolean show_quotes = args.getBoolean("show_quotes");
int zoom = args.getInt("zoom");
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean text_color = prefs.getBoolean("text_color", true);
boolean inline = prefs.getBoolean("inline_images", false);
if (message == null || !message.content)
return null;
@ -2537,9 +2541,6 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
String body = Helper.readText(file);
Document document = Jsoup.parse(body);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean inline = prefs.getBoolean("inline_images", false);
boolean has_images = false;
for (Element img : document.select("img")) {
if (inline) {
@ -2561,7 +2562,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
body = document.html();
}
String html = HtmlHelper.sanitize(context, body, show_images);
String html = HtmlHelper.sanitize(context, body, text_color, show_images);
if (debug) {
Document format = Jsoup.parse(html);
format.outputSettings().prettyPrint(true).outline(true).indentAmount(1);

View File

@ -2011,6 +2011,7 @@ public class FragmentCompose extends FragmentBase {
long answer = args.getLong("answer", -1);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean text_color = prefs.getBoolean("text_color", true);
boolean plain_only = prefs.getBoolean("plain_only", false);
Log.i("Load draft action=" + action + " id=" + id + " reference=" + reference);
@ -2071,7 +2072,7 @@ public class FragmentCompose extends FragmentBase {
data.draft.subject = args.getString("subject", "");
body = args.getString("body", "");
if (!TextUtils.isEmpty(body))
body = HtmlHelper.sanitize(context, body, false);
body = HtmlHelper.sanitize(context, body, text_color, false);
if (answer > 0) {
EntityAnswer a = db.answer().getAnswer(answer);
@ -2137,7 +2138,7 @@ public class FragmentCompose extends FragmentBase {
data.draft.subject = ref.subject;
if (ref.content) {
String html = Helper.readText(ref.getFile(context));
body = HtmlHelper.sanitize(context, html, true);
body = HtmlHelper.sanitize(context, html, text_color, true);
}
} else if ("list".equals(action)) {
data.draft.subject = ref.subject;
@ -2371,7 +2372,7 @@ public class FragmentCompose extends FragmentBase {
if (data.draft.content) {
File file = data.draft.getFile(context);
String html = Helper.readText(file);
html = HtmlHelper.sanitize(context, html, true);
html = HtmlHelper.sanitize(context, html, true, true);
Helper.writeText(file, html);
} else {
if (data.draft.uid == null)
@ -3065,6 +3066,9 @@ public class FragmentCompose extends FragmentBase {
final long id = args.getLong("id");
final boolean show_images = args.getBoolean("show_images", false);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean text_color = prefs.getBoolean("text_color", true);
DB db = DB.getInstance(context);
EntityMessage draft = db.message().getMessage(id);
if (draft == null || !draft.content)
@ -3076,7 +3080,7 @@ public class FragmentCompose extends FragmentBase {
Spanned spannedRef = null;
File refFile = draft.getRefFile(context);
if (refFile.exists()) {
String quote = HtmlHelper.sanitize(context, Helper.readText(refFile), show_images);
String quote = HtmlHelper.sanitize(context, Helper.readText(refFile), text_color, show_images);
Spanned spannedQuote = HtmlHelper.fromHtml(quote,
new Html.ImageGetter() {
@Override

View File

@ -41,7 +41,9 @@ public class FragmentOptions extends FragmentBase {
"subscriptions",
"startup", "cards", "date", "threading", "highlight_unread", "avatars", "generated_icons", "identicons", "circular",
"name_email", "authentication", "subject_top", "subject_italic", "subject_ellipsize", "flags", "preview", "preview_italic",
"addresses", "attachments_alt", "contrast", "monospaced", "inline_images", "collapse_quotes", "autocontent", "seekbar", "actionbar",
"addresses", "attachments_alt",
"contrast", "monospaced", "text_color",
"inline_images", "collapse_quotes", "autocontent", "seekbar", "actionbar",
"autoscroll", "swipenav", "autoexpand", "autoclose", "onclose",
"experiments", "debug",
"biometrics"

View File

@ -66,8 +66,9 @@ public class FragmentOptionsDisplay extends FragmentBase implements SharedPrefer
private SwitchCompat swContrast;
private SwitchCompat swMonospaced;
private SwitchCompat swImagesInline;
private SwitchCompat swTextColor;
private SwitchCompat swCollapseQuotes;
private SwitchCompat swImagesInline;
private SwitchCompat swRemoteContent;
private SwitchCompat swSeekbar;
private SwitchCompat swActionbar;
@ -77,7 +78,8 @@ public class FragmentOptionsDisplay extends FragmentBase implements SharedPrefer
"avatars", "generated_icons", "identicons", "circular", "name_email",
"authentication", "subject_top", "subject_italic", "subject_ellipsize",
"flags", "preview", "preview_italic", "addresses", "attachments_alt",
"contrast", "monospaced", "inline_images", "collapse_quotes", "autocontent", "seekbar", "actionbar",
"contrast", "monospaced", "text_color",
"inline_images", "collapse_quotes", "autocontent", "seekbar", "actionbar",
};
@Override
@ -112,8 +114,9 @@ public class FragmentOptionsDisplay extends FragmentBase implements SharedPrefer
swAttachmentsAlt = view.findViewById(R.id.swAttachmentsAlt);
swContrast = view.findViewById(R.id.swContrast);
swMonospaced = view.findViewById(R.id.swMonospaced);
swImagesInline = view.findViewById(R.id.swImagesInline);
swTextColor = view.findViewById(R.id.swTextColor);
swCollapseQuotes = view.findViewById(R.id.swCollapseQuotes);
swImagesInline = view.findViewById(R.id.swImagesInline);
swRemoteContent = view.findViewById(R.id.swRemoteContent);
swSeekbar = view.findViewById(R.id.swSeekbar);
swActionbar = view.findViewById(R.id.swActionbar);
@ -297,10 +300,10 @@ public class FragmentOptionsDisplay extends FragmentBase implements SharedPrefer
}
});
swImagesInline.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
swTextColor.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
prefs.edit().putBoolean("inline_images", checked).apply();
prefs.edit().putBoolean("text_color", checked).apply();
}
});
@ -311,6 +314,13 @@ public class FragmentOptionsDisplay extends FragmentBase implements SharedPrefer
}
});
swImagesInline.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
prefs.edit().putBoolean("inline_images", checked).apply();
}
});
swRemoteContent.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
@ -416,8 +426,9 @@ public class FragmentOptionsDisplay extends FragmentBase implements SharedPrefer
swAttachmentsAlt.setChecked(prefs.getBoolean("attachments_alt", false));
swContrast.setChecked(prefs.getBoolean("contrast", false));
swMonospaced.setChecked(prefs.getBoolean("monospaced", false));
swImagesInline.setChecked(prefs.getBoolean("inline_images", false));
swTextColor.setChecked(prefs.getBoolean("text_color", true));
swCollapseQuotes.setChecked(prefs.getBoolean("collapse_quotes", false));
swImagesInline.setChecked(prefs.getBoolean("inline_images", false));
swRemoteContent.setChecked(prefs.getBoolean("autocontent", false));
swSeekbar.setChecked(prefs.getBoolean("seekbar", false));
swActionbar.setChecked(prefs.getBoolean("actionbar", true));

View File

@ -93,7 +93,7 @@ public class HtmlHelper {
private static final ExecutorService executor =
Executors.newSingleThreadExecutor(Helper.backgroundThreadFactory);
static String sanitize(Context context, String html, boolean show_images) {
static String sanitize(Context context, String html, boolean text_color, boolean show_images) {
Document parsed = Jsoup.parse(html);
// <html xmlns:v="urn:schemas-microsoft-com:vml"
@ -133,13 +133,15 @@ public class HtmlHelper {
Whitelist whitelist = Whitelist.relaxed()
.addTags("hr", "abbr", "big")
.addAttributes("span", "style")
.removeTags("col", "colgroup", "thead", "tbody")
.removeAttributes("table", "width")
.removeAttributes("td", "colspan", "rowspan", "width")
.removeAttributes("th", "colspan", "rowspan", "width")
.addProtocols("img", "src", "cid")
.addProtocols("img", "src", "data");
if (text_color)
whitelist.addAttributes("span", "style");
final Document document = new Cleaner(whitelist).clean(parsed);
// Sanitize span styles

View File

@ -346,6 +346,29 @@
app:layout_constraintTop_toBottomOf="@id/swContrast"
app:switchPadding="12dp" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swTextColor"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:enabled="true"
android:text="@string/title_advanced_text_color"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swMonospaced"
app:switchPadding="12dp" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swCollapseQuotes"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="@string/title_advanced_collapse_quotes"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swTextColor"
app:switchPadding="12dp" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swImagesInline"
android:layout_width="0dp"
@ -354,7 +377,7 @@
android:text="@string/title_advanced_images_inline"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swMonospaced"
app:layout_constraintTop_toBottomOf="@id/swCollapseQuotes"
app:switchPadding="12dp" />
<TextView
@ -369,17 +392,6 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swImagesInline" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swCollapseQuotes"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="@string/title_advanced_collapse_quotes"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvImagesInlineHint"
app:switchPadding="12dp" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swRemoteContent"
android:layout_width="0dp"
@ -388,7 +400,7 @@
android:text="@string/title_advanced_remote_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swCollapseQuotes"
app:layout_constraintTop_toBottomOf="@id/tvImagesInlineHint"
app:switchPadding="12dp" />
<TextView

View File

@ -256,8 +256,9 @@
<string name="title_advanced_attachments_alt">Show attachments after the 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</string>
<string name="title_advanced_images_inline">Automatically show inline images</string>
<string name="title_advanced_text_color">Show text colors</string>
<string name="title_advanced_collapse_quotes">Collapse quoted text</string>
<string name="title_advanced_images_inline">Automatically show inline images</string>
<string name="title_advanced_remote_content">Automatically show remote content when viewing original messages</string>
<string name="title_advanced_seekbar">Show relative conversation position with a dot</string>
<string name="title_advanced_actionbar">Show conversation action bar</string>