7 Commits

10 changed files with 160 additions and 73 deletions

View File

@@ -4,21 +4,22 @@ apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 30
buildToolsVersion "30.0.1"
buildToolsVersion "30.0.2"
defaultConfig {
applicationId "me.zobrist.tichucounter"
minSdkVersion 16
targetSdkVersion 30
versionCode 2
versionName "1.0.0Beta1"
versionCode 3
versionName "1.0.0Beta2"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}

View File

@@ -6,6 +6,8 @@ import android.os.Bundle
import android.text.InputType
import android.view.Menu
import android.view.MenuItem
import android.view.WindowManager
import android.view.inputmethod.InputMethodManager
import android.widget.ScrollView
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.app.AppCompatDelegate
@@ -31,11 +33,29 @@ class MainActivity : AppCompatActivity() {
inputTeamA.requestFocus()
disableSubmitButton()
updateTheme(this.getSharedPreferences("Settings", Context.MODE_PRIVATE).getInt("Theme", 2))
keepScreenOn(
this.getSharedPreferences("Settings", Context.MODE_PRIVATE)
.getBoolean("Screen_On", false)
)
history = savedInstanceState?.getParcelable("history") ?: History()
updateView()
inputTeamA.setOnFocusChangeListener { view, b ->
if (b) {
hideKeyboard()
}
}
inputTeamB.setOnFocusChangeListener { view, b ->
if (b) {
hideKeyboard()
}
}
inputTeamA.doOnTextChanged { text, start, count, after ->
if (inputTeamA.isFocused) {
if (inputTeamA.text.isNotEmpty()) {
@@ -47,18 +67,18 @@ class MainActivity : AppCompatActivity() {
Round(0, 0)
}
inputTeamB.setText(currentRound.scoreB.toString())
}else{
} else {
updateOnChange = true
}
}else{
} else {
inputTeamA.text.clear()
inputTeamB.text.clear()
}
}
if(currentRound.isValidRound()){
if (currentRound.isValidRound() && inputTeamA.text.isNotEmpty() && inputTeamB.text.isNotEmpty()) {
enableSubmitButton()
}else{
} else {
disableSubmitButton()
}
}
@@ -67,80 +87,89 @@ class MainActivity : AppCompatActivity() {
inputTeamB.doOnTextChanged { text, start, count, after ->
if (inputTeamB.isFocused) {
if (inputTeamB.text.isNotEmpty()){
if(updateOnChange){
if (inputTeamB.text.isNotEmpty()) {
if (updateOnChange) {
currentRound = try {
Round(text.toString().toInt(), false)
} catch (e: java.lang.Exception){
} catch (e: java.lang.Exception) {
Round(0, 0)
}
inputTeamA.setText(currentRound.scoreA.toString())
}else{
} else {
updateOnChange = true
}
}else{
} else {
inputTeamA.text.clear()
inputTeamB.text.clear()
}
}
if(currentRound.isValidRound()){
if (currentRound.isValidRound() && inputTeamA.text.isNotEmpty() && inputTeamB.text.isNotEmpty()) {
enableSubmitButton()
}else{
} else {
disableSubmitButton()
}
}
buttonAdd100.setOnClickListener {
giveFocusToAIfNone()
if (inputTeamA.isFocused) {
val temp = try {
currentRound.scoreA = try {
inputTeamA.text.toString().toInt() + 100
} catch (e: Exception) {
inputTeamB.setText(0.toString())
currentRound.scoreB = 0
inputTeamB.setText(currentRound.scoreB.toString())
100
}
updateOnChange = false
inputTeamA.setText(temp.toString())
inputTeamA.setText(currentRound.scoreA.toString())
}
if (inputTeamB.isFocused) {
val temp = try {
currentRound.scoreB = try {
inputTeamB.text.toString().toInt() + 100
} catch (e: Exception) {
inputTeamA.setText(0.toString())
currentRound.scoreA = 0
inputTeamA.setText(currentRound.scoreA.toString())
100
}
updateOnChange = false
inputTeamB.setText(temp.toString())
inputTeamB.setText(currentRound.scoreB.toString())
}
}
buttonSub100.setOnClickListener {
giveFocusToAIfNone()
if (inputTeamA.isFocused) {
val temp = try {
currentRound.scoreA = try {
inputTeamA.text.toString().toInt() - 100
} catch (e: Exception) {
currentRound.scoreB = 0
inputTeamB.setText(currentRound.scoreB.toString())
-100
}
updateOnChange = false
inputTeamA.setText(temp.toString())
inputTeamA.setText(currentRound.scoreA.toString())
}
if (inputTeamB.isFocused) {
val temp = try {
currentRound.scoreB = try {
inputTeamB.text.toString().toInt() - 100
} catch (e: Exception) {
currentRound.scoreA = 0
inputTeamA.setText(currentRound.scoreA.toString())
-100
}
updateOnChange = false
inputTeamB.setText(temp.toString())
inputTeamB.setText(currentRound.scoreB.toString())
}
}
@@ -199,21 +228,21 @@ class MainActivity : AppCompatActivity() {
giveFocusToAIfNone()
if(inputTeamA.isFocused ){
if (inputTeamA.text.isNotEmpty()){
if (inputTeamA.isFocused) {
if (inputTeamA.text.isNotEmpty()) {
tempInt = inputTeamA.text.toString().toInt() * -1
inputTeamA.setText(tempInt.toString())
}else{
} else {
invertB = false
invertA = true
}
}else if(inputTeamB.isFocused) {
if(inputTeamB.text.isNotEmpty()){
} else if (inputTeamB.isFocused) {
if (inputTeamB.text.isNotEmpty()) {
tempInt = inputTeamB.text.toString().toInt() * -1
inputTeamB.setText(tempInt.toString())
} else{
} else {
invertA = false
invertB = true
}
@@ -242,17 +271,20 @@ class MainActivity : AppCompatActivity() {
if (inputTeamA.text.isNotEmpty() && inputTeamB.text.isNotEmpty()) {
history.logRound(Round(inputTeamA.text.toString().toInt(), inputTeamB.text.toString().toInt()))
history.logRound(
Round(
inputTeamA.text.toString().toInt(),
inputTeamB.text.toString().toInt()
)
)
updateView()
inputTeamA.text.clear()
inputTeamB.text.clear()
disableSubmitButton()
scrollViewHistory.fullScroll(ScrollView.FOCUS_DOWN)
}
}
}
@@ -265,13 +297,30 @@ class MainActivity : AppCompatActivity() {
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)
menu.findItem(R.id.action_screenOn).isChecked =
this.getSharedPreferences("Settings", Context.MODE_PRIVATE)
.getBoolean("Screen_On", false)
return true
}
override fun onOptionsItemSelected(item: MenuItem): Boolean {
return when (item.itemId) {
R.id.action_clear -> {
clearAll()
val builder = AlertDialog.Builder(this)
builder.setMessage(getString(R.string.confirmClear))
.setTitle(R.string.clear)
.setCancelable(false)
.setPositiveButton(getString(R.string.yes)) { dialog, id ->
dialog.dismiss()
clearAll()
}
.setNegativeButton(getString(R.string.no)) { dialog, id ->
dialog.cancel()
}
builder.create().show()
true
}
R.id.action_undo -> {
@@ -282,10 +331,21 @@ class MainActivity : AppCompatActivity() {
chooseThemeDialog()
true
}
R.id.action_screenOn -> {
item.isChecked = !item.isChecked
keepScreenOn(item.isChecked)
true
}
else -> super.onOptionsItemSelected(item)
}
}
private fun hideKeyboard() {
val imm: InputMethodManager =
getSystemService(INPUT_METHOD_SERVICE) as InputMethodManager
imm.hideSoftInputFromWindow(currentFocus!!.windowToken, 0)
}
private fun giveFocusToAIfNone() {
if (!inputTeamA.isFocused && !inputTeamB.isFocused) {
inputTeamA.requestFocus()
@@ -293,10 +353,8 @@ class MainActivity : AppCompatActivity() {
}
private fun undoLastRound() {
history.revertLastRound()
updateView()
}
private fun updateView() {
@@ -318,24 +376,21 @@ class MainActivity : AppCompatActivity() {
history.clearAll()
}
private fun appendToFocusedInput(toAppend: Char){
if(inputTeamA.isFocused){
if(invertA){
private fun appendToFocusedInput(toAppend: Char) {
if (inputTeamA.isFocused) {
if (invertA) {
invertA = false
inputTeamA.text.append('-')
}
inputTeamA.text.append(toAppend)
}else if(inputTeamB.isFocused)
{
if(invertB){
} else if (inputTeamB.isFocused) {
if (invertB) {
invertB = false
inputTeamB.text.append('-')
}
inputTeamB.text.append(toAppend)
}
}
private fun enableSubmitButton() {
@@ -343,7 +398,7 @@ class MainActivity : AppCompatActivity() {
submit.isEnabled = true
}
private fun disableSubmitButton(){
private fun disableSubmitButton() {
submit.imageAlpha = 60 // 0 being transparent and 255 being opaque
submit.isEnabled = false
}
@@ -352,7 +407,7 @@ class MainActivity : AppCompatActivity() {
val builder = AlertDialog.Builder(this)
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("", Context.MODE_PRIVATE).getInt("Theme", 2)
@@ -381,4 +436,16 @@ class MainActivity : AppCompatActivity() {
}
delegate.applyDayNight()
}
private fun keepScreenOn(keepOn: Boolean) {
if (keepOn) {
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
} else {
window.clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
}
val prefs = this.getSharedPreferences("Settings", Context.MODE_PRIVATE).edit()
prefs.putBoolean("Screen_On", keepOn)
prefs.apply()
}
}

View File

@@ -2,7 +2,7 @@ package me.zobrist.tichucounter
import java.io.Serializable
class Round(): Serializable {
class Round() : Serializable {
var scoreA: Int = 0
var scoreB: Int = 0

View File

@@ -17,13 +17,13 @@
app:layout_constraintTop_toTopOf="parent">
<LinearLayout
android:id="@+id/Names"
android:id="@+id/viewNames"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<EditText
android:id="@+id/NameTeamA"
android:id="@+id/nameTeamA"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
@@ -37,7 +37,7 @@
android:textAppearance="@style/TextAppearance.AppCompat.Large" />
<EditText
android:id="@+id/NameTeamB"
android:id="@+id/nameTeamB"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
@@ -53,7 +53,7 @@
</LinearLayout>
<LinearLayout
android:id="@+id/Score"
android:id="@+id/viewScore"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
@@ -86,7 +86,8 @@
android:id="@+id/scrollViewHistory"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="16dp">
android:layout_marginTop="16dp"
android:clickable="true">
<LinearLayout
android:layout_width="match_parent"
@@ -123,7 +124,7 @@
app:layout_constraintStart_toEndOf="@+id/left">
<LinearLayout
android:id="@+id/Input"
android:id="@+id/viewInput"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">

View File

@@ -7,14 +7,14 @@
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<LinearLayout
android:id="@+id/Names"
android:id="@+id/viewNames"
android:layout_width="match_parent"
android:layout_height="0dp"
android:orientation="horizontal"
app:layout_constraintTop_toTopOf="parent">
<EditText
android:id="@+id/NameTeamA"
android:id="@+id/nameTeamA"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
@@ -28,7 +28,7 @@
android:textAppearance="@style/TextAppearance.AppCompat.Large" />
<EditText
android:id="@+id/NameTeamB"
android:id="@+id/nameTeamB"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
@@ -44,11 +44,11 @@
</LinearLayout>
<LinearLayout
android:id="@+id/Score"
android:id="@+id/viewScore"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintTop_toBottomOf="@+id/Names">
app:layout_constraintTop_toBottomOf="@+id/viewNames">
<TextView
android:id="@+id/scoreA"
@@ -86,8 +86,9 @@
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginTop="16dp"
app:layout_constraintBottom_toTopOf="@+id/Input"
app:layout_constraintTop_toBottomOf="@+id/Score">
android:clickable="true"
app:layout_constraintBottom_toTopOf="@+id/viewInput"
app:layout_constraintTop_toBottomOf="@+id/viewScore">
<LinearLayout
android:layout_width="match_parent"
@@ -118,10 +119,10 @@
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="?android:attr/listDivider"
app:layout_constraintBottom_toBottomOf="@+id/Score" />
app:layout_constraintBottom_toBottomOf="@+id/viewScore" />
<LinearLayout
android:id="@+id/Input"
android:id="@+id/viewInput"
android:layout_width="match_parent"
android:layout_height="0dp"
android:orientation="horizontal"

View File

@@ -17,4 +17,9 @@
android:id="@+id/action_theme"
android:orderInCategory="15"
android:title="@string/choose_theme_text" />
<item
android:id="@+id/action_screenOn"
android:checkable="true"
android:orderInCategory="20"
android:title="@string/keep_screen_on" />
</menu>

View File

@@ -1,6 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="clear">Neues Spiel Starten</string>
<string name="undo">Letzte Runde Löschen</string>
<string name="clear">Neues Spiel starten</string>
<string name="undo">Letzte Runde löschen</string>
<string name="choose_theme_text">Theme auswählen</string>
<string name="keep_screen_on">Bildschirm eingeschaltet lassen</string>
<string name="confirmClear">Möchten Sie das laufende Spiel wirklich löshen?</string>
<string name="yes">Ja</string>
<string name="no">Nein</string>
</resources>

View File

@@ -1,6 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="clear">Neus Spil Starte</string>
<string name="undo">Letschti Rundi Lösche</string>
<string name="clear">Neus Spil starte</string>
<string name="undo">Letschti Rundi lösche</string>
<string name="choose_theme_text">Usgsehe ändere</string>
<string name="keep_screen_on">Bildschirm igschalted la</string>
<string name="confirmClear">Wosch ds loufende Spil würklech lösche?</string>
<string name="yes">Ja</string>
<string name="no">Nei</string>
</resources>

View File

@@ -4,7 +4,11 @@
<string name="team_a" translatable="false">Team A</string>
<string name="team_b" translatable="false">Team B</string>
<string name="clear">Start New Game</string>
<string name="undo">Undo Last Round</string>
<string name="clear">Start new game</string>
<string name="undo">Undo last round</string>
<string name="choose_theme_text">Choose theme</string>
<string name="keep_screen_on">Keep screen on</string>
<string name="confirmClear">Do you really want to delete the current game?</string>
<string name="yes">Yes</string>
<string name="no">No</string>
</resources>

View File

@@ -1,6 +1,6 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = "1.3.72"
ext.kotlin_version = "1.4.0"
repositories {
google()
jcenter()