From 7b68feb311007f4651c5c586eb305a9f3ed98a5d Mon Sep 17 00:00:00 2001 From: Armin Friedl Date: Sun, 18 Feb 2024 22:46:03 +0100 Subject: [PATCH] Share intent --- .../friedl/android/woot/ui/WootTextList.kt | 31 +++++++++++++++++-- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/net/friedl/android/woot/ui/WootTextList.kt b/app/src/main/java/net/friedl/android/woot/ui/WootTextList.kt index 8482a5b..9e3f732 100644 --- a/app/src/main/java/net/friedl/android/woot/ui/WootTextList.kt +++ b/app/src/main/java/net/friedl/android/woot/ui/WootTextList.kt @@ -1,5 +1,6 @@ package net.friedl.android.woot.ui +import android.content.Intent import android.widget.Toast import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.fillMaxWidth @@ -114,9 +115,11 @@ fun WootTextCardDetail( Text( text, modifier = modifier.weight(0.8f, fill = true) ) - IconButton(onClick = {}, modifier = modifier.weight(0.1f)) { - Icon(Icons.Default.Share, contentDescription = "Share") - } + + ShareTextButton( + text, + modifier= modifier.weight(0.1f) + ) CopyTextButton( text, @@ -146,4 +149,26 @@ fun CopyTextButton( contentDescription = "Copy to clipboard." ) } +} + +@Composable +fun ShareTextButton( + text: String, + modifier: Modifier = Modifier +) { + val sendIntent: Intent = Intent().apply { + action = Intent.ACTION_SEND + putExtra(Intent.EXTRA_TEXT, text) + type = "text/plain" + } + val shareIntent = Intent.createChooser(sendIntent, null) + val context = LocalContext.current + + IconButton( + onClick = { + context.startActivity(shareIntent) + }, modifier = modifier + ) { + Icon(Icons.Default.Share, contentDescription = "Share") + } } \ No newline at end of file