Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,13 @@ import androidx.compose.ui.res.stringResource
import androidx.compose.ui.semantics.Role
import androidx.compose.ui.text.LinkAnnotation
import androidx.compose.ui.text.SpanStyle
import androidx.compose.ui.text.TextLinkStyles
import androidx.compose.ui.text.buildAnnotatedString
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.withLink
import androidx.compose.ui.unit.dp
import androidx.core.app.ActivityOptionsCompat
import app.grapheneos.info.R
import app.grapheneos.info.ui.reusablecomposables.ClickableText

@Composable
fun AddressInfoItem(
Expand Down Expand Up @@ -95,31 +96,26 @@ fun AddressInfoItem(
)
}

val annotatedString = buildAnnotatedString {
pushLink(LinkAnnotation.Url(addressUrl))
pushStringAnnotation("URL", addressUrl)
pushStyle(SpanStyle(color = MaterialTheme.colorScheme.primary, fontWeight = FontWeight.Bold))

append(address)

pop()
pop()
pop()
val link = LinkAnnotation.Url(
url = addressUrl,
styles = TextLinkStyles(
style = SpanStyle(
color = MaterialTheme.colorScheme.primary,
fontWeight = FontWeight.Bold
)
)
) {
try {
localUriHandler.openUri(addressUrl)
} catch (e: IllegalArgumentException) {
showSnackbarError(activityNotFoundForDonationAddressSnackbarErrorMessage)
}
}

ClickableText(
text = annotatedString,
onClick = { offset ->
annotatedString
.getStringAnnotations("URL", offset, offset).firstOrNull()
?.let { annotation ->
try {
localUriHandler.openUri(annotation.item)
} catch (e: IllegalArgumentException) {
showSnackbarError(activityNotFoundForDonationAddressSnackbarErrorMessage)
}
}
},
Text(
buildAnnotatedString {
withLink(link) { append(address) }
}
)
IconButton(
onClick = {
Expand Down
4 changes: 1 addition & 3 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,7 @@
<string name="share">Share</string>
<string name="ok">OK</string>
<string name="image_enlarged">%1$s (enlarged)</string>
<string name="activity_not_found_for_donation_address_snackbar_error">Couldn\'t find an app to open donation address
with!
</string>
<string name="activity_not_found_for_donation_address_snackbar_error">No wallet app installed to open this address</string>
<string name="cardano_info">Cardano can be used to make donations to the non-profit GrapheneOS Foundation.</string>
<string name="cardano_qr_code_description">Cardano donation QR code</string>
<string name="cardano_handle_notice">
Expand Down