Fixes #5439 by capitalizing first letter of voice input (#5450)

This commit is contained in:
Kanahia 2024-01-19 10:07:39 +05:30 committed by GitHub
parent 1ebbe63fc7
commit b7323d0913
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -35,7 +35,6 @@ import fr.free.nrw.commons.utils.AbstractTextWatcher;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Locale;
import java.util.Objects; import java.util.Objects;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import timber.log.Timber; import timber.log.Timber;
@ -146,9 +145,9 @@ public class UploadMediaDetailAdapter extends
locale locale
); );
try { try {
if (activity == null){ if (activity == null) {
fragment.startActivityForResult(intent, REQUEST_CODE_FOR_VOICE_INPUT); fragment.startActivityForResult(intent, REQUEST_CODE_FOR_VOICE_INPUT);
}else { } else {
activity.startActivityForResult(intent, REQUEST_CODE_FOR_VOICE_INPUT); activity.startActivityForResult(intent, REQUEST_CODE_FOR_VOICE_INPUT);
} }
} catch (Exception e) { } catch (Exception e) {
@ -157,14 +156,18 @@ public class UploadMediaDetailAdapter extends
} }
public void handleSpeechResult(String spokenText) { public void handleSpeechResult(String spokenText) {
if (currentPosition < uploadMediaDetails.size()) { if (!spokenText.isEmpty()) {
UploadMediaDetail uploadMediaDetail = uploadMediaDetails.get(currentPosition); String spokenTextCapitalized =
if (selectedVoiceIcon == SelectedVoiceIcon.CAPTION){ spokenText.substring(0, 1).toUpperCase() + spokenText.substring(1);
uploadMediaDetail.setCaptionText(spokenText); if (currentPosition < uploadMediaDetails.size()) {
}else { UploadMediaDetail uploadMediaDetail = uploadMediaDetails.get(currentPosition);
uploadMediaDetail.setDescriptionText(spokenText); if (selectedVoiceIcon == SelectedVoiceIcon.CAPTION) {
uploadMediaDetail.setCaptionText(spokenTextCapitalized);
} else {
uploadMediaDetail.setDescriptionText(spokenTextCapitalized);
}
notifyItemChanged(currentPosition);
} }
notifyItemChanged(currentPosition);
} }
} }
@ -555,12 +558,15 @@ public class UploadMediaDetailAdapter extends
} }
public interface Callback { public interface Callback {
void showAlert(int mediaDetailDescription, int descriptionInfo); void showAlert(int mediaDetailDescription, int descriptionInfo);
} }
public interface EventListener { public interface EventListener {
void onPrimaryCaptionTextChange(boolean isNotEmpty); void onPrimaryCaptionTextChange(boolean isNotEmpty);
} }
enum SelectedVoiceIcon { enum SelectedVoiceIcon {
CAPTION, CAPTION,
DESCRIPTION DESCRIPTION