From e8be216da29b581179981733a3ad9eafa24ae8b7 Mon Sep 17 00:00:00 2001 From: M66B Date: Sat, 19 Aug 2023 15:31:43 +0200 Subject: [PATCH] Viewport height default --- .../java/eu/faircode/email/FragmentOptionsMisc.java | 13 +++++++++++-- app/src/main/java/eu/faircode/email/WebViewEx.java | 3 ++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/FragmentOptionsMisc.java b/app/src/main/java/eu/faircode/email/FragmentOptionsMisc.java index e18161a00e..c18ae4b504 100644 --- a/app/src/main/java/eu/faircode/email/FragmentOptionsMisc.java +++ b/app/src/main/java/eu/faircode/email/FragmentOptionsMisc.java @@ -1632,6 +1632,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc } }); + etViewportHeight.setHint(Integer.toString(WebViewEx.DEFAULT_VIEWPORT_HEIGHT)); etViewportHeight.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) { @@ -1646,7 +1647,11 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc @Override public void afterTextChanged(Editable edit) { try { - prefs.edit().putInt("viewport_height", Integer.parseInt(edit.toString())).apply(); + String vh = edit.toString(); + if (TextUtils.isEmpty(vh)) + prefs.edit().remove("viewport_height").apply(); + else + prefs.edit().putInt("viewport_height", Integer.parseInt(vh)).apply(); } catch (Throwable ex) { Log.e(ex); } @@ -2597,7 +2602,11 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc swUndoManager.setChecked(prefs.getBoolean("undo_manager", false)); swBrowserZoom.setChecked(prefs.getBoolean("browser_zoom", false)); swFakeDark.setChecked(prefs.getBoolean("fake_dark", false)); - etViewportHeight.setText(Integer.toString(prefs.getInt("viewport_height", 8000))); + if (prefs.contains("viewport_height")) { + int vh = prefs.getInt("viewport_height", WebViewEx.DEFAULT_VIEWPORT_HEIGHT); + etViewportHeight.setText(Integer.toString(vh)); + } else + etViewportHeight.setText(null); swShowRecent.setChecked(prefs.getBoolean("show_recent", false)); swModSeq.setChecked(prefs.getBoolean("use_modseq", true)); swPreamble.setChecked(prefs.getBoolean("preamble", false)); diff --git a/app/src/main/java/eu/faircode/email/WebViewEx.java b/app/src/main/java/eu/faircode/email/WebViewEx.java index 07efa12096..260231deaf 100644 --- a/app/src/main/java/eu/faircode/email/WebViewEx.java +++ b/app/src/main/java/eu/faircode/email/WebViewEx.java @@ -56,13 +56,14 @@ public class WebViewEx extends WebView implements DownloadListener, View.OnLongC private static String userAgent = null; + static final int DEFAULT_VIEWPORT_HEIGHT = 8000; private static final long PAGE_LOADED_FALLBACK_DELAY = 1500L; // milliseconds public WebViewEx(Context context) { super(context); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); - this.viewportHeight = prefs.getInt("viewport_height", 8000); + this.viewportHeight = prefs.getInt("viewport_height", DEFAULT_VIEWPORT_HEIGHT); boolean overview_mode = prefs.getBoolean("overview_mode", false); boolean safe_browsing = prefs.getBoolean("safe_browsing", false);