Notes widget: add share action

This commit is contained in:
MM20 2023-05-23 16:53:03 +02:00
parent a294980627
commit e8d0bb5d63
No known key found for this signature in database
GPG Key ID: 0B61A8F2DEAFA389
2 changed files with 16 additions and 1 deletions

View File

@ -1,5 +1,6 @@
package de.mm20.launcher2.ui.launcher.widgets.notes
import android.content.Intent
import androidx.activity.compose.rememberLauncherForActivityResult
import androidx.activity.result.contract.ActivityResultContracts
import androidx.compose.animation.AnimatedVisibility
@ -15,6 +16,7 @@ import androidx.compose.material.icons.rounded.Add
import androidx.compose.material.icons.rounded.Delete
import androidx.compose.material.icons.rounded.MoreVert
import androidx.compose.material.icons.rounded.SaveAlt
import androidx.compose.material.icons.rounded.Share
import androidx.compose.material3.DropdownMenu
import androidx.compose.material3.DropdownMenuItem
import androidx.compose.material3.Icon
@ -149,6 +151,20 @@ fun NotesWidget(
showMenu = false
},
)
DropdownMenuItem(
text = { Text(stringResource(R.string.menu_share)) },
leadingIcon = {
Icon(Icons.Rounded.Share, null)
},
onClick = {
Intent(Intent.ACTION_SEND).apply {
type = "text/plain"
putExtra(Intent.EXTRA_TEXT, text.text)
context.startActivity(Intent.createChooser(this, null))
}
showMenu = false
},
)
DropdownMenuItem(
text = { Text(stringResource(R.string.notes_widget_action_dismiss)) },
leadingIcon = {

View File

@ -53,7 +53,6 @@ class NotesWidgetVM(
fun exportNote(context: Context, uri: Uri) {
viewModelScope.launch(Dispatchers.IO) {
val text = noteText.value.text
Log.d("MM20", text)
val outputStream = context.contentResolver.openOutputStream(uri)
outputStream?.use {
it.write(text.toByteArray())