Initial commit
This commit is contained in:
141
app/src/main/java/me/zobrist/tichucounter/MainActivity.kt
Normal file
141
app/src/main/java/me/zobrist/tichucounter/MainActivity.kt
Normal file
@@ -0,0 +1,141 @@
|
||||
package me.zobrist.tichucounter
|
||||
|
||||
import android.os.Bundle
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import android.view.Menu
|
||||
import androidx.core.widget.doOnTextChanged
|
||||
import kotlinx.android.synthetic.main.content_main.*
|
||||
import kotlinx.coroutines.sync.Mutex
|
||||
import kotlin.Exception
|
||||
|
||||
class MainActivity : AppCompatActivity() {
|
||||
|
||||
var mut = Mutex()
|
||||
|
||||
private var listA: List<Int> = emptyList()
|
||||
private var listB: List<Int> = emptyList()
|
||||
|
||||
private var tempCounterTeamA: Int = 0
|
||||
private var tempCounterTeamB: Int = 0
|
||||
|
||||
private var counterTeamA: Int = 0
|
||||
private var counterTeamB: Int = 0
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_main)
|
||||
setSupportActionBar(findViewById(R.id.toolbar))
|
||||
|
||||
|
||||
|
||||
inputTeamA.doOnTextChanged { text, start, count, after ->
|
||||
if (inputTeamA.isFocused) {
|
||||
inputTeamB.setText(updateNumber(text, tempCounterTeamA + tempCounterTeamB))
|
||||
}
|
||||
}
|
||||
|
||||
inputTeamB.doOnTextChanged { text, start, count, after ->
|
||||
if (inputTeamB.isFocused) {
|
||||
inputTeamA.setText(updateNumber(text, tempCounterTeamB + tempCounterTeamA))
|
||||
}
|
||||
}
|
||||
|
||||
add100.setOnClickListener {
|
||||
if (inputTeamA.isFocused) {
|
||||
tempCounterTeamA += 100
|
||||
val temp = try {
|
||||
inputTeamA.text.toString().toInt() + 100
|
||||
} catch (e: Exception) {
|
||||
100
|
||||
}
|
||||
inputTeamA.setText(temp.toString())
|
||||
}
|
||||
|
||||
if (inputTeamB.isFocused) {
|
||||
tempCounterTeamB += 100
|
||||
val temp = try {
|
||||
inputTeamB.text.toString().toInt() + 100
|
||||
} catch (e: Exception) {
|
||||
100
|
||||
}
|
||||
inputTeamB.setText(temp.toString())
|
||||
}
|
||||
|
||||
updateTemp()
|
||||
}
|
||||
|
||||
sub100.setOnClickListener {
|
||||
if (inputTeamA.isFocused) {
|
||||
tempCounterTeamA -= 100
|
||||
val temp = try {
|
||||
inputTeamA.text.toString().toInt() - 100
|
||||
} catch (e: Exception) {
|
||||
-100
|
||||
}
|
||||
inputTeamA.setText(temp.toString())
|
||||
|
||||
}
|
||||
|
||||
if (inputTeamB.isFocused) {
|
||||
tempCounterTeamB -= 100
|
||||
val temp = try {
|
||||
inputTeamB.text.toString().toInt() - 100
|
||||
} catch (e: Exception) {
|
||||
-100
|
||||
}
|
||||
inputTeamB.setText(temp.toString())
|
||||
}
|
||||
|
||||
updateTemp()
|
||||
}
|
||||
|
||||
add.setOnClickListener {
|
||||
|
||||
if (inputTeamA.text.isNotEmpty() && inputTeamB.text.isNotEmpty()) {
|
||||
tempCounterTeamA = 0
|
||||
tempCounterTeamB = 0
|
||||
|
||||
counterTeamA += inputTeamA.text.toString().toInt()
|
||||
counterTeamB += inputTeamB.text.toString().toInt()
|
||||
|
||||
historyA.text = historyA.text.toString().plus(scoreA.text.toString().plus("\n"))
|
||||
historyB.text = historyB.text.toString().plus(scoreB.text.toString().plus("\n"))
|
||||
|
||||
scoreA.text = counterTeamA.toString()
|
||||
scoreB.text = counterTeamB.toString()
|
||||
|
||||
inputTeamA.setText("")
|
||||
inputTeamB.setText("")
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
||||
// Inflate the menu; this adds items to the action bar if it is present.
|
||||
menuInflater.inflate(R.menu.menu_main, menu)
|
||||
return true
|
||||
}
|
||||
|
||||
private fun updateNumber(inputText: CharSequence?, offset: Int): String {
|
||||
var toSet: Int = 0
|
||||
|
||||
toSet = try {
|
||||
100 - inputText.toString().toInt()
|
||||
|
||||
} catch (e: Exception) {
|
||||
0
|
||||
}
|
||||
|
||||
toSet += offset
|
||||
|
||||
return "$toSet"
|
||||
}
|
||||
|
||||
private fun updateTemp() {
|
||||
nameTeamA.text = tempCounterTeamA.toString()
|
||||
nameTeamB.text = tempCounterTeamB.toString()
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user