Skip to content

Commit

Permalink
Add https protocol if missing in user website (#108)
Browse files Browse the repository at this point in the history
  • Loading branch information
davotoula authored Mar 13, 2024
1 parent 0446a0c commit f868b77
Showing 1 changed file with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,8 @@ private fun UserProfileDetails(
val context = LocalContext.current
val uiScope = rememberCoroutineScope()
val keyCopiedText = stringResource(id = R.string.settings_keys_key_copied)
val protocolPrefix = "http"
val protocolPrefixReplacement = "https://"

Column(
modifier = Modifier
Expand Down Expand Up @@ -715,17 +717,23 @@ private fun UserProfileDetails(
}

if (state.profileDetails?.website?.isNotEmpty() == true) {
val websiteWithProtocol = if (state.profileDetails.website.startsWith(protocolPrefix, true)) {
state.profileDetails.website
} else {
protocolPrefixReplacement + state.profileDetails.website
}

UserWebsiteText(
website = state.profileDetails.website,
onClick = {
try {
localUriHandler.openUri(state.profileDetails.website)
localUriHandler.openUri(websiteWithProtocol)
} catch (error: ActivityNotFoundException) {
Timber.w(error)
uiScope.launch {
Toast.makeText(
context,
"App not found that could open ${state.profileDetails.website}.",
"App not found that could open $websiteWithProtocol.",
Toast.LENGTH_SHORT,
).show()
}
Expand Down

0 comments on commit f868b77

Please sign in to comment.