Merge pull request 'Add drone build script.' (#3) from feature/droneBuild into master
All checks were successful
continuous-integration/drone/push Build is passing

Reviewed-on: fabian/TichuCounter#3
This commit was merged in pull request #3.
This commit is contained in:
2022-12-08 23:24:50 +01:00
27 changed files with 635 additions and 398 deletions

14
.drone.yml Normal file
View File

@@ -0,0 +1,14 @@
---
kind: pipeline
type: docker
name: Android
steps:
- name: build
image: mingc/android-build-box
commands:
- ./gradlew build
when:
event:
- push
- pull_request

1
.gitignore vendored
View File

@@ -12,3 +12,4 @@
/captures /captures
.externalNativeBuild .externalNativeBuild
.cxx .cxx
.idea

View File

@@ -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">

6
.idea/compiler.xml generated Normal file
View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<bytecodeTargetLevel target="11" />
</component>
</project>

5
.idea/gradle.xml generated
View File

@@ -4,17 +4,16 @@
<component name="GradleSettings"> <component name="GradleSettings">
<option name="linkedExternalProjectsSettings"> <option name="linkedExternalProjectsSettings">
<GradleProjectSettings> <GradleProjectSettings>
<option name="testRunner" value="PLATFORM" /> <option name="testRunner" value="GRADLE" />
<option name="distributionType" value="DEFAULT_WRAPPED" /> <option name="distributionType" value="DEFAULT_WRAPPED" />
<option name="externalProjectPath" value="$PROJECT_DIR$" /> <option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="gradleJvm" value="1.8" /> <option name="gradleJvm" value="Android Studio java home" />
<option name="modules"> <option name="modules">
<set> <set>
<option value="$PROJECT_DIR$" /> <option value="$PROJECT_DIR$" />
<option value="$PROJECT_DIR$/app" /> <option value="$PROJECT_DIR$/app" />
</set> </set>
</option> </option>
<option name="resolveModulePerSourceSet" value="false" />
</GradleProjectSettings> </GradleProjectSettings>
</option> </option>
</component> </component>

View File

@@ -0,0 +1,8 @@
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="ClangTidy" enabled="true" level="WARNING" enabled_by_default="true">
<option name="clangTidyChecks" value="-*,bugprone-argument-comment,bugprone-assert-side-effect,bugprone-bad-signal-to-kill-thread,bugprone-branch-clone,bugprone-copy-constructor-init,bugprone-dangling-handle,bugprone-dynamic-static-initializers,bugprone-fold-init-type,bugprone-forward-declaration-namespace,bugprone-forwarding-reference-overload,bugprone-inaccurate-erase,bugprone-incorrect-roundings,bugprone-integer-division,bugprone-lambda-function-name,bugprone-macro-parentheses,bugprone-macro-repeated-side-effects,bugprone-misplaced-operator-in-strlen-in-alloc,bugprone-misplaced-pointer-arithmetic-in-alloc,bugprone-misplaced-widening-cast,bugprone-move-forwarding-reference,bugprone-multiple-statement-macro,bugprone-no-escape,bugprone-not-null-terminated-result,bugprone-parent-virtual-call,bugprone-posix-return,bugprone-reserved-identifier,bugprone-sizeof-container,bugprone-sizeof-expression,bugprone-spuriously-wake-up-functions,bugprone-string-constructor,bugprone-string-integer-assignment,bugprone-string-literal-with-embedded-nul,bugprone-suspicious-enum-usage,bugprone-suspicious-include,bugprone-suspicious-memset-usage,bugprone-suspicious-missing-comma,bugprone-suspicious-semicolon,bugprone-suspicious-string-compare,bugprone-swapped-arguments,bugprone-terminating-continue,bugprone-throw-keyword-missing,bugprone-too-small-loop-variable,bugprone-undefined-memory-manipulation,bugprone-undelegated-constructor,bugprone-unhandled-self-assignment,bugprone-unused-raii,bugprone-unused-return-value,bugprone-use-after-move,bugprone-virtual-near-miss,cert-dcl21-cpp,cert-dcl58-cpp,cert-err34-c,cert-err52-cpp,cert-err58-cpp,cert-err60-cpp,cert-flp30-c,cert-msc50-cpp,cert-msc51-cpp,cert-str34-c,cppcoreguidelines-interfaces-global-init,cppcoreguidelines-narrowing-conversions,cppcoreguidelines-pro-type-member-init,cppcoreguidelines-pro-type-static-cast-downcast,cppcoreguidelines-slicing,google-default-arguments,google-explicit-constructor,google-runtime-operator,hicpp-exception-baseclass,hicpp-multiway-paths-covered,misc-misplaced-const,misc-new-delete-overloads,misc-no-recursion,misc-non-copyable-objects,misc-throw-by-value-catch-by-reference,misc-unconventional-assign-operator,misc-uniqueptr-reset-release,modernize-avoid-bind,modernize-concat-nested-namespaces,modernize-deprecated-headers,modernize-deprecated-ios-base-aliases,modernize-loop-convert,modernize-make-shared,modernize-make-unique,modernize-pass-by-value,modernize-raw-string-literal,modernize-redundant-void-arg,modernize-replace-auto-ptr,modernize-replace-disallow-copy-and-assign-macro,modernize-replace-random-shuffle,modernize-return-braced-init-list,modernize-shrink-to-fit,modernize-unary-static-assert,modernize-use-auto,modernize-use-bool-literals,modernize-use-emplace,modernize-use-equals-default,modernize-use-equals-delete,modernize-use-nodiscard,modernize-use-noexcept,modernize-use-nullptr,modernize-use-override,modernize-use-transparent-functors,modernize-use-uncaught-exceptions,mpi-buffer-deref,mpi-type-mismatch,openmp-use-default-none,performance-faster-string-find,performance-for-range-copy,performance-implicit-conversion-in-loop,performance-inefficient-algorithm,performance-inefficient-string-concatenation,performance-inefficient-vector-operation,performance-move-const-arg,performance-move-constructor-init,performance-no-automatic-move,performance-noexcept-move-constructor,performance-trivially-destructible,performance-type-promotion-in-math-fn,performance-unnecessary-copy-initialization,performance-unnecessary-value-param,portability-simd-intrinsics,readability-avoid-const-params-in-decls,readability-const-return-type,readability-container-size-empty,readability-convert-member-functions-to-static,readability-delete-null-pointer,readability-deleted-default,readability-inconsistent-declaration-parameter-name,readability-make-member-function-const,readability-misleading-indentation,readability-misplaced-array-index,readability-non-const-parameter,readability-redundant-control-flow,readability-redundant-declaration,readability-redundant-function-ptr-dereference,readability-redundant-smartptr-get,readability-redundant-string-cstr,readability-redundant-string-init,readability-simplify-subscript-expr,readability-static-accessed-through-instance,readability-static-definition-in-anonymous-namespace,readability-string-compare,readability-uniqueptr-delete-release,readability-use-anyofallof,altera-id-dependent-backward-branch,altera-kernel-name-restriction,altera-single-work-item-barrier,altera-unroll-loops,bugprone-implicit-widening-of-multiplication-result,bugprone-signal-handler,bugprone-unhandled-exception-at-new,cert-pos47-c,cert-sig30-c,concurrency-mt-unsafe,concurrency-thread-canceltype-asynchronous,performance-no-int-to-ptr" />
</inspection_tool>
</profile>
</component>

View File

@@ -21,5 +21,10 @@
<option name="name" value="Google" /> <option name="name" value="Google" />
<option name="url" value="https://dl.google.com/dl/android/maven2/" /> <option name="url" value="https://dl.google.com/dl/android/maven2/" />
</remote-repository> </remote-repository>
<remote-repository>
<option name="id" value="MavenRepo" />
<option name="name" value="MavenRepo" />
<option name="url" value="https://repo.maven.apache.org/maven2/" />
</remote-repository>
</component> </component>
</project> </project>

22
.idea/misc.xml generated
View File

@@ -1,11 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="DesignSurface">
<option name="filePathToZoomLevelMap">
<map>
<entry key="app/src/main/res/layout/activity_main.xml" value="0.1" />
<entry key="app/src/main/res/layout/content_main.xml" value="0.1" />
<entry key="app/src/main/res/menu/menu_main.xml" value="0.1390625" />
</map>
</option>
</component>
<component name="NullableNotNullManager"> <component name="NullableNotNullManager">
<option name="myDefaultNullable" value="androidx.annotation.Nullable" /> <option name="myDefaultNullable" value="androidx.annotation.Nullable" />
<option name="myDefaultNotNull" value="androidx.annotation.NonNull" /> <option name="myDefaultNotNull" value="androidx.annotation.NonNull" />
<option name="myNullables"> <option name="myNullables">
<value> <value>
<list size="12"> <list size="15">
<item index="0" class="java.lang.String" itemvalue="org.jetbrains.annotations.Nullable" /> <item index="0" class="java.lang.String" itemvalue="org.jetbrains.annotations.Nullable" />
<item index="1" class="java.lang.String" itemvalue="javax.annotation.Nullable" /> <item index="1" class="java.lang.String" itemvalue="javax.annotation.Nullable" />
<item index="2" class="java.lang.String" itemvalue="javax.annotation.CheckForNull" /> <item index="2" class="java.lang.String" itemvalue="javax.annotation.CheckForNull" />
@@ -18,12 +27,15 @@
<item index="9" class="java.lang.String" itemvalue="org.checkerframework.checker.nullness.compatqual.NullableDecl" /> <item index="9" class="java.lang.String" itemvalue="org.checkerframework.checker.nullness.compatqual.NullableDecl" />
<item index="10" class="java.lang.String" itemvalue="org.checkerframework.checker.nullness.compatqual.NullableType" /> <item index="10" class="java.lang.String" itemvalue="org.checkerframework.checker.nullness.compatqual.NullableType" />
<item index="11" class="java.lang.String" itemvalue="com.android.annotations.Nullable" /> <item index="11" class="java.lang.String" itemvalue="com.android.annotations.Nullable" />
<item index="12" class="java.lang.String" itemvalue="org.eclipse.jdt.annotation.Nullable" />
<item index="13" class="java.lang.String" itemvalue="io.reactivex.annotations.Nullable" />
<item index="14" class="java.lang.String" itemvalue="io.reactivex.rxjava3.annotations.Nullable" />
</list> </list>
</value> </value>
</option> </option>
<option name="myNotNulls"> <option name="myNotNulls">
<value> <value>
<list size="11"> <list size="15">
<item index="0" class="java.lang.String" itemvalue="org.jetbrains.annotations.NotNull" /> <item index="0" class="java.lang.String" itemvalue="org.jetbrains.annotations.NotNull" />
<item index="1" class="java.lang.String" itemvalue="javax.annotation.Nonnull" /> <item index="1" class="java.lang.String" itemvalue="javax.annotation.Nonnull" />
<item index="2" class="java.lang.String" itemvalue="edu.umd.cs.findbugs.annotations.NonNull" /> <item index="2" class="java.lang.String" itemvalue="edu.umd.cs.findbugs.annotations.NonNull" />
@@ -35,11 +47,15 @@
<item index="8" class="java.lang.String" itemvalue="org.checkerframework.checker.nullness.compatqual.NonNullDecl" /> <item index="8" class="java.lang.String" itemvalue="org.checkerframework.checker.nullness.compatqual.NonNullDecl" />
<item index="9" class="java.lang.String" itemvalue="org.checkerframework.checker.nullness.compatqual.NonNullType" /> <item index="9" class="java.lang.String" itemvalue="org.checkerframework.checker.nullness.compatqual.NonNullType" />
<item index="10" class="java.lang.String" itemvalue="com.android.annotations.NonNull" /> <item index="10" class="java.lang.String" itemvalue="com.android.annotations.NonNull" />
<item index="11" class="java.lang.String" itemvalue="org.eclipse.jdt.annotation.NonNull" />
<item index="12" class="java.lang.String" itemvalue="io.reactivex.annotations.NonNull" />
<item index="13" class="java.lang.String" itemvalue="io.reactivex.rxjava3.annotations.NonNull" />
<item index="14" class="java.lang.String" itemvalue="lombok.NonNull" />
</list> </list>
</value> </value>
</option> </option>
</component> </component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.8" project-jdk-type="JavaSDK"> <component name="ProjectRootManager" version="2" languageLevel="JDK_11" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" /> <output url="file://$PROJECT_DIR$/build/classes" />
</component> </component>
<component name="ProjectType"> <component name="ProjectType">

View File

@@ -1,12 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="RunConfigurationProducerService">
<option name="ignoredProducers">
<set>
<option value="org.jetbrains.plugins.gradle.execution.test.runner.AllInPackageGradleConfigurationProducer" />
<option value="org.jetbrains.plugins.gradle.execution.test.runner.TestClassGradleConfigurationProducer" />
<option value="org.jetbrains.plugins.gradle.execution.test.runner.TestMethodGradleConfigurationProducer" />
</set>
</option>
</component>
</project>

View File

@@ -1,15 +1,13 @@
apply plugin: 'com.android.application' apply plugin: 'com.android.application'
apply plugin: 'kotlin-android' apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android { android {
compileSdkVersion 30 compileSdkVersion 32
buildToolsVersion "30.0.2"
defaultConfig { defaultConfig {
applicationId "me.zobrist.tichucounter" applicationId "me.zobrist.tichucounter"
minSdkVersion 16 minSdkVersion 16
targetSdkVersion 30 targetSdkVersion 32
versionCode 7 versionCode 7
versionName "1.0.0" versionName "1.0.0"
@@ -23,6 +21,11 @@ android {
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
} }
} }
buildFeatures {
viewBinding = true
}
compileOptions { compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8 sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8
@@ -30,22 +33,23 @@ android {
kotlinOptions { kotlinOptions {
jvmTarget = '1.8' jvmTarget = '1.8'
} }
namespace 'me.zobrist.tichucounter'
} }
dependencies { dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"]) implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.3.1' implementation 'androidx.core:core-ktx:1.8.0'
implementation 'androidx.appcompat:appcompat:1.2.0' implementation 'androidx.appcompat:appcompat:1.6.0-alpha05'
implementation 'com.google.android.material:material:1.2.0' implementation 'com.google.android.material:material:1.6.1'
implementation 'com.google.android.play:core:1.8.0'
implementation 'com.google.android.play:core-ktx:1.8.1' implementation 'com.google.android.play:core-ktx:1.8.1'
implementation 'com.google.code.gson:gson:2.8.5' implementation 'com.google.android.play:core-ktx:1.8.1'
implementation 'androidx.constraintlayout:constraintlayout:2.0.1' implementation 'com.google.code.gson:gson:2.8.9'
implementation 'androidx.navigation:navigation-fragment-ktx:2.3.0' implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'androidx.navigation:navigation-ui-ktx:2.3.0' implementation 'androidx.navigation:navigation-fragment-ktx:2.4.2'
implementation 'androidx.navigation:navigation-ui-ktx:2.4.2'
testImplementation 'junit:junit:4.12' testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.2' androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
} }

BIN
app/release/app-release.aab Normal file

Binary file not shown.

View File

@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android">
package="me.zobrist.tichucounter">
<application <application
android:allowBackup="true" android:allowBackup="true"
android:icon="@mipmap/ic_launcher" android:icon="@mipmap/ic_launcher"
android:label="@string/app_name" android:label="@string/app_name"
@@ -13,14 +13,22 @@
<activity <activity
android:name=".MainActivity" android:name=".MainActivity"
android:windowSoftInputMode="adjustPan" android:windowSoftInputMode="adjustPan"
android:label="@string/app_name" android:theme="@style/AppTheme.NoActionBar"
android:theme="@style/AppTheme.NoActionBar"> android:exported="true">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN" /> <action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" /> <category android:name="android.intent.category.LAUNCHER" />
</intent-filter> </intent-filter>
</activity> </activity>
<service
android:name="androidx.appcompat.app.AppLocalesMetadataHolderService"
android:enabled="false"
android:exported="false">
<meta-data
android:name="autoStoreLocales"
android:value="true" />
</service>
</application> </application>
</manifest> </manifest>

View File

@@ -0,0 +1,11 @@
package me.zobrist.tichucounter
fun Int.isMultipleOf5(): Boolean
{
return (this % 5) == 0
}
fun Int.isMultipleOf100(): Boolean
{
return (this % 100) == 0
}

View File

@@ -1,58 +1,65 @@
@file:Suppress("unused")
package me.zobrist.tichucounter package me.zobrist.tichucounter
class History
{
private var scores=ArrayList<Round>()
class History { fun getScoreA(): Int
private var scores: ArrayList<Round> = ArrayList() {
var tempScore=0
fun getScoreA(): Int {
var tempScore = 0
scores.forEach { scores.forEach {
tempScore += it.scoreA tempScore+=it.scoreA
} }
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
} }
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"
} }
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"
} }
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()
} }
} }

View File

@@ -1,7 +1,7 @@
package me.zobrist.tichucounter package me.zobrist.tichucounter
import android.app.AlertDialog import android.app.AlertDialog
import android.content.Context import android.content.Intent
import android.os.Bundle import android.os.Bundle
import android.text.InputType import android.text.InputType
import android.view.Menu import android.view.Menu
@@ -11,339 +11,437 @@ import android.view.inputmethod.InputMethodManager
import android.widget.ScrollView import android.widget.ScrollView
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.app.AppCompatDelegate import androidx.appcompat.app.AppCompatDelegate
import androidx.core.os.LocaleListCompat
import androidx.core.widget.doOnTextChanged import androidx.core.widget.doOnTextChanged
import com.google.gson.Gson import com.google.gson.Gson
import kotlinx.android.synthetic.main.content_main.* import me.zobrist.tichucounter.databinding.ActivityMainBinding
import java.util.*
class MainActivity : AppCompatActivity() { class MainActivity : AppCompatActivity()
{
private var updateOnChange: Boolean = true private var updateOnChange: Boolean=true
private lateinit var history: History private lateinit var history: History
private var currentRound = Round() private var currentRound=Round()
private var systemLocale=Locale.getDefault()
override fun onCreate(savedInstanceState: Bundle?) {
private lateinit var binding: ActivityMainBinding
override fun onCreate(savedInstanceState: Bundle?)
{
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main) binding=ActivityMainBinding.inflate(layoutInflater)
setSupportActionBar(findViewById(R.id.toolbar)) setContentView(binding.root)
inputTeamA.setRawInputType(InputType.TYPE_NULL)
inputTeamB.setRawInputType(InputType.TYPE_NULL) setSupportActionBar(binding.toolbar)
inputTeamA.requestFocus()
binding.contentMain.inputTeamA.setRawInputType(InputType.TYPE_NULL)
binding.contentMain.inputTeamB.setRawInputType(InputType.TYPE_NULL)
binding.contentMain.inputTeamA.requestFocus()
disableSubmitButton() disableSubmitButton()
updateTheme(this.getSharedPreferences("Settings", Context.MODE_PRIVATE).getInt("Theme", 2)) updateTheme(this.getSharedPreferences("Settings" , MODE_PRIVATE).getInt("Theme" , 2))
keepScreenOn( keepScreenOn(
this.getSharedPreferences("Settings", Context.MODE_PRIVATE) this.getSharedPreferences("Settings" , MODE_PRIVATE)
.getBoolean("Screen_On", false) .getBoolean("Screen_On" , false)
) )
val json = this.getSharedPreferences("Settings", Context.MODE_PRIVATE).getString("history", "{\"scores\":[]}")
history = Gson().fromJson(json, History::class.java) val json=this.getSharedPreferences("Settings" , MODE_PRIVATE)
nameTeamA.setText(this.getSharedPreferences("Settings", Context.MODE_PRIVATE).getString("nameTeamA", "TeamA")) .getString("history" , "{\"scores\":[]}")
nameTeamB.setText(this.getSharedPreferences("Settings", Context.MODE_PRIVATE).getString("nameTeamB", "TeamB")) history=Gson().fromJson(json , History::class.java)
binding.contentMain.nameTeamA.setText(
this.getSharedPreferences("Settings" , MODE_PRIVATE).getString("nameTeamA" , "TeamA")
)
binding.contentMain.nameTeamB.setText(
this.getSharedPreferences("Settings" , MODE_PRIVATE).getString("nameTeamB" , "TeamB")
)
updateView() updateView()
this.setListenes()
inputTeamA.setOnFocusChangeListener { view, b ->
if (b) { }
private fun setListenes()
{
binding.contentMain.inputTeamA.setOnFocusChangeListener { _ , b ->
if (b)
{
hideKeyboard() hideKeyboard()
} }
} }
inputTeamB.setOnFocusChangeListener { view, b -> binding.contentMain.inputTeamB.setOnFocusChangeListener { _ , b ->
if (b) { if (b)
{
hideKeyboard() hideKeyboard()
} }
} }
inputTeamA.doOnTextChanged { text, start, count, after -> binding.contentMain.inputTeamA.doOnTextChanged { text , _ , _ , _ ->
if (inputTeamA.isFocused) { if (binding.contentMain.inputTeamA.isFocused)
if (inputTeamA.text.isNotEmpty()) { {
if (updateOnChange) { if (binding.contentMain.inputTeamA.text.isNotEmpty())
currentRound = try { {
Round(text.toString().toInt(), true) if (updateOnChange)
{
currentRound=try
{
Round(text.toString().toInt() , true)
} catch (e: java.lang.Exception) {
Round(1, 1)
} }
inputTeamB.setText(currentRound.scoreB.toString()) catch (e: java.lang.Exception)
} else { {
updateOnChange = true Round(1 , 1)
}
binding.contentMain.inputTeamB.setText(currentRound.scoreB.toString())
} }
} else { else
inputTeamA.text.clear() {
inputTeamB.text.clear() updateOnChange=true
}
}
else
{
binding.contentMain.inputTeamA.text.clear()
binding.contentMain.inputTeamB.text.clear()
} }
} }
if (currentRound.isValidRound() && inputTeamA.text.isNotEmpty() && 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 , _ , _ , _ ->
if (binding.contentMain.inputTeamB.isFocused)
{
if (binding.contentMain.inputTeamB.text.isNotEmpty())
{
if (updateOnChange)
{
currentRound=try
{
Round(text.toString().toInt() , false)
inputTeamB.doOnTextChanged { text, start, count, after ->
if (inputTeamB.isFocused) {
if (inputTeamB.text.isNotEmpty()) {
if (updateOnChange) {
currentRound = try {
Round(text.toString().toInt(), false)
} catch (e: java.lang.Exception) {
Round(1, 1)
} }
inputTeamA.setText(currentRound.scoreA.toString()) catch (e: java.lang.Exception)
{
Round(1 , 1)
}
binding.contentMain.inputTeamA.setText(currentRound.scoreA.toString())
} else { }
updateOnChange = true else
{
updateOnChange=true
} }
} else { }
inputTeamA.text.clear() else
inputTeamB.text.clear() {
binding.contentMain.inputTeamA.text.clear()
binding.contentMain.inputTeamB.text.clear()
} }
} }
if (currentRound.isValidRound() && inputTeamA.text.isNotEmpty() && inputTeamB.text.isNotEmpty()) { if (currentRound.isValidRound() && binding.contentMain.inputTeamA.text.isNotEmpty() && binding.contentMain.inputTeamB.text.isNotEmpty())
{
enableSubmitButton() enableSubmitButton()
} else { }
else
{
disableSubmitButton() disableSubmitButton()
} }
} }
buttonAdd100.setOnClickListener { binding.contentMain.buttonAdd100.setOnClickListener {
giveFocusToAIfNone() giveFocusToAIfNone()
if (inputTeamA.isFocused) { if (binding.contentMain.inputTeamA.isFocused)
{
currentRound.scoreA = try { currentRound.scoreA=try
inputTeamA.text.toString().toInt() + 100 {
} catch (e: Exception) { binding.contentMain.inputTeamA.text.toString().toInt() + 100
currentRound.scoreB = 0 }
inputTeamB.setText(currentRound.scoreB.toString()) catch (e: Exception)
{
currentRound.scoreB=0
binding.contentMain.inputTeamB.setText(currentRound.scoreB.toString())
100 100
} }
updateOnChange = false updateOnChange=false
inputTeamA.setText(currentRound.scoreA.toString()) binding.contentMain.inputTeamA.setText(currentRound.scoreA.toString())
} }
if (inputTeamB.isFocused) { if (binding.contentMain.inputTeamB.isFocused)
currentRound.scoreB = try { {
inputTeamB.text.toString().toInt() + 100 currentRound.scoreB=try
} catch (e: Exception) { {
currentRound.scoreA = 0 binding.contentMain.inputTeamB.text.toString().toInt() + 100
inputTeamA.setText(currentRound.scoreA.toString()) }
catch (e: Exception)
{
currentRound.scoreA=0
binding.contentMain.inputTeamA.setText(currentRound.scoreA.toString())
100 100
} }
updateOnChange = false updateOnChange=false
inputTeamB.setText(currentRound.scoreB.toString()) binding.contentMain.inputTeamB.setText(currentRound.scoreB.toString())
} }
} }
buttonSub100.setOnClickListener { binding.contentMain.buttonSub100.setOnClickListener {
giveFocusToAIfNone() giveFocusToAIfNone()
if (inputTeamA.isFocused) { if (binding.contentMain.inputTeamA.isFocused)
currentRound.scoreA = try { {
inputTeamA.text.toString().toInt() - 100 currentRound.scoreA=try
} catch (e: Exception) { {
currentRound.scoreB = 0 binding.contentMain.inputTeamA.text.toString().toInt() - 100
inputTeamB.setText(currentRound.scoreB.toString()) }
catch (e: Exception)
{
currentRound.scoreB=0
binding.contentMain.inputTeamB.setText(currentRound.scoreB.toString())
-100 -100
} }
updateOnChange = false updateOnChange=false
inputTeamA.setText(currentRound.scoreA.toString()) binding.contentMain.inputTeamA.setText(currentRound.scoreA.toString())
} }
if (inputTeamB.isFocused) { if (binding.contentMain.inputTeamB.isFocused)
currentRound.scoreB = try { {
inputTeamB.text.toString().toInt() - 100 currentRound.scoreB=try
} catch (e: Exception) { {
currentRound.scoreA = 0 binding.contentMain.inputTeamB.text.toString().toInt() - 100
inputTeamA.setText(currentRound.scoreA.toString()) }
catch (e: Exception)
{
currentRound.scoreA=0
binding.contentMain.inputTeamA.setText(currentRound.scoreA.toString())
-100 -100
} }
updateOnChange = false updateOnChange=false
inputTeamB.setText(currentRound.scoreB.toString()) binding.contentMain.inputTeamB.setText(currentRound.scoreB.toString())
} }
} }
button0.setOnClickListener { binding.contentMain.button0.setOnClickListener {
giveFocusToAIfNone() giveFocusToAIfNone()
appendToFocusedInput('0') appendToFocusedInput('0')
} }
button1.setOnClickListener { binding.contentMain.button1.setOnClickListener {
giveFocusToAIfNone() giveFocusToAIfNone()
appendToFocusedInput('1') appendToFocusedInput('1')
} }
button2.setOnClickListener { binding.contentMain.button2.setOnClickListener {
giveFocusToAIfNone() giveFocusToAIfNone()
appendToFocusedInput('2') appendToFocusedInput('2')
} }
button3.setOnClickListener { binding.contentMain.button3.setOnClickListener {
giveFocusToAIfNone() giveFocusToAIfNone()
appendToFocusedInput('3') appendToFocusedInput('3')
} }
button4.setOnClickListener { binding.contentMain.button4.setOnClickListener {
giveFocusToAIfNone() giveFocusToAIfNone()
appendToFocusedInput('4') appendToFocusedInput('4')
} }
button5.setOnClickListener { binding.contentMain.button5.setOnClickListener {
giveFocusToAIfNone() giveFocusToAIfNone()
appendToFocusedInput('5') appendToFocusedInput('5')
} }
button6.setOnClickListener { binding.contentMain.button6.setOnClickListener {
giveFocusToAIfNone() giveFocusToAIfNone()
appendToFocusedInput('6') appendToFocusedInput('6')
} }
button7.setOnClickListener { binding.contentMain.button7.setOnClickListener {
giveFocusToAIfNone() giveFocusToAIfNone()
appendToFocusedInput('7') appendToFocusedInput('7')
} }
button8.setOnClickListener { binding.contentMain.button8.setOnClickListener {
giveFocusToAIfNone() giveFocusToAIfNone()
appendToFocusedInput('8') appendToFocusedInput('8')
} }
button9.setOnClickListener { binding.contentMain.button9.setOnClickListener {
giveFocusToAIfNone() giveFocusToAIfNone()
appendToFocusedInput('9') appendToFocusedInput('9')
} }
buttonInv.setOnClickListener { binding.contentMain.buttonInv.setOnClickListener {
val tempInt: Int val tempInt: Int
giveFocusToAIfNone() giveFocusToAIfNone()
if (inputTeamA.isFocused) { if (binding.contentMain.inputTeamA.isFocused)
if (inputTeamA.text.toString().equals("-")) { {
inputTeamA.text.clear() if (binding.contentMain.inputTeamA.text.toString().equals("-"))
} else if (inputTeamA.text.isNotEmpty()) { {
tempInt = inputTeamA.text.toString().toInt() * -1 binding.contentMain.inputTeamA.text.clear()
inputTeamA.setText(tempInt.toString()) }
} else { else if (binding.contentMain.inputTeamA.text.isNotEmpty())
updateOnChange = false {
tempInt=binding.contentMain.inputTeamA.text.toString().toInt() * -1
binding.contentMain.inputTeamA.setText(tempInt.toString())
}
else
{
updateOnChange=false
appendToFocusedInput('-') appendToFocusedInput('-')
currentRound = Round(1,1) currentRound=Round(1 , 1)
} }
} else if (inputTeamB.isFocused) { }
if (inputTeamB.text.toString().equals("-")) { else if (binding.contentMain.inputTeamB.isFocused)
inputTeamB.text.clear() {
} else if (inputTeamB.text.isNotEmpty()) { if (binding.contentMain.inputTeamB.text.toString().equals("-"))
tempInt = inputTeamB.text.toString().toInt() * -1 {
inputTeamB.setText(tempInt.toString()) binding.contentMain.inputTeamB.text.clear()
} else { }
updateOnChange = false else if (binding.contentMain.inputTeamB.text.isNotEmpty())
{
tempInt=binding.contentMain.inputTeamB.text.toString().toInt() * -1
binding.contentMain.inputTeamB.setText(tempInt.toString())
}
else
{
updateOnChange=false
appendToFocusedInput('-') appendToFocusedInput('-')
currentRound = Round(1,1) currentRound=Round(1 , 1)
} }
} }
} }
buttonBack.setOnClickListener { binding.contentMain.buttonBack.setOnClickListener {
giveFocusToAIfNone() giveFocusToAIfNone()
if (inputTeamA.isFocused) { if (binding.contentMain.inputTeamA.isFocused)
if (inputTeamA.text.isNotEmpty()) { {
val string = inputTeamA.text.toString() if (binding.contentMain.inputTeamA.text.isNotEmpty())
inputTeamA.setText(string.substring(0, string.length - 1)) {
val string=binding.contentMain.inputTeamA.text.toString()
binding.contentMain.inputTeamA.setText(string.substring(0 , string.length - 1))
} }
} else if (inputTeamB.isFocused) { }
if (inputTeamB.text.isNotEmpty()) { else if (binding.contentMain.inputTeamB.isFocused)
val string = inputTeamB.text.toString() {
inputTeamB.setText(string.substring(0, string.length - 1)) if (binding.contentMain.inputTeamB.text.isNotEmpty())
{
val string=binding.contentMain.inputTeamB.text.toString()
binding.contentMain.inputTeamB.setText(string.substring(0 , string.length - 1))
} }
} }
} }
submit.setOnClickListener { binding.contentMain.submit.setOnClickListener {
giveFocusToAIfNone() giveFocusToAIfNone()
if (inputTeamA.text.isNotEmpty() && inputTeamB.text.isNotEmpty()) { if (binding.contentMain.inputTeamA.text.isNotEmpty() && binding.contentMain.inputTeamB.text.isNotEmpty())
{
history.logRound( history.logRound(
Round( Round(
inputTeamA.text.toString().toInt(), binding.contentMain.inputTeamA.text.toString().toInt() ,
inputTeamB.text.toString().toInt() binding.contentMain.inputTeamB.text.toString().toInt()
) )
) )
updateView() updateView()
inputTeamA.text.clear() binding.contentMain.inputTeamA.text.clear()
inputTeamB.text.clear() binding.contentMain.inputTeamB.text.clear()
disableSubmitButton() disableSubmitButton()
scrollViewHistory.fullScroll(ScrollView.FOCUS_DOWN) binding.contentMain.scrollViewHistory.fullScroll(ScrollView.FOCUS_DOWN)
} }
} }
} }
override fun onSaveInstanceState(outState: Bundle) { override fun onSaveInstanceState(outState: Bundle)
{
super.onSaveInstanceState(outState) super.onSaveInstanceState(outState)
val prefs = this.getSharedPreferences("Settings", Context.MODE_PRIVATE).edit() val prefs=this.getSharedPreferences("Settings" , MODE_PRIVATE).edit()
prefs.putString("history", Gson().toJson(history)) prefs.putString("history" , Gson().toJson(history))
prefs.putString("nameTeamA", nameTeamA.text.toString()) prefs.putString("nameTeamA" , binding.contentMain.nameTeamA.text.toString())
prefs.putString("nameTeamB", nameTeamB.text.toString()) prefs.putString("nameTeamB" , binding.contentMain.nameTeamB.text.toString())
prefs.apply() prefs.apply()
} }
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)
menu.findItem(R.id.action_screenOn).isChecked = menu.findItem(R.id.action_screenOn).isChecked=
this.getSharedPreferences("Settings", Context.MODE_PRIVATE) this.getSharedPreferences("Settings" , MODE_PRIVATE)
.getBoolean("Screen_On", false) .getBoolean("Screen_On" , false)
return true return true
} }
override fun onOptionsItemSelected(item: MenuItem): Boolean { override fun onOptionsItemSelected(item: MenuItem): Boolean
return when (item.itemId) { {
R.id.action_clear -> { return when (item.itemId)
val builder = AlertDialog.Builder(this) {
R.id.action_clear ->
{
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)
.setCancelable(false) .setCancelable(false)
.setPositiveButton(getString(R.string.yes)) { dialog, id -> .setPositiveButton(getString(R.string.yes)) { dialog , _ ->
dialog.dismiss() dialog.dismiss()
clearAll() clearAll()
} }
.setNegativeButton(getString(R.string.no)) { dialog, id -> .setNegativeButton(getString(R.string.no)) { dialog , _ ->
dialog.cancel() dialog.cancel()
} }
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_screenOn -> { R.id.action_language ->
item.isChecked = !item.isChecked {
chooseLanguageDialog()
true
}
R.id.action_screenOn ->
{
item.isChecked=!item.isChecked
keepScreenOn(item.isChecked) keepScreenOn(item.isChecked)
true true
} }
@@ -351,75 +449,92 @@ 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 (!inputTeamA.isFocused && !inputTeamB.isFocused) { {
inputTeamA.requestFocus() if (!binding.contentMain.inputTeamA.isFocused && !binding.contentMain.inputTeamB.isFocused)
{
binding.contentMain.inputTeamA.requestFocus()
} }
} }
private fun undoLastRound() { private fun undoLastRound()
{
history.revertLastRound() history.revertLastRound()
updateView() updateView()
} }
private fun updateView() { private fun updateView()
scoreA.text = history.getScoreA().toString() {
scoreB.text = history.getScoreB().toString() binding.contentMain.scoreA.text=history.getScoreA().toString()
binding.contentMain.scoreB.text=history.getScoreB().toString()
historyA.text = history.getHistoryA() binding.contentMain.historyA.text=history.getHistoryA()
historyB.text = history.getHistoryB() binding.contentMain.historyB.text=history.getHistoryB()
} }
private fun clearAll() { private fun clearAll()
historyA.text = "" {
historyB.text = "" binding.contentMain.historyA.text=""
inputTeamA.text.clear() binding.contentMain.historyB.text=""
inputTeamB.text.clear() binding.contentMain.inputTeamA.text.clear()
scoreA.text = "0" binding.contentMain.inputTeamB.text.clear()
scoreB.text = "0" binding.contentMain.scoreA.text="0"
binding.contentMain.scoreB.text="0"
history.clearAll() history.clearAll()
} }
private fun appendToFocusedInput(toAppend: Char) { private fun appendToFocusedInput(toAppend: Char)
if (inputTeamA.isFocused) { {
inputTeamA.text.append(toAppend) if (binding.contentMain.inputTeamA.isFocused)
} else if (inputTeamB.isFocused) { {
inputTeamB.text.append(toAppend) binding.contentMain.inputTeamA.text.append(toAppend)
}
else if (binding.contentMain.inputTeamB.isFocused)
{
binding.contentMain.inputTeamB.text.append(toAppend)
} }
} }
private fun enableSubmitButton() { private fun enableSubmitButton()
submit.imageAlpha = 255 // 0 being transparent and 255 being opaque {
submit.isEnabled = true binding.contentMain.submit.imageAlpha=255 // 0 being transparent and 255 being opaque
binding.contentMain.submit.isEnabled=true
} }
private fun disableSubmitButton() { private fun disableSubmitButton()
submit.imageAlpha = 60 // 0 being transparent and 255 being opaque {
submit.isEnabled = false binding.contentMain.submit.imageAlpha=60 // 0 being transparent and 255 being opaque
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("Light", "Dark", "System default") val styles=arrayOf(
getString(R.string.light) ,
getString(R.string.dark) ,
getString(R.string.android_default_text)
)
val checkedItem = val checkedItem=
this.getSharedPreferences("Settings", Context.MODE_PRIVATE).getInt("Theme", 2) this.getSharedPreferences("Settings" , MODE_PRIVATE).getInt("Theme" , 2)
val prefs = this.getSharedPreferences("Settings", Context.MODE_PRIVATE).edit() val prefs=this.getSharedPreferences("Settings" , MODE_PRIVATE).edit()
builder.setSingleChoiceItems(styles, checkedItem) { dialog, which -> builder.setSingleChoiceItems(styles , checkedItem) { dialog , which ->
prefs.putInt("Theme", which) prefs.putInt("Theme" , which)
prefs.apply() prefs.apply()
updateTheme(which) updateTheme(which)
@@ -427,12 +542,53 @@ class MainActivity : AppCompatActivity() {
dialog.dismiss() dialog.dismiss()
} }
val dialog = builder.create() val dialog=builder.create()
dialog.show() dialog.show()
} }
private fun updateTheme(which: Int) { private fun chooseLanguageDialog()
when (which) { {
val builder=AlertDialog.Builder(this)
builder.setTitle(getString(R.string.choose_language_text))
val languages_map=mapOf(
getString(R.string.english) to "en" ,
getString(R.string.german) to "de"
)
val languages_display_keys=languages_map.keys.toTypedArray()
val languages_display_values=languages_map.values.toTypedArray()
val checkedItem=AppCompatDelegate.getApplicationLocales()[0].toString()
var checkedItemIndex=languages_display_values.indexOf(checkedItem)
if (checkedItemIndex == -1)
{
checkedItemIndex=0
}
builder.setSingleChoiceItems(languages_display_keys , checkedItemIndex) { dialog , which ->
val newLocale=
LocaleListCompat.forLanguageTags(languages_map[languages_display_keys[which]])
AppCompatDelegate.setApplicationLocales(newLocale)
startActivity(Intent(this , MainActivity::class.java))
finish()
dialog.dismiss()
}
val dialog=builder.create()
dialog.show()
}
private fun updateTheme(which: Int)
{
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)
@@ -440,15 +596,19 @@ 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)
} }
val prefs = this.getSharedPreferences("Settings", Context.MODE_PRIVATE).edit() val prefs=this.getSharedPreferences("Settings" , MODE_PRIVATE).edit()
prefs.putBoolean("Screen_On", keepOn) prefs.putBoolean("Screen_On" , keepOn)
prefs.apply() prefs.apply()
} }
} }

View File

@@ -2,37 +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 scoreB: Int = 0 var scoreA: Int=0
var scoreB: Int=0
constructor(score: Int, isScoreA: Boolean) : this() { constructor(score: Int , isScoreA: Boolean) : this()
if (isScoreA) { {
scoreA = score if (isScoreA)
scoreB = calculateOtherScore(scoreA) {
} else { scoreA=score
scoreB = score scoreB=calculateOtherScore(scoreA)
scoreA = calculateOtherScore(scoreB) }
else
{
scoreB=score
scoreA=calculateOtherScore(scoreB)
} }
} }
constructor(scoreA: Int, scoreB: Int) : this() { constructor(scoreA: Int , scoreB: Int) : this()
this.scoreA = scoreA {
this.scoreB = scoreB this.scoreA=scoreA
this.scoreB=scoreB
} }
private fun calculateOtherScore(score: Int): Int { private fun calculateOtherScore(score: Int): Int
if (isMultipleOf100(score)) { {
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)
} }
private fun isMultipleOf100(score: Int): Boolean { fun isValidRound(): Boolean
return (score / 100) >= 1 && (score % 100) == 0 {
} return (scoreA.isMultipleOf5()) && scoreB.isMultipleOf5() && (scoreA + scoreB).isMultipleOf100()
fun isValidRound(): Boolean {
return (scoreA % 5 == 0) && (scoreB % 5 == 0) && ((scoreA + scoreB) % 100 == 0)
} }
} }

View File

@@ -20,6 +20,8 @@
</com.google.android.material.appbar.AppBarLayout> </com.google.android.material.appbar.AppBarLayout>
<include layout="@layout/content_main" /> <include
android:id="@+id/contentMain"
layout="@layout/content_main" />
</androidx.coordinatorlayout.widget.CoordinatorLayout> </androidx.coordinatorlayout.widget.CoordinatorLayout>

View File

@@ -59,7 +59,8 @@
android:text="0" android:text="0"
android:textAppearance="@style/TextAppearance.AppCompat.Body1" android:textAppearance="@style/TextAppearance.AppCompat.Body1"
android:textSize="18sp" android:textSize="18sp"
android:textStyle="bold" /> android:textStyle="bold"
tools:ignore="HardcodedText" />
<TextView <TextView
android:id="@+id/scoreB" android:id="@+id/scoreB"
@@ -70,7 +71,8 @@
android:text="0" android:text="0"
android:textAppearance="@style/TextAppearance.AppCompat.Body1" android:textAppearance="@style/TextAppearance.AppCompat.Body1"
android:textSize="18sp" android:textSize="18sp"
android:textStyle="bold" /> android:textStyle="bold"
tools:ignore="HardcodedText" />
</LinearLayout> </LinearLayout>
@@ -136,7 +138,8 @@
android:gravity="center" android:gravity="center"
android:hint="0" android:hint="0"
android:importantForAutofill="no" android:importantForAutofill="no"
android:inputType="numberSigned" /> android:inputType="numberSigned"
tools:ignore="HardcodedText" />
<EditText <EditText
android:id="@+id/inputTeamB" android:id="@+id/inputTeamB"
@@ -147,7 +150,8 @@
android:gravity="center" android:gravity="center"
android:hint="0" android:hint="0"
android:importantForAutofill="no" android:importantForAutofill="no"
android:inputType="numberSigned" /> android:inputType="numberSigned"
tools:ignore="HardcodedText" />
</LinearLayout> </LinearLayout>
<LinearLayout <LinearLayout
@@ -164,7 +168,8 @@
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1" android:layout_weight="1"
android:text="1" /> android:text="1"
tools:ignore="HardcodedText" />
<Button <Button
android:id="@+id/button2" android:id="@+id/button2"
@@ -172,7 +177,8 @@
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1" android:layout_weight="1"
android:text="2" /> android:text="2"
tools:ignore="HardcodedText" />
<Button <Button
android:id="@+id/button3" android:id="@+id/button3"
@@ -180,7 +186,8 @@
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1" android:layout_weight="1"
android:text="3" /> android:text="3"
tools:ignore="HardcodedText" />
<Button <Button
android:id="@+id/buttonAdd100" android:id="@+id/buttonAdd100"
@@ -188,7 +195,8 @@
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1" android:layout_weight="1"
android:text="+100" /> android:text="+100"
tools:ignore="HardcodedText" />
</LinearLayout> </LinearLayout>
<LinearLayout <LinearLayout
@@ -205,7 +213,8 @@
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1" android:layout_weight="1"
android:text="4" /> android:text="4"
tools:ignore="HardcodedText" />
<Button <Button
android:id="@+id/button5" android:id="@+id/button5"
@@ -213,7 +222,8 @@
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1" android:layout_weight="1"
android:text="5" /> android:text="5"
tools:ignore="HardcodedText" />
<Button <Button
android:id="@+id/button6" android:id="@+id/button6"
@@ -221,7 +231,8 @@
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1" android:layout_weight="1"
android:text="6" /> android:text="6"
tools:ignore="HardcodedText" />
<Button <Button
android:id="@+id/buttonSub100" android:id="@+id/buttonSub100"
@@ -229,7 +240,8 @@
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1" android:layout_weight="1"
android:text="-100" /> android:text="-100"
tools:ignore="HardcodedText" />
</LinearLayout> </LinearLayout>
<LinearLayout <LinearLayout
@@ -246,7 +258,8 @@
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1" android:layout_weight="1"
android:text="7" /> android:text="7"
tools:ignore="HardcodedText" />
<Button <Button
android:id="@+id/button8" android:id="@+id/button8"
@@ -254,7 +267,8 @@
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1" android:layout_weight="1"
android:text="8" /> android:text="8"
tools:ignore="HardcodedText" />
<Button <Button
android:id="@+id/button9" android:id="@+id/button9"
@@ -262,7 +276,8 @@
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1" android:layout_weight="1"
android:text="9" /> android:text="9"
tools:ignore="HardcodedText" />
<ImageButton <ImageButton
android:id="@+id/buttonBack" android:id="@+id/buttonBack"
@@ -275,7 +290,7 @@
android:paddingBottom="15dp" android:paddingBottom="15dp"
android:scaleType="fitCenter" android:scaleType="fitCenter"
app:srcCompat="@drawable/back" app:srcCompat="@drawable/back"
android:contentDescription="TODO" /> android:contentDescription="@string/back" />
</LinearLayout> </LinearLayout>

View File

@@ -17,6 +17,10 @@
android:id="@+id/action_theme" android:id="@+id/action_theme"
android:orderInCategory="15" android:orderInCategory="15"
android:title="@string/choose_theme_text" /> android:title="@string/choose_theme_text" />
<item
android:id="@+id/action_language"
android:orderInCategory="16"
android:title="@string/choose_language_text" />
<item <item
android:id="@+id/action_screenOn" android:id="@+id/action_screenOn"
android:checkable="true" android:checkable="true"

View File

@@ -7,4 +7,11 @@
<string name="confirmClear">Möchten Sie das laufende Spiel wirklich löschen?</string> <string name="confirmClear">Möchten Sie das laufende Spiel wirklich löschen?</string>
<string name="yes">Ja</string> <string name="yes">Ja</string>
<string name="no">Nein</string> <string name="no">Nein</string>
<string name="back">Zurück</string>
<string name="choose_language_text">Sprache wählen</string>
<string name="android_default_text">Android Standard</string>
<string name="english">Englisch</string>
<string name="german">Detusch</string>
<string name="light">Hell</string>
<string name="dark">Dunkel</string>
</resources> </resources>

View File

@@ -1,10 +0,0 @@
<?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="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

@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<resources> <resources>
<string name="app_name" translatable="false">Tichu Counter</string> <string name="app_name" translatable="false">Tichu Counter</string>
<!-- Strings used for fragments for navigation -->
<string name="team_a" translatable="false">Team A</string> <string name="team_a" translatable="false">Team A</string>
<string name="team_b" translatable="false">Team B</string> <string name="team_b" translatable="false">Team B</string>
<string name="clear">Start new game</string> <string name="clear">Start new game</string>
<string name="undo">Undo last round</string> <string name="undo">Undo last round</string>
<string name="choose_theme_text">Choose theme</string> <string name="choose_theme_text">Choose theme</string>
@@ -11,4 +11,11 @@
<string name="confirmClear">Do you really want to delete the current game?</string> <string name="confirmClear">Do you really want to delete the current game?</string>
<string name="yes">Yes</string> <string name="yes">Yes</string>
<string name="no">No</string> <string name="no">No</string>
<string name="back">Back</string>
<string name="choose_language_text">Choose language</string>
<string name="android_default_text">Android Default</string>
<string name="english">English</string>
<string name="german">German</string>
<string name="light">Light</string>
<string name="dark">Dark</string>
</resources> </resources>

View File

@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<locale-config xmlns:android="http://schemas.android.com/apk/res/android">
<locale android:name="en"/>
<locale android:name="de"/>
</locale-config>

View File

@@ -9,10 +9,12 @@ 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()
history.getHistoryA() history.getHistoryA()
@@ -20,34 +22,34 @@ class HistoryUnitTest {
history.getScoreA() history.getScoreA()
history.getScoreB() history.getScoreB()
history.logRound(Round(10, 10)) history.logRound(Round(10 , 10))
history.logRound(Round(10, 10)) history.logRound(Round(10 , 10))
history.logRound(Round(10, 10)) history.logRound(Round(10 , 10))
history.logRound(Round(10, 10)) history.logRound(Round(10 , 10))
history.logRound(Round(10, 10)) history.logRound(Round(10 , 10))
history.logRound(Round(10, 10)) history.logRound(Round(10 , 10))
history.logRound(Round(10, 10)) history.logRound(Round(10 , 10))
history.logRound(Round(10, 10)) history.logRound(Round(10 , 10))
history.logRound(Round(10, 10)) history.logRound(Round(10 , 10))
history.logRound(Round(10, 10)) history.logRound(Round(10 , 10))
assertEquals(100, history.getScoreA()) assertEquals(100 , history.getScoreA())
assertEquals(100, history.getScoreB()) assertEquals(100 , history.getScoreB())
history.revertLastRound() history.revertLastRound()
assertEquals(90, history.getScoreA()) assertEquals(90 , history.getScoreA())
assertEquals(90, history.getScoreB()) assertEquals(90 , history.getScoreB())
assertNotEquals("", history.getHistoryA()) assertNotEquals("" , history.getHistoryA())
assertNotEquals("", history.getHistoryB()) assertNotEquals("" , history.getHistoryB())
history.clearAll() history.clearAll()
assertEquals(0, history.getScoreA()) assertEquals(0 , history.getScoreA())
assertEquals(0, history.getScoreB()) assertEquals(0 , history.getScoreB())
assertEquals("", history.getHistoryA()) assertEquals("" , history.getHistoryA())
assertEquals("", history.getHistoryB()) assertEquals("" , history.getHistoryB())
} }
} }

View File

@@ -8,85 +8,70 @@ 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) {
assertEquals(inputScoreB, temp.scoreB) temp=Round(inputScoreA , true)
assertEquals(inputScoreB , temp.scoreB)
assertTrue(temp.isValidRound()) assertTrue(temp.isValidRound())
temp = Round(inputScoreA, false) temp=Round(inputScoreA , false)
assertEquals(inputScoreB, temp.scoreA) assertEquals(inputScoreB , temp.scoreA)
assertTrue(temp.isValidRound()) assertTrue(temp.isValidRound())
inputScoreA -= 5 inputScoreA-=5
inputScoreB += 5 inputScoreB+=5
}
// Team a +100 points for Tichu
inputScoreA = 125 + 100
inputScoreB = -25
// Normal round range -25 to 125 as input
while (inputScoreB >= 125) {
temp = Round(inputScoreA, true)
assertEquals(inputScoreB, temp.scoreB)
assertTrue(temp.isValidRound())
temp = Round(inputScoreA, false)
assertEquals(inputScoreB, temp.scoreA)
assertTrue(temp.isValidRound())
inputScoreA -= 5
inputScoreB += 5
} }
// Double win // Double win
temp = Round(200, true) temp=Round(200 , true)
assertEquals(0, temp.scoreB) assertEquals(0 , temp.scoreB)
assertTrue(temp.isValidRound()) assertTrue(temp.isValidRound())
temp = Round(200, false) temp=Round(200 , false)
assertEquals(0, temp.scoreA) assertEquals(0 , temp.scoreA)
assertTrue(temp.isValidRound()) assertTrue(temp.isValidRound())
// Double win with Tichu // Double win with Tichu
temp = Round(300, true) temp=Round(300 , true)
assertEquals(0, temp.scoreB) assertEquals(0 , temp.scoreB)
assertTrue(temp.isValidRound()) assertTrue(temp.isValidRound())
temp = Round(300, false) temp=Round(300 , false)
assertEquals(0, temp.scoreA) assertEquals(0 , temp.scoreA)
assertTrue(temp.isValidRound()) assertTrue(temp.isValidRound())
// Double win with Grand Tichu // Double win with Grand Tichu
temp = Round(400, true) temp=Round(400 , true)
assertEquals(0, temp.scoreB) assertEquals(0 , temp.scoreB)
assertTrue(temp.isValidRound()) assertTrue(temp.isValidRound())
temp = Round(400, false) temp=Round(400 , false)
assertEquals(0, temp.scoreA) assertEquals(0 , temp.scoreA)
assertTrue(temp.isValidRound()) assertTrue(temp.isValidRound())
//Good rounds //Good rounds
temp = Round(0, 0) temp=Round(0 , 0)
assertTrue(temp.isValidRound()) assertTrue(temp.isValidRound())
//Bad rounds //Bad rounds
temp = Round(5, 12) temp=Round(5 , 12)
assertFalse(temp.isValidRound()) assertFalse(temp.isValidRound())
temp = Round(12, 5) temp=Round(12 , 5)
assertFalse(temp.isValidRound()) assertFalse(temp.isValidRound())
temp = Round(5, 55) temp=Round(5 , 55)
assertFalse(temp.isValidRound()) assertFalse(temp.isValidRound())
} }
} }

View File

@@ -1,12 +1,12 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules. // Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript { buildscript {
ext.kotlin_version = "1.4.10" ext.kotlin_version = "1.7.0"
repositories { repositories {
google() google()
jcenter() mavenCentral()
} }
dependencies { dependencies {
classpath "com.android.tools.build:gradle:4.0.1" classpath 'com.android.tools.build:gradle:7.3.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong // NOTE: Do not place your application dependencies here; they belong
@@ -17,7 +17,7 @@ buildscript {
allprojects { allprojects {
repositories { repositories {
google() google()
jcenter() mavenCentral()
} }
} }

View File

@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-all.zip