clean code
This commit is contained in:
parent
00199369e8
commit
c78e159dc6
4
.gitignore
vendored
4
.gitignore
vendored
@ -10,3 +10,7 @@
|
||||
/captures
|
||||
.externalNativeBuild
|
||||
*.ser
|
||||
*.ser
|
||||
*.apk
|
||||
*.apk
|
||||
*.ser
|
||||
|
BIN
.idea/caches/build_file_checksums.ser
generated
BIN
.idea/caches/build_file_checksums.ser
generated
Binary file not shown.
Binary file not shown.
@ -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
|
||||
|
@ -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")
|
||||
|
Loading…
x
Reference in New Issue
Block a user