diff --git a/app/build.gradle b/app/build.gradle index 593c03a..2832706 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -7,8 +7,8 @@ android { applicationId "landau.sweb" minSdkVersion 21 targetSdkVersion 26 - versionCode 3 - versionName "1.2" + versionCode 4 + versionName "1.3" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } buildTypes { diff --git a/app/src/main/java/landau/sweb/MainActivity.java b/app/src/main/java/landau/sweb/MainActivity.java index 7858814..7d6398d 100644 --- a/app/src/main/java/landau/sweb/MainActivity.java +++ b/app/src/main/java/landau/sweb/MainActivity.java @@ -24,6 +24,7 @@ import android.graphics.Bitmap; import android.graphics.Color; import android.graphics.drawable.Drawable; +import android.graphics.drawable.DrawableContainer; import android.net.Uri; import android.net.http.SslCertificate; import android.net.http.SslError; @@ -118,7 +119,7 @@ private static class Tab { static final String searchUrl = "https://www.google.com/search?q=%s"; static final String searchCompleteUrl = "https://www.google.com/complete/search?client=firefox&q=%s"; - static final String desktopUA = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.167 Safari/537.36"; + static final String desktopUA = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.163 Safari/537.36"; static final String[] adblockRulesList = { "https://easylist.to/easylist/easylist.txt", @@ -337,6 +338,8 @@ public void onPageStarted(WebView view, String url, Bitmap favicon) { progressBar.setVisibility(View.VISIBLE); if (view == getCurrentWebView()) { et.setText(url); + et.setSelection(0); + view.requestFocus(); } injectCSS(view); } @@ -346,7 +349,10 @@ public void onPageFinished(WebView view, String url) { if (view == getCurrentWebView()) { // Don't use the argument url here since navigation to that URL might have been // cancelled due to SSL error - et.setText(view.getUrl()); + if (et.getSelectionStart() == 0 && et.getSelectionEnd() == 0 && et.getText().toString().equals(view.getUrl())) { + // If user haven't started typing anything, focus on webview + view.requestFocus(); + } } injectCSS(view); } @@ -647,7 +653,8 @@ public void uncaughtException(Thread t, Throwable e) { // setup edit text et.setSelected(false); - et.setText(getUrlFromIntent(getIntent())); + String initialUrl = getUrlFromIntent(getIntent()); + et.setText(initialUrl.isEmpty() ? "about:blank" : initialUrl); et.setAdapter(new SearchAutocompleteAdapter(this, text -> { et.setText(text); et.setSelection(text.length()); @@ -1353,13 +1360,27 @@ private void injectCSS(WebView webview) { final String styleElementId = "night_mode_style_4398357"; // should be unique String js; if (isNightMode) { - js = "if (document.head && !document.getElementById('" + styleElementId + "')) {" + - " var style = document.createElement('style');" + + js = "if (document.head) {" + + "if (!window.night_mode_id_list) night_mode_id_list = new Set();" + + "var newset = new Set();" + + " for (var n of document.querySelectorAll(':not(a)')) { " + + " if (!n.id) n.id = 'night_mode_id_' + (night_mode_id_list.size + newset.size);" + + " if (!night_mode_id_list.has(n.id)) newset.add(n.id); " + + " }" + + "for (var item of newset) night_mode_id_list.add(item);" + + "var style = document.getElementById('" + styleElementId + "');" + + "if (!style) {" + + " style = document.createElement('style');" + " style.id = '" + styleElementId + "';" + " style.type = 'text/css';" + " style.innerHTML = '" + css + "';" + " document.head.appendChild(style);" + "}" + + " var css2 = ' ';" + + " for (var nid of newset) css2 += ('#' + nid + '#' + nid + ',');" + + " css2 += '#nonexistent {background-color: #161a1e !important; color: #61615f !important; border-color: #212a32 !important; background-image:none !important; outline-color: #161a1e !important; z-index: 1 !important}';" + + " style.innerHTML += css2;" + + "}" + "var iframes = document.getElementsByTagName('iframe');" + "for (var i = 0; i < iframes.length; i++) {" + " var fr = iframes[i];" + @@ -1373,6 +1394,7 @@ private void injectCSS(WebView webview) { js = "if (document.head && document.getElementById('" + styleElementId + "')) {" + " var style = document.getElementById('" + styleElementId + "');" + " document.head.removeChild(style);" + + " window.night_mode_id_list = undefined;" + "}" + "var iframes = document.getElementsByTagName('iframe');" + "for (var i = 0; i < iframes.length; i++) {" + @@ -1611,6 +1633,7 @@ public long getItemId(int position) { return position; } + @SuppressLint("ClickableViewAccessibility") @Override @SuppressWarnings("ConstantConditions") public View getView(final int position, View convertView, ViewGroup parent) { @@ -1636,6 +1659,13 @@ public View getView(final int position, View convertView, ViewGroup parent) { } return false; }); + //noinspection AndroidLintClickableViewAccessibility + parent.setOnTouchListener((dropdown, event) -> { + if (event.getX() > dropdown.getWidth() - size * 2) { + return true; + } + return false; + }); return convertView; } diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 5e7a902..84fe0c1 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -18,6 +18,8 @@ android:inputType="textUri" android:paddingBottom="10dp" android:paddingTop="10dp" + android:paddingLeft="10dp" + android:paddingRight="10dp" android:selectAllOnFocus="true" android:singleLine="true" />