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/deploymentTargetDropDown.xml b/.idea/deploymentTargetDropDown.xml
new file mode 100644
index 0000000..d67c358
--- /dev/null
+++ b/.idea/deploymentTargetDropDown.xml
@@ -0,0 +1,17 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ 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 @@
+
+
+
+
+
+
+
+
+
-
+
@@ -18,12 +27,15 @@
+
+
+
-
+
@@ -35,11 +47,15 @@
+
+
+
+
-
+
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..eadb626 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -4,7 +4,6 @@ apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 30
- buildToolsVersion "30.0.2"
defaultConfig {
applicationId "me.zobrist.tichucounter"
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..f24e3b0 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -13,8 +13,8 @@
+ android:theme="@style/AppTheme.NoActionBar"
+ android:exported="true">
diff --git a/app/src/main/java/me/zobrist/tichucounter/ContextUtils.kt b/app/src/main/java/me/zobrist/tichucounter/ContextUtils.kt
new file mode 100644
index 0000000..1a92571
--- /dev/null
+++ b/app/src/main/java/me/zobrist/tichucounter/ContextUtils.kt
@@ -0,0 +1,34 @@
+package me.zobrist.tichucounter
+
+import android.content.Context
+import android.content.ContextWrapper
+import android.content.res.Configuration
+import android.content.res.Resources
+import android.os.Build
+import android.os.LocaleList
+import java.util.*
+
+class ContextUtils(base: Context) : ContextWrapper(base) {
+
+ companion object {
+
+ fun updateLocale(c: Context, localeToSwitchTo: Locale): ContextWrapper {
+ var context = c
+ val resources: Resources = context.resources
+ val configuration: Configuration = resources.configuration
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
+ val localeList = LocaleList(localeToSwitchTo)
+ LocaleList.setDefault(localeList)
+ configuration.setLocales(localeList)
+ } else {
+ configuration.locale = localeToSwitchTo
+ }
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
+ context = context.createConfigurationContext(configuration)
+ } else {
+ resources.updateConfiguration(configuration, resources.displayMetrics)
+ }
+ return ContextUtils(context)
+ }
+ }
+}
\ 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..5381396 100644
--- a/app/src/main/java/me/zobrist/tichucounter/MainActivity.kt
+++ b/app/src/main/java/me/zobrist/tichucounter/MainActivity.kt
@@ -2,6 +2,8 @@ package me.zobrist.tichucounter
import android.app.AlertDialog
import android.content.Context
+import android.content.ContextWrapper
+import android.content.Intent
import android.os.Bundle
import android.text.InputType
import android.view.Menu
@@ -14,6 +16,7 @@ import androidx.appcompat.app.AppCompatDelegate
import androidx.core.widget.doOnTextChanged
import com.google.gson.Gson
import kotlinx.android.synthetic.main.content_main.*
+import java.util.*
class MainActivity : AppCompatActivity() {
@@ -21,6 +24,15 @@ class MainActivity : AppCompatActivity() {
private lateinit var history: History
private var currentRound = Round()
+ private var systemLocale = Locale.getDefault()
+
+ override fun attachBaseContext(newBase: Context) {
+ // get chosen language from shread preference
+ val localeString = newBase.getSharedPreferences("Settings", Context.MODE_PRIVATE).getString("Language", systemLocale.toString())
+ val localeToSwitchTo = Locale(localeString)
+ val localeUpdatedContext: ContextWrapper = ContextUtils.updateLocale(newBase, localeToSwitchTo)
+ super.attachBaseContext(localeUpdatedContext)
+ }
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
@@ -36,26 +48,32 @@ class MainActivity : AppCompatActivity() {
.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"))
updateView()
+ this.setListenes()
- inputTeamA.setOnFocusChangeListener { view, b ->
+ }
+
+ private fun setListenes()
+ {
+ inputTeamA.setOnFocusChangeListener { _, b ->
if (b) {
hideKeyboard()
}
}
- inputTeamB.setOnFocusChangeListener { view, b ->
+ inputTeamB.setOnFocusChangeListener { _, b ->
if (b) {
hideKeyboard()
}
}
- inputTeamA.doOnTextChanged { text, start, count, after ->
+ inputTeamA.doOnTextChanged { text, _, _, _ ->
if (inputTeamA.isFocused) {
if (inputTeamA.text.isNotEmpty()) {
if (updateOnChange) {
@@ -82,9 +100,7 @@ class MainActivity : AppCompatActivity() {
}
}
-
-
- inputTeamB.doOnTextChanged { text, start, count, after ->
+ inputTeamB.doOnTextChanged { text, _, _, _ ->
if (inputTeamB.isFocused) {
if (inputTeamB.text.isNotEmpty()) {
if (updateOnChange) {
@@ -323,11 +339,11 @@ class MainActivity : AppCompatActivity() {
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()
}
@@ -342,6 +358,10 @@ class MainActivity : AppCompatActivity() {
chooseThemeDialog()
true
}
+ R.id.action_language -> {
+ chooseLanguageDialog()
+ true
+ }
R.id.action_screenOn -> {
item.isChecked = !item.isChecked
keepScreenOn(item.isChecked)
@@ -409,7 +429,7 @@ class MainActivity : AppCompatActivity() {
val builder = AlertDialog.Builder(this)
builder.setTitle(getString(R.string.choose_theme_text))
- val styles = arrayOf("Light", "Dark", "System default")
+ val styles = arrayOf(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)
@@ -431,6 +451,42 @@ class MainActivity : AppCompatActivity() {
dialog.show()
}
+ private fun chooseLanguageDialog() {
+
+ val builder = AlertDialog.Builder(this)
+ builder.setTitle(getString(R.string.choose_language_text))
+
+ val languages_map = mapOf(
+ getString(R.string.android_default_text) to systemLocale.toString(),
+ 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 = this.getSharedPreferences("Settings", Context.MODE_PRIVATE).getString("Language", R.string.android_default_text.toString())
+ val checkedItemIndex = languages_display_values.indexOf(checkedItem)
+
+ val prefs = this.getSharedPreferences("Settings", Context.MODE_PRIVATE).edit()
+
+
+ builder.setSingleChoiceItems(languages_display_keys, checkedItemIndex) { dialog, which ->
+
+ val temp = languages_map[languages_display_keys[which]]
+ prefs.putString("Language", temp)
+ prefs.apply()
+
+ 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)
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" />
+ android:text="2"
+ tools:ignore="HardcodedText" />
+ android:text="3"
+ tools:ignore="HardcodedText" />
+ android:text="+100"
+ tools:ignore="HardcodedText" />
+ android:text="4"
+ tools:ignore="HardcodedText" />
+ android:text="5"
+ tools:ignore="HardcodedText" />
+ android:text="6"
+ tools:ignore="HardcodedText" />
+ android:text="-100"
+ tools:ignore="HardcodedText" />
+ android:text="7"
+ tools:ignore="HardcodedText" />
+ android:text="8"
+ tools:ignore="HardcodedText" />
+ android:text="9"
+ tools:ignore="HardcodedText" />
+ android:contentDescription="@string/back" />
diff --git a/app/src/main/res/menu/menu_main.xml b/app/src/main/res/menu/menu_main.xml
index dd7f051..e534389 100644
--- a/app/src/main/res/menu/menu_main.xml
+++ b/app/src/main/res/menu/menu_main.xml
@@ -17,6 +17,10 @@
android:id="@+id/action_theme"
android:orderInCategory="15"
android:title="@string/choose_theme_text" />
+
- Möchten Sie das laufende Spiel wirklich löschen?
Ja
Nein
+ Zurück
+ Sprache wählen
+ Android Standard
+ Englisch
+ Detusch
+ Hell
+ Dunkel
\ No newline at end of file
diff --git a/app/src/main/res/values-gsw-rCH/strings.xml b/app/src/main/res/values-gsw-rCH/strings.xml
deleted file mode 100644
index 3559d30..0000000
--- a/app/src/main/res/values-gsw-rCH/strings.xml
+++ /dev/null
@@ -1,10 +0,0 @@
-
-
- Neus Spil starte
- Letschti Rundi lösche
- Usgsehe ändere
- Bildschirm igschalted la
- Wosch ds loufende Spil würklech lösche?
- Ja
- Nei
-
\ No newline at end of file
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 0944156..f00f5be 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -1,9 +1,9 @@
+
Tichu Counter
-
-
Team A
Team B
+
Start new game
Undo last round
Choose theme
@@ -11,4 +11,11 @@
Do you really want to delete the current game?
Yes
No
+ Back
+ Choose language
+ Android Default
+ English
+ German
+ Light
+ Dark
\ No newline at end of file
diff --git a/app/src/main/res/xml/locales_config.xml b/app/src/main/res/xml/locales_config.xml
new file mode 100644
index 0000000..e04caba
--- /dev/null
+++ b/app/src/main/res/xml/locales_config.xml
@@ -0,0 +1,5 @@
+
+
+
+
+
diff --git a/build.gradle b/build.gradle
index 33d6ece..22c3693 100644
--- a/build.gradle
+++ b/build.gradle
@@ -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.2.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()
}
}
diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
index 7a5d152..56d536e 100644
--- a/gradle/wrapper/gradle-wrapper.properties
+++ b/gradle/wrapper/gradle-wrapper.properties
@@ -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.3.3-all.zip