From 769423012d45eb1179a499358b9419c88977289a Mon Sep 17 00:00:00 2001 From: Jonas Kalderstam Date: Tue, 4 Jun 2024 10:08:16 +0200 Subject: [PATCH] Fixed email links not opening email client --- .../feeder/model/html/HtmlLinearizer.kt | 3 ++- .../ui/compose/text/HtmlToAnnotatedString.kt | 3 ++- .../feeder/util/ActivityLauncher.kt | 20 ++++++++++++++++--- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/com/nononsenseapps/feeder/model/html/HtmlLinearizer.kt b/app/src/main/java/com/nononsenseapps/feeder/model/html/HtmlLinearizer.kt index da1480052..c44e38dc4 100644 --- a/app/src/main/java/com/nononsenseapps/feeder/model/html/HtmlLinearizer.kt +++ b/app/src/main/java/com/nononsenseapps/feeder/model/html/HtmlLinearizer.kt @@ -352,7 +352,8 @@ class HtmlLinearizer { } "a" -> { - withLinearTextAnnotation(LinearTextAnnotationLink(element.attr("abs:href"))) { + // abs:href will be blank for mailto: links + withLinearTextAnnotation(LinearTextAnnotationLink(element.attr("abs:href").ifBlank { element.attr("href") })) { linearizeChildren( element.childNodes(), blockStyle = blockStyle, diff --git a/app/src/main/java/com/nononsenseapps/feeder/ui/compose/text/HtmlToAnnotatedString.kt b/app/src/main/java/com/nononsenseapps/feeder/ui/compose/text/HtmlToAnnotatedString.kt index 0d8ffa25b..ba69973e1 100644 --- a/app/src/main/java/com/nononsenseapps/feeder/ui/compose/text/HtmlToAnnotatedString.kt +++ b/app/src/main/java/com/nononsenseapps/feeder/ui/compose/text/HtmlToAnnotatedString.kt @@ -238,7 +238,8 @@ private fun AnnotatedStringComposer.appendTextChildren( } "a" -> { - withAnnotation("URL", element.attr("abs:href") ?: "") { + // abs:href will be blank for mailto: links + withAnnotation("URL", element.attr("abs:href").ifBlank { element.attr("href") }) { appendTextChildren( element.childNodes(), baseUrl = baseUrl, diff --git a/app/src/main/java/com/nononsenseapps/feeder/util/ActivityLauncher.kt b/app/src/main/java/com/nononsenseapps/feeder/util/ActivityLauncher.kt index 90f59a3f8..57f0376ea 100644 --- a/app/src/main/java/com/nononsenseapps/feeder/util/ActivityLauncher.kt +++ b/app/src/main/java/com/nononsenseapps/feeder/util/ActivityLauncher.kt @@ -61,10 +61,24 @@ class ActivityLauncher( @ColorInt toolbarColor: Int, openAdjacentIfSuitable: Boolean = true, ): Boolean { - return when (repository.linkOpener.value) { - LinkOpener.CUSTOM_TAB -> openLinkInCustomTab(link, toolbarColor, openAdjacentIfSuitable) - LinkOpener.DEFAULT_BROWSER -> openLinkInBrowser(link, openAdjacentIfSuitable) + if (link.isBlank()) { + return false } + return if (link.startsWith("mailto:")) { + openEmailClient(link) + } else { + when (repository.linkOpener.value) { + LinkOpener.CUSTOM_TAB -> openLinkInCustomTab(link, toolbarColor, openAdjacentIfSuitable) + LinkOpener.DEFAULT_BROWSER -> openLinkInBrowser(link, openAdjacentIfSuitable) + } + } + } + + private fun openEmailClient(link: String): Boolean { + // example link: mailto:email@exampl.com?subject=subject + val intent = Intent(Intent.ACTION_SENDTO, Uri.parse(link)) + + return startActivity(openAdjacentIfSuitable = true, intent = intent) } /**