commit 44e63f36d62bf6bba80917a45074e5d29f3651c2
parent 25dd79af68247f7cd0a05f63ca0163a1923da926
Author: rhunk <101876869+rhunk@users.noreply.github.com>
Date: Mon, 3 Jun 2024 18:58:43 +0200
refactor(app/home_section): external links
Signed-off-by: rhunk <101876869+rhunk@users.noreply.github.com>
Diffstat:
1 file changed, 21 insertions(+), 46 deletions(-)
diff --git a/app/src/main/kotlin/me/rhunk/snapenhance/ui/manager/pages/home/HomeRootSection.kt b/app/src/main/kotlin/me/rhunk/snapenhance/ui/manager/pages/home/HomeRootSection.kt
@@ -99,12 +99,24 @@ class HomeRootSection : Routes.Route() {
}
}
+ private fun openExternalLink(link: String) {
+ kotlin.runCatching {
+ context.activity?.startActivity(Intent(Intent.ACTION_VIEW).apply {
+ flags = Intent.FLAG_ACTIVITY_NEW_TASK
+ data = Uri.parse(link)
+ })
+ }.onFailure {
+ context.log.error("Failed to open external link", it)
+ context.shortToast("Failed to open external link. Check logs for more details.")
+ }
+ }
+
@Composable
fun ExternalLinkIcon(
modifier: Modifier = Modifier,
size: Dp = 32.dp,
imageVector: ImageVector,
- dataArray: IntArray
+ link: String
) {
Icon(
imageVector = imageVector,
@@ -113,14 +125,7 @@ class HomeRootSection : Routes.Route() {
modifier = Modifier
.size(size)
.then(modifier)
- .clickable {
- context.activity?.startActivity(Intent(Intent.ACTION_VIEW).apply {
- data = Uri.parse(
- dataArray.reversed().map { (-it xor BuildConfig.APPLICATION_ID.hashCode()).toChar() }.joinToString("")
- )
- flags = Intent.FLAG_ACTIVITY_NEW_TASK
- })
- }
+ .clickable { openExternalLink(link) }
)
}
@@ -182,41 +187,19 @@ class HomeRootSection : Routes.Route() {
) {
ExternalLinkIcon(
imageVector = ImageVector.vectorResource(id = R.drawable.ic_telegram),
- // https://t.me/snapenhance
- dataArray = intArrayOf(
- 0xe4f8b47, 0xe4f8b41, 0xe4f8b4e, 0xe4f8b43, 0xe4f8b4c, 0xe4f8b4e, 0xe4f8b47,
- 0xe4f8b54, 0xe4f8b43, 0xe4f8b4e, 0xe4f8b51, 0xe4f8b0d, 0xe4f8b47, 0xe4f8b4f,
- 0xe4f8b0e, 0xe4f8b58, 0xe4f8b0d, 0xe4f8b0d, 0xe4f8b1a, 0xe4f8b51, 0xe4f8b54,
- 0xe4f8b58, 0xe4f8b58, 0xe4f8b4c
- )
+ link = "https://t.me/snapenhance"
)
ExternalLinkIcon(
imageVector = ImageVector.vectorResource(id = R.drawable.ic_github),
- // https://github.com/rhunk/SnapEnhance
- dataArray = intArrayOf(
- 0xe4f8b47, 0xe4f8b41, 0xe4f8b4e, 0xe4f8b43, 0xe4f8b4c, 0xe4f8b4e, 0xe4f8b67,
- 0xe4f8b54, 0xe4f8b43, 0xe4f8b4e, 0xe4f8b71, 0xe4f8b0d, 0xe4f8b49, 0xe4f8b4e,
- 0xe4f8b57, 0xe4f8b4c, 0xe4f8b52, 0xe4f8b0d, 0xe4f8b4f, 0xe4f8b4d, 0xe4f8b41,
- 0xe4f8b0e, 0xe4f8b42, 0xe4f8b57, 0xe4f8b4c, 0xe4f8b58, 0xe4f8b4b, 0xe4f8b45,
- 0xe4f8b0d, 0xe4f8b0d, 0xe4f8b1a, 0xe4f8b51, 0xe4f8b54, 0xe4f8b58, 0xe4f8b58,
- 0xe4f8b4c
- )
+ link = "https://github.com/rhunk/SnapEnhance"
)
ExternalLinkIcon(
size = 36.dp,
modifier = Modifier.offset(y = (-2).dp),
imageVector = Icons.AutoMirrored.Default.Help,
- // https://github.com/rhunk/SnapEnhance/wiki
- dataArray = intArrayOf(
- 0xe4f8b4b, 0xe4f8b49, 0xe4f8b4b, 0xe4f8b55, 0xe4f8b0d, 0xe4f8b47, 0xe4f8b41,
- 0xe4f8b4e, 0xe4f8b43, 0xe4f8b4c, 0xe4f8b4e, 0xe4f8b67, 0xe4f8b54, 0xe4f8b43,
- 0xe4f8b4e, 0xe4f8b71, 0xe4f8b0d, 0xe4f8b49, 0xe4f8b4e, 0xe4f8b57, 0xe4f8b4c,
- 0xe4f8b52, 0xe4f8b0d, 0xe4f8b4f, 0xe4f8b4d, 0xe4f8b41, 0xe4f8b0e, 0xe4f8b42,
- 0xe4f8b57, 0xe4f8b4c, 0xe4f8b58, 0xe4f8b4b, 0xe4f8b45, 0xe4f8b0d, 0xe4f8b0d,
- 0xe4f8b1a, 0xe4f8b51, 0xe4f8b54, 0xe4f8b58, 0xe4f8b58, 0xe4f8b4c
- )
+ link = "https://github.com/rhunk/SnapEnhance/wiki"
)
}
@@ -250,9 +233,7 @@ class HomeRootSection : Routes.Route() {
)
}
Button(onClick = {
- context.activity?.startActivity(Intent(Intent.ACTION_VIEW).apply {
- data = Uri.parse(latestUpdate?.releaseUrl)
- })
+ latestUpdate?.releaseUrl?.let { openExternalLink(it) }
}, modifier = Modifier.height(40.dp)) {
Text(text = translation["update_button"])
}
@@ -306,15 +287,9 @@ class HomeRootSection : Routes.Route() {
onClick = { offset ->
buildSummary.getStringAnnotations(
tag = "git_hash", start = offset, end = offset
- )
- .firstOrNull()?.let {
- context.activity?.startActivity(
- Intent(Intent.ACTION_VIEW).apply {
- data = Uri.parse(
- "https://github.com/rhunk/SnapEnhance/commit/${it.item}"
- )
- })
- }
+ ).firstOrNull()?.let {
+ openExternalLink("https://github.com/rhunk/SnapEnhance/commit/${it.item}")
+ }
}
)
Text(