This commit is contained in:
adrienmalin 2018-12-07 11:59:43 +01:00
parent c78e159dc6
commit 861196e118
2 changed files with 11 additions and 11 deletions

View File

@ -93,15 +93,6 @@ class MatchActivity : AppCompatActivity() {
updateUI()
}
override fun onBackPressed() {
if (matchModel?.pointId == 0)
super.onBackPressed()
else {
matchModel?.undo()
updateUI()
}
}
fun updateUI() {
matchModel?.apply {
textScore?.text = getString(
@ -204,4 +195,13 @@ class MatchActivity : AppCompatActivity() {
hashMapOf(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID to "TTS")
)
}
override fun onBackPressed() {
if (matchModel?.pointId == 0)
super.onBackPressed()
else {
matchModel?.undo()
updateUI()
}
}
}

View File

@ -12,7 +12,7 @@ class MatchModel : ViewModel() {
var relaunchSide: Int = 1
var ttsEnabled: Boolean = false
var sttEnabled: Boolean = false
var pointId: Int = 0
var pointId: Int = -1
var history: MutableList<Point> = ArrayList()
fun startMatch(player1Name: String, player2Name:String, starterId: Int, enableTTS: Boolean, enableSTT: Boolean) {
@ -53,7 +53,7 @@ class MatchModel : ViewModel() {
}
fun undo() {
history[pointId--].let {
history[--pointId].let {
players.zip(it.score).forEach{(player, score) -> player.score = score}
serviceSide = it.serviceSide
relaunchSide = when(serviceSide) {