clean code
This commit is contained in:
		| @ -65,7 +65,7 @@ class MatchActivity : AppCompatActivity() { | ||||
|             findViewById(R.id.imgService1) | ||||
|         ) | ||||
|  | ||||
|         // Init or restore ViewModel | ||||
|         // Init ViewModel | ||||
|         matchModel = ViewModelProviders.of(this).get(MatchModel::class.java) | ||||
|         matchModel?.apply { | ||||
|             if (!matchStarted) { | ||||
| @ -172,10 +172,9 @@ class MatchActivity : AppCompatActivity() { | ||||
|     fun updateScore(view: View) { | ||||
|         matchModel?.apply { | ||||
|             if (!matchFinished) { | ||||
|                 for (side in 0..1) { | ||||
|                     if (view == buttons[side]) { | ||||
|                         updateScore(players[side]) | ||||
|                     } | ||||
|                 when(view) { | ||||
|                     buttons[0] -> updateScore(players[0]) | ||||
|                     buttons[1] -> updateScore(players[1]) | ||||
|                 } | ||||
|                 updateUI() | ||||
|             } | ||||
|  | ||||
| @ -29,7 +29,6 @@ class MatchModel : ViewModel() { | ||||
|     } | ||||
|  | ||||
|     fun updateScore(scorer: Player) { | ||||
|         pointId++ | ||||
|         scorer.score++ | ||||
|         if ((players.sumBy { it.score } % 2 == 0) or (players.all { it.score >= 10 })) { | ||||
|             serviceSide = relaunchSide.also { relaunchSide = serviceSide } | ||||
| @ -46,7 +45,7 @@ class MatchModel : ViewModel() { | ||||
|  | ||||
|     fun saveState() { | ||||
|         val point = Point(players.map { it.score }, serviceSide) | ||||
|         if (pointId == history.size) { | ||||
|         if (++pointId == history.size) { | ||||
|             history.add(point) | ||||
|         } else { | ||||
|             history[pointId] = point | ||||
| @ -54,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) { | ||||
|  | ||||
| @ -44,8 +44,7 @@ class StarterNameActivity : AppCompatActivity() { | ||||
|         enableSttSwitch = findViewById(R.id.enableSttSwitch) | ||||
|  | ||||
|         // Restore previous data | ||||
|         previousMatch = getPreferences(Context.MODE_PRIVATE) | ||||
|         previousMatch?.apply { | ||||
|         previousMatch = getPreferences(Context.MODE_PRIVATE).apply { | ||||
|             previousPlayers = getStringSet("previousPlayers", emptySet()) | ||||
|             val adapter = ArrayAdapter<String>( | ||||
|                 this@StarterNameActivity, | ||||
|  | ||||
| @ -25,10 +25,8 @@ class VictoryActivity : AppCompatActivity() { | ||||
|  | ||||
|         val previousMatch = getPreferences(Context.MODE_PRIVATE) | ||||
|  | ||||
|         // Init victoryModel | ||||
|         victoryModel = ViewModelProviders.of(this).get(VictoryModel::class.java) | ||||
|  | ||||
|         victoryModel?.apply { | ||||
|         // Init VictoryModel | ||||
|         victoryModel = ViewModelProviders.of(this).get(VictoryModel::class.java).apply { | ||||
|             if (!matchFinished) { | ||||
|                 matchFinished = true | ||||
|                 winnerName = intent.getStringExtra("winnerName") | ||||
|  | ||||
		Reference in New Issue
	
	Block a user