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