clean code

This commit is contained in:
adrienmalin 2018-12-07 11:51:05 +01:00
parent 00199369e8
commit c78e159dc6
7 changed files with 13 additions and 14 deletions

4
.gitignore vendored
View File

@ -10,3 +10,7 @@
/captures
.externalNativeBuild
*.ser
*.ser
*.apk
*.apk
*.ser

Binary file not shown.

Binary file not shown.

View File

@ -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()
}

View File

@ -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

View File

@ -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,

View File

@ -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")