try to save the state of the history.

This commit is contained in:
Fabian Zobrist
2020-08-20 15:58:50 +02:00
parent 7d570385fa
commit 4348fa479c
2 changed files with 34 additions and 4 deletions

View File

@@ -1,8 +1,15 @@
package me.zobrist.tichucounter
class History {
import android.os.Parcel
import android.os.Parcelable
class History() : Parcelable {
private var scores: ArrayList<Round> = ArrayList()
constructor(parcel: Parcel) : this(){
scores = parcel.readSerializable() as ArrayList<Round>
}
fun getScoreA(): Int {
var tempScore = 0
scores.forEach {
@@ -52,4 +59,23 @@ class History {
fun isEmpty(): Boolean {
return scores.isEmpty()
}
override fun writeToParcel(parcel: Parcel, flags: Int) {
parcel.writeSerializable(scores)
}
override fun describeContents(): Int {
return 0
}
companion object CREATOR : Parcelable.Creator<History> {
override fun createFromParcel(parcel: Parcel): History {
return History(parcel)
}
override fun newArray(size: Int): Array<History?> {
return arrayOfNulls(size)
}
}
}

View File

@@ -24,6 +24,7 @@ class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
history = savedInstanceState?.getParcelable("history")!!
setContentView(R.layout.activity_main)
setSupportActionBar(findViewById(R.id.toolbar))
inputTeamA.setRawInputType(InputType.TYPE_NULL)
@@ -236,6 +237,11 @@ class MainActivity : AppCompatActivity() {
}
}
override fun onSaveInstanceState(outState: Bundle) {
super.onSaveInstanceState(outState)
outState.putParcelable("history", history)
}
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)
@@ -267,8 +273,7 @@ class MainActivity : AppCompatActivity() {
}
private fun updateView()
{
private fun updateView() {
scoreA.text = history.getScoreA().toString()
scoreB.text = history.getScoreB().toString()
@@ -317,7 +322,6 @@ class MainActivity : AppCompatActivity() {
submit.isEnabled = false
}
private fun chooseThemeDialog() {
val builder = AlertDialog.Builder(this)