mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-12-23 20:31:51 +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.ui.base.activity.BaseActivity
|
||||||
import eu.kanade.tachiyomi.util.system.ThemeUtil
|
import eu.kanade.tachiyomi.util.system.ThemeUtil
|
||||||
import eu.kanade.tachiyomi.util.system.getResourceColor
|
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.isInNightMode
|
||||||
import eu.kanade.tachiyomi.util.system.setDefaultSettings
|
import eu.kanade.tachiyomi.util.system.setDefaultSettings
|
||||||
import eu.kanade.tachiyomi.util.view.invisible
|
import eu.kanade.tachiyomi.util.view.invisible
|
||||||
@ -88,12 +89,13 @@ open class BaseWebViewActivity : BaseActivity() {
|
|||||||
else getResourceColor(android.R.attr.colorPrimary)
|
else getResourceColor(android.R.attr.colorPrimary)
|
||||||
}
|
}
|
||||||
// if the android q+ device has gesture nav, transparent nav bar
|
// if the android q+ device has gesture nav, transparent nav bar
|
||||||
else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q &&
|
else if (v.rootWindowInsets.isBottomTappable()) {
|
||||||
(v.rootWindowInsets.systemWindowInsetBottom != v.rootWindowInsets.tappableElementInsets.bottom)
|
|
||||||
) {
|
|
||||||
getColor(android.R.color.transparent)
|
getColor(android.R.color.transparent)
|
||||||
} else {
|
} else {
|
||||||
getResourceColor(android.R.attr.colorBackground)
|
ColorUtils.setAlphaComponent(
|
||||||
|
getResourceColor(R.attr.colorPrimaryVariant),
|
||||||
|
179
|
||||||
|
)
|
||||||
}
|
}
|
||||||
v.setPadding(
|
v.setPadding(
|
||||||
insets.systemWindowInsetLeft,
|
insets.systemWindowInsetLeft,
|
||||||
@ -123,9 +125,7 @@ open class BaseWebViewActivity : BaseActivity() {
|
|||||||
}
|
}
|
||||||
val marginB = webview.marginBottom
|
val marginB = webview.marginBottom
|
||||||
webview.setOnApplyWindowInsetsListener { v, insets ->
|
webview.setOnApplyWindowInsetsListener { v, insets ->
|
||||||
val bottomInset =
|
val bottomInset = insets.systemWindowInsetBottom
|
||||||
if (Build.VERSION.SDK_INT >= 29) insets.tappableElementInsets.bottom
|
|
||||||
else insets.systemWindowInsetBottom
|
|
||||||
v.updateLayoutParams<ViewGroup.MarginLayoutParams> {
|
v.updateLayoutParams<ViewGroup.MarginLayoutParams> {
|
||||||
bottomMargin = marginB + bottomInset
|
bottomMargin = marginB + bottomInset
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ import android.content.Context
|
|||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.content.res.Configuration
|
import android.content.res.Configuration
|
||||||
import android.graphics.Bitmap
|
import android.graphics.Bitmap
|
||||||
|
import android.graphics.Color
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.view.Menu
|
import android.view.Menu
|
||||||
import android.view.MenuItem
|
import android.view.MenuItem
|
||||||
@ -11,6 +12,7 @@ import android.view.View
|
|||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import android.webkit.WebView
|
import android.webkit.WebView
|
||||||
import android.widget.LinearLayout
|
import android.widget.LinearLayout
|
||||||
|
import androidx.annotation.ColorInt
|
||||||
import androidx.core.graphics.ColorUtils
|
import androidx.core.graphics.ColorUtils
|
||||||
import eu.kanade.tachiyomi.R
|
import eu.kanade.tachiyomi.R
|
||||||
import eu.kanade.tachiyomi.source.SourceManager
|
import eu.kanade.tachiyomi.source.SourceManager
|
||||||
@ -69,6 +71,9 @@ open class WebViewActivity : BaseWebViewActivity() {
|
|||||||
title = view?.title
|
title = view?.title
|
||||||
swipe_refresh.isEnabled = true
|
swipe_refresh.isEnabled = true
|
||||||
swipe_refresh?.isRefreshing = false
|
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?) {
|
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) {
|
override fun onConfigurationChanged(newConfig: Configuration) {
|
||||||
super.onConfigurationChanged(newConfig)
|
super.onConfigurationChanged(newConfig)
|
||||||
invalidateOptionsMenu()
|
invalidateOptionsMenu()
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
android:id="@+id/web_linear_layout"
|
android:id="@+id/web_linear_layout"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
android:fitsSystemWindows="true"
|
||||||
android:layout_height="wrap_content">
|
android:layout_height="wrap_content">
|
||||||
|
|
||||||
<androidx.appcompat.widget.Toolbar
|
<androidx.appcompat.widget.Toolbar
|
||||||
@ -22,7 +23,7 @@
|
|||||||
android:background="?attr/colorSecondary"
|
android:background="?attr/colorSecondary"
|
||||||
android:theme="?attr/actionBarTheme"
|
android:theme="?attr/actionBarTheme"
|
||||||
app:navigationIcon="@drawable/ic_close_24dp"
|
app:navigationIcon="@drawable/ic_close_24dp"
|
||||||
app:layout_scrollFlags="scroll|enterAlways|snap" />
|
app:layout_scrollFlags="scroll|enterAlways" />
|
||||||
|
|
||||||
</com.google.android.material.appbar.AppBarLayout>
|
</com.google.android.material.appbar.AppBarLayout>
|
||||||
|
|
||||||
@ -38,8 +39,9 @@
|
|||||||
android:layout_height="match_parent">
|
android:layout_height="match_parent">
|
||||||
<WebView
|
<WebView
|
||||||
android:id="@+id/webview"
|
android:id="@+id/webview"
|
||||||
|
android:nestedScrollingEnabled="true"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent" >
|
android:layout_height="wrap_content" >
|
||||||
|
|
||||||
<ProgressBar
|
<ProgressBar
|
||||||
android:id="@+id/progressBar"
|
android:id="@+id/progressBar"
|
||||||
|
Loading…
Reference in New Issue
Block a user