Show negative sign if entered first.

This commit is contained in:
2020-09-20 20:30:02 +02:00
parent 214d5e61a4
commit f1dad279e0

View File

@@ -16,9 +16,6 @@ import kotlinx.android.synthetic.main.content_main.*
class MainActivity : AppCompatActivity() { class MainActivity : AppCompatActivity() {
private var invertA: Boolean = false
private var invertB: Boolean = false
private var updateOnChange: Boolean = true private var updateOnChange: Boolean = true
private lateinit var history: History private lateinit var history: History
@@ -64,7 +61,7 @@ class MainActivity : AppCompatActivity() {
Round(text.toString().toInt(), true) Round(text.toString().toInt(), true)
} catch (e: java.lang.Exception) { } catch (e: java.lang.Exception) {
Round(0, 0) Round(1, 1)
} }
inputTeamB.setText(currentRound.scoreB.toString()) inputTeamB.setText(currentRound.scoreB.toString())
} else { } else {
@@ -93,7 +90,7 @@ class MainActivity : AppCompatActivity() {
Round(text.toString().toInt(), false) Round(text.toString().toInt(), false)
} catch (e: java.lang.Exception) { } catch (e: java.lang.Exception) {
Round(0, 0) Round(1, 1)
} }
inputTeamA.setText(currentRound.scoreA.toString()) inputTeamA.setText(currentRound.scoreA.toString())
@@ -229,22 +226,26 @@ class MainActivity : AppCompatActivity() {
giveFocusToAIfNone() giveFocusToAIfNone()
if (inputTeamA.isFocused) { if (inputTeamA.isFocused) {
if (inputTeamA.text.isNotEmpty()) { if (inputTeamA.text.toString().equals("-")) {
inputTeamA.text.clear()
} else if (inputTeamA.text.isNotEmpty()) {
tempInt = inputTeamA.text.toString().toInt() * -1 tempInt = inputTeamA.text.toString().toInt() * -1
inputTeamA.setText(tempInt.toString()) inputTeamA.setText(tempInt.toString())
} else { } else {
invertB = false updateOnChange = false
invertA = true appendToFocusedInput('-')
} }
} else if (inputTeamB.isFocused) { } else if (inputTeamB.isFocused) {
if (inputTeamB.text.isNotEmpty()) { if (inputTeamB.text.toString().equals("-")) {
inputTeamB.text.clear()
} else if (inputTeamB.text.isNotEmpty()) {
tempInt = inputTeamB.text.toString().toInt() * -1 tempInt = inputTeamB.text.toString().toInt() * -1
inputTeamB.setText(tempInt.toString()) inputTeamB.setText(tempInt.toString())
} else { } else {
invertA = false updateOnChange = false
invertB = true appendToFocusedInput('-')
} }
} }
} }
@@ -378,17 +379,8 @@ class MainActivity : AppCompatActivity() {
private fun appendToFocusedInput(toAppend: Char) { private fun appendToFocusedInput(toAppend: Char) {
if (inputTeamA.isFocused) { if (inputTeamA.isFocused) {
if (invertA) {
invertA = false
inputTeamA.text.append('-')
}
inputTeamA.text.append(toAppend) inputTeamA.text.append(toAppend)
} else if (inputTeamB.isFocused) { } else if (inputTeamB.isFocused) {
if (invertB) {
invertB = false
inputTeamB.text.append('-')
}
inputTeamB.text.append(toAppend) inputTeamB.text.append(toAppend)
} }
} }
@@ -409,7 +401,8 @@ class MainActivity : AppCompatActivity() {
builder.setTitle(getString(R.string.choose_theme_text)) builder.setTitle(getString(R.string.choose_theme_text))
val styles = arrayOf("Light", "Dark", "System default") val styles = arrayOf("Light", "Dark", "System default")
val checkedItem = this.getSharedPreferences("Settings", Context.MODE_PRIVATE).getInt("Theme", 2) val checkedItem =
this.getSharedPreferences("Settings", Context.MODE_PRIVATE).getInt("Theme", 2)
val prefs = this.getSharedPreferences("Settings", Context.MODE_PRIVATE).edit() val prefs = this.getSharedPreferences("Settings", Context.MODE_PRIVATE).edit()