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 package dev.msfjarvis.claw.android
import android.app.assist.AssistContent
import android.net.Uri
import android.os.Bundle import android.os.Bundle
import androidx.activity.ComponentActivity import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent import androidx.activity.compose.setContent
@ -14,6 +16,7 @@ import javax.inject.Inject
class MainActivity : ComponentActivity() { class MainActivity : ComponentActivity() {
@Inject lateinit var urlLauncher: UrlLauncher @Inject lateinit var urlLauncher: UrlLauncher
private var webUri: String? = null
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
@ -22,7 +25,12 @@ class MainActivity : ComponentActivity() {
setContent { setContent {
LobstersApp( LobstersApp(
urlLauncher = urlLauncher, 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( fun LobstersApp(
viewModel: ClawViewModel = viewModel(), viewModel: ClawViewModel = viewModel(),
urlLauncher: UrlLauncher, urlLauncher: UrlLauncher,
setWebUri: (String) -> Unit,
) { ) {
val copydown = remember { CopyDown() } val copydown = remember { CopyDown() }
val systemUiController = rememberSystemUiController() val systemUiController = rememberSystemUiController()
@ -117,6 +118,7 @@ fun LobstersApp(
) { paddingValues -> ) { paddingValues ->
NavHost(navController, startDestination = Destinations.Hottest) { NavHost(navController, startDestination = Destinations.Hottest) {
composable(Destinations.Hottest) { composable(Destinations.Hottest) {
setWebUri("https://lobste.rs/")
HottestPosts( HottestPosts(
items, items,
listState, listState,
@ -127,8 +129,10 @@ fun LobstersApp(
) )
} }
composable(Destinations.Comments.format("{postId}")) { backStackEntry -> composable(Destinations.Comments.format("{postId}")) { backStackEntry ->
val postId = requireNotNull(backStackEntry.arguments?.getString("postId"))
setWebUri("https://lobste.rs/s/$postId")
CommentsPage( CommentsPage(
postId = requireNotNull(backStackEntry.arguments?.getString("postId")), postId = postId,
getDetails = viewModel::getPostComments, getDetails = viewModel::getPostComments,
htmlToMarkdown = { source -> copydown.convert(source) }, htmlToMarkdown = { source -> copydown.convert(source) },
paddingValues = paddingValues, paddingValues = paddingValues,