Format all files. And fix Round unit test (that now fails...)
This commit is contained in:
16
.idea/codeStyles/Project.xml
generated
16
.idea/codeStyles/Project.xml
generated
@@ -1,22 +1,6 @@
|
|||||||
<component name="ProjectCodeStyleConfiguration">
|
<component name="ProjectCodeStyleConfiguration">
|
||||||
<code_scheme name="Project" version="173">
|
<code_scheme name="Project" version="173">
|
||||||
<JetCodeStyleSettings>
|
<JetCodeStyleSettings>
|
||||||
<option name="PACKAGES_TO_USE_STAR_IMPORTS">
|
|
||||||
<value>
|
|
||||||
<package name="java.util" alias="false" withSubpackages="false" />
|
|
||||||
<package name="kotlinx.android.synthetic" alias="false" withSubpackages="true" />
|
|
||||||
<package name="io.ktor" alias="false" withSubpackages="true" />
|
|
||||||
</value>
|
|
||||||
</option>
|
|
||||||
<option name="PACKAGES_IMPORT_LAYOUT">
|
|
||||||
<value>
|
|
||||||
<package name="" alias="false" withSubpackages="true" />
|
|
||||||
<package name="java" alias="false" withSubpackages="true" />
|
|
||||||
<package name="javax" alias="false" withSubpackages="true" />
|
|
||||||
<package name="kotlin" alias="false" withSubpackages="true" />
|
|
||||||
<package name="" alias="true" withSubpackages="true" />
|
|
||||||
</value>
|
|
||||||
</option>
|
|
||||||
<option name="CODE_STYLE_DEFAULTS" value="KOTLIN_OFFICIAL" />
|
<option name="CODE_STYLE_DEFAULTS" value="KOTLIN_OFFICIAL" />
|
||||||
</JetCodeStyleSettings>
|
</JetCodeStyleSettings>
|
||||||
<codeStyleSettings language="XML">
|
<codeStyleSettings language="XML">
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ fun Int.isMultipleOf5(): Boolean
|
|||||||
return (this % 5) == 0
|
return (this % 5) == 0
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Int.isMultipleOf100(): Boolean {
|
fun Int.isMultipleOf100(): Boolean
|
||||||
|
{
|
||||||
return (this % 100) == 0
|
return (this % 100) == 0
|
||||||
}
|
}
|
||||||
@@ -1,9 +1,11 @@
|
|||||||
package me.zobrist.tichucounter
|
package me.zobrist.tichucounter
|
||||||
|
|
||||||
class History {
|
class History
|
||||||
private var scores: ArrayList<Round> = ArrayList()
|
{
|
||||||
|
private var scores=ArrayList<Round>()
|
||||||
|
|
||||||
fun getScoreA(): Int {
|
fun getScoreA(): Int
|
||||||
|
{
|
||||||
var tempScore=0
|
var tempScore=0
|
||||||
scores.forEach {
|
scores.forEach {
|
||||||
tempScore+=it.scoreA
|
tempScore+=it.scoreA
|
||||||
@@ -11,7 +13,8 @@ class History {
|
|||||||
return tempScore
|
return tempScore
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getScoreB(): Int {
|
fun getScoreB(): Int
|
||||||
|
{
|
||||||
var tempScore=0
|
var tempScore=0
|
||||||
scores.forEach {
|
scores.forEach {
|
||||||
tempScore+=it.scoreB
|
tempScore+=it.scoreB
|
||||||
@@ -19,7 +22,8 @@ class History {
|
|||||||
return tempScore
|
return tempScore
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getHistoryA(): String {
|
fun getHistoryA(): String
|
||||||
|
{
|
||||||
var tempHistory=String()
|
var tempHistory=String()
|
||||||
scores.forEach {
|
scores.forEach {
|
||||||
tempHistory+=it.scoreA.toString() + "\n"
|
tempHistory+=it.scoreA.toString() + "\n"
|
||||||
@@ -27,7 +31,8 @@ class History {
|
|||||||
return tempHistory
|
return tempHistory
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getHistoryB(): String {
|
fun getHistoryB(): String
|
||||||
|
{
|
||||||
var tempHistory=String()
|
var tempHistory=String()
|
||||||
scores.forEach {
|
scores.forEach {
|
||||||
tempHistory+=it.scoreB.toString() + "\n"
|
tempHistory+=it.scoreB.toString() + "\n"
|
||||||
@@ -35,21 +40,26 @@ class History {
|
|||||||
return tempHistory
|
return tempHistory
|
||||||
}
|
}
|
||||||
|
|
||||||
fun logRound(round: Round) {
|
fun logRound(round: Round)
|
||||||
|
{
|
||||||
scores.add(round)
|
scores.add(round)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun revertLastRound() {
|
fun revertLastRound()
|
||||||
if (scores.isNotEmpty()) {
|
{
|
||||||
|
if (scores.isNotEmpty())
|
||||||
|
{
|
||||||
scores.removeAt(scores.size - 1)
|
scores.removeAt(scores.size - 1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun clearAll() {
|
fun clearAll()
|
||||||
|
{
|
||||||
scores.clear()
|
scores.clear()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun isEmpty(): Boolean {
|
fun isEmpty(): Boolean
|
||||||
|
{
|
||||||
return scores.isEmpty()
|
return scores.isEmpty()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,12 +1,12 @@
|
|||||||
package me.zobrist.tichucounter
|
package me.zobrist.tichucounter
|
||||||
|
|
||||||
import android.app.AlertDialog
|
import android.app.AlertDialog
|
||||||
import android.content.Context
|
|
||||||
import android.content.ContextWrapper
|
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.text.InputType
|
import android.text.InputType
|
||||||
import android.view.*
|
import android.view.Menu
|
||||||
|
import android.view.MenuItem
|
||||||
|
import android.view.WindowManager
|
||||||
import android.view.inputmethod.InputMethodManager
|
import android.view.inputmethod.InputMethodManager
|
||||||
import android.widget.ScrollView
|
import android.widget.ScrollView
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
@@ -17,7 +17,8 @@ import com.google.gson.Gson
|
|||||||
import me.zobrist.tichucounter.databinding.ActivityMainBinding
|
import me.zobrist.tichucounter.databinding.ActivityMainBinding
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
class MainActivity : AppCompatActivity() {
|
class MainActivity : AppCompatActivity()
|
||||||
|
{
|
||||||
|
|
||||||
private var updateOnChange: Boolean=true
|
private var updateOnChange: Boolean=true
|
||||||
|
|
||||||
@@ -29,7 +30,8 @@ class MainActivity : AppCompatActivity() {
|
|||||||
private lateinit var binding: ActivityMainBinding
|
private lateinit var binding: ActivityMainBinding
|
||||||
|
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?)
|
||||||
|
{
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
binding=ActivityMainBinding.inflate(layoutInflater)
|
binding=ActivityMainBinding.inflate(layoutInflater)
|
||||||
setContentView(binding.root)
|
setContentView(binding.root)
|
||||||
@@ -47,10 +49,15 @@ class MainActivity : AppCompatActivity() {
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
val json = this.getSharedPreferences("Settings", MODE_PRIVATE).getString("history", "{\"scores\":[]}")
|
val json=this.getSharedPreferences("Settings" , MODE_PRIVATE)
|
||||||
|
.getString("history" , "{\"scores\":[]}")
|
||||||
history=Gson().fromJson(json , History::class.java)
|
history=Gson().fromJson(json , History::class.java)
|
||||||
binding.contentMain.nameTeamA.setText(this.getSharedPreferences("Settings", MODE_PRIVATE).getString("nameTeamA", "TeamA"))
|
binding.contentMain.nameTeamA.setText(
|
||||||
binding.contentMain.nameTeamB.setText(this.getSharedPreferences("Settings", MODE_PRIVATE).getString("nameTeamB", "TeamB"))
|
this.getSharedPreferences("Settings" , MODE_PRIVATE).getString("nameTeamA" , "TeamA")
|
||||||
|
)
|
||||||
|
binding.contentMain.nameTeamB.setText(
|
||||||
|
this.getSharedPreferences("Settings" , MODE_PRIVATE).getString("nameTeamB" , "TeamB")
|
||||||
|
)
|
||||||
updateView()
|
updateView()
|
||||||
|
|
||||||
this.setListenes()
|
this.setListenes()
|
||||||
@@ -61,69 +68,97 @@ class MainActivity : AppCompatActivity() {
|
|||||||
private fun setListenes()
|
private fun setListenes()
|
||||||
{
|
{
|
||||||
binding.contentMain.inputTeamA.setOnFocusChangeListener { _ , b ->
|
binding.contentMain.inputTeamA.setOnFocusChangeListener { _ , b ->
|
||||||
if (b) {
|
if (b)
|
||||||
|
{
|
||||||
hideKeyboard()
|
hideKeyboard()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
binding.contentMain.inputTeamB.setOnFocusChangeListener { _ , b ->
|
binding.contentMain.inputTeamB.setOnFocusChangeListener { _ , b ->
|
||||||
if (b) {
|
if (b)
|
||||||
|
{
|
||||||
hideKeyboard()
|
hideKeyboard()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
binding.contentMain.inputTeamA.doOnTextChanged { text , _ , _ , _ ->
|
binding.contentMain.inputTeamA.doOnTextChanged { text , _ , _ , _ ->
|
||||||
if (binding.contentMain.inputTeamA.isFocused) {
|
if (binding.contentMain.inputTeamA.isFocused)
|
||||||
if (binding.contentMain.inputTeamA.text.isNotEmpty()) {
|
{
|
||||||
if (updateOnChange) {
|
if (binding.contentMain.inputTeamA.text.isNotEmpty())
|
||||||
currentRound = try {
|
{
|
||||||
|
if (updateOnChange)
|
||||||
|
{
|
||||||
|
currentRound=try
|
||||||
|
{
|
||||||
Round(text.toString().toInt() , true)
|
Round(text.toString().toInt() , true)
|
||||||
|
|
||||||
} catch (e: java.lang.Exception) {
|
}
|
||||||
|
catch (e: java.lang.Exception)
|
||||||
|
{
|
||||||
Round(1 , 1)
|
Round(1 , 1)
|
||||||
}
|
}
|
||||||
binding.contentMain.inputTeamB.setText(currentRound.scoreB.toString())
|
binding.contentMain.inputTeamB.setText(currentRound.scoreB.toString())
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
updateOnChange=true
|
updateOnChange=true
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
binding.contentMain.inputTeamA.text.clear()
|
binding.contentMain.inputTeamA.text.clear()
|
||||||
binding.contentMain.inputTeamB.text.clear()
|
binding.contentMain.inputTeamB.text.clear()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (currentRound.isValidRound() && binding.contentMain.inputTeamA.text.isNotEmpty() && binding.contentMain.inputTeamB.text.isNotEmpty()) {
|
if (currentRound.isValidRound() && binding.contentMain.inputTeamA.text.isNotEmpty() && binding.contentMain.inputTeamB.text.isNotEmpty())
|
||||||
|
{
|
||||||
enableSubmitButton()
|
enableSubmitButton()
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
disableSubmitButton()
|
disableSubmitButton()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
binding.contentMain.inputTeamB.doOnTextChanged { text , _ , _ , _ ->
|
binding.contentMain.inputTeamB.doOnTextChanged { text , _ , _ , _ ->
|
||||||
if (binding.contentMain.inputTeamB.isFocused) {
|
if (binding.contentMain.inputTeamB.isFocused)
|
||||||
if (binding.contentMain.inputTeamB.text.isNotEmpty()) {
|
{
|
||||||
if (updateOnChange) {
|
if (binding.contentMain.inputTeamB.text.isNotEmpty())
|
||||||
currentRound = try {
|
{
|
||||||
|
if (updateOnChange)
|
||||||
|
{
|
||||||
|
currentRound=try
|
||||||
|
{
|
||||||
Round(text.toString().toInt() , false)
|
Round(text.toString().toInt() , false)
|
||||||
|
|
||||||
} catch (e: java.lang.Exception) {
|
}
|
||||||
|
catch (e: java.lang.Exception)
|
||||||
|
{
|
||||||
Round(1 , 1)
|
Round(1 , 1)
|
||||||
}
|
}
|
||||||
binding.contentMain.inputTeamA.setText(currentRound.scoreA.toString())
|
binding.contentMain.inputTeamA.setText(currentRound.scoreA.toString())
|
||||||
|
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
updateOnChange=true
|
updateOnChange=true
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
binding.contentMain.inputTeamA.text.clear()
|
binding.contentMain.inputTeamA.text.clear()
|
||||||
binding.contentMain.inputTeamB.text.clear()
|
binding.contentMain.inputTeamB.text.clear()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (currentRound.isValidRound() && binding.contentMain.inputTeamA.text.isNotEmpty() && binding.contentMain.inputTeamB.text.isNotEmpty()) {
|
if (currentRound.isValidRound() && binding.contentMain.inputTeamA.text.isNotEmpty() && binding.contentMain.inputTeamB.text.isNotEmpty())
|
||||||
|
{
|
||||||
enableSubmitButton()
|
enableSubmitButton()
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
disableSubmitButton()
|
disableSubmitButton()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -131,11 +166,15 @@ class MainActivity : AppCompatActivity() {
|
|||||||
binding.contentMain.buttonAdd100.setOnClickListener {
|
binding.contentMain.buttonAdd100.setOnClickListener {
|
||||||
giveFocusToAIfNone()
|
giveFocusToAIfNone()
|
||||||
|
|
||||||
if (binding.contentMain.inputTeamA.isFocused) {
|
if (binding.contentMain.inputTeamA.isFocused)
|
||||||
|
{
|
||||||
|
|
||||||
currentRound.scoreA = try {
|
currentRound.scoreA=try
|
||||||
|
{
|
||||||
binding.contentMain.inputTeamA.text.toString().toInt() + 100
|
binding.contentMain.inputTeamA.text.toString().toInt() + 100
|
||||||
} catch (e: Exception) {
|
}
|
||||||
|
catch (e: Exception)
|
||||||
|
{
|
||||||
currentRound.scoreB=0
|
currentRound.scoreB=0
|
||||||
binding.contentMain.inputTeamB.setText(currentRound.scoreB.toString())
|
binding.contentMain.inputTeamB.setText(currentRound.scoreB.toString())
|
||||||
100
|
100
|
||||||
@@ -144,10 +183,14 @@ class MainActivity : AppCompatActivity() {
|
|||||||
binding.contentMain.inputTeamA.setText(currentRound.scoreA.toString())
|
binding.contentMain.inputTeamA.setText(currentRound.scoreA.toString())
|
||||||
}
|
}
|
||||||
|
|
||||||
if (binding.contentMain.inputTeamB.isFocused) {
|
if (binding.contentMain.inputTeamB.isFocused)
|
||||||
currentRound.scoreB = try {
|
{
|
||||||
|
currentRound.scoreB=try
|
||||||
|
{
|
||||||
binding.contentMain.inputTeamB.text.toString().toInt() + 100
|
binding.contentMain.inputTeamB.text.toString().toInt() + 100
|
||||||
} catch (e: Exception) {
|
}
|
||||||
|
catch (e: Exception)
|
||||||
|
{
|
||||||
currentRound.scoreA=0
|
currentRound.scoreA=0
|
||||||
binding.contentMain.inputTeamA.setText(currentRound.scoreA.toString())
|
binding.contentMain.inputTeamA.setText(currentRound.scoreA.toString())
|
||||||
100
|
100
|
||||||
@@ -162,10 +205,14 @@ class MainActivity : AppCompatActivity() {
|
|||||||
binding.contentMain.buttonSub100.setOnClickListener {
|
binding.contentMain.buttonSub100.setOnClickListener {
|
||||||
giveFocusToAIfNone()
|
giveFocusToAIfNone()
|
||||||
|
|
||||||
if (binding.contentMain.inputTeamA.isFocused) {
|
if (binding.contentMain.inputTeamA.isFocused)
|
||||||
currentRound.scoreA = try {
|
{
|
||||||
|
currentRound.scoreA=try
|
||||||
|
{
|
||||||
binding.contentMain.inputTeamA.text.toString().toInt() - 100
|
binding.contentMain.inputTeamA.text.toString().toInt() - 100
|
||||||
} catch (e: Exception) {
|
}
|
||||||
|
catch (e: Exception)
|
||||||
|
{
|
||||||
currentRound.scoreB=0
|
currentRound.scoreB=0
|
||||||
binding.contentMain.inputTeamB.setText(currentRound.scoreB.toString())
|
binding.contentMain.inputTeamB.setText(currentRound.scoreB.toString())
|
||||||
-100
|
-100
|
||||||
@@ -174,10 +221,14 @@ class MainActivity : AppCompatActivity() {
|
|||||||
binding.contentMain.inputTeamA.setText(currentRound.scoreA.toString())
|
binding.contentMain.inputTeamA.setText(currentRound.scoreA.toString())
|
||||||
}
|
}
|
||||||
|
|
||||||
if (binding.contentMain.inputTeamB.isFocused) {
|
if (binding.contentMain.inputTeamB.isFocused)
|
||||||
currentRound.scoreB = try {
|
{
|
||||||
|
currentRound.scoreB=try
|
||||||
|
{
|
||||||
binding.contentMain.inputTeamB.text.toString().toInt() - 100
|
binding.contentMain.inputTeamB.text.toString().toInt() - 100
|
||||||
} catch (e: Exception) {
|
}
|
||||||
|
catch (e: Exception)
|
||||||
|
{
|
||||||
currentRound.scoreA=0
|
currentRound.scoreA=0
|
||||||
binding.contentMain.inputTeamA.setText(currentRound.scoreA.toString())
|
binding.contentMain.inputTeamA.setText(currentRound.scoreA.toString())
|
||||||
-100
|
-100
|
||||||
@@ -242,26 +293,39 @@ class MainActivity : AppCompatActivity() {
|
|||||||
|
|
||||||
giveFocusToAIfNone()
|
giveFocusToAIfNone()
|
||||||
|
|
||||||
if (binding.contentMain.inputTeamA.isFocused) {
|
if (binding.contentMain.inputTeamA.isFocused)
|
||||||
if (binding.contentMain.inputTeamA.text.toString().equals("-")) {
|
{
|
||||||
|
if (binding.contentMain.inputTeamA.text.toString().equals("-"))
|
||||||
|
{
|
||||||
binding.contentMain.inputTeamA.text.clear()
|
binding.contentMain.inputTeamA.text.clear()
|
||||||
} else if (binding.contentMain.inputTeamA.text.isNotEmpty()) {
|
}
|
||||||
|
else if (binding.contentMain.inputTeamA.text.isNotEmpty())
|
||||||
|
{
|
||||||
tempInt=binding.contentMain.inputTeamA.text.toString().toInt() * -1
|
tempInt=binding.contentMain.inputTeamA.text.toString().toInt() * -1
|
||||||
binding.contentMain.inputTeamA.setText(tempInt.toString())
|
binding.contentMain.inputTeamA.setText(tempInt.toString())
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
updateOnChange=false
|
updateOnChange=false
|
||||||
appendToFocusedInput('-')
|
appendToFocusedInput('-')
|
||||||
currentRound=Round(1 , 1)
|
currentRound=Round(1 , 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
} else if (binding.contentMain.inputTeamB.isFocused) {
|
}
|
||||||
if (binding.contentMain.inputTeamB.text.toString().equals("-")) {
|
else if (binding.contentMain.inputTeamB.isFocused)
|
||||||
|
{
|
||||||
|
if (binding.contentMain.inputTeamB.text.toString().equals("-"))
|
||||||
|
{
|
||||||
binding.contentMain.inputTeamB.text.clear()
|
binding.contentMain.inputTeamB.text.clear()
|
||||||
} else if (binding.contentMain.inputTeamB.text.isNotEmpty()) {
|
}
|
||||||
|
else if (binding.contentMain.inputTeamB.text.isNotEmpty())
|
||||||
|
{
|
||||||
tempInt=binding.contentMain.inputTeamB.text.toString().toInt() * -1
|
tempInt=binding.contentMain.inputTeamB.text.toString().toInt() * -1
|
||||||
binding.contentMain.inputTeamB.setText(tempInt.toString())
|
binding.contentMain.inputTeamB.setText(tempInt.toString())
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
updateOnChange=false
|
updateOnChange=false
|
||||||
appendToFocusedInput('-')
|
appendToFocusedInput('-')
|
||||||
currentRound=Round(1 , 1)
|
currentRound=Round(1 , 1)
|
||||||
@@ -272,14 +336,19 @@ class MainActivity : AppCompatActivity() {
|
|||||||
binding.contentMain.buttonBack.setOnClickListener {
|
binding.contentMain.buttonBack.setOnClickListener {
|
||||||
giveFocusToAIfNone()
|
giveFocusToAIfNone()
|
||||||
|
|
||||||
if (binding.contentMain.inputTeamA.isFocused) {
|
if (binding.contentMain.inputTeamA.isFocused)
|
||||||
if (binding.contentMain.inputTeamA.text.isNotEmpty()) {
|
{
|
||||||
|
if (binding.contentMain.inputTeamA.text.isNotEmpty())
|
||||||
|
{
|
||||||
val string=binding.contentMain.inputTeamA.text.toString()
|
val string=binding.contentMain.inputTeamA.text.toString()
|
||||||
binding.contentMain.inputTeamA.setText(string.substring(0 , string.length - 1))
|
binding.contentMain.inputTeamA.setText(string.substring(0 , string.length - 1))
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (binding.contentMain.inputTeamB.isFocused) {
|
}
|
||||||
if (binding.contentMain.inputTeamB.text.isNotEmpty()) {
|
else if (binding.contentMain.inputTeamB.isFocused)
|
||||||
|
{
|
||||||
|
if (binding.contentMain.inputTeamB.text.isNotEmpty())
|
||||||
|
{
|
||||||
val string=binding.contentMain.inputTeamB.text.toString()
|
val string=binding.contentMain.inputTeamB.text.toString()
|
||||||
binding.contentMain.inputTeamB.setText(string.substring(0 , string.length - 1))
|
binding.contentMain.inputTeamB.setText(string.substring(0 , string.length - 1))
|
||||||
}
|
}
|
||||||
@@ -289,7 +358,8 @@ class MainActivity : AppCompatActivity() {
|
|||||||
binding.contentMain.submit.setOnClickListener {
|
binding.contentMain.submit.setOnClickListener {
|
||||||
giveFocusToAIfNone()
|
giveFocusToAIfNone()
|
||||||
|
|
||||||
if (binding.contentMain.inputTeamA.text.isNotEmpty() && binding.contentMain.inputTeamB.text.isNotEmpty()) {
|
if (binding.contentMain.inputTeamA.text.isNotEmpty() && binding.contentMain.inputTeamB.text.isNotEmpty())
|
||||||
|
{
|
||||||
|
|
||||||
history.logRound(
|
history.logRound(
|
||||||
Round(
|
Round(
|
||||||
@@ -309,7 +379,8 @@ class MainActivity : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onSaveInstanceState(outState: Bundle) {
|
override fun onSaveInstanceState(outState: Bundle)
|
||||||
|
{
|
||||||
super.onSaveInstanceState(outState)
|
super.onSaveInstanceState(outState)
|
||||||
|
|
||||||
val prefs=this.getSharedPreferences("Settings" , MODE_PRIVATE).edit()
|
val prefs=this.getSharedPreferences("Settings" , MODE_PRIVATE).edit()
|
||||||
@@ -320,7 +391,8 @@ class MainActivity : AppCompatActivity() {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
||||||
|
|
||||||
@@ -331,9 +403,12 @@ class MainActivity : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
override fun onOptionsItemSelected(item: MenuItem): Boolean
|
||||||
return when (item.itemId) {
|
{
|
||||||
R.id.action_clear -> {
|
return when (item.itemId)
|
||||||
|
{
|
||||||
|
R.id.action_clear ->
|
||||||
|
{
|
||||||
val builder=AlertDialog.Builder(this)
|
val builder=AlertDialog.Builder(this)
|
||||||
builder.setMessage(getString(R.string.confirmClear))
|
builder.setMessage(getString(R.string.confirmClear))
|
||||||
.setTitle(R.string.clear)
|
.setTitle(R.string.clear)
|
||||||
@@ -349,19 +424,23 @@ class MainActivity : AppCompatActivity() {
|
|||||||
builder.create().show()
|
builder.create().show()
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
R.id.action_undo -> {
|
R.id.action_undo ->
|
||||||
|
{
|
||||||
undoLastRound()
|
undoLastRound()
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
R.id.action_theme -> {
|
R.id.action_theme ->
|
||||||
|
{
|
||||||
chooseThemeDialog()
|
chooseThemeDialog()
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
R.id.action_language -> {
|
R.id.action_language ->
|
||||||
|
{
|
||||||
chooseLanguageDialog()
|
chooseLanguageDialog()
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
R.id.action_screenOn -> {
|
R.id.action_screenOn ->
|
||||||
|
{
|
||||||
item.isChecked=!item.isChecked
|
item.isChecked=!item.isChecked
|
||||||
keepScreenOn(item.isChecked)
|
keepScreenOn(item.isChecked)
|
||||||
true
|
true
|
||||||
@@ -370,24 +449,29 @@ class MainActivity : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun hideKeyboard() {
|
private fun hideKeyboard()
|
||||||
|
{
|
||||||
val imm: InputMethodManager=
|
val imm: InputMethodManager=
|
||||||
getSystemService(INPUT_METHOD_SERVICE) as InputMethodManager
|
getSystemService(INPUT_METHOD_SERVICE) as InputMethodManager
|
||||||
imm.hideSoftInputFromWindow(currentFocus!!.windowToken , 0)
|
imm.hideSoftInputFromWindow(currentFocus!!.windowToken , 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun giveFocusToAIfNone() {
|
private fun giveFocusToAIfNone()
|
||||||
if (!binding.contentMain.inputTeamA.isFocused && !binding.contentMain.inputTeamB.isFocused) {
|
{
|
||||||
|
if (!binding.contentMain.inputTeamA.isFocused && !binding.contentMain.inputTeamB.isFocused)
|
||||||
|
{
|
||||||
binding.contentMain.inputTeamA.requestFocus()
|
binding.contentMain.inputTeamA.requestFocus()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun undoLastRound() {
|
private fun undoLastRound()
|
||||||
|
{
|
||||||
history.revertLastRound()
|
history.revertLastRound()
|
||||||
updateView()
|
updateView()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun updateView() {
|
private fun updateView()
|
||||||
|
{
|
||||||
binding.contentMain.scoreA.text=history.getScoreA().toString()
|
binding.contentMain.scoreA.text=history.getScoreA().toString()
|
||||||
binding.contentMain.scoreB.text=history.getScoreB().toString()
|
binding.contentMain.scoreB.text=history.getScoreB().toString()
|
||||||
|
|
||||||
@@ -395,7 +479,8 @@ class MainActivity : AppCompatActivity() {
|
|||||||
binding.contentMain.historyB.text=history.getHistoryB()
|
binding.contentMain.historyB.text=history.getHistoryB()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun clearAll() {
|
private fun clearAll()
|
||||||
|
{
|
||||||
binding.contentMain.historyA.text=""
|
binding.contentMain.historyA.text=""
|
||||||
binding.contentMain.historyB.text=""
|
binding.contentMain.historyB.text=""
|
||||||
binding.contentMain.inputTeamA.text.clear()
|
binding.contentMain.inputTeamA.text.clear()
|
||||||
@@ -406,29 +491,40 @@ class MainActivity : AppCompatActivity() {
|
|||||||
history.clearAll()
|
history.clearAll()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun appendToFocusedInput(toAppend: Char) {
|
private fun appendToFocusedInput(toAppend: Char)
|
||||||
if (binding.contentMain.inputTeamA.isFocused) {
|
{
|
||||||
|
if (binding.contentMain.inputTeamA.isFocused)
|
||||||
|
{
|
||||||
binding.contentMain.inputTeamA.text.append(toAppend)
|
binding.contentMain.inputTeamA.text.append(toAppend)
|
||||||
} else if (binding.contentMain.inputTeamB.isFocused) {
|
}
|
||||||
|
else if (binding.contentMain.inputTeamB.isFocused)
|
||||||
|
{
|
||||||
binding.contentMain.inputTeamB.text.append(toAppend)
|
binding.contentMain.inputTeamB.text.append(toAppend)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun enableSubmitButton() {
|
private fun enableSubmitButton()
|
||||||
|
{
|
||||||
binding.contentMain.submit.imageAlpha=255 // 0 being transparent and 255 being opaque
|
binding.contentMain.submit.imageAlpha=255 // 0 being transparent and 255 being opaque
|
||||||
binding.contentMain.submit.isEnabled=true
|
binding.contentMain.submit.isEnabled=true
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun disableSubmitButton() {
|
private fun disableSubmitButton()
|
||||||
|
{
|
||||||
binding.contentMain.submit.imageAlpha=60 // 0 being transparent and 255 being opaque
|
binding.contentMain.submit.imageAlpha=60 // 0 being transparent and 255 being opaque
|
||||||
binding.contentMain.submit.isEnabled=false
|
binding.contentMain.submit.isEnabled=false
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun chooseThemeDialog() {
|
private fun chooseThemeDialog()
|
||||||
|
{
|
||||||
|
|
||||||
val builder=AlertDialog.Builder(this)
|
val builder=AlertDialog.Builder(this)
|
||||||
builder.setTitle(getString(R.string.choose_theme_text))
|
builder.setTitle(getString(R.string.choose_theme_text))
|
||||||
val styles = arrayOf(getString(R.string.light), getString(R.string.dark), getString(R.string.android_default_text))
|
val styles=arrayOf(
|
||||||
|
getString(R.string.light) ,
|
||||||
|
getString(R.string.dark) ,
|
||||||
|
getString(R.string.android_default_text)
|
||||||
|
)
|
||||||
|
|
||||||
val checkedItem=
|
val checkedItem=
|
||||||
this.getSharedPreferences("Settings" , MODE_PRIVATE).getInt("Theme" , 2)
|
this.getSharedPreferences("Settings" , MODE_PRIVATE).getInt("Theme" , 2)
|
||||||
@@ -450,14 +546,16 @@ class MainActivity : AppCompatActivity() {
|
|||||||
dialog.show()
|
dialog.show()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun chooseLanguageDialog() {
|
private fun chooseLanguageDialog()
|
||||||
|
{
|
||||||
|
|
||||||
val builder=AlertDialog.Builder(this)
|
val builder=AlertDialog.Builder(this)
|
||||||
builder.setTitle(getString(R.string.choose_language_text))
|
builder.setTitle(getString(R.string.choose_language_text))
|
||||||
|
|
||||||
val languages_map=mapOf(
|
val languages_map=mapOf(
|
||||||
getString(R.string.english) to "en" ,
|
getString(R.string.english) to "en" ,
|
||||||
getString(R.string.german) to "de")
|
getString(R.string.german) to "de"
|
||||||
|
)
|
||||||
|
|
||||||
val languages_display_keys=languages_map.keys.toTypedArray()
|
val languages_display_keys=languages_map.keys.toTypedArray()
|
||||||
val languages_display_values=languages_map.values.toTypedArray()
|
val languages_display_values=languages_map.values.toTypedArray()
|
||||||
@@ -472,7 +570,8 @@ class MainActivity : AppCompatActivity() {
|
|||||||
|
|
||||||
builder.setSingleChoiceItems(languages_display_keys , checkedItemIndex) { dialog , which ->
|
builder.setSingleChoiceItems(languages_display_keys , checkedItemIndex) { dialog , which ->
|
||||||
|
|
||||||
val newLocale = LocaleListCompat.forLanguageTags(languages_map[languages_display_keys[which]])
|
val newLocale=
|
||||||
|
LocaleListCompat.forLanguageTags(languages_map[languages_display_keys[which]])
|
||||||
|
|
||||||
AppCompatDelegate.setApplicationLocales(newLocale)
|
AppCompatDelegate.setApplicationLocales(newLocale)
|
||||||
|
|
||||||
@@ -486,8 +585,10 @@ class MainActivity : AppCompatActivity() {
|
|||||||
dialog.show()
|
dialog.show()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun updateTheme(which: Int) {
|
private fun updateTheme(which: Int)
|
||||||
when (which) {
|
{
|
||||||
|
when (which)
|
||||||
|
{
|
||||||
0 -> AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO)
|
0 -> AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO)
|
||||||
1 -> AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES)
|
1 -> AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES)
|
||||||
2 -> AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM)
|
2 -> AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM)
|
||||||
@@ -495,10 +596,14 @@ class MainActivity : AppCompatActivity() {
|
|||||||
delegate.applyDayNight()
|
delegate.applyDayNight()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun keepScreenOn(keepOn: Boolean) {
|
private fun keepScreenOn(keepOn: Boolean)
|
||||||
if (keepOn) {
|
{
|
||||||
|
if (keepOn)
|
||||||
|
{
|
||||||
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
|
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
window.clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
|
window.clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,33 +2,46 @@ package me.zobrist.tichucounter
|
|||||||
|
|
||||||
import java.io.Serializable
|
import java.io.Serializable
|
||||||
|
|
||||||
class Round() : Serializable {
|
class Round() : Serializable
|
||||||
|
{
|
||||||
var scoreA: Int=0
|
var scoreA: Int=0
|
||||||
var scoreB: Int=0
|
var scoreB: Int=0
|
||||||
|
|
||||||
constructor(score: Int, isScoreA: Boolean) : this() {
|
constructor(score: Int , isScoreA: Boolean) : this()
|
||||||
if (isScoreA) {
|
{
|
||||||
|
if (isScoreA)
|
||||||
|
{
|
||||||
scoreA=score
|
scoreA=score
|
||||||
scoreB=calculateOtherScore(scoreA)
|
scoreB=calculateOtherScore(scoreA)
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
scoreB=score
|
scoreB=score
|
||||||
scoreA=calculateOtherScore(scoreB)
|
scoreA=calculateOtherScore(scoreB)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor(scoreA: Int, scoreB: Int) : this() {
|
constructor(scoreA: Int , scoreB: Int) : this()
|
||||||
|
{
|
||||||
this.scoreA=scoreA
|
this.scoreA=scoreA
|
||||||
this.scoreB=scoreB
|
this.scoreB=scoreB
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun calculateOtherScore(score: Int): Int {
|
private fun calculateOtherScore(score: Int): Int
|
||||||
if (score.isMultipleOf100() && score != 0) {
|
{
|
||||||
|
if (score.isMultipleOf100() && score != 0)
|
||||||
|
{
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
if (score in 101 ..125)
|
||||||
|
{
|
||||||
|
return 0 - (score % 100)
|
||||||
|
}
|
||||||
return 100 - (score % 100)
|
return 100 - (score % 100)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun isValidRound(): Boolean {
|
fun isValidRound(): Boolean
|
||||||
|
{
|
||||||
return (scoreA.isMultipleOf5()) && scoreB.isMultipleOf5() && (scoreA + scoreB).isMultipleOf100()
|
return (scoreA.isMultipleOf5()) && scoreB.isMultipleOf5() && (scoreA + scoreB).isMultipleOf100()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -9,9 +9,11 @@ import org.junit.Test
|
|||||||
*
|
*
|
||||||
* See [testing documentation](http://d.android.com/tools/testing).
|
* See [testing documentation](http://d.android.com/tools/testing).
|
||||||
*/
|
*/
|
||||||
class HistoryUnitTest {
|
class HistoryUnitTest
|
||||||
|
{
|
||||||
@Test
|
@Test
|
||||||
fun calculation_isCorrect() {
|
fun calculation_isCorrect()
|
||||||
|
{
|
||||||
val history=History()
|
val history=History()
|
||||||
|
|
||||||
history.revertLastRound()
|
history.revertLastRound()
|
||||||
|
|||||||
@@ -8,16 +8,19 @@ import org.junit.Test
|
|||||||
*
|
*
|
||||||
* See [testing documentation](http://d.android.com/tools/testing).
|
* See [testing documentation](http://d.android.com/tools/testing).
|
||||||
*/
|
*/
|
||||||
class RoundUnitTest {
|
class RoundUnitTest
|
||||||
|
{
|
||||||
@Test
|
@Test
|
||||||
fun calculation_isCorrect() {
|
fun calculation_isCorrect()
|
||||||
|
{
|
||||||
|
|
||||||
var inputScoreA=125
|
var inputScoreA=125
|
||||||
var inputScoreB=-25
|
var inputScoreB=-25
|
||||||
var temp: Round
|
var temp: Round
|
||||||
|
|
||||||
// Normal round range -25 to 125 as input
|
// Normal round range -25 to 125 as input
|
||||||
while (inputScoreB >= 125) {
|
while (inputScoreB <= 125)
|
||||||
|
{
|
||||||
temp=Round(inputScoreA , true)
|
temp=Round(inputScoreA , true)
|
||||||
assertEquals(inputScoreB , temp.scoreB)
|
assertEquals(inputScoreB , temp.scoreB)
|
||||||
assertTrue(temp.isValidRound())
|
assertTrue(temp.isValidRound())
|
||||||
@@ -35,7 +38,8 @@ class RoundUnitTest {
|
|||||||
inputScoreB=-25
|
inputScoreB=-25
|
||||||
|
|
||||||
// Normal round range -25 to 125 as input
|
// Normal round range -25 to 125 as input
|
||||||
while (inputScoreB >= 125) {
|
while (inputScoreB <= 125)
|
||||||
|
{
|
||||||
temp=Round(inputScoreA , true)
|
temp=Round(inputScoreA , true)
|
||||||
assertEquals(inputScoreB , temp.scoreB)
|
assertEquals(inputScoreB , temp.scoreB)
|
||||||
assertTrue(temp.isValidRound())
|
assertTrue(temp.isValidRound())
|
||||||
|
|||||||
Reference in New Issue
Block a user