Auto original dark

This commit is contained in:
M66B 2021-09-17 22:23:16 +02:00
parent 522cd30e7c
commit a67e679e17
4 changed files with 11 additions and 39 deletions

View File

@ -4178,20 +4178,11 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
if (full) {
TextView tvDark = dview.findViewById(R.id.tvDark);
CheckBox cbDark = dview.findViewById(R.id.cbDark);
CheckBox cbAlwaysImages = dview.findViewById(R.id.cbAlwaysImages);
boolean confirm_html = prefs.getBoolean("confirm_html", true);
cbDark.setChecked(prefs.getBoolean("html_dark", confirm_html));
cbAlwaysImages.setChecked(prefs.getBoolean("html_always_images", false));
cbDark.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
prefs.edit().putBoolean("html_dark", isChecked).apply();
}
});
cbAlwaysImages.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
@ -4201,10 +4192,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
boolean isDark = Helper.isDarkTheme(context);
boolean canDark = WebViewEx.isFeatureSupported(WebViewFeature.FORCE_DARK);
tvDark.setVisibility(isDark && !canDark ? View.VISIBLE : View.GONE);
cbDark.setVisibility(isDark && canDark ? View.VISIBLE : View.GONE);
} else {
boolean disable_tracking = prefs.getBoolean("disable_tracking", true);
@ -7266,8 +7254,6 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
boolean overview_mode = prefs.getBoolean("overview_mode", false);
boolean safe_browsing = prefs.getBoolean("safe_browsing", false);
boolean confirm_html = prefs.getBoolean("confirm_html", true);
boolean html_dark = prefs.getBoolean("html_dark", confirm_html);
View view = inflater.inflate(R.layout.fragment_open_full, container, false);
WebView wv = view.findViewById(R.id.wv);
@ -7289,8 +7275,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
settings.setSafeBrowsingEnabled(safe_browsing);
if (html_dark &&
WebViewEx.isFeatureSupported(WebViewFeature.FORCE_DARK))
if (WebViewEx.isFeatureSupported(WebViewFeature.FORCE_DARK))
WebSettingsCompat.setForceDark(settings,
Helper.isDarkTheme(getContext()) ? FORCE_DARK_ON : FORCE_DARK_OFF);

View File

@ -23,7 +23,10 @@ import android.content.Context;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.graphics.Bitmap;
import android.graphics.BlendMode;
import android.graphics.Color;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Build;
import android.util.Pair;
@ -104,23 +107,18 @@ public class WebViewEx extends WebView implements DownloadListener, View.OnLongC
int zoom = prefs.getInt("view_zoom", compact ? 0 : 1);
int message_zoom = prefs.getInt("message_zoom", 100);
boolean monospaced = prefs.getBoolean("monospaced", false);
boolean confirm_html = prefs.getBoolean("confirm_html", true);
boolean html_dark = prefs.getBoolean("html_dark", confirm_html);
WebSettings settings = getSettings();
boolean forced = false;
boolean dark = Helper.isDarkTheme(context);
if (html_dark &&
WebViewEx.isFeatureSupported(WebViewFeature.FORCE_DARK)) {
if (WebViewEx.isFeatureSupported(WebViewFeature.FORCE_DARK)) {
WebSettingsCompat.setForceDark(settings, dark ? FORCE_DARK_ON : FORCE_DARK_OFF);
forced = true;
setBackgroundColor(Color.TRANSPARENT);
} else {
if (!dark)
setBackgroundColor(Color.TRANSPARENT);
}
setBackgroundColor(dark && !forced
? Color.WHITE
: ColorUtils.setAlphaComponent(Color.WHITE, 127));
float fontSize = 16f /* Default */ * message_zoom / 100f;
if (zoom == 0 /* small */)
fontSize *= HtmlHelper.FONT_SMALL;
@ -178,7 +176,7 @@ public class WebViewEx extends WebView implements DownloadListener, View.OnLongC
});
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
setOnScrollChangeListener(new View.OnScrollChangeListener() {
setOnScrollChangeListener(new OnScrollChangeListener() {
@Override
public void onScrollChange(View v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {
Log.i("Scroll (x,y)=" + scrollX + "," + scrollY);

View File

@ -32,16 +32,6 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvMessage" />
<CheckBox
android:id="@+id/cbDark"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="@string/title_ask_show_html_dark"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvDark" />
<CheckBox
android:id="@+id/cbAlwaysImages"
android:layout_width="wrap_content"
@ -50,7 +40,7 @@
android:text="@string/title_ask_show_html_images"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/cbDark" />
app:layout_constraintTop_toBottomOf="@id/tvDark" />
<CheckBox
android:id="@+id/cbNotAgain"

View File

@ -1101,7 +1101,6 @@
<string name="title_ask_delete_rule">Delete rule permanently?</string>
<string name="title_ask_discard">Discard draft?</string>
<string name="title_ask_show_html">Showing the original message can leak privacy sensitive information</string>
<string name="title_ask_show_html_dark">Use dark theme</string>
<string name="title_ask_show_html_remark">Displaying the original message on a dark background is not possible as it may make dark texts and images invisible</string>
<string name="title_ask_show_html_images">Always show images on showing original messages</string>
<string name="title_ask_show_image">Showing images can leak privacy sensitive information</string>