diff --git a/android/src/main/AndroidManifest.xml b/android/src/main/AndroidManifest.xml index e9600bc3..387aef8d 100644 --- a/android/src/main/AndroidManifest.xml +++ b/android/src/main/AndroidManifest.xml @@ -18,6 +18,43 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/android/src/main/kotlin/dev/msfjarvis/claw/android/ui/LobstersApp.kt b/android/src/main/kotlin/dev/msfjarvis/claw/android/ui/LobstersApp.kt index b948d88c..10c91adc 100644 --- a/android/src/main/kotlin/dev/msfjarvis/claw/android/ui/LobstersApp.kt +++ b/android/src/main/kotlin/dev/msfjarvis/claw/android/ui/LobstersApp.kt @@ -24,9 +24,12 @@ import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.font.FontWeight import androidx.lifecycle.viewmodel.compose.viewModel +import androidx.navigation.NavType import androidx.navigation.compose.NavHost import androidx.navigation.compose.composable import androidx.navigation.compose.rememberNavController +import androidx.navigation.navArgument +import androidx.navigation.navDeepLink import androidx.paging.compose.collectAsLazyPagingItems import com.google.accompanist.insets.ProvideWindowInsets import com.google.accompanist.insets.navigationBarsPadding @@ -40,6 +43,7 @@ import dev.msfjarvis.claw.android.ui.lists.DatabasePosts import dev.msfjarvis.claw.android.ui.lists.HottestPosts import dev.msfjarvis.claw.android.ui.navigation.Destinations import dev.msfjarvis.claw.android.viewmodel.ClawViewModel +import dev.msfjarvis.claw.api.LobstersApi import dev.msfjarvis.claw.common.R as commonR import dev.msfjarvis.claw.common.comments.CommentsPage import dev.msfjarvis.claw.common.comments.HTMLConverter @@ -137,7 +141,12 @@ fun LobstersApp( navController, startDestination = Destinations.startDestination.getRoute(), ) { - composable(Destinations.Hottest.getRoute()) { + val uri = LobstersApi.BASE_URL + composable( + route = Destinations.Hottest.getRoute(), + deepLinks = + listOf(navDeepLink { uriPattern = uri }, navDeepLink { uriPattern = "$uri/" }), + ) { setWebUri("https://lobste.rs/") HottestPosts( items = networkPosts, @@ -158,7 +167,15 @@ fun LobstersApp( modifier = Modifier.padding(bottom = paddingValues.calculateBottomPadding()), ) } - composable(Destinations.Comments.getRoute("{postId}")) { backStackEntry -> + composable( + route = Destinations.Comments.getRoute("{postId}"), + arguments = listOf(navArgument("postId") { type = NavType.StringType }), + deepLinks = + listOf( + navDeepLink { uriPattern = "$uri/s/{postId}/.*" }, + navDeepLink { uriPattern = "$uri/s/{postId}" }, + ), + ) { backStackEntry -> val postId = requireNotNull(backStackEntry.arguments?.getString("postId")) setWebUri("https://lobste.rs/s/$postId") CommentsPage( diff --git a/common/src/commonMain/kotlin/dev/msfjarvis/claw/common/comments/CommentEntry.kt b/common/src/commonMain/kotlin/dev/msfjarvis/claw/common/comments/CommentEntry.kt index ec3e8f76..3eda3ca7 100644 --- a/common/src/commonMain/kotlin/dev/msfjarvis/claw/common/comments/CommentEntry.kt +++ b/common/src/commonMain/kotlin/dev/msfjarvis/claw/common/comments/CommentEntry.kt @@ -61,10 +61,21 @@ fun CommentsHeader( Spacer(Modifier.height(4.dp)) 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( link = postDetails.url, modifier = - Modifier.clickable { postActions.viewPost(postDetails.url, postDetails.commentsUrl) }, + Modifier.clickable { + postActions.viewPost( + postDetails.url, + postDetails.commentsUrl.replaceAfterLast('/', "r") + ) + }, ) Spacer(Modifier.height(4.dp)) }