android: add support for links in recents

This commit is contained in:
Harsh Shandilya 2021-11-15 22:34:14 +05:30
parent 2cc08008fd
commit a73871f421
No known key found for this signature in database
GPG key ID: 366D7BBAD1031E80
2 changed files with 14 additions and 2 deletions

View file

@ -1,5 +1,7 @@
package dev.msfjarvis.claw.android
import android.app.assist.AssistContent
import android.net.Uri
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
@ -14,6 +16,7 @@ import javax.inject.Inject
class MainActivity : ComponentActivity() {
@Inject lateinit var urlLauncher: UrlLauncher
private var webUri: String? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
@ -22,7 +25,12 @@ class MainActivity : ComponentActivity() {
setContent {
LobstersApp(
urlLauncher = urlLauncher,
)
) { url -> webUri = url }
}
}
override fun onProvideAssistContent(outContent: AssistContent?) {
super.onProvideAssistContent(outContent)
webUri?.let { outContent?.webUri = Uri.parse(it) }
}
}

View file

@ -44,6 +44,7 @@ private const val ScrollDelta = 50
fun LobstersApp(
viewModel: ClawViewModel = viewModel(),
urlLauncher: UrlLauncher,
setWebUri: (String) -> Unit,
) {
val copydown = remember { CopyDown() }
val systemUiController = rememberSystemUiController()
@ -117,6 +118,7 @@ fun LobstersApp(
) { paddingValues ->
NavHost(navController, startDestination = Destinations.Hottest) {
composable(Destinations.Hottest) {
setWebUri("https://lobste.rs/")
HottestPosts(
items,
listState,
@ -127,8 +129,10 @@ fun LobstersApp(
)
}
composable(Destinations.Comments.format("{postId}")) { backStackEntry ->
val postId = requireNotNull(backStackEntry.arguments?.getString("postId"))
setWebUri("https://lobste.rs/s/$postId")
CommentsPage(
postId = requireNotNull(backStackEntry.arguments?.getString("postId")),
postId = postId,
getDetails = viewModel::getPostComments,
htmlToMarkdown = { source -> copydown.convert(source) },
paddingValues = paddingValues,