diff --git a/app/src/main/java/me/zobrist/tichucounter/MainActivity.kt b/app/src/main/java/me/zobrist/tichucounter/MainActivity.kt index 71b5204..c636d1b 100644 --- a/app/src/main/java/me/zobrist/tichucounter/MainActivity.kt +++ b/app/src/main/java/me/zobrist/tichucounter/MainActivity.kt @@ -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 diff --git a/app/src/main/res/drawable/back.png b/app/src/main/res/drawable/back.png new file mode 100644 index 0000000..72b8bd7 Binary files /dev/null and b/app/src/main/res/drawable/back.png differ diff --git a/app/src/main/res/layout/content_main.xml b/app/src/main/res/layout/content_main.xml index e21b4ae..dff5ef9 100644 --- a/app/src/main/res/layout/content_main.xml +++ b/app/src/main/res/layout/content_main.xml @@ -14,23 +14,32 @@ app:layout_constraintTop_toTopOf="parent"> + + + android:gravity="center" /> + android:gravity="center" /> @@ -72,6 +81,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" + android:gravity="center" android:textAppearance="@style/TextAppearance.AppCompat.Body1" android:textSize="18sp" /> @@ -80,11 +90,19 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" + android:gravity="center" android:textAppearance="@style/TextAppearance.AppCompat.Body1" android:textSize="18sp" /> + + + android:inputType="numberSigned" + android:gravity="center"/> + android:inputType="numberSigned" + android:gravity="center"/>