mirror of
https://github.com/mihonapp/mihon.git
synced 2025-11-15 13:37:29 +01:00
[CI SKIP] More consistent "WebView" wording
This commit is contained in:
@@ -4,30 +4,30 @@ import android.content.Context
|
||||
import android.content.pm.PackageManager
|
||||
import android.webkit.WebView
|
||||
|
||||
object WebviewUtil {
|
||||
object WebViewUtil {
|
||||
val WEBVIEW_UA_VERSION_REGEX by lazy {
|
||||
Regex(""".*Chrome/(\d+)\..*""")
|
||||
}
|
||||
|
||||
const val MINIMUM_WEBVIEW_VERSION = 79
|
||||
|
||||
fun supportsWebview(context: Context): Boolean {
|
||||
fun supportsWebView(context: Context): Boolean {
|
||||
return context.packageManager.hasSystemFeature(PackageManager.FEATURE_WEBVIEW)
|
||||
}
|
||||
}
|
||||
|
||||
fun WebView.isOutdated(): Boolean {
|
||||
return getWebviewMajorVersion(this) < WebviewUtil.MINIMUM_WEBVIEW_VERSION
|
||||
return getWebViewMajorVersion(this) < WebViewUtil.MINIMUM_WEBVIEW_VERSION
|
||||
}
|
||||
|
||||
// Based on https://stackoverflow.com/a/29218966
|
||||
private fun getWebviewMajorVersion(webview: WebView): Int {
|
||||
private fun getWebViewMajorVersion(webview: WebView): Int {
|
||||
val originalUA: String = webview.settings.userAgentString
|
||||
|
||||
// Next call to getUserAgentString() will get us the default
|
||||
webview.settings.userAgentString = null
|
||||
|
||||
val uaRegexMatch = WebviewUtil.WEBVIEW_UA_VERSION_REGEX.matchEntire(webview.settings.userAgentString)
|
||||
val uaRegexMatch = WebViewUtil.WEBVIEW_UA_VERSION_REGEX.matchEntire(webview.settings.userAgentString)
|
||||
val webViewVersion: Int = if (uaRegexMatch != null && uaRegexMatch.groupValues.size > 1) {
|
||||
uaRegexMatch.groupValues[1].toInt()
|
||||
} else {
|
||||
Reference in New Issue
Block a user