mirror of
https://github.com/msfjarvis/compose-lobsters
synced 2025-08-14 08:17:04 +05:30
android: port deeplinks from develop branch
Fixes #306 Co-Authored-By: Aditya Wasan <adityawasan55@gmail.com>
This commit is contained in:
parent
85d92dd132
commit
a58c30ea6b
3 changed files with 68 additions and 3 deletions
|
@ -18,6 +18,43 @@
|
|||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.VIEW" />
|
||||
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
<category android:name="android.intent.category.BROWSABLE" />
|
||||
|
||||
<data
|
||||
android:ssp="//lobste.rs"
|
||||
android:scheme="https" />
|
||||
|
||||
<data
|
||||
android:host="lobste.rs"
|
||||
android:scheme="https"
|
||||
android:path="/"/>
|
||||
</intent-filter>
|
||||
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.VIEW" />
|
||||
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
<category android:name="android.intent.category.BROWSABLE" />
|
||||
|
||||
<data
|
||||
android:host="lobste.rs"
|
||||
android:scheme="https"
|
||||
android:pathPattern="/s/......"/>
|
||||
|
||||
<data
|
||||
android:host="lobste.rs"
|
||||
android:scheme="https"
|
||||
android:pathPattern="/s/....../"/>
|
||||
|
||||
<data
|
||||
android:host="lobste.rs"
|
||||
android:scheme="https"
|
||||
android:pathPattern="/s/....../...*"/>
|
||||
</intent-filter>
|
||||
</activity>
|
||||
</application>
|
||||
</manifest>
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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))
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue