Prevent crash on devices with bad webview
This commit is contained in:
5 files changed
+37
No files matched your search
@@ -93,6 +93,7 @@ dependencies {
|
||||
implementation "androidx.fragment:fragment:1.3.0-rc01"
|
||||
implementation "androidx.preference:preference:1.1.1"
|
||||
implementation "androidx.recyclerview:recyclerview:1.2.0-beta01"
|
||||
implementation 'androidx.webkit:webkit:1.4.0'
|
||||
implementation 'com.google.android.material:material:1.3.0-beta01'
|
||||
implementation 'com.getkeepsafe.relinker:relinker:1.4.1'
|
||||
implementation 'com.getkeepsafe.taptargetview:taptargetview:1.13.0'
|
||||
|
||||
@@ -28,6 +28,7 @@ import com.hippo.ehviewer.client.EhCookieStore;
|
||||
import com.hippo.ehviewer.client.EhUrl;
|
||||
import com.hippo.ehviewer.ui.SettingsActivity;
|
||||
import com.hippo.ehviewer.ui.scene.BaseScene;
|
||||
import com.hippo.util.WebViewUtil;
|
||||
|
||||
import okhttp3.HttpUrl;
|
||||
|
||||
@@ -58,6 +59,10 @@ public class SignInRequiredPreference extends Preference implements Preference.O
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
if (!WebViewUtil.available(getContext())) {
|
||||
mActivity.showTip(R.string.error_no_webview, BaseScene.LENGTH_SHORT);
|
||||
return true;
|
||||
}
|
||||
EhCookieStore store = EhApplication.getEhCookieStore(getContext());
|
||||
HttpUrl e = HttpUrl.get(EhUrl.HOST_E);
|
||||
HttpUrl ex = HttpUrl.get(EhUrl.HOST_EX);
|
||||
|
||||
@@ -45,6 +45,7 @@ import com.hippo.ehviewer.ui.MainActivity;
|
||||
import com.hippo.scene.Announcer;
|
||||
import com.hippo.scene.SceneFragment;
|
||||
import com.hippo.util.ExceptionUtils;
|
||||
import com.hippo.util.WebViewUtil;
|
||||
import com.hippo.yorozuya.AssertUtils;
|
||||
import com.hippo.yorozuya.IntIdGenerator;
|
||||
import com.hippo.yorozuya.ViewUtils;
|
||||
@@ -225,6 +226,10 @@ public final class SignInScene extends SolidScene implements EditText.OnEditorAc
|
||||
} else if (mSignIn == v) {
|
||||
signIn();
|
||||
} else if (mSignInViaWebView == v) {
|
||||
if (!WebViewUtil.available(getContext())) {
|
||||
showTip(R.string.error_no_webview, BaseScene.LENGTH_SHORT);
|
||||
return;
|
||||
}
|
||||
startScene(new Announcer(WebViewSignInScene.class).setRequestCode(this, REQUEST_CODE_WEBVIEW));
|
||||
} else if (mSignInViaCookies == v) {
|
||||
startScene(new Announcer(CookieSignInScene.class).setRequestCode(this, REQUEST_CODE_COOKIE));
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.hippo.util;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.os.Build;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.webkit.WebViewCompat;
|
||||
|
||||
public class WebViewUtil {
|
||||
private static final String TAG = "WebViewUtil";
|
||||
|
||||
public static boolean available(Context context) {
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
|
||||
return false;
|
||||
}
|
||||
PackageInfo webViewPackageInfo = WebViewCompat.getCurrentWebViewPackage(context);
|
||||
if (webViewPackageInfo == null) {
|
||||
Log.d(TAG, "WebView not available");
|
||||
return false;
|
||||
}
|
||||
Log.d(TAG, "WebView version: " + webViewPackageInfo.versionName);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -809,4 +809,5 @@
|
||||
<string name="settings_advanced_clear_memory_cache_done">Memory cache cleaning completed</string>
|
||||
<string name="action_add_tag">Add tag</string>
|
||||
<string name="action_add_tag_tip">Enter new tags, separated with comma</string>
|
||||
<string name="error_no_webview">WebView is not available.</string>
|
||||
</resources>
|
||||
Reference in new issue
Block a user