Add option to open manga details in a WebView
Cette révision appartient à :
Parent
8d4c0f505c
révision
e7606e6dca
5 fichiers modifiés avec 79 ajouts et 7 suppressions
|
@ -15,12 +15,7 @@ import android.support.customtabs.CustomTabsIntent
|
||||||
import android.support.v4.content.pm.ShortcutInfoCompat
|
import android.support.v4.content.pm.ShortcutInfoCompat
|
||||||
import android.support.v4.content.pm.ShortcutManagerCompat
|
import android.support.v4.content.pm.ShortcutManagerCompat
|
||||||
import android.support.v4.graphics.drawable.IconCompat
|
import android.support.v4.graphics.drawable.IconCompat
|
||||||
import android.view.LayoutInflater
|
import android.view.*
|
||||||
import android.view.Menu
|
|
||||||
import android.view.MenuInflater
|
|
||||||
import android.view.MenuItem
|
|
||||||
import android.view.View
|
|
||||||
import android.view.ViewGroup
|
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import com.afollestad.materialdialogs.MaterialDialog
|
import com.afollestad.materialdialogs.MaterialDialog
|
||||||
import com.bumptech.glide.load.engine.DiskCacheStrategy
|
import com.bumptech.glide.load.engine.DiskCacheStrategy
|
||||||
|
@ -138,6 +133,7 @@ class MangaInfoController : NucleusController<MangaInfoPresenter>(),
|
||||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||||
when (item.itemId) {
|
when (item.itemId) {
|
||||||
R.id.action_open_in_browser -> openInBrowser()
|
R.id.action_open_in_browser -> openInBrowser()
|
||||||
|
R.id.action_open_in_web_view -> openInWebView()
|
||||||
R.id.action_share -> shareManga()
|
R.id.action_share -> shareManga()
|
||||||
R.id.action_add_to_home_screen -> addToHomeScreen()
|
R.id.action_add_to_home_screen -> addToHomeScreen()
|
||||||
else -> return super.onOptionsItemSelected(item)
|
else -> return super.onOptionsItemSelected(item)
|
||||||
|
@ -302,6 +298,19 @@ class MangaInfoController : NucleusController<MangaInfoPresenter>(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun openInWebView() {
|
||||||
|
val source = presenter.source as? HttpSource ?: return
|
||||||
|
|
||||||
|
val url = try {
|
||||||
|
source.mangaDetailsRequest(presenter.manga).url().toString()
|
||||||
|
} catch (e: Exception) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
parentController?.router?.pushController(MangaWebViewController(source.id, url)
|
||||||
|
.withFadeTransaction())
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called to run Intent with [Intent.ACTION_SEND], which show share dialog.
|
* Called to run Intent with [Intent.ACTION_SEND], which show share dialog.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -0,0 +1,51 @@
|
||||||
|
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.webkit.WebView
|
||||||
|
import eu.kanade.tachiyomi.R
|
||||||
|
import eu.kanade.tachiyomi.source.SourceManager
|
||||||
|
import eu.kanade.tachiyomi.source.online.HttpSource
|
||||||
|
import eu.kanade.tachiyomi.ui.base.controller.BaseController
|
||||||
|
import uy.kohesive.injekt.injectLazy
|
||||||
|
|
||||||
|
class MangaWebViewController(bundle: Bundle? = null) : BaseController(bundle) {
|
||||||
|
|
||||||
|
private val sourceManager by injectLazy<SourceManager>()
|
||||||
|
|
||||||
|
constructor(sourceId: Long, url: String) : this(Bundle().apply {
|
||||||
|
putLong(SOURCE_KEY, sourceId)
|
||||||
|
putString(URL_KEY, url)
|
||||||
|
})
|
||||||
|
|
||||||
|
override fun inflateView(inflater: LayoutInflater, container: ViewGroup): View {
|
||||||
|
return inflater.inflate(R.layout.manga_info_web_controller, container, false)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onViewCreated(view: View) {
|
||||||
|
super.onViewCreated(view)
|
||||||
|
val source = sourceManager.get(args.getLong(SOURCE_KEY)) as? HttpSource ?: return
|
||||||
|
val url = args.getString(URL_KEY) ?: return
|
||||||
|
val headers = source.headers.toMultimap().mapValues { it.value.getOrNull(0) ?: "" }
|
||||||
|
|
||||||
|
val web = view as WebView
|
||||||
|
web.settings.javaScriptEnabled = true
|
||||||
|
web.settings.userAgentString = source.headers["User-Agent"]
|
||||||
|
web.loadUrl(url, headers)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onDestroyView(view: View) {
|
||||||
|
val web = view as WebView
|
||||||
|
web.stopLoading()
|
||||||
|
web.destroy()
|
||||||
|
super.onDestroyView(view)
|
||||||
|
}
|
||||||
|
|
||||||
|
private companion object {
|
||||||
|
const val SOURCE_KEY = "source_key"
|
||||||
|
const val URL_KEY = "url_key"
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
7
app/src/main/res/layout/manga_info_web_controller.xml
Fichier normal
7
app/src/main/res/layout/manga_info_web_controller.xml
Fichier normal
|
@ -0,0 +1,7 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<WebView
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
|
</WebView>
|
|
@ -12,8 +12,12 @@
|
||||||
android:title="@string/action_open_in_browser"
|
android:title="@string/action_open_in_browser"
|
||||||
app:showAsAction="never"/>
|
app:showAsAction="never"/>
|
||||||
|
|
||||||
|
<item android:id="@+id/action_open_in_web_view"
|
||||||
|
android:title="@string/action_open_in_web_view"
|
||||||
|
app:showAsAction="never"/>
|
||||||
|
|
||||||
<item android:id="@+id/action_add_to_home_screen"
|
<item android:id="@+id/action_add_to_home_screen"
|
||||||
android:title="@string/action_add_to_home_screen"
|
android:title="@string/action_add_to_home_screen"
|
||||||
app:showAsAction="never"/>
|
app:showAsAction="never"/>
|
||||||
|
|
||||||
</menu>
|
</menu>
|
||||||
|
|
|
@ -73,6 +73,7 @@
|
||||||
<string name="action_resume">Resume</string>
|
<string name="action_resume">Resume</string>
|
||||||
<string name="action_move">Move</string>
|
<string name="action_move">Move</string>
|
||||||
<string name="action_open_in_browser">Open in browser</string>
|
<string name="action_open_in_browser">Open in browser</string>
|
||||||
|
<string name="action_open_in_web_view">Open in web view</string>
|
||||||
<string name="action_add_to_home_screen">Add to home screen</string>
|
<string name="action_add_to_home_screen">Add to home screen</string>
|
||||||
<string name="action_display_mode">Change display mode</string>
|
<string name="action_display_mode">Change display mode</string>
|
||||||
<string name="action_display">Display</string>
|
<string name="action_display">Display</string>
|
||||||
|
|
Référencer dans un nouveau ticket