try to save the state of the history.
This commit is contained in:
@@ -1,8 +1,15 @@
|
|||||||
package me.zobrist.tichucounter
|
package me.zobrist.tichucounter
|
||||||
|
|
||||||
class History {
|
import android.os.Parcel
|
||||||
|
import android.os.Parcelable
|
||||||
|
|
||||||
|
class History() : Parcelable {
|
||||||
private var scores: ArrayList<Round> = ArrayList()
|
private var scores: ArrayList<Round> = ArrayList()
|
||||||
|
|
||||||
|
constructor(parcel: Parcel) : this(){
|
||||||
|
scores = parcel.readSerializable() as ArrayList<Round>
|
||||||
|
}
|
||||||
|
|
||||||
fun getScoreA(): Int {
|
fun getScoreA(): Int {
|
||||||
var tempScore = 0
|
var tempScore = 0
|
||||||
scores.forEach {
|
scores.forEach {
|
||||||
@@ -52,4 +59,23 @@ class History {
|
|||||||
fun isEmpty(): Boolean {
|
fun isEmpty(): Boolean {
|
||||||
return scores.isEmpty()
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -24,6 +24,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
|
|
||||||
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)
|
||||||
@@ -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 {
|
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
||||||
// Inflate the menu; this adds items to the action bar if it is present.
|
// Inflate the menu; this adds items to the action bar if it is present.
|
||||||
menuInflater.inflate(R.menu.menu_main, menu)
|
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()
|
scoreA.text = history.getScoreA().toString()
|
||||||
scoreB.text = history.getScoreB().toString()
|
scoreB.text = history.getScoreB().toString()
|
||||||
|
|
||||||
@@ -317,7 +322,6 @@ class MainActivity : AppCompatActivity() {
|
|||||||
submit.isEnabled = false
|
submit.isEnabled = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private fun chooseThemeDialog() {
|
private fun chooseThemeDialog() {
|
||||||
|
|
||||||
val builder = AlertDialog.Builder(this)
|
val builder = AlertDialog.Builder(this)
|
||||||
|
|||||||
Reference in New Issue
Block a user