Release v2.22.1 (#358)
Release — F-Droid repo + Gitea/Codeberg release + Play / detect (push) Successful in 10s
Release — F-Droid repo + Gitea/Codeberg release + Play / release (push) Successful in 14m6s
Release — F-Droid repo + Gitea/Codeberg release + Play / play (push) Failing after 1m28s

Patch release for #357.

- Tapping a meeting link in an event's location opened it in a maps app. Links in the location are now underlined and open in the browser, the same way description links do. Tapping the rest of the location still opens maps, so a location with both an address and a link works for both.
- Link detection moved into `WebLinks.kt` with unit tests. It now matches a capitalised scheme (`Https://`), lower-cases the scheme before launching, and leaves `<…>` out of the URL (the Outlook/Teams style). This applies to description links too.
- Links open with `CATEGORY_BROWSABLE` through one helper. A failed launch shows a "No app can open this link" toast instead of doing nothing or crashing on a `SecurityException`.
- The location's maps tap has an "Open in maps" accessibility label (new `onTapLabel` on `copyOnLongPress`).

The issue only asked for links to open in the browser. Inline links instead of switching the whole tap target came out of review: they keep the address reachable when a location holds both.

Plus the release commit: CHANGELOG section, versionName 2.22.1 / versionCode 22201, and the 22201 changelogs for every store locale. Merging this to main triggers the release pipeline.

Closes #357
This commit is contained in:
Jean-Luc Makiola
2026-10-02 18:45:38 +02:00
parent 5f07adef2f
commit 06ee010f07
24 changed files with 149 additions and 34 deletions
+2 -2
View File
@@ -28,8 +28,8 @@ android {
// which builds this version and then creates the matching vX.Y.Z tag +
// release itself (versionCode is pinned to MAJOR*10000 + MINOR*100 +
// PATCH from versionName, e.g. 2.7.2 -> 20702). See docs/RELEASING.md.
versionCode = 22200
versionName = "2.22.0"
versionCode = 22201
versionName = "2.22.1"
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}
@@ -65,9 +65,9 @@ fun rememberFieldCopier(snackbarHostState: SnackbarHostState): FieldCopier {
/**
* Long-press to copy [text] whole, filed on the clipboard under [label].
*
* [onTap] carries a field's existing tap action through; a field without one
* stays unclickable rather than growing a ripple that leads nowhere, and gets
* its long press announced through semantics instead. That branch merges the
* [onTap] carries a field's existing tap action through, announced as
* [onTapLabel]; a field without one stays unclickable rather than growing a
* ripple that leads nowhere, and gets its long press announced through semantics instead. That branch merges the
* node it sits on, so a screen reader lands on the field itself and finds the
* action there — a bare container is never focused.
*/
@@ -77,11 +77,13 @@ fun Modifier.copyOnLongPress(
text: String,
copy: FieldCopier,
onTap: (() -> Unit)? = null,
onTapLabel: String? = null,
): Modifier {
val actionLabel = stringResource(R.string.field_copy_action)
return if (onTap != null) {
combinedClickable(
onClick = onTap,
onClickLabel = onTapLabel,
onLongClickLabel = actionLabel,
onLongClick = { copy(label, text) },
)
@@ -1,11 +1,11 @@
package de.jeanlucmakiola.calendula.ui.detail
import android.Manifest
import android.content.ActivityNotFoundException
import android.content.Context
import android.content.Intent
import android.content.pm.PackageManager
import android.net.Uri
import android.widget.Toast
import androidx.activity.compose.rememberLauncherForActivityResult
import androidx.activity.result.contract.ActivityResultContracts
import androidx.compose.foundation.background
@@ -534,7 +534,7 @@ private fun EventDetailContent(
)
}
// Location (conditional, tap → maps).
// Location (conditional). URLs open in the browser, the rest in maps.
instance.location?.takeIf { it.isNotBlank() }?.let { location ->
val context = LocalContext.current
val locationLabel = stringResource(R.string.event_detail_location)
@@ -544,7 +544,7 @@ private fun EventDetailContent(
iconContentDescription = locationLabel,
) {
Text(
text = location,
text = linkifyUrls(location, MaterialTheme.colorScheme.primary),
style = MaterialTheme.typography.titleMedium,
color = MaterialTheme.colorScheme.primary,
modifier = Modifier
@@ -554,6 +554,7 @@ private fun EventDetailContent(
text = location,
copy = copyField,
onTap = { openInMaps(context, location) },
onTapLabel = stringResource(R.string.event_detail_open_in_maps),
)
.padding(vertical = 2.dp),
)
@@ -846,21 +847,23 @@ private fun foreignTimeZone(
)
}
/** Wrap http(s) URLs in [text] as tappable links tinted [linkColor]. */
/** Wrap http(s) URLs in [text] as links tinted [linkColor] that open in the browser. */
@Composable
private fun linkifyUrls(text: String, linkColor: Color): AnnotatedString = remember(text, linkColor) {
val regex = Regex("""https?://\S+""")
val styles = TextLinkStyles(
style = SpanStyle(color = linkColor, textDecoration = TextDecoration.Underline),
)
buildAnnotatedString {
append(text)
for (match in regex.findAll(text)) {
// Trim trailing punctuation that commonly abuts a URL in prose.
val raw = match.value
val url = raw.trimEnd('.', ',', ';', ':', '!', '?', ')', ']', '"', '\'')
val end = match.range.first + url.length
addLink(LinkAnnotation.Url(url, styles), match.range.first, end)
private fun linkifyUrls(text: String, linkColor: Color): AnnotatedString {
val context = LocalContext.current
return remember(text, linkColor, context) {
val styles = TextLinkStyles(
style = SpanStyle(color = linkColor, textDecoration = TextDecoration.Underline),
)
buildAnnotatedString {
append(text)
for (link in findWebLinks(text)) {
addLink(
LinkAnnotation.Url(link.url, styles) { openWebLink(context, link.url) },
link.start,
link.end,
)
}
}
}
}
@@ -915,21 +918,19 @@ private fun formatWhen(
private fun Instant.toJavaLocalDateTime(zid: ZoneId): java.time.LocalDateTime =
java.time.LocalDateTime.ofInstant(java.time.Instant.ofEpochMilli(toEpochMilliseconds()), zid)
/** Open [url] in a browsable app, or say so when none can take it. */
private fun openWebLink(context: Context, url: String) {
val intent = Intent(Intent.ACTION_VIEW, Uri.parse(url)).addCategory(Intent.CATEGORY_BROWSABLE)
if (runCatching { context.startActivity(intent) }.isFailure) {
Toast.makeText(context, R.string.link_open_failed, Toast.LENGTH_SHORT).show()
}
}
/** Open a maps intent for [query]; fall back to a web maps URL if no app handles geo:. */
private fun openInMaps(context: Context, query: String) {
val encoded = Uri.encode(query)
val geo = Intent(Intent.ACTION_VIEW, Uri.parse("geo:0,0?q=$encoded"))
try {
context.startActivity(geo)
} catch (e: ActivityNotFoundException) {
val web = Intent(
Intent.ACTION_VIEW,
Uri.parse("https://www.google.com/maps/search/?api=1&query=$encoded"),
)
try {
context.startActivity(web)
} catch (e2: ActivityNotFoundException) {
// No browser either — nothing sensible to do; swallow.
}
if (runCatching { context.startActivity(geo) }.isFailure) {
openWebLink(context, "https://www.google.com/maps/search/?api=1&query=$encoded")
}
}
@@ -0,0 +1,18 @@
package de.jeanlucmakiola.calendula.ui.detail
/** An http(s) URL found in free text, spanning [start] until [end] (exclusive). */
internal data class WebLink(val start: Int, val end: Int, val url: String)
private val webLinkRegex = Regex("""https?://[^\s<>"]+""", RegexOption.IGNORE_CASE)
/**
* Find the http(s) URLs in [text]. Trailing prose punctuation is left out of
* each match, and the scheme is lower-cased so intent filters match it.
*/
internal fun findWebLinks(text: String): List<WebLink> = webLinkRegex.findAll(text).mapNotNull { match ->
val raw = match.value.trimEnd('.', ',', ';', ':', '!', '?', ')', ']', '\'')
val schemeEnd = raw.indexOf(':')
if (raw.length <= schemeEnd + 3) return@mapNotNull null
val url = raw.substring(0, schemeEnd).lowercase() + raw.substring(schemeEnd)
WebLink(match.range.first, match.range.first + raw.length, url)
}.toList()
+2
View File
@@ -211,6 +211,8 @@
<string name="event_detail_calendar_unknown">Unknown calendar</string>
<string name="event_detail_title">Title</string>
<string name="event_detail_location">Location</string>
<string name="event_detail_open_in_maps">Open in maps</string>
<string name="link_open_failed">No app can open this link</string>
<string name="event_detail_description">Description</string>
<string name="event_detail_attendees">Attendees</string>
<string name="event_detail_recurrence">Recurrence</string>
@@ -0,0 +1,52 @@
package de.jeanlucmakiola.calendula.ui.detail
import com.google.common.truth.Truth.assertThat
import org.junit.jupiter.api.Test
class WebLinksTest {
@Test
fun `a plain address has no links`() {
assertThat(findWebLinks("Office B, 12 Main St.")).isEmpty()
}
@Test
fun `a bare meeting link spans the whole text`() {
val text = "https://meet.google.com/abc-defg-hij"
assertThat(findWebLinks(text)).containsExactly(WebLink(0, text.length, text))
}
@Test
fun `a capitalised scheme is matched and lower-cased`() {
val links = findWebLinks("Https://zoom.us/j/123")
assertThat(links.single().url).isEqualTo("https://zoom.us/j/123")
assertThat(links.single().end).isEqualTo(21)
}
@Test
fun `angle brackets around a link stay outside it`() {
val text = "Microsoft Teams Meeting <https://teams.microsoft.com/l/meetup-join/x>"
val link = findWebLinks(text).single()
assertThat(link.url).isEqualTo("https://teams.microsoft.com/l/meetup-join/x")
assertThat(text.substring(link.start, link.end)).isEqualTo(link.url)
}
@Test
fun `trailing punctuation is left out of the link`() {
val link = findWebLinks("Office B (https://office.example.com).").single()
assertThat(link.url).isEqualTo("https://office.example.com")
}
@Test
fun `every link in the text is found`() {
val links = findWebLinks("Room 3 / https://zoom.us/j/1 / https://meet.google.com/x")
assertThat(links.map { it.url })
.containsExactly("https://zoom.us/j/1", "https://meet.google.com/x")
.inOrder()
}
@Test
fun `other schemes and a bare scheme are not links`() {
assertThat(findWebLinks("ftp://example.com mailto:a@b.c https://")).isEmpty()
}
}