Skip to content

Commit

Permalink
Fixed email links not opening email client
Browse files Browse the repository at this point in the history
  • Loading branch information
spacecowboy committed Jun 4, 2024
1 parent 347ed83 commit 7694230
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 protected]?subject=subject
val intent = Intent(Intent.ACTION_SENDTO, Uri.parse(link))

return startActivity(openAdjacentIfSuitable = true, intent = intent)
}

/**
Expand Down

0 comments on commit 7694230

Please sign in to comment.