* 订阅界面webView支持css prefers-color-scheme: dark 查询,需webView v76或更高版本

* 如webView低于v76可以用js调用activity.isNightTheme()来获取当前是否暗模式
pull/1090/head 3.21.062820
gedoor 3 years ago
parent 3e033e0d27
commit 029be1d6a8
  1. 1
      app/build.gradle
  2. 2
      app/src/main/assets/updateLog.md
  3. 25
      app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt

@ -136,6 +136,7 @@ dependencies {
implementation 'com.google.android.material:material:1.3.0' implementation 'com.google.android.material:material:1.3.0'
implementation 'com.google.android:flexbox:1.1.0' implementation 'com.google.android:flexbox:1.1.0'
implementation 'com.google.code.gson:gson:2.8.6' implementation 'com.google.code.gson:gson:2.8.6'
implementation 'androidx.webkit:webkit:1.4.0'
//media //media
def media2_version = "1.1.3" def media2_version = "1.1.3"

@ -9,6 +9,8 @@
* 漫画源看书显示乱码,**阅读与其他软件的源并不通用**,请导入阅读的支持的漫画源! * 漫画源看书显示乱码,**阅读与其他软件的源并不通用**,请导入阅读的支持的漫画源!
**2021/06/26** **2021/06/26**
* 订阅界面webView支持css prefers-color-scheme: dark 查询,需webView v76或更高版本
* 如webView低于v76可以用js调用activity.isNightTheme()来获取当前是否暗模式
* 修复一些书籍导出epub失败 by ag2s20150909 * 修复一些书籍导出epub失败 by ag2s20150909
**2021/06/22** **2021/06/22**

@ -12,6 +12,8 @@ import android.view.*
import android.webkit.* import android.webkit.*
import androidx.activity.viewModels import androidx.activity.viewModels
import androidx.core.view.size import androidx.core.view.size
import androidx.webkit.WebSettingsCompat
import androidx.webkit.WebViewFeature
import io.legado.app.R import io.legado.app.R
import io.legado.app.base.VMBaseActivity import io.legado.app.base.VMBaseActivity
import io.legado.app.constant.AppConst import io.legado.app.constant.AppConst
@ -95,6 +97,11 @@ class ReadRssActivity : VMBaseActivity<ActivityRssReadBinding, ReadRssViewModel>
return super.onCompatOptionsItemSelected(item) return super.onCompatOptionsItemSelected(item)
} }
@JavascriptInterface
fun isNightTheme(): Boolean {
return AppConfig.isNightTheme(this)
}
@SuppressLint("SetJavaScriptEnabled") @SuppressLint("SetJavaScriptEnabled")
private fun initWebView() { private fun initWebView() {
binding.webView.webChromeClient = RssWebChromeClient() binding.webView.webChromeClient = RssWebChromeClient()
@ -105,6 +112,7 @@ class ReadRssActivity : VMBaseActivity<ActivityRssReadBinding, ReadRssViewModel>
allowContentAccess = true allowContentAccess = true
//javaScriptEnabled = true //javaScriptEnabled = true
} }
binding.webView.addJavascriptInterface(this, "app")
upWebViewTheme() upWebViewTheme()
binding.webView.setOnLongClickListener { binding.webView.setOnLongClickListener {
val hitTestResult = binding.webView.hitTestResult val hitTestResult = binding.webView.hitTestResult
@ -193,8 +201,21 @@ class ReadRssActivity : VMBaseActivity<ActivityRssReadBinding, ReadRssViewModel>
private fun upWebViewTheme() { private fun upWebViewTheme() {
if (AppConfig.isNightTheme) { if (AppConfig.isNightTheme) {
binding.webView if (WebViewFeature.isFeatureSupported(WebViewFeature.FORCE_DARK_STRATEGY)) {
.evaluateJavascript(AppConst.darkWebViewJs, null) WebSettingsCompat.setForceDarkStrategy(
binding.webView.settings,
WebSettingsCompat.DARK_STRATEGY_PREFER_WEB_THEME_OVER_USER_AGENT_DARKENING
)
}
if (WebViewFeature.isFeatureSupported(WebViewFeature.FORCE_DARK)) {
WebSettingsCompat.setForceDark(
binding.webView.settings,
WebSettingsCompat.FORCE_DARK_ON
)
} else {
binding.webView
.evaluateJavascript(AppConst.darkWebViewJs, null)
}
} }
} }

Loading…
Cancel
Save