mirror of
https://github.com/null2264/yokai.git
synced 2025-06-21 10:44:42 +00:00
Use webpage's dark theme (if applicable) automatically if app is in dark mode
So far only mangadex is the one I know with good support but its here now
This commit is contained in:
parent
4892096f5e
commit
7207da8df4
2 changed files with 20 additions and 1 deletions
|
@ -102,6 +102,7 @@ dependencies {
|
|||
implementation("androidx.appcompat:appcompat:1.3.1")
|
||||
implementation("androidx.cardview:cardview:1.0.0")
|
||||
implementation("com.google.android.material:material:1.4.0")
|
||||
implementation("androidx.webkit:webkit:1.4.0")
|
||||
implementation("androidx.recyclerview:recyclerview:1.2.1")
|
||||
implementation("androidx.preference:preference:1.1.1")
|
||||
implementation("androidx.annotation:annotation:1.2.0")
|
||||
|
|
|
@ -16,6 +16,8 @@ import androidx.core.net.toUri
|
|||
import androidx.core.view.isInvisible
|
||||
import androidx.core.view.isVisible
|
||||
import androidx.core.view.updateLayoutParams
|
||||
import androidx.webkit.WebSettingsCompat.*
|
||||
import androidx.webkit.WebViewFeature
|
||||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.databinding.WebviewActivityBinding
|
||||
import eu.kanade.tachiyomi.ui.base.activity.BaseActivity
|
||||
|
@ -104,6 +106,7 @@ open class BaseWebViewActivity : BaseActivity<WebviewActivityBinding>() {
|
|||
insets
|
||||
}
|
||||
|
||||
setWebDarkMode()
|
||||
binding.swipeRefresh.isEnabled = false
|
||||
|
||||
if (bundle == null) {
|
||||
|
@ -134,6 +137,21 @@ open class BaseWebViewActivity : BaseActivity<WebviewActivityBinding>() {
|
|||
}
|
||||
}
|
||||
|
||||
private fun setWebDarkMode() {
|
||||
if (WebViewFeature.isFeatureSupported(WebViewFeature.FORCE_DARK_STRATEGY)) {
|
||||
setForceDarkStrategy(
|
||||
binding.webview.settings,
|
||||
DARK_STRATEGY_WEB_THEME_DARKENING_ONLY
|
||||
)
|
||||
if (WebViewFeature.isFeatureSupported(WebViewFeature.FORCE_DARK)) {
|
||||
setForceDark(
|
||||
binding.webview.settings,
|
||||
if (isInNightMode()) FORCE_DARK_ON else FORCE_DARK_OFF
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onProvideAssistContent(outContent: AssistContent?) {
|
||||
super.onProvideAssistContent(outContent)
|
||||
binding.webview.url?.let { outContent?.webUri = it.toUri() }
|
||||
|
@ -159,7 +177,7 @@ open class BaseWebViewActivity : BaseActivity<WebviewActivityBinding>() {
|
|||
getResourceColor(R.attr.colorSurface),
|
||||
255
|
||||
)
|
||||
binding.toolbar.setBackgroundColor(getResourceColor(R.attr.colorSecondary))
|
||||
setWebDarkMode()
|
||||
binding.toolbar.setBackgroundColor(getResourceColor(R.attr.colorSurface))
|
||||
binding.toolbar.popupTheme = if (lightMode) R.style.ThemeOverlay_MaterialComponents else R
|
||||
.style.ThemeOverlay_MaterialComponents_Dark
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue