mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-11-09 20:15:05 +01:00
Fix WebView's infinite expansion
This commit is contained in:
parent
b4d97516a2
commit
0b432ae87f
@ -15,6 +15,7 @@ import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.ui.base.activity.BaseActivity
|
||||
import eu.kanade.tachiyomi.util.system.ThemeUtil
|
||||
import eu.kanade.tachiyomi.util.system.getResourceColor
|
||||
import eu.kanade.tachiyomi.util.system.isBottomTappable
|
||||
import eu.kanade.tachiyomi.util.system.isInNightMode
|
||||
import eu.kanade.tachiyomi.util.system.setDefaultSettings
|
||||
import eu.kanade.tachiyomi.util.view.invisible
|
||||
@ -88,12 +89,13 @@ open class BaseWebViewActivity : BaseActivity() {
|
||||
else getResourceColor(android.R.attr.colorPrimary)
|
||||
}
|
||||
// if the android q+ device has gesture nav, transparent nav bar
|
||||
else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q &&
|
||||
(v.rootWindowInsets.systemWindowInsetBottom != v.rootWindowInsets.tappableElementInsets.bottom)
|
||||
) {
|
||||
else if (v.rootWindowInsets.isBottomTappable()) {
|
||||
getColor(android.R.color.transparent)
|
||||
} else {
|
||||
getResourceColor(android.R.attr.colorBackground)
|
||||
ColorUtils.setAlphaComponent(
|
||||
getResourceColor(R.attr.colorPrimaryVariant),
|
||||
179
|
||||
)
|
||||
}
|
||||
v.setPadding(
|
||||
insets.systemWindowInsetLeft,
|
||||
@ -123,9 +125,7 @@ open class BaseWebViewActivity : BaseActivity() {
|
||||
}
|
||||
val marginB = webview.marginBottom
|
||||
webview.setOnApplyWindowInsetsListener { v, insets ->
|
||||
val bottomInset =
|
||||
if (Build.VERSION.SDK_INT >= 29) insets.tappableElementInsets.bottom
|
||||
else insets.systemWindowInsetBottom
|
||||
val bottomInset = insets.systemWindowInsetBottom
|
||||
v.updateLayoutParams<ViewGroup.MarginLayoutParams> {
|
||||
bottomMargin = marginB + bottomInset
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.res.Configuration
|
||||
import android.graphics.Bitmap
|
||||
import android.graphics.Color
|
||||
import android.os.Bundle
|
||||
import android.view.Menu
|
||||
import android.view.MenuItem
|
||||
@ -11,6 +12,7 @@ import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.webkit.WebView
|
||||
import android.widget.LinearLayout
|
||||
import androidx.annotation.ColorInt
|
||||
import androidx.core.graphics.ColorUtils
|
||||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.source.SourceManager
|
||||
@ -69,6 +71,9 @@ open class WebViewActivity : BaseWebViewActivity() {
|
||||
title = view?.title
|
||||
swipe_refresh.isEnabled = true
|
||||
swipe_refresh?.isRefreshing = false
|
||||
val thing = view?.evaluateJavascript("getComputedStyle(document.querySelector('body')).backgroundColor") {
|
||||
nested_view.setBackgroundColor(parseHTMLColor(it))
|
||||
}
|
||||
}
|
||||
|
||||
override fun onPageStarted(view: WebView?, url: String?, favicon: Bitmap?) {
|
||||
@ -87,6 +92,16 @@ open class WebViewActivity : BaseWebViewActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
@ColorInt
|
||||
fun parseHTMLColor(color: String): Int {
|
||||
val trimmedColor = color.trim('"')
|
||||
val rgb = Regex("""^rgb\((\d+),\s*(\d+),\s*(\d+)\)$""").find(trimmedColor)
|
||||
val red = rgb?.groupValues?.getOrNull(1)?.toIntOrNull() ?: return getResourceColor(android.R.attr.colorBackground)
|
||||
val green = rgb.groupValues.getOrNull(2)?.toIntOrNull() ?: return getResourceColor(android.R.attr.colorBackground)
|
||||
val blue = rgb.groupValues.getOrNull(3)?.toIntOrNull() ?: return getResourceColor(android.R.attr.colorBackground)
|
||||
return Color.rgb(red, green, blue)
|
||||
}
|
||||
|
||||
override fun onConfigurationChanged(newConfig: Configuration) {
|
||||
super.onConfigurationChanged(newConfig)
|
||||
invalidateOptionsMenu()
|
||||
|
@ -13,6 +13,7 @@
|
||||
android:orientation="vertical"
|
||||
android:id="@+id/web_linear_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:fitsSystemWindows="true"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<androidx.appcompat.widget.Toolbar
|
||||
@ -22,7 +23,7 @@
|
||||
android:background="?attr/colorSecondary"
|
||||
android:theme="?attr/actionBarTheme"
|
||||
app:navigationIcon="@drawable/ic_close_24dp"
|
||||
app:layout_scrollFlags="scroll|enterAlways|snap" />
|
||||
app:layout_scrollFlags="scroll|enterAlways" />
|
||||
|
||||
</com.google.android.material.appbar.AppBarLayout>
|
||||
|
||||
@ -38,8 +39,9 @@
|
||||
android:layout_height="match_parent">
|
||||
<WebView
|
||||
android:id="@+id/webview"
|
||||
android:nestedScrollingEnabled="true"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" >
|
||||
android:layout_height="wrap_content" >
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/progressBar"
|
||||
|
Loading…
Reference in New Issue
Block a user