Improve regex

This commit is contained in:
adrienmalin
2018-12-17 18:11:18 +01:00
parent 98fec45f4f
commit 8c483824b8
5 changed files with 23 additions and 19 deletions

View File

@ -57,8 +57,8 @@ class MatchActivity : AppCompatActivity() {
val player1Name = getStringExtra("player1Name")
val player2Name = getStringExtra("player2Name")
players = listOf(
Player(player1Name, 0, Pattern.compile(getString(R.string.pattern, player1Name))),
Player(player2Name, 0, Pattern.compile(getString(R.string.pattern, player2Name)))
Player(player1Name, 0),
Player(player2Name, 0)
)
serviceSide = getIntExtra("starterId", 0)
relaunchSide = when(serviceSide) {

View File

@ -1,9 +1,6 @@
package adrienmalin.pingpoints
import java.util.regex.Pattern
data class Player (
var name: String,
var score: Int,
var pattern: Pattern? = null
)
var score: Int
)

View File

@ -11,11 +11,10 @@ import android.speech.RecognitionListener
import android.speech.RecognizerIntent
import android.speech.SpeechRecognizer
import android.support.v4.app.DialogFragment
import android.util.Log
import android.view.LayoutInflater
import android.widget.ImageView
import android.widget.TextView
import java.util.*
import java.util.regex.Pattern
import kotlin.math.max
import kotlin.math.min
@ -26,6 +25,7 @@ class SttDialog : DialogFragment() {
var icStt: ImageView? = null
var stt: SpeechRecognizer? = null
var sttIntent: Intent? = null
var pattern: Pattern? = null
inner class SttListener : RecognitionListener {
val ERROR_NOT_UNDERSTOOD = 1
@ -51,12 +51,18 @@ class SttDialog : DialogFragment() {
matchModel?.apply {
for (result in results) {
partialResultsTextView?.text = result
for (player in players) {
if (player.pattern?.matcher(result)?.find() == true) {
dismiss()
updateScore(player)
updateUI()
return
pattern?.apply{
val matcher = matcher(result)
if (matcher.matches()) {
val name_found = matcher.group(1)
for (player in players) {
if (name_found == player.name) {
dismiss()
updateScore(player)
updateUI()
return
}
}
}
}
}
@ -116,6 +122,7 @@ class SttDialog : DialogFragment() {
showPopUp(R.string.STT_unavailable)
}
}
pattern = Pattern.compile(getString(R.string.pattern), Pattern.CASE_INSENSITIVE)
}
}
}