Display Toast on Startup, and on STT clicked.

Moved the check on STT provider to only display toast if there is no provider.
Disabled STT button when there is no provider.
This commit is contained in:
Inhishonor
2025-02-21 13:36:39 -08:00
parent e4cb42089b
commit 332f58ceb2
@@ -237,7 +237,6 @@ class ComposeActivity : QkThemedActivity(), ComposeView {
} }
return activities.isNotEmpty() return activities.isNotEmpty()
} }
private val speechResultLauncher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result -> private val speechResultLauncher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
if (result.resultCode != Activity.RESULT_OK) if (result.resultCode != Activity.RESULT_OK)
return@registerForActivityResult return@registerForActivityResult
@@ -257,19 +256,20 @@ class ComposeActivity : QkThemedActivity(), ComposeView {
message.setSelection(message.text.length) message.setSelection(message.text.length)
message.requestFocus() message.requestFocus()
} }
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
AndroidInjection.inject(this) AndroidInjection.inject(this)
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
if (!isSpeechRecognitionAvailable()) {
// Show a message when there is no STT provider
Toast.makeText(this, getString(R.string.stt_toast_no_provider), Toast.LENGTH_SHORT).show()
}
setContentView(R.layout.compose_activity) setContentView(R.layout.compose_activity)
showBackButton(true) showBackButton(true)
viewModel.bindView(this) viewModel.bindView(this)
val isSpeechRecognitionAvailable = isSpeechRecognitionAvailable()
if (isSpeechRecognitionAvailable) {
contentView.layoutTransition = LayoutTransition().apply {
disableTransitionType(LayoutTransition.CHANGING)
}
contentView.layoutTransition = LayoutTransition().apply {
disableTransitionType(LayoutTransition.CHANGING)
}
chipsAdapter.view = chips chipsAdapter.view = chips
chips.itemAnimator = null chips.itemAnimator = null
@@ -321,12 +321,13 @@ class ComposeActivity : QkThemedActivity(), ComposeView {
when (event.action) { when (event.action) {
ACTION_DROP -> { ACTION_DROP -> {
speechToTextFrame.x = (event.x - (speechToTextFrame.width / 2)) speechToTextFrame.x = (event.x - (speechToTextFrame.width / 2))
speechToTextFrame.y =(event.y - (speechToTextFrame.height / 2)) speechToTextFrame.y = (event.y - (speechToTextFrame.height / 2))
// get offset from root view as a percentage of root view for saving // get offset from root view as a percentage of root view for saving
prefs.showSttOffsetX.set((speechToTextFrame.x - contentView.x) / contentView.width) prefs.showSttOffsetX.set((speechToTextFrame.x - contentView.x) / contentView.width)
prefs.showSttOffsetY.set((speechToTextFrame.y - contentView.y) / contentView.height) prefs.showSttOffsetY.set((speechToTextFrame.y - contentView.y) / contentView.height)
} }
ACTION_DRAG_ENDED, ACTION_DRAG_EXITED -> { ACTION_DRAG_ENDED, ACTION_DRAG_EXITED -> {
speechToTextFrame.isVisible = true speechToTextFrame.isVisible = true
} }
@@ -368,7 +369,8 @@ class ComposeActivity : QkThemedActivity(), ComposeView {
.autoDisposable(scope()) .autoDisposable(scope())
.subscribe { .subscribe {
audioMsgRecord.isVisible = it audioMsgRecord.isVisible = it
audioMsgDuration.isVisible = it // chronometer follows record button visibility audioMsgDuration.isVisible =
it // chronometer follows record button visibility
audioMsgBluetooth.isVisible = !it audioMsgBluetooth.isVisible = !it
} }
@@ -397,12 +399,14 @@ class ComposeActivity : QkThemedActivity(), ComposeView {
} }
audioMsgPlayerSeekBar.isEnabled = true audioMsgPlayerSeekBar.isEnabled = true
} }
QkMediaPlayer.PlayingState.Paused -> { QkMediaPlayer.PlayingState.Paused -> {
audioMsgPlayerPlayPause.tag = QkMediaPlayer.PlayingState.Paused audioMsgPlayerPlayPause.tag = QkMediaPlayer.PlayingState.Paused
QkMediaPlayer.pause() QkMediaPlayer.pause()
audioMsgPlayerPlayPause.setImageResource(R.drawable.exo_icon_play) audioMsgPlayerPlayPause.setImageResource(R.drawable.exo_icon_play)
seekBarUpdater?.dispose() seekBarUpdater?.dispose()
} }
else -> { else -> {
audioMsgPlayerPlayPause.tag = QkMediaPlayer.PlayingState.Stopped audioMsgPlayerPlayPause.tag = QkMediaPlayer.PlayingState.Stopped
QkMediaPlayer.reset() QkMediaPlayer.reset()
@@ -413,7 +417,6 @@ class ComposeActivity : QkThemedActivity(), ComposeView {
} }
} }
} }
// audio msg player seek bar handler // audio msg player seek bar handler
audioMsgPlayerSeekBar.setOnSeekBarChangeListener( audioMsgPlayerSeekBar.setOnSeekBarChangeListener(
object : SeekBar.OnSeekBarChangeListener { object : SeekBar.OnSeekBarChangeListener {
@@ -428,9 +431,6 @@ class ComposeActivity : QkThemedActivity(), ComposeView {
) )
window.callback = ComposeWindowCallback(window.callback, this) window.callback = ComposeWindowCallback(window.callback, this)
} else {
Toast.makeText(this, getString(R.string.stt_toast_no_provider), Toast.LENGTH_SHORT).show()
}
} }
override fun onStart() { override fun onStart() {
@@ -667,15 +667,18 @@ class ComposeActivity : QkThemedActivity(), ComposeView {
} }
override fun startSpeechRecognition() { override fun startSpeechRecognition() {
startActivityForResult( if (isSpeechRecognitionAvailable()) {
Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH).putExtra( startActivityForResult(
RecognizerIntent.EXTRA_LANGUAGE_MODEL, Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH).putExtra(
RecognizerIntent.LANGUAGE_MODEL_FREE_FORM RecognizerIntent.EXTRA_LANGUAGE_MODEL,
), RecognizerIntent.LANGUAGE_MODEL_FREE_FORM
// include below if want a custom message that the STT can (optionally) display ),
// .putExtra(RecognizerIntent.EXTRA_PROMPT, getString(R.string.stt_toast_extra_prompt)) ComposeView.SpeechRecognitionRequestCode
ComposeView.SpeechRecognitionRequestCode )
) } else {
// Display a message or handle the lack of STT provider in a way that suits your app
Toast.makeText(this, getString(R.string.stt_toast_no_provider), Toast.LENGTH_SHORT).show()
}
} }
override fun themeChanged() { override fun themeChanged() {