mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-11-10 12:47:48 +01:00
Allow back button to navigate to previous URL in WebView, add Forward, Refresh, and Close menu options (#2176)
This commit is contained in:
parent
b8b118bdeb
commit
ebeee70931
3 changed files with 60 additions and 3 deletions
|
@ -1,9 +1,7 @@
|
|||
package eu.kanade.tachiyomi.ui.manga.info
|
||||
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.view.*
|
||||
import android.webkit.WebView
|
||||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.source.SourceManager
|
||||
|
@ -16,6 +14,10 @@ class MangaWebViewController(bundle: Bundle? = null) : BaseController(bundle) {
|
|||
|
||||
private val sourceManager by injectLazy<SourceManager>()
|
||||
|
||||
init {
|
||||
setHasOptionsMenu(true)
|
||||
}
|
||||
|
||||
constructor(sourceId: Long, url: String) : this(Bundle().apply {
|
||||
putLong(SOURCE_KEY, sourceId)
|
||||
putString(URL_KEY, url)
|
||||
|
@ -43,6 +45,40 @@ class MangaWebViewController(bundle: Bundle? = null) : BaseController(bundle) {
|
|||
web.loadUrl(url, headers)
|
||||
}
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
|
||||
inflater.inflate(R.menu.web_view, menu)
|
||||
}
|
||||
|
||||
override fun onPrepareOptionsMenu(menu: Menu) {
|
||||
val web = view as WebView
|
||||
menu.findItem(R.id.action_forward).isVisible = web.canGoForward()
|
||||
}
|
||||
|
||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||
when (item.itemId) {
|
||||
R.id.action_forward -> {
|
||||
val web = view as WebView
|
||||
if (web.canGoForward()) web.goForward()
|
||||
}
|
||||
R.id.action_refresh -> {
|
||||
val web = view as WebView
|
||||
web.reload()
|
||||
}
|
||||
R.id.action_close -> router.popController(this)
|
||||
else -> return super.onOptionsItemSelected(item)
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
override fun handleBack(): Boolean {
|
||||
val web = view as WebView
|
||||
if (web.canGoBack()) {
|
||||
web.goBack()
|
||||
return true
|
||||
}
|
||||
return super.handleBack()
|
||||
}
|
||||
|
||||
override fun onDestroyView(view: View) {
|
||||
val web = view as WebView
|
||||
web.stopLoading()
|
||||
|
|
19
app/src/main/res/menu/web_view.xml
Normal file
19
app/src/main/res/menu/web_view.xml
Normal file
|
@ -0,0 +1,19 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
|
||||
<item
|
||||
android:id="@+id/action_forward"
|
||||
android:title="@string/action_forward"
|
||||
app:showAsAction="never" />
|
||||
|
||||
<item
|
||||
android:id="@+id/action_refresh"
|
||||
android:title="@string/action_refresh"
|
||||
app:showAsAction="never" />
|
||||
|
||||
<item android:id="@+id/action_close"
|
||||
android:title="@string/action_close"
|
||||
app:showAsAction="never"/>
|
||||
|
||||
</menu>
|
|
@ -95,6 +95,8 @@
|
|||
<string name="action_restore">Restore</string>
|
||||
<string name="action_open">Open</string>
|
||||
<string name="action_login">Log in</string>
|
||||
<string name="action_forward">Forward</string>
|
||||
<string name="action_refresh">Refresh</string>
|
||||
|
||||
<!-- Operations -->
|
||||
<string name="deleting">Deleting…</string>
|
||||
|
|
Loading…
Reference in a new issue