This commit is contained in:
Parneet Singh 2025-01-08 08:19:59 +05:30 committed by GitHub
commit badb937c41
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 26 additions and 5 deletions

View file

@ -9,6 +9,7 @@ import android.content.Intent
import android.database.sqlite.SQLiteException
import android.os.Build
import android.os.Process
import android.speech.SpeechRecognizer
import android.util.Log
import androidx.multidex.MultiDexApplication
import com.facebook.drawee.backends.pipeline.Fresco
@ -91,6 +92,13 @@ class CommonsApplication : MultiDexApplication() {
@Inject
lateinit var contributionDao: ContributionDao
/**
* Flag to check if speech recognition is available.
*/
val isVoiceRecognitionAvailable by lazy {
SpeechRecognizer.isRecognitionAvailable(this)
}
/**
* Used to declare and initialize various components and dependencies
*/

View file

@ -121,7 +121,8 @@ class DescriptionEditActivity :
savedLanguageValue,
descriptionAndCaptions,
recentLanguagesDao,
voiceInputResultLauncher
voiceInputResultLauncher,
CommonsApplication.instance.isVoiceRecognitionAvailable
)
uploadMediaDetailAdapter.setCallback { titleStringID: Int, messageStringId: Int ->
showInfoAlert(

View file

@ -60,27 +60,35 @@ public class UploadMediaDetailAdapter extends
private Activity activity;
private final ActivityResultLauncher<Intent> voiceInputResultLauncher;
private SelectedVoiceIcon selectedVoiceIcon;
boolean isVoiceRecognitionAvailable;
private RowItemDescriptionBinding binding;
public UploadMediaDetailAdapter(Fragment fragment, String savedLanguageValue,
RecentLanguagesDao recentLanguagesDao, ActivityResultLauncher<Intent> voiceInputResultLauncher) {
RecentLanguagesDao recentLanguagesDao,
ActivityResultLauncher<Intent> voiceInputResultLauncher,
boolean isVoiceRecognitionAvailable) {
uploadMediaDetails = new ArrayList<>();
selectedLanguages = new HashMap<>();
this.savedLanguageValue = savedLanguageValue;
this.recentLanguagesDao = recentLanguagesDao;
this.fragment = fragment;
this.voiceInputResultLauncher = voiceInputResultLauncher;
this.isVoiceRecognitionAvailable = isVoiceRecognitionAvailable;
}
public UploadMediaDetailAdapter(Activity activity, final String savedLanguageValue,
List<UploadMediaDetail> uploadMediaDetails, RecentLanguagesDao recentLanguagesDao, ActivityResultLauncher<Intent> voiceInputResultLauncher) {
List<UploadMediaDetail> uploadMediaDetails,
RecentLanguagesDao recentLanguagesDao,
ActivityResultLauncher<Intent> voiceInputResultLauncher,
boolean isVoiceRecognitionAvailable) {
this.uploadMediaDetails = uploadMediaDetails;
selectedLanguages = new HashMap<>();
this.savedLanguageValue = savedLanguageValue;
this.recentLanguagesDao = recentLanguagesDao;
this.activity = activity;
this.voiceInputResultLauncher = voiceInputResultLauncher;
this.isVoiceRecognitionAvailable = isVoiceRecognitionAvailable;
}
public void setCallback(Callback callback) {
@ -274,6 +282,7 @@ public class UploadMediaDetailAdapter extends
selectedVoiceIcon = SelectedVoiceIcon.CAPTION;
startSpeechInput(descriptionLanguages.getText().toString());
});
captionInputLayout.setEndIconVisible(isVoiceRecognitionAvailable);
descInputLayout.setEndIconMode(TextInputLayout.END_ICON_CUSTOM);
descInputLayout.setEndIconDrawable(R.drawable.baseline_keyboard_voice);
descInputLayout.setEndIconOnClickListener(v -> {
@ -281,6 +290,7 @@ public class UploadMediaDetailAdapter extends
selectedVoiceIcon = SelectedVoiceIcon.DESCRIPTION;
startSpeechInput(descriptionLanguages.getText().toString());
});
descInputLayout.setEndIconVisible(isVoiceRecognitionAvailable);
if (position == 0) {
removeButton.setVisibility(View.GONE);

View file

@ -26,6 +26,7 @@ import androidx.exifinterface.media.ExifInterface;
import androidx.recyclerview.widget.LinearLayoutManager;
import fr.free.nrw.commons.CameraPosition;
import fr.free.nrw.commons.locationpicker.LocationPicker;
import fr.free.nrw.commons.CommonsApplication;
import fr.free.nrw.commons.R;
import fr.free.nrw.commons.contributions.MainActivity;
import fr.free.nrw.commons.databinding.FragmentUploadMediaDetailFragmentBinding;
@ -295,7 +296,8 @@ public class UploadMediaDetailFragment extends UploadBaseFragment implements
*/
private void initRecyclerView() {
uploadMediaDetailAdapter = new UploadMediaDetailAdapter(this,
defaultKvStore.getString(Prefs.DESCRIPTION_LANGUAGE, ""), recentLanguagesDao, voiceInputResultLauncher);
defaultKvStore.getString(Prefs.DESCRIPTION_LANGUAGE, ""), recentLanguagesDao, voiceInputResultLauncher,
CommonsApplication.getInstance().isVoiceRecognitionAvailable());
uploadMediaDetailAdapter.setCallback(this::showInfoAlert);
uploadMediaDetailAdapter.setEventListener(this);
binding.rvDescriptions.setLayoutManager(new LinearLayoutManager(getContext()));

View file

@ -78,7 +78,7 @@ class UploadMediaDetailAdapterUnitTest {
uploadMediaDetails = mutableListOf(uploadMediaDetail, uploadMediaDetail)
activity = Robolectric.buildActivity(UploadActivity::class.java).get()
fragment = mock(UploadMediaDetailFragment::class.java)
adapter = UploadMediaDetailAdapter(fragment, "", recentLanguagesDao, mockResultLauncher)
adapter = UploadMediaDetailAdapter(fragment, "", recentLanguagesDao, mockResultLauncher, true)
context = ApplicationProvider.getApplicationContext()
Whitebox.setInternalState(adapter, "uploadMediaDetails", uploadMediaDetails)
Whitebox.setInternalState(adapter, "eventListener", eventListener)