mirror of
https://github.com/M66B/FairEmail.git
synced 2026-03-31 14:17:03 +02:00
View source: add dark mode
This commit is contained in:
@@ -42,6 +42,8 @@ import androidx.activity.OnBackPressedCallback;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.constraintlayout.widget.Group;
|
||||
import androidx.preference.PreferenceManager;
|
||||
import androidx.webkit.WebSettingsCompat;
|
||||
import androidx.webkit.WebViewFeature;
|
||||
|
||||
import org.jsoup.nodes.Document;
|
||||
import org.jsoup.nodes.Element;
|
||||
@@ -60,9 +62,10 @@ public class ActivityCode extends ActivityBase {
|
||||
private ContentLoadingProgressBar pbWait;
|
||||
private Group grpReady;
|
||||
|
||||
private boolean force_light = false;
|
||||
private boolean sanitize = false;
|
||||
private boolean lines = false;
|
||||
private boolean links = false;
|
||||
private boolean sanitize = false;
|
||||
|
||||
private static final int REQUEST_SAVE = 1;
|
||||
|
||||
@@ -71,9 +74,10 @@ public class ActivityCode extends ActivityBase {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
if (savedInstanceState != null) {
|
||||
force_light = savedInstanceState.getBoolean("fair:force_light");
|
||||
sanitize = savedInstanceState.getBoolean("fair:sanitize");
|
||||
lines = savedInstanceState.getBoolean("fair:lines");
|
||||
links = savedInstanceState.getBoolean("fair:links");
|
||||
sanitize = savedInstanceState.getBoolean("fair:sanitize");
|
||||
}
|
||||
|
||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
@@ -106,6 +110,8 @@ public class ActivityCode extends ActivityBase {
|
||||
settings.setBlockNetworkImage(true);
|
||||
settings.setJavaScriptEnabled(true);
|
||||
|
||||
setDarkMode();
|
||||
|
||||
wvCode.setWebViewClient(new WebViewClient() {
|
||||
@Override
|
||||
public boolean shouldOverrideUrlLoading(WebView view, String url) {
|
||||
@@ -141,9 +147,10 @@ public class ActivityCode extends ActivityBase {
|
||||
|
||||
@Override
|
||||
protected void onSaveInstanceState(Bundle outState) {
|
||||
outState.putBoolean("fair:force_light", force_light);
|
||||
outState.putBoolean("fair:sanitize", sanitize);
|
||||
outState.putBoolean("fair:lines", lines);
|
||||
outState.putBoolean("fair:links", links);
|
||||
outState.putBoolean("fair:sanitize", sanitize);
|
||||
super.onSaveInstanceState(outState);
|
||||
}
|
||||
|
||||
@@ -159,6 +166,12 @@ public class ActivityCode extends ActivityBase {
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
boolean debug = prefs.getBoolean("debug", false);
|
||||
|
||||
boolean dark = Helper.isDarkTheme(this);
|
||||
boolean canDarken = WebViewEx.isFeatureSupported(this, WebViewFeature.ALGORITHMIC_DARKENING);
|
||||
menu.findItem(R.id.menu_force_light)
|
||||
.setVisible(dark && canDarken)
|
||||
.getIcon().setLevel(force_light ? 1 : 0);
|
||||
|
||||
menu.findItem(R.id.menu_sanitize)
|
||||
.setVisible(BuildConfig.DEBUG || debug)
|
||||
.setChecked(sanitize)
|
||||
@@ -178,7 +191,12 @@ public class ActivityCode extends ActivityBase {
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
int itemId = item.getItemId();
|
||||
if (itemId == R.id.menu_sanitize) {
|
||||
if (itemId == R.id.menu_force_light) {
|
||||
force_light = !force_light;
|
||||
invalidateOptionsMenu();
|
||||
setDarkMode();
|
||||
return true;
|
||||
} else if (itemId == R.id.menu_sanitize) {
|
||||
sanitize = !sanitize;
|
||||
invalidateOptionsMenu();
|
||||
load();
|
||||
@@ -219,6 +237,14 @@ public class ActivityCode extends ActivityBase {
|
||||
}
|
||||
}
|
||||
|
||||
private void setDarkMode() {
|
||||
WebSettings settings = wvCode.getSettings();
|
||||
boolean dark = (Helper.isDarkTheme(this) && !force_light);
|
||||
boolean canDarken = WebViewEx.isFeatureSupported(this, WebViewFeature.ALGORITHMIC_DARKENING);
|
||||
if (canDarken)
|
||||
WebSettingsCompat.setAlgorithmicDarkeningAllowed(settings, dark);
|
||||
}
|
||||
|
||||
private void load() {
|
||||
Intent intent = getIntent();
|
||||
long id = intent.getLongExtra("id", -1L);
|
||||
|
||||
Reference in New Issue
Block a user