Skip to content

Commit

Permalink
refactor(app/home_section): external links
Browse files Browse the repository at this point in the history
Signed-off-by: rhunk <[email protected]>
  • Loading branch information
rhunk committed Jun 3, 2024
1 parent 25dd79a commit 44e63f3
Showing 1 changed file with 21 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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) }
)
}

Expand Down Expand Up @@ -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"
)
}

Expand Down Expand Up @@ -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"])
}
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 44e63f3

Please sign in to comment.