Viewport height default

This commit is contained in:
M66B 2023-08-19 15:31:43 +02:00
parent c9b0d0ae4a
commit e8be216da2
2 changed files with 13 additions and 3 deletions

View File

@ -1632,6 +1632,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
} }
}); });
etViewportHeight.setHint(Integer.toString(WebViewEx.DEFAULT_VIEWPORT_HEIGHT));
etViewportHeight.addTextChangedListener(new TextWatcher() { etViewportHeight.addTextChangedListener(new TextWatcher() {
@Override @Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) { public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
@ -1646,7 +1647,11 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
@Override @Override
public void afterTextChanged(Editable edit) { public void afterTextChanged(Editable edit) {
try { 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) { } catch (Throwable ex) {
Log.e(ex); Log.e(ex);
} }
@ -2597,7 +2602,11 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
swUndoManager.setChecked(prefs.getBoolean("undo_manager", false)); swUndoManager.setChecked(prefs.getBoolean("undo_manager", false));
swBrowserZoom.setChecked(prefs.getBoolean("browser_zoom", false)); swBrowserZoom.setChecked(prefs.getBoolean("browser_zoom", false));
swFakeDark.setChecked(prefs.getBoolean("fake_dark", 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)); swShowRecent.setChecked(prefs.getBoolean("show_recent", false));
swModSeq.setChecked(prefs.getBoolean("use_modseq", true)); swModSeq.setChecked(prefs.getBoolean("use_modseq", true));
swPreamble.setChecked(prefs.getBoolean("preamble", false)); swPreamble.setChecked(prefs.getBoolean("preamble", false));

View File

@ -56,13 +56,14 @@ public class WebViewEx extends WebView implements DownloadListener, View.OnLongC
private static String userAgent = null; private static String userAgent = null;
static final int DEFAULT_VIEWPORT_HEIGHT = 8000;
private static final long PAGE_LOADED_FALLBACK_DELAY = 1500L; // milliseconds private static final long PAGE_LOADED_FALLBACK_DELAY = 1500L; // milliseconds
public WebViewEx(Context context) { public WebViewEx(Context context) {
super(context); super(context);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(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 overview_mode = prefs.getBoolean("overview_mode", false);
boolean safe_browsing = prefs.getBoolean("safe_browsing", false); boolean safe_browsing = prefs.getBoolean("safe_browsing", false);