search: speech recognizer 1 kinda fix

This commit is contained in:
Yuriy Liskov
2022-08-14 19:05:49 +03:00
parent a2bf5193c9
commit 1ec09ecebe
4 changed files with 10 additions and 0 deletions

View File

@@ -459,4 +459,5 @@
<string name="subtitle_yellow_black">Жёлтые на чёрном фоне</string>
<string name="player_pixel_ratio">Соотношение сторон пикселя</string>
<string name="color_scheme_dark_grey_monochrome">Тёмно-серая (монохромная)</string>
<string name="disable_mic_permission">Пожалуйста, отключите доступ к микрофону для приложения, чтобы этот распознаватель работал правильно.</string>
</resources>

View File

@@ -459,4 +459,5 @@
<string name="subtitle_yellow_black">Жовті на чорному фоні</string>
<string name="player_pixel_ratio">Співвідношення сторін пікселя</string>
<string name="color_scheme_dark_grey_monochrome">Темно-сіра (монохромна)</string>
<string name="disable_mic_permission">Будь ласка, вимкніть доступ до мікрофона для програми, щоб цей розпізнавач працював належним чином.</string>
</resources>

View File

@@ -467,4 +467,5 @@
<string name="subtitle_yellow_black">Yellow on black background</string>
<string name="player_pixel_ratio">Pixel ratio</string>
<string name="color_scheme_dark_grey_monochrome">Dark Grey (monochrome)</string>
<string name="disable_mic_permission">Please, disable microphone access for the app in order this recognizer to work properly.</string>
</resources>

View File

@@ -16,12 +16,14 @@ import androidx.leanback.widget.ListRowPresenter;
import androidx.leanback.widget.ObjectAdapter;
import androidx.leanback.widget.RowPresenter.ViewHolder;
import androidx.leanback.widget.SpeechRecognitionCallback;
import com.liskovsoft.sharedutils.helpers.MessageHelpers;
import com.liskovsoft.sharedutils.helpers.PermissionHelpers;
import com.liskovsoft.sharedutils.mylogger.Log;
import com.liskovsoft.smartyoutubetv2.common.app.models.search.SearchTagsProvider;
import com.liskovsoft.smartyoutubetv2.common.app.models.search.vineyard.Tag;
import com.liskovsoft.smartyoutubetv2.common.app.views.SearchView;
import com.liskovsoft.smartyoutubetv2.common.prefs.SearchData;
import com.liskovsoft.smartyoutubetv2.tv.R;
import com.liskovsoft.smartyoutubetv2.tv.adapter.vineyard.PaginationAdapter;
import com.liskovsoft.smartyoutubetv2.tv.adapter.vineyard.TagAdapter;
import com.liskovsoft.smartyoutubetv2.tv.presenter.CustomListRowPresenter;
@@ -148,6 +150,7 @@ public abstract class SearchTagsFragmentBase extends SearchSupportFragment
switch (SearchData.instance(getContext()).getSpeechRecognizerType()) {
case SearchData.SPEECH_RECOGNIZER_SYSTEM:
// Do nothing unless we have old api.
// Internal recognizer needs API >= 23. See: androidx.leanback.widget.SearchBar.startRecognition()
if (Build.VERSION.SDK_INT < 23) {
setSpeechRecognitionCallback(mDefaultCallback);
@@ -251,6 +254,10 @@ public abstract class SearchTagsFragmentBase extends SearchSupportFragment
@SuppressWarnings("deprecation")
private final SpeechRecognitionCallback mDefaultCallback = () -> {
if (isAdded()) {
if (PermissionHelpers.hasMicPermissions(getContext())) {
MessageHelpers.showMessage(getContext(), R.string.disable_mic_permission);
}
try {
startActivityForResult(getRecognizerIntent(), REQUEST_SPEECH);
} catch (ActivityNotFoundException e) {