mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-28 13:23:58 +01:00
Merge 471716e267 into fdbe504ca9
This commit is contained in:
commit
badb937c41
5 changed files with 26 additions and 5 deletions
|
|
@ -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
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -121,7 +121,8 @@ class DescriptionEditActivity :
|
|||
savedLanguageValue,
|
||||
descriptionAndCaptions,
|
||||
recentLanguagesDao,
|
||||
voiceInputResultLauncher
|
||||
voiceInputResultLauncher,
|
||||
CommonsApplication.instance.isVoiceRecognitionAvailable
|
||||
)
|
||||
uploadMediaDetailAdapter.setCallback { titleStringID: Int, messageStringId: Int ->
|
||||
showInfoAlert(
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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()));
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue