From 480d412e4cc7913a4258602ace947ff3fdf3fa82 Mon Sep 17 00:00:00 2001 From: Nik Clayton Date: Fri, 7 Jul 2023 18:50:19 +0200 Subject: [PATCH] Set default alt-text to media label when pasting images (#3800) GBoard and other IME's support pasting images, which are converted to attachments. Sometimes these have labels that describe the image. If present, set it as the default alt-text. Fixes #3799 --- .../tusky/components/compose/ComposeActivity.kt | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/keylesspalace/tusky/components/compose/ComposeActivity.kt b/app/src/main/java/com/keylesspalace/tusky/components/compose/ComposeActivity.kt index d5862dad..c3476821 100644 --- a/app/src/main/java/com/keylesspalace/tusky/components/compose/ComposeActivity.kt +++ b/app/src/main/java/com/keylesspalace/tusky/components/compose/ComposeActivity.kt @@ -943,7 +943,10 @@ class ComposeActivity : val split = contentInfo.partition { item: ClipData.Item -> item.uri != null } split.first?.let { content -> for (i in 0 until content.clip.itemCount) { - pickMedia(content.clip.getItemAt(i).uri) + pickMedia( + content.clip.getItemAt(i).uri, + contentInfo.clip.description.label as String? + ) } } return split.second @@ -1064,9 +1067,9 @@ class ComposeActivity : viewModel.removeMediaFromQueue(item) } - private fun pickMedia(uri: Uri) { + private fun pickMedia(uri: Uri, description: String? = null) { lifecycleScope.launch { - viewModel.pickMedia(uri).onFailure { throwable -> + viewModel.pickMedia(uri, description).onFailure { throwable -> val errorString = when (throwable) { is FileSizeException -> { val decimalFormat = DecimalFormat("0.##")