Merge pull request 'Add drone build script.' (#3) from feature/droneBuild into master
All checks were successful
continuous-integration/drone/push Build is passing
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:
14
.drone.yml
Normal file
14
.drone.yml
Normal 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
1
.gitignore
vendored
@@ -12,3 +12,4 @@
|
||||
/captures
|
||||
.externalNativeBuild
|
||||
.cxx
|
||||
.idea
|
||||
|
||||
16
.idea/codeStyles/Project.xml
generated
16
.idea/codeStyles/Project.xml
generated
@@ -1,22 +1,6 @@
|
||||
<component name="ProjectCodeStyleConfiguration">
|
||||
<code_scheme name="Project" version="173">
|
||||
<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" />
|
||||
</JetCodeStyleSettings>
|
||||
<codeStyleSettings language="XML">
|
||||
|
||||
6
.idea/compiler.xml
generated
Normal file
6
.idea/compiler.xml
generated
Normal 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
5
.idea/gradle.xml
generated
@@ -4,17 +4,16 @@
|
||||
<component name="GradleSettings">
|
||||
<option name="linkedExternalProjectsSettings">
|
||||
<GradleProjectSettings>
|
||||
<option name="testRunner" value="PLATFORM" />
|
||||
<option name="testRunner" value="GRADLE" />
|
||||
<option name="distributionType" value="DEFAULT_WRAPPED" />
|
||||
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
||||
<option name="gradleJvm" value="1.8" />
|
||||
<option name="gradleJvm" value="Android Studio java home" />
|
||||
<option name="modules">
|
||||
<set>
|
||||
<option value="$PROJECT_DIR$" />
|
||||
<option value="$PROJECT_DIR$/app" />
|
||||
</set>
|
||||
</option>
|
||||
<option name="resolveModulePerSourceSet" value="false" />
|
||||
</GradleProjectSettings>
|
||||
</option>
|
||||
</component>
|
||||
|
||||
8
.idea/inspectionProfiles/Project_Default.xml
generated
Normal file
8
.idea/inspectionProfiles/Project_Default.xml
generated
Normal 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>
|
||||
5
.idea/jarRepositories.xml
generated
5
.idea/jarRepositories.xml
generated
@@ -21,5 +21,10 @@
|
||||
<option name="name" value="Google" />
|
||||
<option name="url" value="https://dl.google.com/dl/android/maven2/" />
|
||||
</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>
|
||||
</project>
|
||||
22
.idea/misc.xml
generated
22
.idea/misc.xml
generated
@@ -1,11 +1,20 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<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">
|
||||
<option name="myDefaultNullable" value="androidx.annotation.Nullable" />
|
||||
<option name="myDefaultNotNull" value="androidx.annotation.NonNull" />
|
||||
<option name="myNullables">
|
||||
<value>
|
||||
<list size="12">
|
||||
<list size="15">
|
||||
<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="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="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="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>
|
||||
</value>
|
||||
</option>
|
||||
<option name="myNotNulls">
|
||||
<value>
|
||||
<list size="11">
|
||||
<list size="15">
|
||||
<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="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="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="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>
|
||||
</value>
|
||||
</option>
|
||||
</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" />
|
||||
</component>
|
||||
<component name="ProjectType">
|
||||
|
||||
12
.idea/runConfigurations.xml
generated
12
.idea/runConfigurations.xml
generated
@@ -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>
|
||||
@@ -1,15 +1,13 @@
|
||||
apply plugin: 'com.android.application'
|
||||
apply plugin: 'kotlin-android'
|
||||
apply plugin: 'kotlin-android-extensions'
|
||||
|
||||
android {
|
||||
compileSdkVersion 30
|
||||
buildToolsVersion "30.0.2"
|
||||
compileSdkVersion 32
|
||||
|
||||
defaultConfig {
|
||||
applicationId "me.zobrist.tichucounter"
|
||||
minSdkVersion 16
|
||||
targetSdkVersion 30
|
||||
targetSdkVersion 32
|
||||
versionCode 7
|
||||
versionName "1.0.0"
|
||||
|
||||
@@ -23,6 +21,11 @@ android {
|
||||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
|
||||
}
|
||||
}
|
||||
|
||||
buildFeatures {
|
||||
viewBinding = true
|
||||
}
|
||||
|
||||
compileOptions {
|
||||
sourceCompatibility JavaVersion.VERSION_1_8
|
||||
targetCompatibility JavaVersion.VERSION_1_8
|
||||
@@ -30,22 +33,23 @@ android {
|
||||
kotlinOptions {
|
||||
jvmTarget = '1.8'
|
||||
}
|
||||
namespace 'me.zobrist.tichucounter'
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation fileTree(dir: "libs", include: ["*.jar"])
|
||||
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
||||
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 'com.google.android.play:core:1.8.0'
|
||||
implementation 'androidx.core:core-ktx:1.8.0'
|
||||
implementation 'androidx.appcompat:appcompat:1.6.0-alpha05'
|
||||
implementation 'com.google.android.material:material:1.6.1'
|
||||
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'
|
||||
implementation 'com.google.android.play:core-ktx:1.8.1'
|
||||
implementation 'com.google.code.gson:gson:2.8.9'
|
||||
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
|
||||
implementation 'androidx.navigation:navigation-fragment-ktx:2.4.2'
|
||||
implementation 'androidx.navigation:navigation-ui-ktx:2.4.2'
|
||||
testImplementation 'junit:junit:4.12'
|
||||
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
|
||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
|
||||
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
|
||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
|
||||
|
||||
}
|
||||
BIN
app/release/app-release.aab
Normal file
BIN
app/release/app-release.aab
Normal file
Binary file not shown.
@@ -1,8 +1,8 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="me.zobrist.tichucounter">
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<application
|
||||
|
||||
android:allowBackup="true"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
@@ -13,14 +13,22 @@
|
||||
<activity
|
||||
android:name=".MainActivity"
|
||||
android:windowSoftInputMode="adjustPan"
|
||||
android:label="@string/app_name"
|
||||
android:theme="@style/AppTheme.NoActionBar">
|
||||
android:theme="@style/AppTheme.NoActionBar"
|
||||
android:exported="true">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<service
|
||||
android:name="androidx.appcompat.app.AppLocalesMetadataHolderService"
|
||||
android:enabled="false"
|
||||
android:exported="false">
|
||||
<meta-data
|
||||
android:name="autoStoreLocales"
|
||||
android:value="true" />
|
||||
</service>
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
11
app/src/main/java/me/zobrist/tichucounter/Extensions.kt
Normal file
11
app/src/main/java/me/zobrist/tichucounter/Extensions.kt
Normal 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
|
||||
}
|
||||
@@ -1,12 +1,11 @@
|
||||
@file:Suppress("unused")
|
||||
|
||||
package me.zobrist.tichucounter
|
||||
|
||||
class History
|
||||
{
|
||||
private var scores=ArrayList<Round>()
|
||||
|
||||
class History {
|
||||
private var scores: ArrayList<Round> = ArrayList()
|
||||
|
||||
fun getScoreA(): Int {
|
||||
fun getScoreA(): Int
|
||||
{
|
||||
var tempScore=0
|
||||
scores.forEach {
|
||||
tempScore+=it.scoreA
|
||||
@@ -14,7 +13,8 @@ class History {
|
||||
return tempScore
|
||||
}
|
||||
|
||||
fun getScoreB(): Int {
|
||||
fun getScoreB(): Int
|
||||
{
|
||||
var tempScore=0
|
||||
scores.forEach {
|
||||
tempScore+=it.scoreB
|
||||
@@ -22,7 +22,8 @@ class History {
|
||||
return tempScore
|
||||
}
|
||||
|
||||
fun getHistoryA(): String {
|
||||
fun getHistoryA(): String
|
||||
{
|
||||
var tempHistory=String()
|
||||
scores.forEach {
|
||||
tempHistory+=it.scoreA.toString() + "\n"
|
||||
@@ -30,7 +31,8 @@ class History {
|
||||
return tempHistory
|
||||
}
|
||||
|
||||
fun getHistoryB(): String {
|
||||
fun getHistoryB(): String
|
||||
{
|
||||
var tempHistory=String()
|
||||
scores.forEach {
|
||||
tempHistory+=it.scoreB.toString() + "\n"
|
||||
@@ -38,21 +40,26 @@ class History {
|
||||
return tempHistory
|
||||
}
|
||||
|
||||
fun logRound(round: Round) {
|
||||
fun logRound(round: Round)
|
||||
{
|
||||
scores.add(round)
|
||||
}
|
||||
|
||||
fun revertLastRound() {
|
||||
if (scores.isNotEmpty()) {
|
||||
fun revertLastRound()
|
||||
{
|
||||
if (scores.isNotEmpty())
|
||||
{
|
||||
scores.removeAt(scores.size - 1)
|
||||
}
|
||||
}
|
||||
|
||||
fun clearAll() {
|
||||
fun clearAll()
|
||||
{
|
||||
scores.clear()
|
||||
}
|
||||
|
||||
fun isEmpty(): Boolean {
|
||||
fun isEmpty(): Boolean
|
||||
{
|
||||
return scores.isEmpty()
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
package me.zobrist.tichucounter
|
||||
|
||||
import android.app.AlertDialog
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.text.InputType
|
||||
import android.view.Menu
|
||||
@@ -11,242 +11,321 @@ import android.view.inputmethod.InputMethodManager
|
||||
import android.widget.ScrollView
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.appcompat.app.AppCompatDelegate
|
||||
import androidx.core.os.LocaleListCompat
|
||||
import androidx.core.widget.doOnTextChanged
|
||||
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 lateinit var history: History
|
||||
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)
|
||||
setContentView(R.layout.activity_main)
|
||||
setSupportActionBar(findViewById(R.id.toolbar))
|
||||
inputTeamA.setRawInputType(InputType.TYPE_NULL)
|
||||
inputTeamB.setRawInputType(InputType.TYPE_NULL)
|
||||
inputTeamA.requestFocus()
|
||||
binding=ActivityMainBinding.inflate(layoutInflater)
|
||||
setContentView(binding.root)
|
||||
|
||||
setSupportActionBar(binding.toolbar)
|
||||
|
||||
binding.contentMain.inputTeamA.setRawInputType(InputType.TYPE_NULL)
|
||||
binding.contentMain.inputTeamB.setRawInputType(InputType.TYPE_NULL)
|
||||
binding.contentMain.inputTeamA.requestFocus()
|
||||
disableSubmitButton()
|
||||
updateTheme(this.getSharedPreferences("Settings", Context.MODE_PRIVATE).getInt("Theme", 2))
|
||||
updateTheme(this.getSharedPreferences("Settings" , MODE_PRIVATE).getInt("Theme" , 2))
|
||||
keepScreenOn(
|
||||
this.getSharedPreferences("Settings", Context.MODE_PRIVATE)
|
||||
this.getSharedPreferences("Settings" , MODE_PRIVATE)
|
||||
.getBoolean("Screen_On" , false)
|
||||
)
|
||||
|
||||
val json = this.getSharedPreferences("Settings", Context.MODE_PRIVATE).getString("history", "{\"scores\":[]}")
|
||||
|
||||
val json=this.getSharedPreferences("Settings" , 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"))
|
||||
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()
|
||||
|
||||
this.setListenes()
|
||||
|
||||
inputTeamA.setOnFocusChangeListener { view, b ->
|
||||
if (b) {
|
||||
|
||||
}
|
||||
|
||||
private fun setListenes()
|
||||
{
|
||||
binding.contentMain.inputTeamA.setOnFocusChangeListener { _ , b ->
|
||||
if (b)
|
||||
{
|
||||
hideKeyboard()
|
||||
}
|
||||
}
|
||||
|
||||
inputTeamB.setOnFocusChangeListener { view, b ->
|
||||
if (b) {
|
||||
binding.contentMain.inputTeamB.setOnFocusChangeListener { _ , b ->
|
||||
if (b)
|
||||
{
|
||||
hideKeyboard()
|
||||
}
|
||||
}
|
||||
|
||||
inputTeamA.doOnTextChanged { text, start, count, after ->
|
||||
if (inputTeamA.isFocused) {
|
||||
if (inputTeamA.text.isNotEmpty()) {
|
||||
if (updateOnChange) {
|
||||
currentRound = try {
|
||||
binding.contentMain.inputTeamA.doOnTextChanged { text , _ , _ , _ ->
|
||||
if (binding.contentMain.inputTeamA.isFocused)
|
||||
{
|
||||
if (binding.contentMain.inputTeamA.text.isNotEmpty())
|
||||
{
|
||||
if (updateOnChange)
|
||||
{
|
||||
currentRound=try
|
||||
{
|
||||
Round(text.toString().toInt() , true)
|
||||
|
||||
} catch (e: java.lang.Exception) {
|
||||
}
|
||||
catch (e: java.lang.Exception)
|
||||
{
|
||||
Round(1 , 1)
|
||||
}
|
||||
inputTeamB.setText(currentRound.scoreB.toString())
|
||||
} else {
|
||||
binding.contentMain.inputTeamB.setText(currentRound.scoreB.toString())
|
||||
}
|
||||
else
|
||||
{
|
||||
updateOnChange=true
|
||||
}
|
||||
} else {
|
||||
inputTeamA.text.clear()
|
||||
inputTeamB.text.clear()
|
||||
}
|
||||
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()
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
disableSubmitButton()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
inputTeamB.doOnTextChanged { text, start, count, after ->
|
||||
if (inputTeamB.isFocused) {
|
||||
if (inputTeamB.text.isNotEmpty()) {
|
||||
if (updateOnChange) {
|
||||
currentRound = try {
|
||||
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)
|
||||
|
||||
} catch (e: java.lang.Exception) {
|
||||
}
|
||||
catch (e: java.lang.Exception)
|
||||
{
|
||||
Round(1 , 1)
|
||||
}
|
||||
inputTeamA.setText(currentRound.scoreA.toString())
|
||||
binding.contentMain.inputTeamA.setText(currentRound.scoreA.toString())
|
||||
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
updateOnChange=true
|
||||
}
|
||||
|
||||
} else {
|
||||
inputTeamA.text.clear()
|
||||
inputTeamB.text.clear()
|
||||
}
|
||||
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()
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
disableSubmitButton()
|
||||
}
|
||||
}
|
||||
|
||||
buttonAdd100.setOnClickListener {
|
||||
binding.contentMain.buttonAdd100.setOnClickListener {
|
||||
giveFocusToAIfNone()
|
||||
|
||||
if (inputTeamA.isFocused) {
|
||||
if (binding.contentMain.inputTeamA.isFocused)
|
||||
{
|
||||
|
||||
currentRound.scoreA = try {
|
||||
inputTeamA.text.toString().toInt() + 100
|
||||
} catch (e: Exception) {
|
||||
currentRound.scoreA=try
|
||||
{
|
||||
binding.contentMain.inputTeamA.text.toString().toInt() + 100
|
||||
}
|
||||
catch (e: Exception)
|
||||
{
|
||||
currentRound.scoreB=0
|
||||
inputTeamB.setText(currentRound.scoreB.toString())
|
||||
binding.contentMain.inputTeamB.setText(currentRound.scoreB.toString())
|
||||
100
|
||||
}
|
||||
updateOnChange=false
|
||||
inputTeamA.setText(currentRound.scoreA.toString())
|
||||
binding.contentMain.inputTeamA.setText(currentRound.scoreA.toString())
|
||||
}
|
||||
|
||||
if (inputTeamB.isFocused) {
|
||||
currentRound.scoreB = try {
|
||||
inputTeamB.text.toString().toInt() + 100
|
||||
} catch (e: Exception) {
|
||||
if (binding.contentMain.inputTeamB.isFocused)
|
||||
{
|
||||
currentRound.scoreB=try
|
||||
{
|
||||
binding.contentMain.inputTeamB.text.toString().toInt() + 100
|
||||
}
|
||||
catch (e: Exception)
|
||||
{
|
||||
currentRound.scoreA=0
|
||||
inputTeamA.setText(currentRound.scoreA.toString())
|
||||
binding.contentMain.inputTeamA.setText(currentRound.scoreA.toString())
|
||||
100
|
||||
|
||||
}
|
||||
updateOnChange=false
|
||||
inputTeamB.setText(currentRound.scoreB.toString())
|
||||
binding.contentMain.inputTeamB.setText(currentRound.scoreB.toString())
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
buttonSub100.setOnClickListener {
|
||||
binding.contentMain.buttonSub100.setOnClickListener {
|
||||
giveFocusToAIfNone()
|
||||
|
||||
if (inputTeamA.isFocused) {
|
||||
currentRound.scoreA = try {
|
||||
inputTeamA.text.toString().toInt() - 100
|
||||
} catch (e: Exception) {
|
||||
if (binding.contentMain.inputTeamA.isFocused)
|
||||
{
|
||||
currentRound.scoreA=try
|
||||
{
|
||||
binding.contentMain.inputTeamA.text.toString().toInt() - 100
|
||||
}
|
||||
catch (e: Exception)
|
||||
{
|
||||
currentRound.scoreB=0
|
||||
inputTeamB.setText(currentRound.scoreB.toString())
|
||||
binding.contentMain.inputTeamB.setText(currentRound.scoreB.toString())
|
||||
-100
|
||||
}
|
||||
updateOnChange=false
|
||||
inputTeamA.setText(currentRound.scoreA.toString())
|
||||
binding.contentMain.inputTeamA.setText(currentRound.scoreA.toString())
|
||||
}
|
||||
|
||||
if (inputTeamB.isFocused) {
|
||||
currentRound.scoreB = try {
|
||||
inputTeamB.text.toString().toInt() - 100
|
||||
} catch (e: Exception) {
|
||||
if (binding.contentMain.inputTeamB.isFocused)
|
||||
{
|
||||
currentRound.scoreB=try
|
||||
{
|
||||
binding.contentMain.inputTeamB.text.toString().toInt() - 100
|
||||
}
|
||||
catch (e: Exception)
|
||||
{
|
||||
currentRound.scoreA=0
|
||||
inputTeamA.setText(currentRound.scoreA.toString())
|
||||
binding.contentMain.inputTeamA.setText(currentRound.scoreA.toString())
|
||||
-100
|
||||
}
|
||||
updateOnChange=false
|
||||
inputTeamB.setText(currentRound.scoreB.toString())
|
||||
binding.contentMain.inputTeamB.setText(currentRound.scoreB.toString())
|
||||
}
|
||||
}
|
||||
|
||||
button0.setOnClickListener {
|
||||
binding.contentMain.button0.setOnClickListener {
|
||||
giveFocusToAIfNone()
|
||||
appendToFocusedInput('0')
|
||||
}
|
||||
|
||||
button1.setOnClickListener {
|
||||
binding.contentMain.button1.setOnClickListener {
|
||||
giveFocusToAIfNone()
|
||||
appendToFocusedInput('1')
|
||||
}
|
||||
|
||||
button2.setOnClickListener {
|
||||
binding.contentMain.button2.setOnClickListener {
|
||||
giveFocusToAIfNone()
|
||||
appendToFocusedInput('2')
|
||||
}
|
||||
|
||||
button3.setOnClickListener {
|
||||
binding.contentMain.button3.setOnClickListener {
|
||||
giveFocusToAIfNone()
|
||||
appendToFocusedInput('3')
|
||||
}
|
||||
|
||||
button4.setOnClickListener {
|
||||
binding.contentMain.button4.setOnClickListener {
|
||||
giveFocusToAIfNone()
|
||||
appendToFocusedInput('4')
|
||||
}
|
||||
|
||||
button5.setOnClickListener {
|
||||
binding.contentMain.button5.setOnClickListener {
|
||||
giveFocusToAIfNone()
|
||||
appendToFocusedInput('5')
|
||||
}
|
||||
|
||||
button6.setOnClickListener {
|
||||
binding.contentMain.button6.setOnClickListener {
|
||||
giveFocusToAIfNone()
|
||||
appendToFocusedInput('6')
|
||||
}
|
||||
|
||||
button7.setOnClickListener {
|
||||
binding.contentMain.button7.setOnClickListener {
|
||||
giveFocusToAIfNone()
|
||||
appendToFocusedInput('7')
|
||||
}
|
||||
|
||||
button8.setOnClickListener {
|
||||
binding.contentMain.button8.setOnClickListener {
|
||||
giveFocusToAIfNone()
|
||||
appendToFocusedInput('8')
|
||||
}
|
||||
|
||||
button9.setOnClickListener {
|
||||
binding.contentMain.button9.setOnClickListener {
|
||||
giveFocusToAIfNone()
|
||||
appendToFocusedInput('9')
|
||||
}
|
||||
|
||||
buttonInv.setOnClickListener {
|
||||
binding.contentMain.buttonInv.setOnClickListener {
|
||||
val tempInt: Int
|
||||
|
||||
giveFocusToAIfNone()
|
||||
|
||||
if (inputTeamA.isFocused) {
|
||||
if (inputTeamA.text.toString().equals("-")) {
|
||||
inputTeamA.text.clear()
|
||||
} else if (inputTeamA.text.isNotEmpty()) {
|
||||
tempInt = inputTeamA.text.toString().toInt() * -1
|
||||
inputTeamA.setText(tempInt.toString())
|
||||
} else {
|
||||
if (binding.contentMain.inputTeamA.isFocused)
|
||||
{
|
||||
if (binding.contentMain.inputTeamA.text.toString().equals("-"))
|
||||
{
|
||||
binding.contentMain.inputTeamA.text.clear()
|
||||
}
|
||||
else if (binding.contentMain.inputTeamA.text.isNotEmpty())
|
||||
{
|
||||
tempInt=binding.contentMain.inputTeamA.text.toString().toInt() * -1
|
||||
binding.contentMain.inputTeamA.setText(tempInt.toString())
|
||||
}
|
||||
else
|
||||
{
|
||||
updateOnChange=false
|
||||
appendToFocusedInput('-')
|
||||
currentRound=Round(1 , 1)
|
||||
}
|
||||
|
||||
|
||||
} else if (inputTeamB.isFocused) {
|
||||
if (inputTeamB.text.toString().equals("-")) {
|
||||
inputTeamB.text.clear()
|
||||
} else if (inputTeamB.text.isNotEmpty()) {
|
||||
tempInt = inputTeamB.text.toString().toInt() * -1
|
||||
inputTeamB.setText(tempInt.toString())
|
||||
} else {
|
||||
}
|
||||
else if (binding.contentMain.inputTeamB.isFocused)
|
||||
{
|
||||
if (binding.contentMain.inputTeamB.text.toString().equals("-"))
|
||||
{
|
||||
binding.contentMain.inputTeamB.text.clear()
|
||||
}
|
||||
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('-')
|
||||
currentRound=Round(1 , 1)
|
||||
@@ -254,95 +333,114 @@ class MainActivity : AppCompatActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
buttonBack.setOnClickListener {
|
||||
binding.contentMain.buttonBack.setOnClickListener {
|
||||
giveFocusToAIfNone()
|
||||
|
||||
if (inputTeamA.isFocused) {
|
||||
if (inputTeamA.text.isNotEmpty()) {
|
||||
val string = inputTeamA.text.toString()
|
||||
inputTeamA.setText(string.substring(0, string.length - 1))
|
||||
if (binding.contentMain.inputTeamA.isFocused)
|
||||
{
|
||||
if (binding.contentMain.inputTeamA.text.isNotEmpty())
|
||||
{
|
||||
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()) {
|
||||
val string = inputTeamB.text.toString()
|
||||
inputTeamB.setText(string.substring(0, string.length - 1))
|
||||
}
|
||||
else if (binding.contentMain.inputTeamB.isFocused)
|
||||
{
|
||||
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()
|
||||
|
||||
if (inputTeamA.text.isNotEmpty() && inputTeamB.text.isNotEmpty()) {
|
||||
if (binding.contentMain.inputTeamA.text.isNotEmpty() && binding.contentMain.inputTeamB.text.isNotEmpty())
|
||||
{
|
||||
|
||||
history.logRound(
|
||||
Round(
|
||||
inputTeamA.text.toString().toInt(),
|
||||
inputTeamB.text.toString().toInt()
|
||||
binding.contentMain.inputTeamA.text.toString().toInt() ,
|
||||
binding.contentMain.inputTeamB.text.toString().toInt()
|
||||
)
|
||||
)
|
||||
|
||||
updateView()
|
||||
|
||||
inputTeamA.text.clear()
|
||||
inputTeamB.text.clear()
|
||||
binding.contentMain.inputTeamA.text.clear()
|
||||
binding.contentMain.inputTeamB.text.clear()
|
||||
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)
|
||||
|
||||
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("nameTeamA", nameTeamA.text.toString())
|
||||
prefs.putString("nameTeamB", nameTeamB.text.toString())
|
||||
prefs.putString("nameTeamA" , binding.contentMain.nameTeamA.text.toString())
|
||||
prefs.putString("nameTeamB" , binding.contentMain.nameTeamB.text.toString())
|
||||
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.
|
||||
menuInflater.inflate(R.menu.menu_main , menu)
|
||||
|
||||
menu.findItem(R.id.action_screenOn).isChecked=
|
||||
this.getSharedPreferences("Settings", Context.MODE_PRIVATE)
|
||||
this.getSharedPreferences("Settings" , MODE_PRIVATE)
|
||||
.getBoolean("Screen_On" , false)
|
||||
return true
|
||||
}
|
||||
|
||||
|
||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||
return when (item.itemId) {
|
||||
R.id.action_clear -> {
|
||||
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 ->
|
||||
.setPositiveButton(getString(R.string.yes)) { dialog , _ ->
|
||||
dialog.dismiss()
|
||||
clearAll()
|
||||
}
|
||||
.setNegativeButton(getString(R.string.no)) { dialog, id ->
|
||||
.setNegativeButton(getString(R.string.no)) { dialog , _ ->
|
||||
dialog.cancel()
|
||||
}
|
||||
|
||||
builder.create().show()
|
||||
true
|
||||
}
|
||||
R.id.action_undo -> {
|
||||
R.id.action_undo ->
|
||||
{
|
||||
undoLastRound()
|
||||
true
|
||||
}
|
||||
R.id.action_theme -> {
|
||||
R.id.action_theme ->
|
||||
{
|
||||
chooseThemeDialog()
|
||||
true
|
||||
}
|
||||
R.id.action_screenOn -> {
|
||||
R.id.action_language ->
|
||||
{
|
||||
chooseLanguageDialog()
|
||||
true
|
||||
}
|
||||
R.id.action_screenOn ->
|
||||
{
|
||||
item.isChecked=!item.isChecked
|
||||
keepScreenOn(item.isChecked)
|
||||
true
|
||||
@@ -351,70 +449,87 @@ class MainActivity : AppCompatActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
private fun hideKeyboard() {
|
||||
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()
|
||||
private fun giveFocusToAIfNone()
|
||||
{
|
||||
if (!binding.contentMain.inputTeamA.isFocused && !binding.contentMain.inputTeamB.isFocused)
|
||||
{
|
||||
binding.contentMain.inputTeamA.requestFocus()
|
||||
}
|
||||
}
|
||||
|
||||
private fun undoLastRound() {
|
||||
private fun undoLastRound()
|
||||
{
|
||||
history.revertLastRound()
|
||||
updateView()
|
||||
}
|
||||
|
||||
private fun updateView() {
|
||||
scoreA.text = history.getScoreA().toString()
|
||||
scoreB.text = history.getScoreB().toString()
|
||||
private fun updateView()
|
||||
{
|
||||
binding.contentMain.scoreA.text=history.getScoreA().toString()
|
||||
binding.contentMain.scoreB.text=history.getScoreB().toString()
|
||||
|
||||
historyA.text = history.getHistoryA()
|
||||
historyB.text = history.getHistoryB()
|
||||
binding.contentMain.historyA.text=history.getHistoryA()
|
||||
binding.contentMain.historyB.text=history.getHistoryB()
|
||||
}
|
||||
|
||||
private fun clearAll() {
|
||||
historyA.text = ""
|
||||
historyB.text = ""
|
||||
inputTeamA.text.clear()
|
||||
inputTeamB.text.clear()
|
||||
scoreA.text = "0"
|
||||
scoreB.text = "0"
|
||||
private fun clearAll()
|
||||
{
|
||||
binding.contentMain.historyA.text=""
|
||||
binding.contentMain.historyB.text=""
|
||||
binding.contentMain.inputTeamA.text.clear()
|
||||
binding.contentMain.inputTeamB.text.clear()
|
||||
binding.contentMain.scoreA.text="0"
|
||||
binding.contentMain.scoreB.text="0"
|
||||
|
||||
history.clearAll()
|
||||
}
|
||||
|
||||
private fun appendToFocusedInput(toAppend: Char) {
|
||||
if (inputTeamA.isFocused) {
|
||||
inputTeamA.text.append(toAppend)
|
||||
} else if (inputTeamB.isFocused) {
|
||||
inputTeamB.text.append(toAppend)
|
||||
private fun appendToFocusedInput(toAppend: Char)
|
||||
{
|
||||
if (binding.contentMain.inputTeamA.isFocused)
|
||||
{
|
||||
binding.contentMain.inputTeamA.text.append(toAppend)
|
||||
}
|
||||
else if (binding.contentMain.inputTeamB.isFocused)
|
||||
{
|
||||
binding.contentMain.inputTeamB.text.append(toAppend)
|
||||
}
|
||||
}
|
||||
|
||||
private fun enableSubmitButton() {
|
||||
submit.imageAlpha = 255 // 0 being transparent and 255 being opaque
|
||||
submit.isEnabled = true
|
||||
private fun enableSubmitButton()
|
||||
{
|
||||
binding.contentMain.submit.imageAlpha=255 // 0 being transparent and 255 being opaque
|
||||
binding.contentMain.submit.isEnabled=true
|
||||
}
|
||||
|
||||
private fun disableSubmitButton() {
|
||||
submit.imageAlpha = 60 // 0 being transparent and 255 being opaque
|
||||
submit.isEnabled = false
|
||||
private fun disableSubmitButton()
|
||||
{
|
||||
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)
|
||||
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=
|
||||
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 ->
|
||||
@@ -431,8 +546,49 @@ class MainActivity : AppCompatActivity() {
|
||||
dialog.show()
|
||||
}
|
||||
|
||||
private fun updateTheme(which: Int) {
|
||||
when (which) {
|
||||
private fun chooseLanguageDialog()
|
||||
{
|
||||
|
||||
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)
|
||||
1 -> AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES)
|
||||
2 -> AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM)
|
||||
@@ -440,14 +596,18 @@ class MainActivity : AppCompatActivity() {
|
||||
delegate.applyDayNight()
|
||||
}
|
||||
|
||||
private fun keepScreenOn(keepOn: Boolean) {
|
||||
if (keepOn) {
|
||||
private fun keepScreenOn(keepOn: Boolean)
|
||||
{
|
||||
if (keepOn)
|
||||
{
|
||||
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
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.apply()
|
||||
}
|
||||
|
||||
@@ -2,37 +2,46 @@ package me.zobrist.tichucounter
|
||||
|
||||
import java.io.Serializable
|
||||
|
||||
class Round() : Serializable {
|
||||
class Round() : Serializable
|
||||
{
|
||||
var scoreA: Int=0
|
||||
var scoreB: Int=0
|
||||
|
||||
constructor(score: Int, isScoreA: Boolean) : this() {
|
||||
if (isScoreA) {
|
||||
constructor(score: Int , isScoreA: Boolean) : this()
|
||||
{
|
||||
if (isScoreA)
|
||||
{
|
||||
scoreA=score
|
||||
scoreB=calculateOtherScore(scoreA)
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
scoreB=score
|
||||
scoreA=calculateOtherScore(scoreB)
|
||||
}
|
||||
}
|
||||
|
||||
constructor(scoreA: Int, scoreB: Int) : this() {
|
||||
constructor(scoreA: Int , scoreB: Int) : this()
|
||||
{
|
||||
this.scoreA=scoreA
|
||||
this.scoreB=scoreB
|
||||
}
|
||||
|
||||
private fun calculateOtherScore(score: Int): Int {
|
||||
if (isMultipleOf100(score)) {
|
||||
private fun calculateOtherScore(score: Int): Int
|
||||
{
|
||||
if (score.isMultipleOf100() && score != 0)
|
||||
{
|
||||
return 0
|
||||
}
|
||||
if (score in 101 ..125)
|
||||
{
|
||||
return 0 - (score % 100)
|
||||
}
|
||||
return 100 - (score % 100)
|
||||
}
|
||||
|
||||
private fun isMultipleOf100(score: Int): Boolean {
|
||||
return (score / 100) >= 1 && (score % 100) == 0
|
||||
}
|
||||
|
||||
fun isValidRound(): Boolean {
|
||||
return (scoreA % 5 == 0) && (scoreB % 5 == 0) && ((scoreA + scoreB) % 100 == 0)
|
||||
fun isValidRound(): Boolean
|
||||
{
|
||||
return (scoreA.isMultipleOf5()) && scoreB.isMultipleOf5() && (scoreA + scoreB).isMultipleOf100()
|
||||
}
|
||||
}
|
||||
@@ -20,6 +20,8 @@
|
||||
|
||||
</com.google.android.material.appbar.AppBarLayout>
|
||||
|
||||
<include layout="@layout/content_main" />
|
||||
<include
|
||||
android:id="@+id/contentMain"
|
||||
layout="@layout/content_main" />
|
||||
|
||||
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
||||
@@ -59,7 +59,8 @@
|
||||
android:text="0"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Body1"
|
||||
android:textSize="18sp"
|
||||
android:textStyle="bold" />
|
||||
android:textStyle="bold"
|
||||
tools:ignore="HardcodedText" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/scoreB"
|
||||
@@ -70,7 +71,8 @@
|
||||
android:text="0"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Body1"
|
||||
android:textSize="18sp"
|
||||
android:textStyle="bold" />
|
||||
android:textStyle="bold"
|
||||
tools:ignore="HardcodedText" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
@@ -136,7 +138,8 @@
|
||||
android:gravity="center"
|
||||
android:hint="0"
|
||||
android:importantForAutofill="no"
|
||||
android:inputType="numberSigned" />
|
||||
android:inputType="numberSigned"
|
||||
tools:ignore="HardcodedText" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/inputTeamB"
|
||||
@@ -147,7 +150,8 @@
|
||||
android:gravity="center"
|
||||
android:hint="0"
|
||||
android:importantForAutofill="no"
|
||||
android:inputType="numberSigned" />
|
||||
android:inputType="numberSigned"
|
||||
tools:ignore="HardcodedText" />
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
@@ -164,7 +168,8 @@
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="1" />
|
||||
android:text="1"
|
||||
tools:ignore="HardcodedText" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/button2"
|
||||
@@ -172,7 +177,8 @@
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="2" />
|
||||
android:text="2"
|
||||
tools:ignore="HardcodedText" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/button3"
|
||||
@@ -180,7 +186,8 @@
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="3" />
|
||||
android:text="3"
|
||||
tools:ignore="HardcodedText" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/buttonAdd100"
|
||||
@@ -188,7 +195,8 @@
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="+100" />
|
||||
android:text="+100"
|
||||
tools:ignore="HardcodedText" />
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
@@ -205,7 +213,8 @@
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="4" />
|
||||
android:text="4"
|
||||
tools:ignore="HardcodedText" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/button5"
|
||||
@@ -213,7 +222,8 @@
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="5" />
|
||||
android:text="5"
|
||||
tools:ignore="HardcodedText" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/button6"
|
||||
@@ -221,7 +231,8 @@
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="6" />
|
||||
android:text="6"
|
||||
tools:ignore="HardcodedText" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/buttonSub100"
|
||||
@@ -229,7 +240,8 @@
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="-100" />
|
||||
android:text="-100"
|
||||
tools:ignore="HardcodedText" />
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
@@ -246,7 +258,8 @@
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="7" />
|
||||
android:text="7"
|
||||
tools:ignore="HardcodedText" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/button8"
|
||||
@@ -254,7 +267,8 @@
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="8" />
|
||||
android:text="8"
|
||||
tools:ignore="HardcodedText" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/button9"
|
||||
@@ -262,7 +276,8 @@
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="9" />
|
||||
android:text="9"
|
||||
tools:ignore="HardcodedText" />
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/buttonBack"
|
||||
@@ -275,7 +290,7 @@
|
||||
android:paddingBottom="15dp"
|
||||
android:scaleType="fitCenter"
|
||||
app:srcCompat="@drawable/back"
|
||||
android:contentDescription="TODO" />
|
||||
android:contentDescription="@string/back" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
@@ -17,6 +17,10 @@
|
||||
android:id="@+id/action_theme"
|
||||
android:orderInCategory="15"
|
||||
android:title="@string/choose_theme_text" />
|
||||
<item
|
||||
android:id="@+id/action_language"
|
||||
android:orderInCategory="16"
|
||||
android:title="@string/choose_language_text" />
|
||||
<item
|
||||
android:id="@+id/action_screenOn"
|
||||
android:checkable="true"
|
||||
|
||||
@@ -7,4 +7,11 @@
|
||||
<string name="confirmClear">Möchten Sie das laufende Spiel wirklich löschen?</string>
|
||||
<string name="yes">Ja</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>
|
||||
@@ -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>
|
||||
@@ -1,9 +1,9 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<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_b" translatable="false">Team B</string>
|
||||
|
||||
<string name="clear">Start new game</string>
|
||||
<string name="undo">Undo last round</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="yes">Yes</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>
|
||||
5
app/src/main/res/xml/locales_config.xml
Normal file
5
app/src/main/res/xml/locales_config.xml
Normal 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>
|
||||
@@ -9,9 +9,11 @@ import org.junit.Test
|
||||
*
|
||||
* See [testing documentation](http://d.android.com/tools/testing).
|
||||
*/
|
||||
class HistoryUnitTest {
|
||||
class HistoryUnitTest
|
||||
{
|
||||
@Test
|
||||
fun calculation_isCorrect() {
|
||||
fun calculation_isCorrect()
|
||||
{
|
||||
val history=History()
|
||||
|
||||
history.revertLastRound()
|
||||
|
||||
@@ -8,34 +8,19 @@ import org.junit.Test
|
||||
*
|
||||
* See [testing documentation](http://d.android.com/tools/testing).
|
||||
*/
|
||||
class RoundUnitTest {
|
||||
class RoundUnitTest
|
||||
{
|
||||
@Test
|
||||
fun calculation_isCorrect() {
|
||||
fun calculation_isCorrect()
|
||||
{
|
||||
|
||||
var inputScoreA=125
|
||||
var inputScoreB=-25
|
||||
var temp: Round
|
||||
|
||||
// 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
|
||||
}
|
||||
|
||||
// Team a +100 points for Tichu
|
||||
inputScoreA = 125 + 100
|
||||
inputScoreB = -25
|
||||
|
||||
// Normal round range -25 to 125 as input
|
||||
while (inputScoreB >= 125) {
|
||||
while (inputScoreB <= 125)
|
||||
{
|
||||
temp=Round(inputScoreA , true)
|
||||
assertEquals(inputScoreB , temp.scoreB)
|
||||
assertTrue(temp.isValidRound())
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
// Top-level build file where you can add configuration options common to all sub-projects/modules.
|
||||
buildscript {
|
||||
ext.kotlin_version = "1.4.10"
|
||||
ext.kotlin_version = "1.7.0"
|
||||
repositories {
|
||||
google()
|
||||
jcenter()
|
||||
mavenCentral()
|
||||
}
|
||||
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"
|
||||
|
||||
// NOTE: Do not place your application dependencies here; they belong
|
||||
@@ -17,7 +17,7 @@ buildscript {
|
||||
allprojects {
|
||||
repositories {
|
||||
google()
|
||||
jcenter()
|
||||
mavenCentral()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
2
gradle/wrapper/gradle-wrapper.properties
vendored
2
gradle/wrapper/gradle-wrapper.properties
vendored
@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user