|
@@ -1,72 +1,31 @@
|
|
|
package eu.kanade.tachiyomi.ui.webview
|
|
|
|
|
|
-import android.annotation.SuppressLint
|
|
|
import android.content.Context
|
|
|
import android.content.Intent
|
|
|
-import android.content.pm.ApplicationInfo
|
|
|
import android.graphics.Bitmap
|
|
|
import android.os.Bundle
|
|
|
import android.view.Menu
|
|
|
import android.view.MenuItem
|
|
|
-import android.webkit.WebChromeClient
|
|
|
import android.webkit.WebView
|
|
|
-import android.widget.Toast
|
|
|
import androidx.core.graphics.ColorUtils
|
|
|
-import androidx.core.view.isInvisible
|
|
|
-import androidx.core.view.isVisible
|
|
|
-import eu.kanade.tachiyomi.BuildConfig
|
|
|
import eu.kanade.tachiyomi.R
|
|
|
-import eu.kanade.tachiyomi.databinding.WebviewActivityBinding
|
|
|
import eu.kanade.tachiyomi.source.SourceManager
|
|
|
import eu.kanade.tachiyomi.source.online.HttpSource
|
|
|
-import eu.kanade.tachiyomi.ui.base.activity.BaseActivity
|
|
|
import eu.kanade.tachiyomi.util.system.WebViewClientCompat
|
|
|
import eu.kanade.tachiyomi.util.system.WebViewUtil
|
|
|
import eu.kanade.tachiyomi.util.system.getResourceColor
|
|
|
import eu.kanade.tachiyomi.util.system.openInBrowser
|
|
|
-import eu.kanade.tachiyomi.util.system.setDefaultSettings
|
|
|
import eu.kanade.tachiyomi.util.system.toast
|
|
|
-import kotlinx.coroutines.flow.launchIn
|
|
|
-import kotlinx.coroutines.flow.onEach
|
|
|
-import reactivecircus.flowbinding.appcompat.navigationClicks
|
|
|
-import reactivecircus.flowbinding.swiperefreshlayout.refreshes
|
|
|
import uy.kohesive.injekt.injectLazy
|
|
|
|
|
|
-class WebViewActivity : BaseActivity<WebviewActivityBinding>() {
|
|
|
+class WebViewActivity : BaseWebViewActivity() {
|
|
|
|
|
|
private val sourceManager by injectLazy<SourceManager>()
|
|
|
|
|
|
- private var bundle: Bundle? = null
|
|
|
-
|
|
|
- @SuppressLint("SetJavaScriptEnabled")
|
|
|
override fun onCreate(savedInstanceState: Bundle?) {
|
|
|
super.onCreate(savedInstanceState)
|
|
|
|
|
|
- if (!WebViewUtil.supportsWebView(this)) {
|
|
|
- toast(R.string.information_webview_required, Toast.LENGTH_LONG)
|
|
|
- finish()
|
|
|
- }
|
|
|
-
|
|
|
- try {
|
|
|
- binding = WebviewActivityBinding.inflate(layoutInflater)
|
|
|
- setContentView(binding.root)
|
|
|
- } catch (e: Exception) {
|
|
|
- // Potentially throws errors like "Error inflating class android.webkit.WebView"
|
|
|
- toast(R.string.information_webview_required, Toast.LENGTH_LONG)
|
|
|
- finish()
|
|
|
- }
|
|
|
-
|
|
|
title = intent.extras?.getString(TITLE_KEY)
|
|
|
- setSupportActionBar(binding.toolbar)
|
|
|
- supportActionBar?.setDisplayHomeAsUpEnabled(true)
|
|
|
- binding.toolbar.navigationClicks()
|
|
|
- .onEach { super.onBackPressed() }
|
|
|
- .launchIn(scope)
|
|
|
-
|
|
|
- binding.swipeRefresh.isEnabled = false
|
|
|
- binding.swipeRefresh.refreshes()
|
|
|
- .onEach { refreshPage() }
|
|
|
- .launchIn(scope)
|
|
|
|
|
|
if (bundle == null) {
|
|
|
val url = intent.extras!!.getString(URL_KEY) ?: return
|
|
@@ -79,26 +38,8 @@ class WebViewActivity : BaseActivity<WebviewActivityBinding>() {
|
|
|
}
|
|
|
headers["X-Requested-With"] = WebViewUtil.REQUESTED_WITH
|
|
|
|
|
|
- binding.webview.setDefaultSettings()
|
|
|
-
|
|
|
supportActionBar?.subtitle = url
|
|
|
|
|
|
- // Debug mode (chrome://inspect/#devices)
|
|
|
- if (BuildConfig.DEBUG && 0 != applicationInfo.flags and ApplicationInfo.FLAG_DEBUGGABLE) {
|
|
|
- WebView.setWebContentsDebuggingEnabled(true)
|
|
|
- }
|
|
|
-
|
|
|
- binding.webview.webChromeClient = object : WebChromeClient() {
|
|
|
- override fun onProgressChanged(view: WebView?, newProgress: Int) {
|
|
|
- binding.progressBar.isVisible = true
|
|
|
- binding.progressBar.progress = newProgress
|
|
|
- if (newProgress == 100) {
|
|
|
- binding.progressBar.isInvisible = true
|
|
|
- }
|
|
|
- super.onProgressChanged(view, newProgress)
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
binding.webview.webViewClient = object : WebViewClientCompat() {
|
|
|
override fun shouldOverrideUrlCompat(view: WebView, url: String): Boolean {
|
|
|
view.loadUrl(url, headers)
|
|
@@ -124,16 +65,9 @@ class WebViewActivity : BaseActivity<WebviewActivityBinding>() {
|
|
|
}
|
|
|
|
|
|
binding.webview.loadUrl(url, headers)
|
|
|
- } else {
|
|
|
- binding.webview.restoreState(bundle)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- override fun onDestroy() {
|
|
|
- binding.webview?.destroy()
|
|
|
- super.onDestroy()
|
|
|
- }
|
|
|
-
|
|
|
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
|
|
menuInflater.inflate(R.menu.webview, menu)
|
|
|
return true
|
|
@@ -153,11 +87,6 @@ class WebViewActivity : BaseActivity<WebviewActivityBinding>() {
|
|
|
return super.onPrepareOptionsMenu(menu)
|
|
|
}
|
|
|
|
|
|
- override fun onBackPressed() {
|
|
|
- if (binding.webview.canGoBack()) binding.webview.goBack()
|
|
|
- else super.onBackPressed()
|
|
|
- }
|
|
|
-
|
|
|
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
|
|
when (item.itemId) {
|
|
|
R.id.action_web_back -> binding.webview.goBack()
|
|
@@ -169,11 +98,6 @@ class WebViewActivity : BaseActivity<WebviewActivityBinding>() {
|
|
|
return super.onOptionsItemSelected(item)
|
|
|
}
|
|
|
|
|
|
- private fun refreshPage() {
|
|
|
- binding.swipeRefresh.isRefreshing = true
|
|
|
- binding.webview.reload()
|
|
|
- }
|
|
|
-
|
|
|
private fun shareWebpage() {
|
|
|
try {
|
|
|
val intent = Intent(Intent.ACTION_SEND).apply {
|