Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix broken external links #1395

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package org.jellyfin.mobile.webapp

import android.content.Intent
import android.net.Uri
import android.net.http.SslError
import android.webkit.SslErrorHandler
import android.webkit.WebResourceRequest
import android.webkit.WebResourceResponse
import android.webkit.WebView
import androidx.core.content.ContextCompat.startActivity
import androidx.webkit.WebResourceErrorCompat
import androidx.webkit.WebViewAssetLoader.AssetsPathHandler
import androidx.webkit.WebViewClientCompat
Expand Down Expand Up @@ -37,6 +39,22 @@ abstract class JellyfinWebViewClient(

abstract fun onErrorReceived()

override fun shouldOverrideUrlLoading(view: WebView, request: WebResourceRequest): Boolean {
Timber.d("shouldOverrideUrlLoading: %s", request.url.toString())
return when {
!request.hasGesture() -> false
request.url.toString().startsWith(server.hostname) -> false
else -> {
Timber.d("shouldOverrideUrlLoading: external link with gesture, handle with system")
val intent = Intent(Intent.ACTION_VIEW, request.url)
if (intent.resolveActivity(view.context.packageManager) != null) {
startActivity(view.context, intent, null)
}
true
}
}
}

override fun shouldInterceptRequest(webView: WebView, request: WebResourceRequest): WebResourceResponse? {
val url = request.url
val path = url.path?.lowercase(Locale.ROOT) ?: return null
Expand Down