Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove garbage alt text from images attached via Gboard #4068

Merged
merged 3 commits into from
Oct 25, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1057,9 +1057,28 @@ class ComposeActivity :
viewModel.removeMediaFromQueue(item)
}

private fun sanitizePickMediaDescription(description: String?): String? {
if (description == null) {
return null
}

// The Gboard android keyboard attaches this text whenever the user
// pastes something from the keyboard's suggestion bar.
// Due to different end user locales, the exact text may vary, but at
// least in version 13.4.08, all of the translations contained the
// string "Gboard".
if ("Gboard" in description) {
return null
}

return description
}

private fun pickMedia(uri: Uri, description: String? = null) {
var sanitizedDescription = sanitizePickMediaDescription(description)

lifecycleScope.launch {
viewModel.pickMedia(uri, description).onFailure { throwable ->
viewModel.pickMedia(uri, sanitizedDescription).onFailure { throwable ->
val errorString = when (throwable) {
is FileSizeException -> {
val decimalFormat = DecimalFormat("0.##")
Expand Down