fix mute on STT and starterRadioButton restoration
This commit is contained in:
		| @ -69,7 +69,12 @@ class StarterNameActivity : AppCompatActivity() { | ||||
|                     TextView.BufferType.EDITABLE) | ||||
|                 setAdapter(adapter) | ||||
|             } | ||||
|             starterRadioGroup?.check(getInt("previousStarterId", R.id.radioPlayer1Starts)) | ||||
|             starterRadioGroup?.check( | ||||
|                 when(getInt("previousStarterId", 0)) { | ||||
|                     1 -> R.id.radioPlayer2Starts | ||||
|                     else -> R.id.radioPlayer1Starts | ||||
|                 } | ||||
|             ) | ||||
|             enableTtsSwitch?.isChecked = getBoolean("enableTTS", false) | ||||
|             enableSttSwitch?.isChecked = getBoolean("enableSTT", false) | ||||
|         } | ||||
| @ -151,6 +156,10 @@ class StarterNameActivity : AppCompatActivity() { | ||||
|         val player1Name = player1NameInput?.text.toString() | ||||
|         val player2Name = player2NameInput?.text.toString() | ||||
|         val radioStarterId = starterRadioGroup?.checkedRadioButtonId | ||||
|         val starterId = when(radioStarterId) { | ||||
|             R.id.radioPlayer2Starts -> 1 | ||||
|             else -> 0 | ||||
|         } | ||||
|         val enableTTS = enableTtsSwitch?.isChecked | ||||
|         val enableSTT = enableSttSwitch?.isChecked | ||||
|  | ||||
| @ -158,7 +167,7 @@ class StarterNameActivity : AppCompatActivity() { | ||||
|         previousMatch?.edit()?.apply{ | ||||
|             player1Name.let { putString("previousPlayer1", it) } | ||||
|             player2Name.let { putString("previousPlayer2", it) } | ||||
|             radioStarterId?.let{ putInt("previousStarterId", it) } | ||||
|             putInt("previousStarterId", starterId) | ||||
|             putStringSet("previousPlayers", previousPlayers.plus(player1Name).plus(player2Name)) | ||||
|             enableTTS?.let { putBoolean("enableTTS", it) } | ||||
|             enableSTT?.let { putBoolean("enableSTT", it) } | ||||
| @ -169,13 +178,7 @@ class StarterNameActivity : AppCompatActivity() { | ||||
|             Intent(this, MatchActivity::class.java).apply { | ||||
|                 putExtra("player1Name", player1Name) | ||||
|                 putExtra("player2Name", player2Name) | ||||
|                 putExtra( | ||||
|                     "starterId", | ||||
|                     when(radioStarterId) { | ||||
|                         R.id.radioPlayer2Starts -> 1 | ||||
|                         else -> 0 | ||||
|                     } | ||||
|                 ) | ||||
|                 putExtra("starterId", starterId) | ||||
|                 putExtra("enableTTS", enableTTS) | ||||
|                 putExtra("enableSTT", enableSTT) | ||||
|             } | ||||
|  | ||||
| @ -31,6 +31,12 @@ class SttDialog : DialogFragment() { | ||||
|         var minRms: Float = 0f | ||||
|         var maxRms: Float = 0f | ||||
|  | ||||
|         override fun onReadyForSpeech(arg0: Bundle?) {} | ||||
|  | ||||
|         override fun onBeginningOfSpeech() {} | ||||
|  | ||||
|         override fun onBufferReceived(buffer: ByteArray?) {} | ||||
|  | ||||
|         override fun onRmsChanged(rmsdB: Float) { | ||||
|             minRms = min(rmsdB, minRms) | ||||
|             maxRms = max(rmsdB, maxRms) | ||||
| @ -66,26 +72,17 @@ class SttDialog : DialogFragment() { | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         override fun onEndOfSpeech() {} | ||||
|  | ||||
|         override fun onError(errorCode: Int) { | ||||
|             muteAudio() | ||||
|  | ||||
|             // Restart STT | ||||
|             stt?.apply{ | ||||
|                 stopListening() | ||||
|                 cancel() | ||||
|                 destroy() | ||||
|             } | ||||
|  | ||||
|             stt?.destroy() | ||||
|             stt = SpeechRecognizer.createSpeechRecognizer(activity).apply { | ||||
|                 setRecognitionListener(SttListener()) | ||||
|                 startListening(sttIntent) | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         override fun onReadyForSpeech(arg0: Bundle?) {} | ||||
|         override fun onBeginningOfSpeech() {} | ||||
|         override fun onBufferReceived(buffer: ByteArray?) {} | ||||
|         override fun onEndOfSpeech() {} | ||||
|         override fun onEvent(arg0: Int, arg1: Bundle?) {} | ||||
|     } | ||||
|  | ||||
| @ -119,6 +116,7 @@ class SttDialog : DialogFragment() { | ||||
|                             showPopUp(R.string.STT_unavailable) | ||||
|                         } | ||||
|                     } | ||||
|                     muteAudio() | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|  | ||||
		Reference in New Issue
	
	Block a user