Improve regex
This commit is contained in:
		| @ -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) { | ||||
|  | ||||
| @ -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 | ||||
| ) | ||||
|  | ||||
| @ -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) | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|  | ||||
| @ -32,8 +32,8 @@ | ||||
|     <string name="share_subject">Match Ping Points : %s contre %s</string> | ||||
|     <string name="share_message">"%s contre %s:\n%s a gagné par %d à %d\nPing Points est disponible sur Google Play"</string> | ||||
|     <string name="match_point">Balle de match</string> | ||||
|     <string name="STT_hint">Dîtes : \"point %s\"\nou \"point %s\"</string> | ||||
|     <string name="pattern">(?i:(point|.) %s)</string> | ||||
|     <string name="STT_hint">Dîtes : \"Point pour %s\"\nou \"Point pour %s\"</string> | ||||
|     <string name="pattern">point pour (.+)</string> | ||||
|     <string name="not_understood">Pouvez-vous répéter ?</string> | ||||
|     <string name="STT_disabled">Reconnaissance vocale désactivée.</string> | ||||
| </resources> | ||||
| @ -37,8 +37,8 @@ | ||||
|     <string name="share_subject">Ping Points Match: %s vs. %s</string> | ||||
|     <string name="share_message">%s vs. %s:\n%s won by %d to %d\nGet Ping Points on Google Play</string> | ||||
|     <string name="match_point">Match point</string> | ||||
|     <string name="STT_hint">Say: \"point %s\"\nor \"point %s\"</string> | ||||
|     <string name="pattern">(?i:(point|.) %s)</string> | ||||
|     <string name="STT_hint">Say: \"Point for %s\"\nor \"Point for %s\"</string> | ||||
|     <string name="pattern">point for (.+)</string> | ||||
|     <string name="not_understood">Can you repeat, please?</string> | ||||
|     <string name="score" translatable="false">%d - %d</string> | ||||
|     <string name="STT_disabled">Voice recognition disabled.</string> | ||||
|  | ||||
		Reference in New Issue
	
	Block a user