@@ -18,19 +18,28 @@ class VoiceDialogFragment : DialogFragment(), VoiceInput.VoiceInputPresenter {
1818
1919 val input: VoiceInput = VoiceInput (this )
2020
21- private var suggestions: List < String > = emptyList ()
21+ private var suggestions: Array < out String > = arrayOf ()
2222
2323 fun setSuggestions (vararg suggestions : String ) {
24- this .suggestions = listOf ( * suggestions)
24+ this .suggestions = suggestions
2525 }
2626
2727 // region Lifecycle
28- override fun onCreateView (inflater : LayoutInflater , container : ViewGroup ? , savedInstanceState : Bundle ? ): View ? =
29- inflater.inflate(R .layout.layout_voice_overlay, null )
28+ override fun onCreateView (inflater : LayoutInflater , container : ViewGroup ? , savedInstanceState : Bundle ? ): View ? {
29+ return inflater.inflate(R .layout.layout_voice_overlay, null )
30+ }
31+
32+ override fun onSaveInstanceState (outState : Bundle ) {
33+ super .onSaveInstanceState(outState)
34+ outState.putStringArray(keySuggestions, suggestions)
35+ }
3036
3137 override fun onViewCreated (view : View , savedInstanceState : Bundle ? ) {
3238 closeButton.setOnClickListener { dismiss() }
3339 micButton.setOnClickListener { input.toggleVoiceRecognition() }
40+ savedInstanceState?.let {
41+ suggestions = it.getStringArray(keySuggestions)
42+ }
3443 }
3544
3645 override fun onAttach (context : Context ? ) {
@@ -53,7 +62,8 @@ class VoiceDialogFragment : DialogFragment(), VoiceInput.VoiceInputPresenter {
5362 // region Helpers
5463 companion object {
5564
56- const val SEPARATOR = " • "
65+ const val separator = " • "
66+ const val keySuggestions = " keySuggestions"
5767 }
5868 // endregion
5969
@@ -66,7 +76,7 @@ class VoiceDialogFragment : DialogFragment(), VoiceInput.VoiceInputPresenter {
6676 hint.visibility = View .GONE
6777 } else {
6878 hint.visibility = View .VISIBLE
69- suggestionText.text = suggestions.fold(" " ) { acc, it -> " $acc$SEPARATOR $it \n " }
79+ suggestionText.text = suggestions.fold(" " ) { acc, it -> " $acc$separator $it \n " }
7080 }
7181 }
7282
0 commit comments