From fe7a2f2a8c98dfb94f35fb51f6ffb12acc795c87 Mon Sep 17 00:00:00 2001 From: Giannis Karyotakis <110292528+karyotakisg@users.noreply.github.com> Date: Sun, 2 Jun 2024 20:36:43 +0300 Subject: [PATCH] Fix voice input bug (#5739) * Fix voice input bug * Add javadocs --------- Co-authored-by: vtalos --- .../upload/UploadMediaDetailAdapter.java | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/fr/free/nrw/commons/upload/UploadMediaDetailAdapter.java b/app/src/main/java/fr/free/nrw/commons/upload/UploadMediaDetailAdapter.java index d7fe5ffd5..6bdc562c2 100644 --- a/app/src/main/java/fr/free/nrw/commons/upload/UploadMediaDetailAdapter.java +++ b/app/src/main/java/fr/free/nrw/commons/upload/UploadMediaDetailAdapter.java @@ -160,18 +160,30 @@ public class UploadMediaDetailAdapter extends } } + /** + * Handles the result of the speech input by processing the spoken text. + * If the spoken text is not empty, it capitalizes the first letter of the spoken text + * and updates the appropriate field (caption or description) of the current + * UploadMediaDetail based on the selected voice icon. + * Finally, it notifies the adapter that the data set has changed. + * + * @param spokenText the text input received from speech recognition. + */ public void handleSpeechResult(String spokenText) { if (!spokenText.isEmpty()) { String spokenTextCapitalized = spokenText.substring(0, 1).toUpperCase() + spokenText.substring(1); if (currentPosition < uploadMediaDetails.size()) { UploadMediaDetail uploadMediaDetail = uploadMediaDetails.get(currentPosition); - if (selectedVoiceIcon == SelectedVoiceIcon.CAPTION) { - uploadMediaDetail.setCaptionText(spokenTextCapitalized); - } else { - uploadMediaDetail.setDescriptionText(spokenTextCapitalized); + switch (selectedVoiceIcon) { + case CAPTION: + uploadMediaDetail.setCaptionText(spokenTextCapitalized); + break; + case DESCRIPTION: + uploadMediaDetail.setDescriptionText(spokenTextCapitalized); + break; } - notifyItemChanged(currentPosition); + notifyDataSetChanged(); } } }