NoteDirectEditFragment (app/src/main/java/it/niedermann/owncloud/notes/edit/NoteDirectEditFragment.kt) loads the Nextcloud Text editor for the user's account and configures the WebViewClient with onReceivedError and onReceivedSslError overrides but no shouldOverrideUrlLoading.
When the rendered editor contains links (a markdown link to another site, a mention to a user on a different Nextcloud server, a mailto: in a frontmatter table) and the user taps one, the WebView navigates itself to that URL. The edit session is lost and the user is now stuck in a non-editor page inside a fragment that was only set up to render the editor.
Most Nextcloud Android surfaces (Files, Talk, ...) handle this by keeping same-server URLs inside the WebView and routing everything else out via Intent.ACTION_VIEW.
Suggested fix
Override shouldOverrideUrlLoading:
- If the URL starts with the current account URL, return
false so it stays in the WebView.
- Otherwise, dispatch
Intent.ACTION_VIEW and wrap the launch in try/catch (ActivityNotFoundException) so a device with no handler for the scheme does not crash the fragment.
override fun shouldOverrideUrlLoading(view: WebView?, request: WebResourceRequest?): Boolean {
val url = request?.url ?: return false
val scheme = url.scheme?.lowercase()
val accountUrl = runCatching { account.url }.getOrNull()
if ((scheme == "http" || scheme == "https") &&
accountUrl != null && url.toString().startsWith(accountUrl)
) {
return false
}
return try {
val intent = Intent(Intent.ACTION_VIEW, url).apply {
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
}
startActivity(intent)
true
} catch (e: ActivityNotFoundException) {
Log.w(TAG, "No app available to open $url", e)
true
}
}
A PR with the change is at #3192.
NoteDirectEditFragment(app/src/main/java/it/niedermann/owncloud/notes/edit/NoteDirectEditFragment.kt) loads the Nextcloud Text editor for the user's account and configures theWebViewClientwithonReceivedErrorandonReceivedSslErroroverrides but noshouldOverrideUrlLoading.When the rendered editor contains links (a markdown link to another site, a mention to a user on a different Nextcloud server, a
mailto:in a frontmatter table) and the user taps one, the WebView navigates itself to that URL. The edit session is lost and the user is now stuck in a non-editor page inside a fragment that was only set up to render the editor.Most Nextcloud Android surfaces (Files, Talk, ...) handle this by keeping same-server URLs inside the WebView and routing everything else out via
Intent.ACTION_VIEW.Suggested fix
Override
shouldOverrideUrlLoading:falseso it stays in the WebView.Intent.ACTION_VIEWand wrap the launch intry/catch (ActivityNotFoundException)so a device with no handler for the scheme does not crash the fragment.A PR with the change is at #3192.