mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-29 22:03:55 +01:00
hide voice input if service not available
Signed-off-by: parneet-guraya <gurayaparneet@gmail.com>
This commit is contained in:
parent
5500b03976
commit
471716e267
5 changed files with 26 additions and 5 deletions
|
|
@ -9,6 +9,7 @@ import android.content.Intent
|
||||||
import android.database.sqlite.SQLiteException
|
import android.database.sqlite.SQLiteException
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.os.Process
|
import android.os.Process
|
||||||
|
import android.speech.SpeechRecognizer
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import androidx.multidex.MultiDexApplication
|
import androidx.multidex.MultiDexApplication
|
||||||
import com.facebook.drawee.backends.pipeline.Fresco
|
import com.facebook.drawee.backends.pipeline.Fresco
|
||||||
|
|
@ -91,6 +92,13 @@ class CommonsApplication : MultiDexApplication() {
|
||||||
@Inject
|
@Inject
|
||||||
lateinit var contributionDao: ContributionDao
|
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
|
* Used to declare and initialize various components and dependencies
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -121,7 +121,8 @@ class DescriptionEditActivity :
|
||||||
savedLanguageValue,
|
savedLanguageValue,
|
||||||
descriptionAndCaptions,
|
descriptionAndCaptions,
|
||||||
recentLanguagesDao,
|
recentLanguagesDao,
|
||||||
voiceInputResultLauncher
|
voiceInputResultLauncher,
|
||||||
|
CommonsApplication.instance.isVoiceRecognitionAvailable
|
||||||
)
|
)
|
||||||
uploadMediaDetailAdapter.setCallback { titleStringID: Int, messageStringId: Int ->
|
uploadMediaDetailAdapter.setCallback { titleStringID: Int, messageStringId: Int ->
|
||||||
showInfoAlert(
|
showInfoAlert(
|
||||||
|
|
|
||||||
|
|
@ -59,27 +59,35 @@ public class UploadMediaDetailAdapter extends
|
||||||
private Activity activity;
|
private Activity activity;
|
||||||
private final ActivityResultLauncher<Intent> voiceInputResultLauncher;
|
private final ActivityResultLauncher<Intent> voiceInputResultLauncher;
|
||||||
private SelectedVoiceIcon selectedVoiceIcon;
|
private SelectedVoiceIcon selectedVoiceIcon;
|
||||||
|
boolean isVoiceRecognitionAvailable;
|
||||||
|
|
||||||
private RowItemDescriptionBinding binding;
|
private RowItemDescriptionBinding binding;
|
||||||
|
|
||||||
public UploadMediaDetailAdapter(Fragment fragment, String savedLanguageValue,
|
public UploadMediaDetailAdapter(Fragment fragment, String savedLanguageValue,
|
||||||
RecentLanguagesDao recentLanguagesDao, ActivityResultLauncher<Intent> voiceInputResultLauncher) {
|
RecentLanguagesDao recentLanguagesDao,
|
||||||
|
ActivityResultLauncher<Intent> voiceInputResultLauncher,
|
||||||
|
boolean isVoiceRecognitionAvailable) {
|
||||||
uploadMediaDetails = new ArrayList<>();
|
uploadMediaDetails = new ArrayList<>();
|
||||||
selectedLanguages = new HashMap<>();
|
selectedLanguages = new HashMap<>();
|
||||||
this.savedLanguageValue = savedLanguageValue;
|
this.savedLanguageValue = savedLanguageValue;
|
||||||
this.recentLanguagesDao = recentLanguagesDao;
|
this.recentLanguagesDao = recentLanguagesDao;
|
||||||
this.fragment = fragment;
|
this.fragment = fragment;
|
||||||
this.voiceInputResultLauncher = voiceInputResultLauncher;
|
this.voiceInputResultLauncher = voiceInputResultLauncher;
|
||||||
|
this.isVoiceRecognitionAvailable = isVoiceRecognitionAvailable;
|
||||||
}
|
}
|
||||||
|
|
||||||
public UploadMediaDetailAdapter(Activity activity, final String savedLanguageValue,
|
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;
|
this.uploadMediaDetails = uploadMediaDetails;
|
||||||
selectedLanguages = new HashMap<>();
|
selectedLanguages = new HashMap<>();
|
||||||
this.savedLanguageValue = savedLanguageValue;
|
this.savedLanguageValue = savedLanguageValue;
|
||||||
this.recentLanguagesDao = recentLanguagesDao;
|
this.recentLanguagesDao = recentLanguagesDao;
|
||||||
this.activity = activity;
|
this.activity = activity;
|
||||||
this.voiceInputResultLauncher = voiceInputResultLauncher;
|
this.voiceInputResultLauncher = voiceInputResultLauncher;
|
||||||
|
this.isVoiceRecognitionAvailable = isVoiceRecognitionAvailable;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCallback(Callback callback) {
|
public void setCallback(Callback callback) {
|
||||||
|
|
@ -273,6 +281,7 @@ public class UploadMediaDetailAdapter extends
|
||||||
selectedVoiceIcon = SelectedVoiceIcon.CAPTION;
|
selectedVoiceIcon = SelectedVoiceIcon.CAPTION;
|
||||||
startSpeechInput(descriptionLanguages.getText().toString());
|
startSpeechInput(descriptionLanguages.getText().toString());
|
||||||
});
|
});
|
||||||
|
captionInputLayout.setEndIconVisible(isVoiceRecognitionAvailable);
|
||||||
descInputLayout.setEndIconMode(TextInputLayout.END_ICON_CUSTOM);
|
descInputLayout.setEndIconMode(TextInputLayout.END_ICON_CUSTOM);
|
||||||
descInputLayout.setEndIconDrawable(R.drawable.baseline_keyboard_voice);
|
descInputLayout.setEndIconDrawable(R.drawable.baseline_keyboard_voice);
|
||||||
descInputLayout.setEndIconOnClickListener(v -> {
|
descInputLayout.setEndIconOnClickListener(v -> {
|
||||||
|
|
@ -280,6 +289,7 @@ public class UploadMediaDetailAdapter extends
|
||||||
selectedVoiceIcon = SelectedVoiceIcon.DESCRIPTION;
|
selectedVoiceIcon = SelectedVoiceIcon.DESCRIPTION;
|
||||||
startSpeechInput(descriptionLanguages.getText().toString());
|
startSpeechInput(descriptionLanguages.getText().toString());
|
||||||
});
|
});
|
||||||
|
descInputLayout.setEndIconVisible(isVoiceRecognitionAvailable);
|
||||||
|
|
||||||
if (position == 0) {
|
if (position == 0) {
|
||||||
removeButton.setVisibility(View.GONE);
|
removeButton.setVisibility(View.GONE);
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,7 @@ import androidx.exifinterface.media.ExifInterface;
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||||
import fr.free.nrw.commons.CameraPosition;
|
import fr.free.nrw.commons.CameraPosition;
|
||||||
import fr.free.nrw.commons.locationpicker.LocationPicker;
|
import fr.free.nrw.commons.locationpicker.LocationPicker;
|
||||||
|
import fr.free.nrw.commons.CommonsApplication;
|
||||||
import fr.free.nrw.commons.R;
|
import fr.free.nrw.commons.R;
|
||||||
import fr.free.nrw.commons.contributions.MainActivity;
|
import fr.free.nrw.commons.contributions.MainActivity;
|
||||||
import fr.free.nrw.commons.databinding.FragmentUploadMediaDetailFragmentBinding;
|
import fr.free.nrw.commons.databinding.FragmentUploadMediaDetailFragmentBinding;
|
||||||
|
|
@ -295,7 +296,8 @@ public class UploadMediaDetailFragment extends UploadBaseFragment implements
|
||||||
*/
|
*/
|
||||||
private void initRecyclerView() {
|
private void initRecyclerView() {
|
||||||
uploadMediaDetailAdapter = new UploadMediaDetailAdapter(this,
|
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.setCallback(this::showInfoAlert);
|
||||||
uploadMediaDetailAdapter.setEventListener(this);
|
uploadMediaDetailAdapter.setEventListener(this);
|
||||||
binding.rvDescriptions.setLayoutManager(new LinearLayoutManager(getContext()));
|
binding.rvDescriptions.setLayoutManager(new LinearLayoutManager(getContext()));
|
||||||
|
|
|
||||||
|
|
@ -78,7 +78,7 @@ class UploadMediaDetailAdapterUnitTest {
|
||||||
uploadMediaDetails = mutableListOf(uploadMediaDetail, uploadMediaDetail)
|
uploadMediaDetails = mutableListOf(uploadMediaDetail, uploadMediaDetail)
|
||||||
activity = Robolectric.buildActivity(UploadActivity::class.java).get()
|
activity = Robolectric.buildActivity(UploadActivity::class.java).get()
|
||||||
fragment = mock(UploadMediaDetailFragment::class.java)
|
fragment = mock(UploadMediaDetailFragment::class.java)
|
||||||
adapter = UploadMediaDetailAdapter(fragment, "", recentLanguagesDao, mockResultLauncher)
|
adapter = UploadMediaDetailAdapter(fragment, "", recentLanguagesDao, mockResultLauncher, true)
|
||||||
context = ApplicationProvider.getApplicationContext()
|
context = ApplicationProvider.getApplicationContext()
|
||||||
Whitebox.setInternalState(adapter, "uploadMediaDetails", uploadMediaDetails)
|
Whitebox.setInternalState(adapter, "uploadMediaDetails", uploadMediaDetails)
|
||||||
Whitebox.setInternalState(adapter, "eventListener", eventListener)
|
Whitebox.setInternalState(adapter, "eventListener", eventListener)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue