File tree Expand file tree Collapse file tree
app/src/main/java/friendly/android Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -56,7 +56,6 @@ import androidx.compose.ui.platform.LocalContext
5656import androidx.compose.ui.res.painterResource
5757import androidx.compose.ui.res.stringResource
5858import androidx.compose.ui.unit.dp
59- import androidx.core.net.toUri
6059import friendly.android.ProfileScreenViewModel.UserProfile
6160import friendly.sdk.Nickname
6261import friendly.sdk.SocialLink
@@ -383,7 +382,7 @@ private fun copyToClipboardIn(
383382}
384383
385384private fun openSocialLink (context : Context , socialLink : SocialLink ) {
386- val intent = Intent (Intent .ACTION_VIEW , socialLink.string.toUri ())
385+ val intent = Intent (Intent .ACTION_VIEW , socialLink.toNormalizedUri ())
387386 context.startActivity(intent)
388387}
389388
Original file line number Diff line number Diff line change 1+ package friendly.android
2+
3+ import android.net.Uri
4+ import android.util.Patterns
5+ import androidx.core.net.toUri
6+ import friendly.sdk.SocialLink
7+
8+ /* *
9+ * Automatically uses https protocol if no one was specified.
10+ *
11+ * @return A valid [Uri] if [SocialLink] is a valid URI or null in it is
12+ * invalid.
13+ */
14+ fun SocialLink.toNormalizedUri (): Uri ? {
15+ val string = this .string
16+
17+ if (! Patterns .WEB_URL .matcher(string).matches()) return null
18+
19+ val startsWithHttp = string.startsWith(" http://" , ignoreCase = true )
20+ val startsWithHttps = string.startsWith(" https://" , ignoreCase = true )
21+ if (startsWithHttp || startsWithHttps) return string.toUri()
22+
23+ return " https://$string " .toUri()
24+ }
You can’t perform that action at this time.
0 commit comments