- fix loading history form savedInstance.

- fix add or sub 100 does not update other score
This commit is contained in:
2020-08-21 10:32:54 +02:00
parent 4348fa479c
commit 30c030dc5f

View File

@@ -19,12 +19,11 @@ class MainActivity : AppCompatActivity() {
private var updateOnChange: Boolean = true private var updateOnChange: Boolean = true
private var history = History() private lateinit var history: History
private var currentRound = Round() private var currentRound = Round()
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
history = savedInstanceState?.getParcelable("history")!!
setContentView(R.layout.activity_main) setContentView(R.layout.activity_main)
setSupportActionBar(findViewById(R.id.toolbar)) setSupportActionBar(findViewById(R.id.toolbar))
inputTeamA.setRawInputType(InputType.TYPE_NULL) inputTeamA.setRawInputType(InputType.TYPE_NULL)
@@ -33,15 +32,18 @@ class MainActivity : AppCompatActivity() {
disableSubmitButton() disableSubmitButton()
updateTheme(this.getSharedPreferences("Settings", Context.MODE_PRIVATE).getInt("Theme", 2)) updateTheme(this.getSharedPreferences("Settings", Context.MODE_PRIVATE).getInt("Theme", 2))
history = savedInstanceState?.getParcelable("history") ?: History()
updateView()
inputTeamA.doOnTextChanged { text, start, count, after -> inputTeamA.doOnTextChanged { text, start, count, after ->
if (inputTeamA.isFocused) { if (inputTeamA.isFocused) {
if (inputTeamA.text.isNotEmpty()){ if (inputTeamA.text.isNotEmpty()) {
if(updateOnChange){ if (updateOnChange) {
currentRound = try { currentRound = try {
Round(text.toString().toInt(), true) Round(text.toString().toInt(), true)
} catch (e: java.lang.Exception){ } catch (e: java.lang.Exception) {
Round(0, 0) Round(0, 0)
} }
inputTeamB.setText(currentRound.scoreB.toString()) inputTeamB.setText(currentRound.scoreB.toString())
@@ -98,7 +100,9 @@ class MainActivity : AppCompatActivity() {
val temp = try { val temp = try {
inputTeamA.text.toString().toInt() + 100 inputTeamA.text.toString().toInt() + 100
} catch (e: Exception) { } catch (e: Exception) {
inputTeamB.setText(0.toString())
100 100
} }
updateOnChange = false updateOnChange = false
inputTeamA.setText(temp.toString()) inputTeamA.setText(temp.toString())
@@ -108,7 +112,9 @@ class MainActivity : AppCompatActivity() {
val temp = try { val temp = try {
inputTeamB.text.toString().toInt() + 100 inputTeamB.text.toString().toInt() + 100
} catch (e: Exception) { } catch (e: Exception) {
inputTeamA.setText(0.toString())
100 100
} }
updateOnChange = false updateOnChange = false
inputTeamB.setText(temp.toString()) inputTeamB.setText(temp.toString())