Merge branch 'release/1.0.0'

This commit is contained in:
2020-10-04 21:50:32 +02:00
13 changed files with 219 additions and 137 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 1
versionName "1.0"
versionCode 7
versionName "1.0.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
@@ -37,11 +38,14 @@ dependencies {
implementation 'androidx.core:core-ktx:1.3.1'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.2.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.google.android.play:core:1.8.0'
implementation 'com.google.android.play:core-ktx:1.8.1'
implementation 'com.google.code.gson:gson:2.8.5'
implementation 'androidx.constraintlayout:constraintlayout:2.0.1'
implementation 'androidx.navigation:navigation-fragment-ktx:2.3.0'
implementation 'androidx.navigation:navigation-ui-ktx:2.3.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}

View File

@@ -8,7 +8,8 @@
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
android:theme="@style/AppTheme"
android:fullBackupContent="@xml/backup_descriptor">
<activity
android:name=".MainActivity"
android:windowSoftInputMode="adjustPan"

View File

@@ -2,16 +2,10 @@
package me.zobrist.tichucounter
import android.os.Parcel
import android.os.Parcelable
class History() : Parcelable {
class History {
private var scores: ArrayList<Round> = ArrayList()
constructor(parcel: Parcel) : this() {
scores = parcel.readSerializable() as ArrayList<Round>
}
fun getScoreA(): Int {
var tempScore = 0
scores.forEach {
@@ -31,7 +25,7 @@ class History() : Parcelable {
fun getHistoryA(): String {
var tempHistory = String()
scores.forEach {
tempHistory = tempHistory.plus(it.scoreA.toString()).plus("\n")
tempHistory += it.scoreA.toString() + "\n"
}
return tempHistory
}
@@ -39,7 +33,7 @@ class History() : Parcelable {
fun getHistoryB(): String {
var tempHistory = String()
scores.forEach {
tempHistory = tempHistory.plus(it.scoreB.toString()).plus("\n")
tempHistory += it.scoreB.toString() + "\n"
}
return tempHistory
}
@@ -61,23 +55,4 @@ class History() : Parcelable {
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

@@ -6,17 +6,17 @@ 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
import androidx.core.widget.doOnTextChanged
import com.google.gson.Gson
import kotlinx.android.synthetic.main.content_main.*
class MainActivity : AppCompatActivity() {
private var invertA: Boolean = false
private var invertB: Boolean = false
private var updateOnChange: Boolean = true
private lateinit var history: History
@@ -31,11 +31,30 @@ 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()
val json = this.getSharedPreferences("Settings", Context.MODE_PRIVATE).getString("history", "{\"scores\":[]}")
history = Gson().fromJson(json, History::class.java)
nameTeamA.setText(this.getSharedPreferences("Settings", Context.MODE_PRIVATE).getString("nameTeamA", "TeamA"))
nameTeamB.setText(this.getSharedPreferences("Settings", Context.MODE_PRIVATE).getString("nameTeamB", "TeamB"))
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()) {
@@ -44,7 +63,7 @@ class MainActivity : AppCompatActivity() {
Round(text.toString().toInt(), true)
} catch (e: java.lang.Exception) {
Round(0, 0)
Round(1, 1)
}
inputTeamB.setText(currentRound.scoreB.toString())
} else {
@@ -56,7 +75,7 @@ class MainActivity : AppCompatActivity() {
}
}
if(currentRound.isValidRound()){
if (currentRound.isValidRound() && inputTeamA.text.isNotEmpty() && inputTeamB.text.isNotEmpty()) {
enableSubmitButton()
} else {
disableSubmitButton()
@@ -73,7 +92,7 @@ class MainActivity : AppCompatActivity() {
Round(text.toString().toInt(), false)
} catch (e: java.lang.Exception) {
Round(0, 0)
Round(1, 1)
}
inputTeamA.setText(currentRound.scoreA.toString())
@@ -87,7 +106,7 @@ class MainActivity : AppCompatActivity() {
}
}
if(currentRound.isValidRound()){
if (currentRound.isValidRound() && inputTeamA.text.isNotEmpty() && inputTeamB.text.isNotEmpty()) {
enableSubmitButton()
} else {
disableSubmitButton()
@@ -95,52 +114,61 @@ class MainActivity : AppCompatActivity() {
}
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())
}
}
@@ -200,22 +228,28 @@ class MainActivity : AppCompatActivity() {
giveFocusToAIfNone()
if (inputTeamA.isFocused) {
if (inputTeamA.text.isNotEmpty()){
if (inputTeamA.text.toString().equals("-")) {
inputTeamA.text.clear()
} else if (inputTeamA.text.isNotEmpty()) {
tempInt = inputTeamA.text.toString().toInt() * -1
inputTeamA.setText(tempInt.toString())
} else {
invertB = false
invertA = true
updateOnChange = false
appendToFocusedInput('-')
currentRound = Round(1,1)
}
} else if (inputTeamB.isFocused) {
if(inputTeamB.text.isNotEmpty()){
if (inputTeamB.text.toString().equals("-")) {
inputTeamB.text.clear()
} else if (inputTeamB.text.isNotEmpty()) {
tempInt = inputTeamB.text.toString().toInt() * -1
inputTeamB.setText(tempInt.toString())
} else {
invertA = false
invertB = true
updateOnChange = false
appendToFocusedInput('-')
currentRound = Round(1,1)
}
}
}
@@ -242,36 +276,62 @@ 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)
}
}
}
override fun onSaveInstanceState(outState: Bundle) {
super.onSaveInstanceState(outState)
outState.putParcelable("history", history)
val prefs = this.getSharedPreferences("Settings", Context.MODE_PRIVATE).edit()
prefs.putString("history", Gson().toJson(history))
prefs.putString("nameTeamA", nameTeamA.text.toString())
prefs.putString("nameTeamB", nameTeamB.text.toString())
prefs.apply()
}
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 -> {
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 +342,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 +364,8 @@ class MainActivity : AppCompatActivity() {
}
private fun undoLastRound() {
history.revertLastRound()
updateView()
}
private fun updateView() {
@@ -320,22 +389,10 @@ class MainActivity : AppCompatActivity() {
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){
invertB = false
inputTeamB.text.append('-')
}
} else if (inputTeamB.isFocused) {
inputTeamB.text.append(toAppend)
}
}
private fun enableSubmitButton() {
@@ -354,7 +411,8 @@ class MainActivity : AppCompatActivity() {
builder.setTitle(getString(R.string.choose_theme_text))
val styles = arrayOf("Light", "Dark", "System default")
val checkedItem = this.getSharedPreferences("", Context.MODE_PRIVATE).getInt("Theme", 2)
val checkedItem =
this.getSharedPreferences("Settings", Context.MODE_PRIVATE).getInt("Theme", 2)
val prefs = this.getSharedPreferences("Settings", Context.MODE_PRIVATE).edit()
@@ -381,4 +439,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

@@ -1,6 +1,8 @@
package me.zobrist.tichucounter
class Round() {
import java.io.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"
@@ -34,10 +34,10 @@
android:selectAllOnFocus="true"
android:singleLine="true"
android:text="@string/team_a"
android:textAppearance="@style/TextAppearance.AppCompat.Display1" />
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"
@@ -48,12 +48,12 @@
android:selectAllOnFocus="true"
android:singleLine="true"
android:text="@string/team_b"
android:textAppearance="@style/TextAppearance.AppCompat.Display1" />
android:textAppearance="@style/TextAppearance.AppCompat.Large" />
</LinearLayout>
<LinearLayout
android:id="@+id/Score"
android:id="@+id/viewScore"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
@@ -66,7 +66,8 @@
android:gravity="center"
android:text="0"
android:textAppearance="@style/TextAppearance.AppCompat.Body1"
android:textSize="18sp" />
android:textSize="18sp"
android:textStyle="bold" />
<TextView
android:id="@+id/scoreB"
@@ -76,7 +77,8 @@
android:gravity="center"
android:text="0"
android:textAppearance="@style/TextAppearance.AppCompat.Body1"
android:textSize="18sp" />
android:textSize="18sp"
android:textStyle="bold" />
</LinearLayout>
@@ -84,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="false">
<LinearLayout
android:layout_width="match_parent"
@@ -121,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">
@@ -270,7 +273,8 @@
android:paddingTop="15dp"
android:paddingBottom="15dp"
android:scaleType="fitCenter"
app:srcCompat="@drawable/back" />
app:srcCompat="@drawable/back"
android:contentDescription="TODO" />
</LinearLayout>
@@ -309,7 +313,8 @@
android:layout_height="match_parent"
android:layout_weight="1.0"
android:scaleType="fitCenter"
app:srcCompat="@drawable/checkmark" />
app:srcCompat="@drawable/checkmark"
android:contentDescription="TODO" />
</LinearLayout>
</LinearLayout>

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"
@@ -25,30 +25,30 @@
android:selectAllOnFocus="true"
android:singleLine="true"
android:text="@string/team_a"
android:textAppearance="@style/TextAppearance.AppCompat.Display1" />
android:textAppearance="@style/TextAppearance.AppCompat.Large" />
<EditText
android:id="@+id/NameTeamB"
android:imeOptions="actionDone"
android:id="@+id/nameTeamB"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:autofillHints=""
android:gravity="center"
android:imeOptions="actionDone"
android:inputType="text"
android:selectAllOnFocus="true"
android:singleLine="true"
android:text="@string/team_b"
android:textAppearance="@style/TextAppearance.AppCompat.Display1" />
android:textAppearance="@style/TextAppearance.AppCompat.Large" />
</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"
@@ -58,7 +58,8 @@
android:gravity="center"
android:text="0"
android:textAppearance="@style/TextAppearance.AppCompat.Body1"
android:textSize="18sp" />
android:textSize="18sp"
android:textStyle="bold" />
<TextView
android:id="@+id/scoreB"
@@ -68,7 +69,8 @@
android:gravity="center"
android:text="0"
android:textAppearance="@style/TextAppearance.AppCompat.Body1"
android:textSize="18sp" />
android:textSize="18sp"
android:textStyle="bold" />
</LinearLayout>
@@ -84,8 +86,8 @@
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">
app:layout_constraintBottom_toTopOf="@+id/viewInput"
app:layout_constraintTop_toBottomOf="@+id/viewScore">
<LinearLayout
android:layout_width="match_parent"
@@ -116,10 +118,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"
@@ -272,7 +274,8 @@
android:paddingTop="15dp"
android:paddingBottom="15dp"
android:scaleType="fitCenter"
app:srcCompat="@drawable/back" />
app:srcCompat="@drawable/back"
android:contentDescription="TODO" />
</LinearLayout>
@@ -314,6 +317,7 @@
android:layout_height="match_parent"
android:layout_weight="1.0"
android:scaleType="fitCenter"
app:srcCompat="@drawable/checkmark" />
app:srcCompat="@drawable/checkmark"
android:contentDescription="TODO" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

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öschen?</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

@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<full-backup-content>
<!-- Exclude specific shared preferences that contain GCM registration Id -->
</full-backup-content>

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.10"
repositories {
google()
jcenter()