- Add functionality for on screen buttons.
- Improve layout.
This commit is contained in:
@@ -1,13 +1,13 @@
|
||||
package me.zobrist.tichucounter
|
||||
|
||||
import android.os.Bundle
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import android.view.Menu
|
||||
import android.view.MenuItem
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.core.widget.doOnTextChanged
|
||||
import kotlinx.android.synthetic.main.content_main.*
|
||||
import android.text.InputType
|
||||
import kotlinx.coroutines.sync.Mutex
|
||||
import kotlin.Exception
|
||||
|
||||
class MainActivity : AppCompatActivity() {
|
||||
|
||||
@@ -26,22 +26,34 @@ class MainActivity : AppCompatActivity() {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_main)
|
||||
setSupportActionBar(findViewById(R.id.toolbar))
|
||||
inputTeamA.setRawInputType(InputType.TYPE_NULL)
|
||||
inputTeamB.setRawInputType(InputType.TYPE_NULL)
|
||||
|
||||
|
||||
|
||||
inputTeamA.doOnTextChanged { text, start, count, after ->
|
||||
if (inputTeamA.isFocused) {
|
||||
inputTeamB.setText(updateNumber(text, tempCounterTeamA + tempCounterTeamB))
|
||||
if (inputTeamA.text.isNotEmpty()){
|
||||
inputTeamB.setText(updateNumber(text, tempCounterTeamA + tempCounterTeamB))
|
||||
}else{
|
||||
inputTeamA.text.clear()
|
||||
inputTeamB.text.clear()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
inputTeamB.doOnTextChanged { text, start, count, after ->
|
||||
if (inputTeamB.isFocused) {
|
||||
inputTeamA.setText(updateNumber(text, tempCounterTeamB + tempCounterTeamA))
|
||||
if (inputTeamB.text.isNotEmpty()){
|
||||
inputTeamA.setText(updateNumber(text, tempCounterTeamB + tempCounterTeamA))
|
||||
}else{
|
||||
inputTeamA.text.clear()
|
||||
inputTeamB.text.clear()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
add100.setOnClickListener {
|
||||
buttonAdd100.setOnClickListener {
|
||||
if (inputTeamA.isFocused) {
|
||||
tempCounterTeamA += 100
|
||||
val temp = try {
|
||||
@@ -63,7 +75,7 @@ class MainActivity : AppCompatActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
sub100.setOnClickListener {
|
||||
buttonSub100.setOnClickListener {
|
||||
if (inputTeamA.isFocused) {
|
||||
tempCounterTeamA -= 100
|
||||
val temp = try {
|
||||
@@ -86,6 +98,61 @@ class MainActivity : AppCompatActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
button0.setOnClickListener {
|
||||
appedtoFocusedInput('0')
|
||||
}
|
||||
|
||||
button1.setOnClickListener {
|
||||
appedtoFocusedInput('1')
|
||||
}
|
||||
|
||||
button2.setOnClickListener {
|
||||
appedtoFocusedInput('2')
|
||||
}
|
||||
|
||||
button3.setOnClickListener {
|
||||
appedtoFocusedInput('3')
|
||||
}
|
||||
|
||||
button4.setOnClickListener {
|
||||
appedtoFocusedInput('4')
|
||||
}
|
||||
|
||||
button5.setOnClickListener {
|
||||
appedtoFocusedInput('5')
|
||||
}
|
||||
|
||||
button6.setOnClickListener {
|
||||
appedtoFocusedInput('6')
|
||||
}
|
||||
|
||||
button7.setOnClickListener {
|
||||
appedtoFocusedInput('7')
|
||||
}
|
||||
|
||||
button8.setOnClickListener {
|
||||
appedtoFocusedInput('8')
|
||||
}
|
||||
|
||||
button9.setOnClickListener {
|
||||
appedtoFocusedInput('9')
|
||||
}
|
||||
|
||||
buttonBack.setOnClickListener{
|
||||
if(inputTeamA.isFocused ){
|
||||
if(inputTeamA.text.isNotEmpty()){
|
||||
var string = inputTeamA.text.toString()
|
||||
inputTeamA.setText(string.substring(0, string.length -1))
|
||||
}
|
||||
|
||||
}else if(inputTeamB.isFocused) {
|
||||
if(inputTeamB.text.isNotEmpty()) {
|
||||
var string = inputTeamB.text.toString()
|
||||
inputTeamB.setText(string.substring(0, string.length - 1))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
add.setOnClickListener {
|
||||
|
||||
if (inputTeamA.text.isNotEmpty() && inputTeamB.text.isNotEmpty()) {
|
||||
@@ -101,8 +168,8 @@ class MainActivity : AppCompatActivity() {
|
||||
scoreA.text = counterTeamA.toString()
|
||||
scoreB.text = counterTeamB.toString()
|
||||
|
||||
inputTeamA.setText("")
|
||||
inputTeamB.setText("")
|
||||
inputTeamA.text.clear()
|
||||
inputTeamB.text.clear()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -126,12 +193,21 @@ class MainActivity : AppCompatActivity() {
|
||||
private fun clearAll() {
|
||||
historyA.text = ""
|
||||
historyB.text = ""
|
||||
inputTeamA.setText("")
|
||||
inputTeamB.setText("")
|
||||
inputTeamA.text.clear()
|
||||
inputTeamB.text.clear()
|
||||
scoreA.text = ""
|
||||
scoreB.text = ""
|
||||
}
|
||||
|
||||
private fun appedtoFocusedInput(toAppend: Char){
|
||||
if(inputTeamA.isFocused){
|
||||
inputTeamA.text.append(toAppend)
|
||||
}else if(inputTeamB.isFocused)
|
||||
{
|
||||
inputTeamB.text.append(toAppend)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private fun updateNumber(inputText: CharSequence?, offset: Int): String {
|
||||
var toSet: Int = 0
|
||||
|
||||
Reference in New Issue
Block a user