Skip to content

Commit ce5f922

Browse files
fix: speech to text button on chat activity not working #2469
Add restoreActivityState() in STTFragment to make invisible views visible and perform other tasks
1 parent 17b05dc commit ce5f922

File tree

2 files changed

+20
-11
lines changed

2 files changed

+20
-11
lines changed

app/src/main/java/org/fossasia/susi/ai/chat/ChatActivity.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -639,4 +639,8 @@ class ChatActivity : AppCompatActivity(), IChatView {
639639
companion object {
640640
val ALARM = "ALARM"
641641
}
642+
643+
fun setChatSearchInputGone() {
644+
chatSearchInput.visibility = View.GONE
645+
}
642646
}

app/src/main/java/org/fossasia/susi/ai/chat/STTfragment.kt

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -113,13 +113,7 @@ class STTFragment : Fragment() {
113113
val thisActivity = activity
114114
if (thisActivity is ChatActivity) thisActivity.setText(voiceResults[0])
115115
recognizer.destroy()
116-
if ((activity as ChatActivity).recordingThread != null) {
117-
chatPresenter.startHotwordDetection()
118-
}
119-
(activity as ChatActivity).fabsetting.show()
120-
activity?.searchChat?.show()
121-
activity?.voiceSearchChat?.show()
122-
activity?.btnSpeak?.isEnabled = true
116+
restoreActivityState()
123117
activity?.supportFragmentManager?.popBackStackImmediate()
124118
}
125119

@@ -132,10 +126,7 @@ class STTFragment : Fragment() {
132126
Toast.makeText(activity?.applicationContext, "Could not recognize speech, try again.", Toast.LENGTH_SHORT).show()
133127
speechProgress?.onResultOrOnError()
134128
recognizer.destroy()
135-
activity?.fabsetting?.show()
136-
activity?.searchChat?.show()
137-
activity?.voiceSearchChat?.show()
138-
activity?.btnSpeak?.isEnabled = true
129+
restoreActivityState()
139130
activity?.supportFragmentManager?.popBackStackImmediate()
140131
}
141132

@@ -170,6 +161,18 @@ class STTFragment : Fragment() {
170161
recognizer.startListening(intent)
171162
}
172163

164+
private fun restoreActivityState() {
165+
if ((activity as ChatActivity).recordingThread != null) {
166+
chatPresenter.startHotwordDetection()
167+
}
168+
(activity as ChatActivity).fabsetting.show()
169+
activity?.searchChat?.show()
170+
activity?.voiceSearchChat?.show()
171+
activity?.btnSpeak?.isEnabled = true
172+
(activity as ChatActivity)?.setChatSearchInputGone()
173+
recognizer?.destroy()
174+
}
175+
173176
override fun onPause() {
174177
super.onPause()
175178
if (thisActivity is ChatActivity) {
@@ -185,6 +188,8 @@ class STTFragment : Fragment() {
185188

186189
override fun onDestroyView() {
187190
super.onDestroyView()
191+
restoreActivityState()
192+
activity?.supportFragmentManager?.popBackStack()
188193
mainHandler.removeCallbacks(runnable)
189194
subHandler.removeCallbacks(delayRunnable)
190195
}

0 commit comments

Comments
 (0)