@@ -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