android: move comments URL hackery to the right location

This commit is contained in:
Harsh Shandilya 2022-03-02 13:40:57 +05:30
parent de28ae2d95
commit c556f26d77
No known key found for this signature in database
GPG key ID: 366D7BBAD1031E80
2 changed files with 8 additions and 13 deletions

View file

@ -95,7 +95,13 @@ fun rememberPostActions(
} }
override fun viewCommentsPage(commentsUrl: String) { override fun viewCommentsPage(commentsUrl: String) {
urlLauncher.openUri(commentsUrl) // Post links from lobste.rs are of the form $baseUrl/s/$postId/$postTitle
// Interestingly, lobste.rs does not actually care for the value of $postTitle, and will
// happily accept both a missing as well as a completely arbitrary $postTitle. We
// leverage this to create a new URL format which looks like
// $baseUrl/s/$postId/$postTitle/r, and does not trigger our deeplinks,
// instead opening in the custom tab as we want it to.
urlLauncher.openUri(commentsUrl.replaceAfterLast('/', "r"))
} }
override fun toggleSave(post: SavedPost) { override fun toggleSave(post: SavedPost) {

View file

@ -61,21 +61,10 @@ fun CommentsHeader(
Spacer(Modifier.height(4.dp)) Spacer(Modifier.height(4.dp))
if (postDetails.url.isNotBlank()) { if (postDetails.url.isNotBlank()) {
// Post links from lobste.rs are of the form $baseUrl/s/$postId/$postTitle
// Interestingly, lobste.rs does not actually care for the value of $postTitle, and will
// happily accept both a missing as well as a completely arbitrary $postTitle. We
// leverage this to create a new URL format which looks like
// $baseUrl/s/$postId/$postTitle/r, and does not trigger our deeplinks,
// instead opening in the custom tab as we want it to.
PostLink( PostLink(
link = postDetails.url, link = postDetails.url,
modifier = modifier =
Modifier.clickable { Modifier.clickable { postActions.viewPost(postDetails.url, postDetails.commentsUrl) },
postActions.viewPost(
postDetails.url,
postDetails.commentsUrl.replaceAfterLast('/', "r")
)
},
) )
Spacer(Modifier.height(4.dp)) Spacer(Modifier.height(4.dp))
} }