|
|
|
@ -14,7 +14,9 @@ import androidx.activity.viewModels |
|
|
|
|
import androidx.core.view.size |
|
|
|
|
import io.legado.app.R |
|
|
|
|
import io.legado.app.base.VMBaseActivity |
|
|
|
|
import io.legado.app.constant.AppConst |
|
|
|
|
import io.legado.app.databinding.ActivityRssReadBinding |
|
|
|
|
import io.legado.app.help.AppConfig |
|
|
|
|
import io.legado.app.lib.theme.DrawableUtils |
|
|
|
|
import io.legado.app.lib.theme.primaryTextColor |
|
|
|
|
import io.legado.app.service.help.Download |
|
|
|
@ -94,79 +96,17 @@ class ReadRssActivity : VMBaseActivity<ActivityRssReadBinding, ReadRssViewModel> |
|
|
|
|
return super.onCompatOptionsItemSelected(item) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@SuppressLint("SetJavaScriptEnabled") |
|
|
|
|
private fun initWebView() { |
|
|
|
|
binding.webView.webChromeClient = object : WebChromeClient() { |
|
|
|
|
override fun onShowCustomView(view: View?, callback: CustomViewCallback?) { |
|
|
|
|
requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_SENSOR |
|
|
|
|
binding.llView.invisible() |
|
|
|
|
binding.customWebView.addView(view) |
|
|
|
|
customWebViewCallback = callback |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override fun onHideCustomView() { |
|
|
|
|
binding.customWebView.removeAllViews() |
|
|
|
|
binding.llView.visible() |
|
|
|
|
requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
binding.webView.webViewClient = object : WebViewClient() { |
|
|
|
|
override fun shouldOverrideUrlLoading( |
|
|
|
|
view: WebView?, |
|
|
|
|
request: WebResourceRequest? |
|
|
|
|
): Boolean { |
|
|
|
|
request?.let { |
|
|
|
|
if (it.url.scheme == "http" || it.url.scheme == "https") { |
|
|
|
|
return false |
|
|
|
|
} else if (it.url.scheme == "yuedu") { |
|
|
|
|
when (it.url.host) { |
|
|
|
|
"booksource" -> { |
|
|
|
|
val intent = Intent( |
|
|
|
|
this@ReadRssActivity, |
|
|
|
|
ImportBookSourceActivity::class.java |
|
|
|
|
) |
|
|
|
|
intent.data = it.url |
|
|
|
|
startActivity(intent) |
|
|
|
|
} |
|
|
|
|
"rsssource" -> { |
|
|
|
|
val intent = Intent( |
|
|
|
|
this@ReadRssActivity, |
|
|
|
|
ImportRssSourceActivity::class.java |
|
|
|
|
) |
|
|
|
|
intent.data = it.url |
|
|
|
|
startActivity(intent) |
|
|
|
|
} |
|
|
|
|
"replace" -> { |
|
|
|
|
val intent = Intent( |
|
|
|
|
this@ReadRssActivity, |
|
|
|
|
ImportReplaceRuleActivity::class.java |
|
|
|
|
) |
|
|
|
|
intent.data = it.url |
|
|
|
|
startActivity(intent) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return true |
|
|
|
|
} |
|
|
|
|
openUrl(it.url) |
|
|
|
|
} |
|
|
|
|
return true |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Suppress("DEPRECATION") |
|
|
|
|
override fun shouldOverrideUrlLoading(view: WebView?, url: String?): Boolean { |
|
|
|
|
if (url?.startsWith("http", true) == true) { |
|
|
|
|
return false |
|
|
|
|
} |
|
|
|
|
url?.let { |
|
|
|
|
openUrl(it) |
|
|
|
|
} |
|
|
|
|
return true |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
binding.webView.webChromeClient = RssWebChromeClient() |
|
|
|
|
binding.webView.webViewClient = RssWebViewClient() |
|
|
|
|
binding.webView.settings.apply { |
|
|
|
|
mixedContentMode = WebSettings.MIXED_CONTENT_ALWAYS_ALLOW |
|
|
|
|
domStorageEnabled = true |
|
|
|
|
allowContentAccess = true |
|
|
|
|
//javaScriptEnabled = true |
|
|
|
|
} |
|
|
|
|
upWebViewTheme() |
|
|
|
|
binding.webView.setOnLongClickListener { |
|
|
|
|
val hitTestResult = binding.webView.hitTestResult |
|
|
|
|
if (hitTestResult.type == WebView.HitTestResult.IMAGE_TYPE || |
|
|
|
@ -207,6 +147,7 @@ class ReadRssActivity : VMBaseActivity<ActivityRssReadBinding, ReadRssViewModel> |
|
|
|
|
Download.start(this, downloadId, fileName) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private fun saveImage() { |
|
|
|
@ -254,6 +195,13 @@ class ReadRssActivity : VMBaseActivity<ActivityRssReadBinding, ReadRssViewModel> |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private fun upWebViewTheme() { |
|
|
|
|
if (AppConfig.isNightTheme) { |
|
|
|
|
binding.webView |
|
|
|
|
.evaluateJavascript(AppConst.darkWebViewJs, null) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override fun upStarMenu() { |
|
|
|
|
if (viewModel.rssStar != null) { |
|
|
|
|
starMenuItem?.setIcon(R.drawable.ic_star) |
|
|
|
@ -336,4 +284,78 @@ class ReadRssActivity : VMBaseActivity<ActivityRssReadBinding, ReadRssViewModel> |
|
|
|
|
binding.webView.destroy() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
inner class RssWebChromeClient : WebChromeClient() { |
|
|
|
|
override fun onShowCustomView(view: View?, callback: CustomViewCallback?) { |
|
|
|
|
requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_SENSOR |
|
|
|
|
binding.llView.invisible() |
|
|
|
|
binding.customWebView.addView(view) |
|
|
|
|
customWebViewCallback = callback |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override fun onHideCustomView() { |
|
|
|
|
binding.customWebView.removeAllViews() |
|
|
|
|
binding.llView.visible() |
|
|
|
|
requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
inner class RssWebViewClient : WebViewClient() { |
|
|
|
|
override fun shouldOverrideUrlLoading( |
|
|
|
|
view: WebView?, |
|
|
|
|
request: WebResourceRequest? |
|
|
|
|
): Boolean { |
|
|
|
|
request?.let { |
|
|
|
|
if (it.url.scheme == "http" || it.url.scheme == "https") { |
|
|
|
|
return false |
|
|
|
|
} else if (it.url.scheme == "yuedu") { |
|
|
|
|
when (it.url.host) { |
|
|
|
|
"booksource" -> { |
|
|
|
|
val intent = Intent( |
|
|
|
|
this@ReadRssActivity, |
|
|
|
|
ImportBookSourceActivity::class.java |
|
|
|
|
) |
|
|
|
|
intent.data = it.url |
|
|
|
|
startActivity(intent) |
|
|
|
|
} |
|
|
|
|
"rsssource" -> { |
|
|
|
|
val intent = Intent( |
|
|
|
|
this@ReadRssActivity, |
|
|
|
|
ImportRssSourceActivity::class.java |
|
|
|
|
) |
|
|
|
|
intent.data = it.url |
|
|
|
|
startActivity(intent) |
|
|
|
|
} |
|
|
|
|
"replace" -> { |
|
|
|
|
val intent = Intent( |
|
|
|
|
this@ReadRssActivity, |
|
|
|
|
ImportReplaceRuleActivity::class.java |
|
|
|
|
) |
|
|
|
|
intent.data = it.url |
|
|
|
|
startActivity(intent) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return true |
|
|
|
|
} |
|
|
|
|
openUrl(it.url) |
|
|
|
|
} |
|
|
|
|
return true |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Suppress("DEPRECATION") |
|
|
|
|
override fun shouldOverrideUrlLoading(view: WebView?, url: String?): Boolean { |
|
|
|
|
if (url?.startsWith("http", true) == true) { |
|
|
|
|
return false |
|
|
|
|
} |
|
|
|
|
url?.let { |
|
|
|
|
openUrl(it) |
|
|
|
|
} |
|
|
|
|
return true |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override fun onPageFinished(view: WebView?, url: String?) { |
|
|
|
|
super.onPageFinished(view, url) |
|
|
|
|
upWebViewTheme() |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|