From 398abd512ce77cc76560f36203b4c7fe9d91fda7 Mon Sep 17 00:00:00 2001 From: dimitris Date: Sat, 16 May 2026 14:46:38 +0200 Subject: [PATCH 1/2] fix(direct-edit): route off-server links out of the editor WebView The direct-edit WebView loads the Nextcloud Text editor for the user's account but never overrides shouldOverrideUrlLoading, so any link the editor renders (mentions to other users, file references, embedded images, mailto: in a markdown table) navigates the editor WebView itself and breaks the edit session. Override shouldOverrideUrlLoading to keep navigations whose URL starts with the current account URL inside the WebView and route everything else out via Intent.ACTION_VIEW. Wrap the launch in try/catch so a missing handler does not crash the Fragment. Signed-off-by: dimitris --- .../notes/edit/NoteDirectEditFragment.kt | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/app/src/main/java/it/niedermann/owncloud/notes/edit/NoteDirectEditFragment.kt b/app/src/main/java/it/niedermann/owncloud/notes/edit/NoteDirectEditFragment.kt index 95b76550d..a4809394a 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/edit/NoteDirectEditFragment.kt +++ b/app/src/main/java/it/niedermann/owncloud/notes/edit/NoteDirectEditFragment.kt @@ -7,6 +7,8 @@ package it.niedermann.owncloud.notes.edit import android.annotation.SuppressLint +import android.content.ActivityNotFoundException +import android.content.Intent import android.net.http.SslError import android.os.Bundle import android.util.Log @@ -302,6 +304,30 @@ class NoteDirectEditFragment : BaseNoteFragment(), Branded { super.onReceivedSslError(view, handler, error) } } + + 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 + } + } } } From 967565247ad14d7adcaec40ed513bd51f2ad226a Mon Sep 17 00:00:00 2001 From: dimitris Date: Thu, 9 Jul 2026 09:58:22 +0200 Subject: [PATCH 2/2] fix(direct-edit): collapse shouldOverrideUrlLoading to a single exit Codacy (detekt ReturnCount) flagged the new shouldOverrideUrlLoading override for having more than two return statements. Fold the two early `return false` branches and the `return try` into one `return !staysOnServer`, wrapping only the external-launch in the guarded block. Behaviour is unchanged: off-server links are routed out via ACTION_VIEW and on-server (or missing) URLs stay in the WebView. Signed-off-by: dimitris --- .../notes/edit/NoteDirectEditFragment.kt | 22 +++++++++---------- 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/it/niedermann/owncloud/notes/edit/NoteDirectEditFragment.kt b/app/src/main/java/it/niedermann/owncloud/notes/edit/NoteDirectEditFragment.kt index a4809394a..9d957b5d9 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/edit/NoteDirectEditFragment.kt +++ b/app/src/main/java/it/niedermann/owncloud/notes/edit/NoteDirectEditFragment.kt @@ -312,21 +312,19 @@ class NoteDirectEditFragment : BaseNoteFragment(), Branded { val url = request?.url ?: return false val scheme = url.scheme?.lowercase() val accountUrl = runCatching { account.url }.getOrNull() - if ((scheme == "http" || scheme == "https") && + val staysOnServer = (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) + if (!staysOnServer) { + try { + val intent = Intent(Intent.ACTION_VIEW, url).apply { + addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) + } + startActivity(intent) + } catch (e: ActivityNotFoundException) { + Log.w(TAG, "No app available to open $url", e) } - startActivity(intent) - true - } catch (e: ActivityNotFoundException) { - Log.w(TAG, "No app available to open $url", e) - true } + return !staysOnServer } } }