优化webViewActivity

pull/1395/head
gedoor 3 years ago
parent dd49db3579
commit f0cb003f20
  1. 34
      app/src/main/java/io/legado/app/ui/web/WebViewActivity.kt

@ -4,11 +4,13 @@ import android.annotation.SuppressLint
import android.content.pm.ActivityInfo
import android.net.Uri
import android.os.Bundle
import android.view.KeyEvent
import android.view.Menu
import android.view.MenuItem
import android.view.View
import android.webkit.*
import androidx.activity.viewModels
import androidx.core.view.size
import androidx.webkit.WebSettingsCompat
import androidx.webkit.WebViewFeature
import io.legado.app.R
@ -131,6 +133,38 @@ class WebViewActivity : VMBaseActivity<ActivityWebViewBinding, WebViewModel>() {
}
}
override fun onKeyLongPress(keyCode: Int, event: KeyEvent?): Boolean {
when (keyCode) {
KeyEvent.KEYCODE_BACK -> {
finish()
return true
}
}
return super.onKeyLongPress(keyCode, event)
}
override fun onKeyUp(keyCode: Int, event: KeyEvent?): Boolean {
event?.let {
when (keyCode) {
KeyEvent.KEYCODE_BACK -> if (event.isTracking && !event.isCanceled && binding.webView.canGoBack()) {
if (binding.customWebView.size > 0) {
customWebViewCallback?.onCustomViewHidden()
return true
} else if (binding.webView.copyBackForwardList().size > 1) {
binding.webView.goBack()
return true
}
}
}
}
return super.onKeyUp(keyCode, event)
}
override fun onDestroy() {
super.onDestroy()
binding.webView.destroy()
}
inner class CustomWebChromeClient : WebChromeClient() {
override fun onReceivedTitle(view: WebView?, title: String?) {

Loading…
Cancel
Save