Skip to content

Commit

Permalink
fix: speech to text button on chat activity not working #2469
Browse files Browse the repository at this point in the history
    Add restoreActivityState() in STTFragment to make invisible views visible and perform other tasks
  • Loading branch information
shubhamkumar1739 committed Feb 15, 2020
1 parent 17b05dc commit 7de9407
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 16 deletions.
4 changes: 4 additions & 0 deletions app/src/main/java/org/fossasia/susi/ai/chat/ChatActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -639,4 +639,8 @@ class ChatActivity : AppCompatActivity(), IChatView {
companion object {
val ALARM = "ALARM"
}

fun setChatSearchInputGone() {
chatSearchInput.visibility = View.GONE
}
}
39 changes: 23 additions & 16 deletions app/src/main/java/org/fossasia/susi/ai/chat/STTfragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,7 @@ class STTFragment : Fragment() {
val thisActivity = activity
if (thisActivity is ChatActivity) thisActivity.setText(voiceResults[0])
recognizer.destroy()
if ((activity as ChatActivity).recordingThread != null) {
chatPresenter.startHotwordDetection()
}
(activity as ChatActivity).fabsetting.show()
activity?.searchChat?.show()
activity?.voiceSearchChat?.show()
activity?.btnSpeak?.isEnabled = true
restoreActivityState()
activity?.supportFragmentManager?.popBackStackImmediate()
}

Expand All @@ -128,15 +122,14 @@ class STTFragment : Fragment() {
}

override fun onError(error: Int) {
Timber.d("Error listening for speech: %s", error)
Toast.makeText(activity?.applicationContext, "Could not recognize speech, try again.", Toast.LENGTH_SHORT).show()
speechProgress?.onResultOrOnError()
recognizer.destroy()
activity?.fabsetting?.show()
activity?.searchChat?.show()
activity?.voiceSearchChat?.show()
activity?.btnSpeak?.isEnabled = true
activity?.supportFragmentManager?.popBackStackImmediate()
if (activity != null) {
Timber.d("Error listening for speech: %s", error)
Toast.makeText(activity?.applicationContext, "Could not recognize speech, try again.", Toast.LENGTH_SHORT).show()
speechProgress?.onResultOrOnError()
recognizer.destroy()
restoreActivityState()
activity?.supportFragmentManager?.popBackStackImmediate()
}
}

override fun onBeginningOfSpeech() {
Expand Down Expand Up @@ -170,6 +163,18 @@ class STTFragment : Fragment() {
recognizer.startListening(intent)
}

private fun restoreActivityState() {
if ((activity as ChatActivity).recordingThread != null) {
chatPresenter.startHotwordDetection()
}
(activity as ChatActivity).fabsetting.show()
activity?.searchChat?.show()
activity?.voiceSearchChat?.show()
activity?.btnSpeak?.isEnabled = true
(activity as ChatActivity)?.setChatSearchInputGone()
recognizer?.destroy()
}

override fun onPause() {
super.onPause()
if (thisActivity is ChatActivity) {
Expand All @@ -185,6 +190,8 @@ class STTFragment : Fragment() {

override fun onDestroyView() {
super.onDestroyView()
restoreActivityState()
activity?.supportFragmentManager?.popBackStack()
mainHandler.removeCallbacks(runnable)
subHandler.removeCallbacks(delayRunnable)
}
Expand Down

0 comments on commit 7de9407

Please sign in to comment.