Open decode error pages in webview instead of browser

This commit is contained in:
arkon 2020-04-10 11:49:51 -04:00
parent fdc7981d18
commit 51d93f0217
6 changed files with 19 additions and 19 deletions

View File

@ -302,7 +302,7 @@ open class BrowseCatalogueController(bundle: Bundle) :
val source = presenter.source as? HttpSource ?: return val source = presenter.source as? HttpSource ?: return
val activity = activity ?: return val activity = activity ?: return
val intent = WebViewActivity.newIntent(activity, source.id, source.baseUrl, presenter.source.name) val intent = WebViewActivity.newIntent(activity, source.baseUrl, source.id, presenter.source.name)
startActivity(intent) startActivity(intent)
} }

View File

@ -315,7 +315,7 @@ class MangaInfoController : NucleusController<MangaInfoPresenter>(),
} }
val activity = activity ?: return val activity = activity ?: return
val intent = WebViewActivity.newIntent(activity, source.id, url, presenter.manga.title) val intent = WebViewActivity.newIntent(activity, url, source.id, presenter.manga.title)
startActivity(intent) startActivity(intent)
} }

View File

@ -1,10 +1,8 @@
package eu.kanade.tachiyomi.ui.reader.viewer.pager package eu.kanade.tachiyomi.ui.reader.viewer.pager
import android.annotation.SuppressLint import android.annotation.SuppressLint
import android.content.Intent
import android.graphics.PointF import android.graphics.PointF
import android.graphics.drawable.Drawable import android.graphics.drawable.Drawable
import android.net.Uri
import android.view.GestureDetector import android.view.GestureDetector
import android.view.Gravity import android.view.Gravity
import android.view.MotionEvent import android.view.MotionEvent
@ -32,6 +30,7 @@ import eu.kanade.tachiyomi.source.model.Page
import eu.kanade.tachiyomi.ui.reader.model.ReaderPage import eu.kanade.tachiyomi.ui.reader.model.ReaderPage
import eu.kanade.tachiyomi.ui.reader.viewer.ReaderProgressBar import eu.kanade.tachiyomi.ui.reader.viewer.ReaderProgressBar
import eu.kanade.tachiyomi.ui.reader.viewer.pager.PagerConfig.ZoomType import eu.kanade.tachiyomi.ui.reader.viewer.pager.PagerConfig.ZoomType
import eu.kanade.tachiyomi.ui.webview.WebViewActivity
import eu.kanade.tachiyomi.util.system.ImageUtil import eu.kanade.tachiyomi.util.system.ImageUtil
import eu.kanade.tachiyomi.util.system.dpToPx import eu.kanade.tachiyomi.util.system.dpToPx
import eu.kanade.tachiyomi.util.view.gone import eu.kanade.tachiyomi.util.view.gone
@ -417,9 +416,9 @@ class PagerPageHolder(
layoutParams = FrameLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT).apply { layoutParams = FrameLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT).apply {
setMargins(margins, margins, margins, margins) setMargins(margins, margins, margins, margins)
} }
setText(R.string.action_open_in_browser) setText(R.string.action_open_in_web_view)
setOnClickListener { setOnClickListener {
val intent = Intent(Intent.ACTION_VIEW, Uri.parse(imageUrl)) val intent = WebViewActivity.newIntent(context, imageUrl!!)
context.startActivity(intent) context.startActivity(intent)
} }

View File

@ -1,10 +1,8 @@
package eu.kanade.tachiyomi.ui.reader.viewer.webtoon package eu.kanade.tachiyomi.ui.reader.viewer.webtoon
import android.annotation.SuppressLint import android.annotation.SuppressLint
import android.content.Intent
import android.content.res.Resources import android.content.res.Resources
import android.graphics.drawable.Drawable import android.graphics.drawable.Drawable
import android.net.Uri
import android.view.Gravity import android.view.Gravity
import android.view.ViewGroup import android.view.ViewGroup
import android.view.ViewGroup.LayoutParams.MATCH_PARENT import android.view.ViewGroup.LayoutParams.MATCH_PARENT
@ -30,6 +28,7 @@ import eu.kanade.tachiyomi.data.glide.GlideApp
import eu.kanade.tachiyomi.source.model.Page import eu.kanade.tachiyomi.source.model.Page
import eu.kanade.tachiyomi.ui.reader.model.ReaderPage import eu.kanade.tachiyomi.ui.reader.model.ReaderPage
import eu.kanade.tachiyomi.ui.reader.viewer.ReaderProgressBar import eu.kanade.tachiyomi.ui.reader.viewer.ReaderProgressBar
import eu.kanade.tachiyomi.ui.webview.WebViewActivity
import eu.kanade.tachiyomi.util.system.ImageUtil import eu.kanade.tachiyomi.util.system.ImageUtil
import eu.kanade.tachiyomi.util.system.dpToPx import eu.kanade.tachiyomi.util.system.dpToPx
import eu.kanade.tachiyomi.util.view.gone import eu.kanade.tachiyomi.util.view.gone
@ -460,9 +459,9 @@ class WebtoonPageHolder(
layoutParams = FrameLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT).apply { layoutParams = FrameLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT).apply {
setMargins(0, margins, 0, margins) setMargins(0, margins, 0, margins)
} }
setText(R.string.action_open_in_browser) setText(R.string.action_open_in_web_view)
setOnClickListener { setOnClickListener {
val intent = Intent(Intent.ACTION_VIEW, Uri.parse(imageUrl)) val intent = WebViewActivity.newIntent(context, imageUrl!!)
context.startActivity(intent) context.startActivity(intent)
} }

View File

@ -55,15 +55,17 @@ class WebViewActivity : BaseActivity() {
} }
if (bundle == null) { if (bundle == null) {
val source = sourceManager.get(intent.extras!!.getLong(SOURCE_KEY)) as? HttpSource
?: return
val url = intent.extras!!.getString(URL_KEY) ?: return val url = intent.extras!!.getString(URL_KEY) ?: return
val headers = source.headers.toMultimap().mapValues { it.value.getOrNull(0) ?: "" } var headers = emptyMap<String, String>()
val source = sourceManager.get(intent.extras!!.getLong(SOURCE_KEY)) as? HttpSource
if (source != null) {
headers = source.headers.toMultimap().mapValues { it.value.getOrNull(0) ?: "" }
binding.webview.settings.userAgentString = source.headers["User-Agent"]
}
supportActionBar?.subtitle = url supportActionBar?.subtitle = url
binding.webview.settings.javaScriptEnabled = true binding.webview.settings.javaScriptEnabled = true
binding.webview.settings.userAgentString = source.headers["User-Agent"]
binding.webview.webChromeClient = object : WebChromeClient() { binding.webview.webChromeClient = object : WebChromeClient() {
override fun onProgressChanged(view: WebView?, newProgress: Int) { override fun onProgressChanged(view: WebView?, newProgress: Int) {
@ -166,14 +168,14 @@ class WebViewActivity : BaseActivity() {
} }
companion object { companion object {
private const val SOURCE_KEY = "source_key"
private const val URL_KEY = "url_key" private const val URL_KEY = "url_key"
private const val SOURCE_KEY = "source_key"
private const val TITLE_KEY = "title_key" private const val TITLE_KEY = "title_key"
fun newIntent(context: Context, sourceId: Long, url: String, title: String?): Intent { fun newIntent(context: Context, url: String, sourceId: Long? = null, title: String? = null): Intent {
val intent = Intent(context, WebViewActivity::class.java) val intent = Intent(context, WebViewActivity::class.java)
intent.putExtra(SOURCE_KEY, sourceId)
intent.putExtra(URL_KEY, url) intent.putExtra(URL_KEY, url)
intent.putExtra(SOURCE_KEY, sourceId)
intent.putExtra(TITLE_KEY, title) intent.putExtra(TITLE_KEY, title)
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP) intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
return intent return intent

View File

@ -500,7 +500,7 @@
<string name="chapter_subtitle">Chapter %1$s</string> <string name="chapter_subtitle">Chapter %1$s</string>
<string name="no_next_chapter">Next chapter not found</string> <string name="no_next_chapter">Next chapter not found</string>
<string name="no_previous_chapter">Previous chapter not found</string> <string name="no_previous_chapter">Previous chapter not found</string>
<string name="decode_image_error">The image could not be decoded</string> <string name="decode_image_error">The image couldn\'t be loaded</string>
<string name="confirm_set_image_as_cover">Use this image as cover art?</string> <string name="confirm_set_image_as_cover">Use this image as cover art?</string>
<string name="viewer_for_this_series">Viewer for this series</string> <string name="viewer_for_this_series">Viewer for this series</string>
<string name="transition_finished">Finished:</string> <string name="transition_finished">Finished:</string>