diff --git a/.drone.yml b/.drone.yml new file mode 100644 index 0000000..82e296e --- /dev/null +++ b/.drone.yml @@ -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 \ No newline at end of file diff --git a/.gitignore b/.gitignore index 603b140..f0f71e2 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,4 @@ /captures .externalNativeBuild .cxx +.idea diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml index 3cc336b..88ea3aa 100644 --- a/.idea/codeStyles/Project.xml +++ b/.idea/codeStyles/Project.xml @@ -1,22 +1,6 @@ - - diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..fb7f4a8 --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml index ac6b0ae..66ff961 100644 --- a/.idea/gradle.xml +++ b/.idea/gradle.xml @@ -4,17 +4,16 @@ diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..bbc6cd7 --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,8 @@ + + + + \ No newline at end of file diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml index a5f05cd..e34606c 100644 --- a/.idea/jarRepositories.xml +++ b/.idea/jarRepositories.xml @@ -21,5 +21,10 @@ \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index ae2bfea..9f83b5d 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,11 +1,20 @@ + + + - + diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml deleted file mode 100644 index 7f68460..0000000 --- a/.idea/runConfigurations.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index 609f0dc..a93790f 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -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' } \ No newline at end of file diff --git a/app/release/app-release.aab b/app/release/app-release.aab new file mode 100644 index 0000000..f803bcf Binary files /dev/null and b/app/release/app-release.aab differ diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index e35f381..3f3aab9 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,8 +1,8 @@ - + + android:theme="@style/AppTheme.NoActionBar" + android:exported="true"> + + + \ No newline at end of file diff --git a/app/src/main/java/me/zobrist/tichucounter/Extensions.kt b/app/src/main/java/me/zobrist/tichucounter/Extensions.kt new file mode 100644 index 0000000..5f1693f --- /dev/null +++ b/app/src/main/java/me/zobrist/tichucounter/Extensions.kt @@ -0,0 +1,11 @@ +package me.zobrist.tichucounter + +fun Int.isMultipleOf5(): Boolean +{ + return (this % 5) == 0 +} + +fun Int.isMultipleOf100(): Boolean +{ + return (this % 100) == 0 +} \ No newline at end of file diff --git a/app/src/main/java/me/zobrist/tichucounter/History.kt b/app/src/main/java/me/zobrist/tichucounter/History.kt index 15da7af..f7ddc25 100644 --- a/app/src/main/java/me/zobrist/tichucounter/History.kt +++ b/app/src/main/java/me/zobrist/tichucounter/History.kt @@ -1,58 +1,65 @@ -@file:Suppress("unused") - package me.zobrist.tichucounter +class History +{ + private var scores=ArrayList() -class History { - private var scores: ArrayList = ArrayList() - - fun getScoreA(): Int { - var tempScore = 0 + fun getScoreA(): Int + { + var tempScore=0 scores.forEach { - tempScore += it.scoreA + tempScore+=it.scoreA } return tempScore } - fun getScoreB(): Int { - var tempScore = 0 + fun getScoreB(): Int + { + var tempScore=0 scores.forEach { - tempScore += it.scoreB + tempScore+=it.scoreB } return tempScore } - fun getHistoryA(): String { - var tempHistory = String() + fun getHistoryA(): String + { + var tempHistory=String() scores.forEach { - tempHistory += it.scoreA.toString() + "\n" + tempHistory+=it.scoreA.toString() + "\n" } return tempHistory } - fun getHistoryB(): String { - var tempHistory = String() + fun getHistoryB(): String + { + var tempHistory=String() scores.forEach { - tempHistory += it.scoreB.toString() + "\n" + tempHistory+=it.scoreB.toString() + "\n" } 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() } } \ No newline at end of file diff --git a/app/src/main/java/me/zobrist/tichucounter/MainActivity.kt b/app/src/main/java/me/zobrist/tichucounter/MainActivity.kt index 4a8f94e..21dd10d 100644 --- a/app/src/main/java/me/zobrist/tichucounter/MainActivity.kt +++ b/app/src/main/java/me/zobrist/tichucounter/MainActivity.kt @@ -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,339 +11,437 @@ 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 var updateOnChange: Boolean=true 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) - 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) - .getBoolean("Screen_On", false) + this.getSharedPreferences("Settings" , MODE_PRIVATE) + .getBoolean("Screen_On" , false) ) - val json = this.getSharedPreferences("Settings", Context.MODE_PRIVATE).getString("history", "{\"scores\":[]}") - history = Gson().fromJson(json, History::class.java) - nameTeamA.setText(this.getSharedPreferences("Settings", Context.MODE_PRIVATE).getString("nameTeamA", "TeamA")) - nameTeamB.setText(this.getSharedPreferences("Settings", Context.MODE_PRIVATE).getString("nameTeamB", "TeamB")) + + val json=this.getSharedPreferences("Settings" , MODE_PRIVATE) + .getString("history" , "{\"scores\":[]}") + 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() + 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 { - Round(text.toString().toInt(), true) + 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) { - Round(1, 1) } - inputTeamB.setText(currentRound.scoreB.toString()) - } else { - updateOnChange = true + catch (e: java.lang.Exception) + { + Round(1 , 1) + } + binding.contentMain.inputTeamB.setText(currentRound.scoreB.toString()) } - } else { - inputTeamA.text.clear() - inputTeamB.text.clear() + else + { + 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() - } else { + } + else + { 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() - 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.scoreB = 0 - inputTeamB.setText(currentRound.scoreB.toString()) + currentRound.scoreA=try + { + binding.contentMain.inputTeamA.text.toString().toInt() + 100 + } + catch (e: Exception) + { + currentRound.scoreB=0 + binding.contentMain.inputTeamB.setText(currentRound.scoreB.toString()) 100 } - updateOnChange = false - inputTeamA.setText(currentRound.scoreA.toString()) + updateOnChange=false + binding.contentMain.inputTeamA.setText(currentRound.scoreA.toString()) } - if (inputTeamB.isFocused) { - currentRound.scoreB = try { - inputTeamB.text.toString().toInt() + 100 - } catch (e: Exception) { - currentRound.scoreA = 0 - inputTeamA.setText(currentRound.scoreA.toString()) + if (binding.contentMain.inputTeamB.isFocused) + { + currentRound.scoreB=try + { + binding.contentMain.inputTeamB.text.toString().toInt() + 100 + } + catch (e: Exception) + { + currentRound.scoreA=0 + binding.contentMain.inputTeamA.setText(currentRound.scoreA.toString()) 100 } - updateOnChange = false - inputTeamB.setText(currentRound.scoreB.toString()) + updateOnChange=false + 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) { - currentRound.scoreB = 0 - inputTeamB.setText(currentRound.scoreB.toString()) + if (binding.contentMain.inputTeamA.isFocused) + { + currentRound.scoreA=try + { + binding.contentMain.inputTeamA.text.toString().toInt() - 100 + } + catch (e: Exception) + { + currentRound.scoreB=0 + binding.contentMain.inputTeamB.setText(currentRound.scoreB.toString()) -100 } - updateOnChange = false - inputTeamA.setText(currentRound.scoreA.toString()) + updateOnChange=false + binding.contentMain.inputTeamA.setText(currentRound.scoreA.toString()) } - if (inputTeamB.isFocused) { - currentRound.scoreB = try { - inputTeamB.text.toString().toInt() - 100 - } catch (e: Exception) { - currentRound.scoreA = 0 - inputTeamA.setText(currentRound.scoreA.toString()) + if (binding.contentMain.inputTeamB.isFocused) + { + currentRound.scoreB=try + { + binding.contentMain.inputTeamB.text.toString().toInt() - 100 + } + catch (e: Exception) + { + currentRound.scoreA=0 + binding.contentMain.inputTeamA.setText(currentRound.scoreA.toString()) -100 } - updateOnChange = false - inputTeamB.setText(currentRound.scoreB.toString()) + updateOnChange=false + 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 { - updateOnChange = false + 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) + 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 { - updateOnChange = false + } + 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) + currentRound=Round(1 , 1) } } } - 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() - prefs.putString("history", Gson().toJson(history)) - prefs.putString("nameTeamA", nameTeamA.text.toString()) - prefs.putString("nameTeamB", nameTeamB.text.toString()) + val prefs=this.getSharedPreferences("Settings" , MODE_PRIVATE).edit() + prefs.putString("history" , Gson().toJson(history)) + 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) + menuInflater.inflate(R.menu.menu_main , menu) - menu.findItem(R.id.action_screenOn).isChecked = - this.getSharedPreferences("Settings", Context.MODE_PRIVATE) - .getBoolean("Screen_On", false) + menu.findItem(R.id.action_screenOn).isChecked= + 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 -> { - val builder = AlertDialog.Builder(this) + 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 -> { - item.isChecked = !item.isChecked + R.id.action_language -> + { + chooseLanguageDialog() + true + } + R.id.action_screenOn -> + { + item.isChecked=!item.isChecked keepScreenOn(item.isChecked) true } @@ -351,75 +449,92 @@ class MainActivity : AppCompatActivity() { } } - private fun hideKeyboard() { - val imm: InputMethodManager = + private fun hideKeyboard() + { + val imm: InputMethodManager= getSystemService(INPUT_METHOD_SERVICE) as InputMethodManager - imm.hideSoftInputFromWindow(currentFocus!!.windowToken, 0) + 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) + 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) + val checkedItem= + 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() updateTheme(which) @@ -427,12 +542,53 @@ class MainActivity : AppCompatActivity() { dialog.dismiss() } - val dialog = builder.create() + val dialog=builder.create() 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,15 +596,19 @@ 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() - prefs.putBoolean("Screen_On", keepOn) + val prefs=this.getSharedPreferences("Settings" , MODE_PRIVATE).edit() + prefs.putBoolean("Screen_On" , keepOn) prefs.apply() } } \ No newline at end of file diff --git a/app/src/main/java/me/zobrist/tichucounter/Round.kt b/app/src/main/java/me/zobrist/tichucounter/Round.kt index 3f0b7f6..93188e3 100644 --- a/app/src/main/java/me/zobrist/tichucounter/Round.kt +++ b/app/src/main/java/me/zobrist/tichucounter/Round.kt @@ -2,37 +2,46 @@ package me.zobrist.tichucounter import java.io.Serializable -class Round() : Serializable { - var scoreA: Int = 0 - var scoreB: Int = 0 +class Round() : Serializable +{ + var scoreA: Int=0 + var scoreB: Int=0 - constructor(score: Int, isScoreA: Boolean) : this() { - if (isScoreA) { - scoreA = score - scoreB = calculateOtherScore(scoreA) - } else { - scoreB = score - scoreA = calculateOtherScore(scoreB) + constructor(score: Int , isScoreA: Boolean) : this() + { + if (isScoreA) + { + scoreA=score + scoreB=calculateOtherScore(scoreA) + } + else + { + scoreB=score + scoreA=calculateOtherScore(scoreB) } } - constructor(scoreA: Int, scoreB: Int) : this() { - this.scoreA = scoreA - this.scoreB = scoreB + 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() } } \ No newline at end of file diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 9c96440..4c98b99 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -20,6 +20,8 @@ - + \ No newline at end of file diff --git a/app/src/main/res/layout/content_main.xml b/app/src/main/res/layout/content_main.xml index 4b36db1..fac6752 100644 --- a/app/src/main/res/layout/content_main.xml +++ b/app/src/main/res/layout/content_main.xml @@ -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" /> + android:textStyle="bold" + tools:ignore="HardcodedText" /> @@ -136,7 +138,8 @@ android:gravity="center" android:hint="0" android:importantForAutofill="no" - android:inputType="numberSigned" /> + android:inputType="numberSigned" + tools:ignore="HardcodedText" /> + android:inputType="numberSigned" + tools:ignore="HardcodedText" /> + android:text="1" + tools:ignore="HardcodedText" />