fix mute on STT and starterRadioButton restoration

This commit is contained in:
adrienmalin 2018-12-08 15:07:26 +01:00
parent fb2f81226f
commit 719b0c252c
4 changed files with 25 additions and 23 deletions

View File

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

View File

@ -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()
}
}
}

View File

@ -54,7 +54,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content" tools:layout_editor_absoluteY="93dp"
tools:layout_editor_absoluteX="16dp" android:id="@+id/radioPlayer2Starts"
android:layout_weight="0"/>
android:layout_weight="0" android:checked="true"/>
<AutoCompleteTextView
android:text="@string/player_2_default_name"
android:layout_width="match_parent"

View File

@ -50,7 +50,8 @@
android:layout_height="wrap_content" tools:layout_editor_absoluteY="93dp"
tools:layout_editor_absoluteX="16dp" android:id="@+id/radioPlayer2Starts"
android:layout_width="wrap_content" android:layout_weight="1"
android:gravity="bottom"/>
android:gravity="bottom"
android:checked="false"/>
</RadioGroup>
<LinearLayout
android:orientation="vertical"