Added setting to show hidden texts

pull/163/head
M66B 5 years ago
parent f508149ab0
commit 52639dd5c5

@ -38,10 +38,11 @@ import androidx.preference.PreferenceManager;
public class FragmentOptionsPrivacy extends FragmentBase implements SharedPreferences.OnSharedPreferenceChangeListener {
private SwitchCompat swDisableTracking;
private SwitchCompat swDisplayHidden;
private SwitchCompat swNoHistory;
private final static String[] RESET_OPTIONS = new String[]{
"disable_tracking", "no_history"
"disable_tracking", "display_hidden", "no_history"
};
@Override
@ -55,6 +56,7 @@ public class FragmentOptionsPrivacy extends FragmentBase implements SharedPrefer
// Get controls
swDisableTracking = view.findViewById(R.id.swDisableTracking);
swDisplayHidden = view.findViewById(R.id.swDisplayHidden);
swNoHistory = view.findViewById(R.id.swNoHistory);
setOptions();
@ -70,6 +72,13 @@ public class FragmentOptionsPrivacy extends FragmentBase implements SharedPrefer
}
});
swDisplayHidden.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
prefs.edit().putBoolean("display_hidden", checked).apply();
}
});
swNoHistory.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
@ -125,6 +134,7 @@ public class FragmentOptionsPrivacy extends FragmentBase implements SharedPrefer
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
swDisableTracking.setChecked(prefs.getBoolean("disable_tracking", true));
swDisplayHidden.setChecked(prefs.getBoolean("display_hidden", false));
swNoHistory.setChecked(prefs.getBoolean("no_history", false));
}
}

@ -82,6 +82,7 @@ public class HtmlHelper {
static String sanitize(Context context, String html, boolean show_images) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean text_color = prefs.getBoolean("text_color", true);
boolean display_hidden = prefs.getBoolean("display_hidden", false);
boolean disable_tracking = prefs.getBoolean("disable_tracking", true);
Document parsed = JsoupEx.parse(html);
@ -148,21 +149,22 @@ public class HtmlHelper {
font.tagName("span");
}
// Sanitize span styles
for (Element span : document.select("*")) {
String style = span.attr("style");
// Sanitize styles
for (Element element : document.select("*")) {
String style = element.attr("style");
if (!TextUtils.isEmpty(style)) {
StringBuilder sb = new StringBuilder();
String[] params = style.split(";");
for (String param : params) {
String[] kv = param.split(":");
if (kv.length == 2)
switch (kv[0].trim().toLowerCase(Locale.ROOT)) {
if (kv.length == 2) {
String key = kv[0].trim().toLowerCase(Locale.ROOT);
String value = kv[1].toLowerCase(Locale.ROOT)
.replace(" ", "");
switch (key) {
case "color":
String c = kv[1]
.toLowerCase(Locale.ROOT)
.replace(" ", "")
String c = value
.replace("inherit", "")
.replace("initial", "")
.replace("windowtext", "")
@ -201,7 +203,7 @@ public class HtmlHelper {
sb.append("color:").append(c).append(";");
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N)
span.attr("color", c);
element.attr("color", c);
}
break;
@ -212,13 +214,21 @@ public class HtmlHelper {
case "line-through":
sb.append(param).append(";");
break;
case "display":
if ("none".equals(value) && !display_hidden) {
Log.i("Removing element " + element.tagName());
element.remove();
}
break;
}
}
}
if (sb.length() == 0)
span.removeAttr("style");
element.removeAttr("style");
else
span.attr("style", sb.toString());
element.attr("style", sb.toString());
}
}

@ -23,6 +23,29 @@
app:layout_constraintTop_toTopOf="parent"
app:switchPadding="12dp" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swDisplayHidden"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="@string/title_advanced_display_hidden"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swDisableTracking"
app:switchPadding="12dp" />
<TextView
android:id="@+id/tvDisplayHiddenHint"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="48dp"
android:text="@string/title_advanced_display_hidden_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/swDisplayHidden" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swNoHistory"
android:layout_width="0dp"
@ -31,7 +54,7 @@
android:text="@string/title_advanced_recents"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swDisableTracking"
app:layout_constraintTop_toBottomOf="@id/tvDisplayHiddenHint"
app:switchPadding="12dp" />
<TextView

@ -308,6 +308,7 @@
<string name="title_advanced_alert_once" translatable="false">MIUI notification sound workaround</string>
<string name="title_advanced_tracking">Automatically recognize and disable tracking images</string>
<string name="title_advanced_display_hidden">Display hidden message texts</string>
<string name="title_advanced_recents">Hide FairEmail from screen with recent apps</string>
<string name="title_advanced_badge_hint">Only available on supported launchers</string>
@ -362,6 +363,8 @@
<string name="title_advanced_autoclose_hint">Automatically close conversations when all messages are archived, sent or trashed</string>
<string name="title_advanced_sender_hint">Most providers do not allow modified sender addresses</string>
<string name="title_advanced_display_hidden_hint">This can result in odd looking and double texts</string>
<string name="title_advanced_subscribed_only_hint">Enabling this will delete all local folders without subscription</string>
<string name="title_advanced_english_hint">This will restart the app</string>
<string name="title_advanced_experiments_hint">List of current experimental features</string>

Loading…
Cancel
Save