Use correct binding. Remove unneeded code.
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -12,3 +12,4 @@
|
|||||||
/captures
|
/captures
|
||||||
.externalNativeBuild
|
.externalNativeBuild
|
||||||
.cxx
|
.cxx
|
||||||
|
.idea
|
||||||
|
|||||||
17
.idea/deploymentTargetDropDown.xml
generated
17
.idea/deploymentTargetDropDown.xml
generated
@@ -1,17 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="deploymentTargetDropDown">
|
|
||||||
<targetSelectedWithDropDown>
|
|
||||||
<Target>
|
|
||||||
<type value="QUICK_BOOT_TARGET" />
|
|
||||||
<deviceKey>
|
|
||||||
<Key>
|
|
||||||
<type value="VIRTUAL_DEVICE_PATH" />
|
|
||||||
<value value="$USER_HOME$/.android/avd/Pixel_3a_API_29.avd" />
|
|
||||||
</Key>
|
|
||||||
</deviceKey>
|
|
||||||
</Target>
|
|
||||||
</targetSelectedWithDropDown>
|
|
||||||
<timeTargetWasSelectedWithDropDown value="2022-06-26T09:26:31.554432Z" />
|
|
||||||
</component>
|
|
||||||
</project>
|
|
||||||
@@ -39,7 +39,7 @@ dependencies {
|
|||||||
implementation fileTree(dir: "libs", include: ["*.jar"])
|
implementation fileTree(dir: "libs", include: ["*.jar"])
|
||||||
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
||||||
implementation 'androidx.core:core-ktx:1.8.0'
|
implementation 'androidx.core:core-ktx:1.8.0'
|
||||||
implementation 'androidx.appcompat:appcompat:1.4.2'
|
implementation 'androidx.appcompat:appcompat:1.6.0-alpha05'
|
||||||
implementation 'com.google.android.material:material:1.6.1'
|
implementation 'com.google.android.material:material:1.6.1'
|
||||||
implementation 'com.google.android.play:core-ktx:1.8.1'
|
implementation 'com.google.android.play:core-ktx:1.8.1'
|
||||||
implementation 'com.google.android.play:core-ktx:1.8.1'
|
implementation 'com.google.android.play:core-ktx:1.8.1'
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
package="me.zobrist.tichucounter">
|
package="me.zobrist.tichucounter">
|
||||||
|
|
||||||
<application
|
<application
|
||||||
|
|
||||||
android:allowBackup="true"
|
android:allowBackup="true"
|
||||||
android:icon="@mipmap/ic_launcher"
|
android:icon="@mipmap/ic_launcher"
|
||||||
android:label="@string/app_name"
|
android:label="@string/app_name"
|
||||||
@@ -21,6 +22,14 @@
|
|||||||
<category android:name="android.intent.category.LAUNCHER" />
|
<category android:name="android.intent.category.LAUNCHER" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
|
<service
|
||||||
|
android:name="androidx.appcompat.app.AppLocalesMetadataHolderService"
|
||||||
|
android:enabled="false"
|
||||||
|
android:exported="false">
|
||||||
|
<meta-data
|
||||||
|
android:name="autoStoreLocales"
|
||||||
|
android:value="true" />
|
||||||
|
</service>
|
||||||
</application>
|
</application>
|
||||||
|
|
||||||
</manifest>
|
</manifest>
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -6,16 +6,15 @@ import android.content.ContextWrapper
|
|||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.text.InputType
|
import android.text.InputType
|
||||||
import android.view.Menu
|
import android.view.*
|
||||||
import android.view.MenuItem
|
|
||||||
import android.view.WindowManager
|
|
||||||
import android.view.inputmethod.InputMethodManager
|
import android.view.inputmethod.InputMethodManager
|
||||||
import android.widget.ScrollView
|
import android.widget.ScrollView
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import androidx.appcompat.app.AppCompatDelegate
|
import androidx.appcompat.app.AppCompatDelegate
|
||||||
|
import androidx.core.os.LocaleListCompat
|
||||||
import androidx.core.widget.doOnTextChanged
|
import androidx.core.widget.doOnTextChanged
|
||||||
import com.google.gson.Gson
|
import com.google.gson.Gson
|
||||||
import me.zobrist.tichucounter.databinding.ContentMainBinding
|
import me.zobrist.tichucounter.databinding.ActivityMainBinding
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
class MainActivity : AppCompatActivity() {
|
class MainActivity : AppCompatActivity() {
|
||||||
@@ -26,43 +25,32 @@ class MainActivity : AppCompatActivity() {
|
|||||||
private var currentRound = Round()
|
private var currentRound = Round()
|
||||||
private var systemLocale = Locale.getDefault()
|
private var systemLocale = Locale.getDefault()
|
||||||
|
|
||||||
private lateinit var binding: ContentMainBinding
|
|
||||||
|
|
||||||
|
private lateinit var binding: ActivityMainBinding
|
||||||
|
|
||||||
override fun attachBaseContext(newBase: Context) {
|
|
||||||
// get chosen language from shread preference
|
|
||||||
val localeString = newBase.getSharedPreferences("Settings", Context.MODE_PRIVATE).getString("Language", systemLocale.toString())
|
|
||||||
|
|
||||||
if(localeString != null)
|
|
||||||
{
|
|
||||||
val localeToSwitchTo = Locale(localeString)
|
|
||||||
val localeUpdatedContext: ContextWrapper = ContextUtils.updateLocale(newBase, localeToSwitchTo)
|
|
||||||
super.attachBaseContext(localeUpdatedContext)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
binding = ContentMainBinding.inflate(layoutInflater)
|
binding = ActivityMainBinding.inflate(layoutInflater)
|
||||||
|
setContentView(binding.root)
|
||||||
|
|
||||||
setContentView(R.layout.activity_main)
|
setSupportActionBar(binding.toolbar)
|
||||||
setSupportActionBar(findViewById(R.id.toolbar))
|
|
||||||
|
|
||||||
binding.inputTeamA.setRawInputType(InputType.TYPE_NULL)
|
binding.contentMain.inputTeamA.setRawInputType(InputType.TYPE_NULL)
|
||||||
binding.inputTeamB.setRawInputType(InputType.TYPE_NULL)
|
binding.contentMain.inputTeamB.setRawInputType(InputType.TYPE_NULL)
|
||||||
binding.inputTeamA.requestFocus()
|
binding.contentMain.inputTeamA.requestFocus()
|
||||||
disableSubmitButton()
|
disableSubmitButton()
|
||||||
updateTheme(this.getSharedPreferences("Settings", Context.MODE_PRIVATE).getInt("Theme", 2))
|
updateTheme(this.getSharedPreferences("Settings", MODE_PRIVATE).getInt("Theme", 2))
|
||||||
keepScreenOn(
|
keepScreenOn(
|
||||||
this.getSharedPreferences("Settings", Context.MODE_PRIVATE)
|
this.getSharedPreferences("Settings", MODE_PRIVATE)
|
||||||
.getBoolean("Screen_On", false)
|
.getBoolean("Screen_On", false)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
val json = this.getSharedPreferences("Settings", Context.MODE_PRIVATE).getString("history", "{\"scores\":[]}")
|
val json = this.getSharedPreferences("Settings", MODE_PRIVATE).getString("history", "{\"scores\":[]}")
|
||||||
history = Gson().fromJson(json, History::class.java)
|
history = Gson().fromJson(json, History::class.java)
|
||||||
binding.nameTeamA.setText(this.getSharedPreferences("Settings", Context.MODE_PRIVATE).getString("nameTeamA", "TeamA"))
|
binding.contentMain.nameTeamA.setText(this.getSharedPreferences("Settings", MODE_PRIVATE).getString("nameTeamA", "TeamA"))
|
||||||
binding.nameTeamB.setText(this.getSharedPreferences("Settings", Context.MODE_PRIVATE).getString("nameTeamB", "TeamB"))
|
binding.contentMain.nameTeamB.setText(this.getSharedPreferences("Settings", MODE_PRIVATE).getString("nameTeamB", "TeamB"))
|
||||||
updateView()
|
updateView()
|
||||||
|
|
||||||
this.setListenes()
|
this.setListenes()
|
||||||
@@ -72,21 +60,21 @@ class MainActivity : AppCompatActivity() {
|
|||||||
|
|
||||||
private fun setListenes()
|
private fun setListenes()
|
||||||
{
|
{
|
||||||
binding.inputTeamA.setOnFocusChangeListener { _, b ->
|
binding.contentMain.inputTeamA.setOnFocusChangeListener { _, b ->
|
||||||
if (b) {
|
if (b) {
|
||||||
hideKeyboard()
|
hideKeyboard()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
binding.inputTeamB.setOnFocusChangeListener { _, b ->
|
binding.contentMain.inputTeamB.setOnFocusChangeListener { _, b ->
|
||||||
if (b) {
|
if (b) {
|
||||||
hideKeyboard()
|
hideKeyboard()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
binding.inputTeamA.doOnTextChanged { text, _, _, _ ->
|
binding.contentMain.inputTeamA.doOnTextChanged { text, _, _, _ ->
|
||||||
if (binding.inputTeamA.isFocused) {
|
if (binding.contentMain.inputTeamA.isFocused) {
|
||||||
if (binding.inputTeamA.text.isNotEmpty()) {
|
if (binding.contentMain.inputTeamA.text.isNotEmpty()) {
|
||||||
if (updateOnChange) {
|
if (updateOnChange) {
|
||||||
currentRound = try {
|
currentRound = try {
|
||||||
Round(text.toString().toInt(), true)
|
Round(text.toString().toInt(), true)
|
||||||
@@ -94,26 +82,26 @@ class MainActivity : AppCompatActivity() {
|
|||||||
} catch (e: java.lang.Exception) {
|
} catch (e: java.lang.Exception) {
|
||||||
Round(1, 1)
|
Round(1, 1)
|
||||||
}
|
}
|
||||||
binding.inputTeamB.setText(currentRound.scoreB.toString())
|
binding.contentMain.inputTeamB.setText(currentRound.scoreB.toString())
|
||||||
} else {
|
} else {
|
||||||
updateOnChange = true
|
updateOnChange = true
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
binding.inputTeamA.text.clear()
|
binding.contentMain.inputTeamA.text.clear()
|
||||||
binding.inputTeamB.text.clear()
|
binding.contentMain.inputTeamB.text.clear()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (currentRound.isValidRound() && binding.inputTeamA.text.isNotEmpty() && binding.inputTeamB.text.isNotEmpty()) {
|
if (currentRound.isValidRound() && binding.contentMain.inputTeamA.text.isNotEmpty() && binding.contentMain.inputTeamB.text.isNotEmpty()) {
|
||||||
enableSubmitButton()
|
enableSubmitButton()
|
||||||
} else {
|
} else {
|
||||||
disableSubmitButton()
|
disableSubmitButton()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
binding.inputTeamB.doOnTextChanged { text, _, _, _ ->
|
binding.contentMain.inputTeamB.doOnTextChanged { text, _, _, _ ->
|
||||||
if (binding.inputTeamB.isFocused) {
|
if (binding.contentMain.inputTeamB.isFocused) {
|
||||||
if (binding.inputTeamB.text.isNotEmpty()) {
|
if (binding.contentMain.inputTeamB.text.isNotEmpty()) {
|
||||||
if (updateOnChange) {
|
if (updateOnChange) {
|
||||||
currentRound = try {
|
currentRound = try {
|
||||||
Round(text.toString().toInt(), false)
|
Round(text.toString().toInt(), false)
|
||||||
@@ -121,145 +109,145 @@ class MainActivity : AppCompatActivity() {
|
|||||||
} catch (e: java.lang.Exception) {
|
} catch (e: java.lang.Exception) {
|
||||||
Round(1, 1)
|
Round(1, 1)
|
||||||
}
|
}
|
||||||
binding.inputTeamA.setText(currentRound.scoreA.toString())
|
binding.contentMain.inputTeamA.setText(currentRound.scoreA.toString())
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
updateOnChange = true
|
updateOnChange = true
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
binding.inputTeamA.text.clear()
|
binding.contentMain.inputTeamA.text.clear()
|
||||||
binding.inputTeamB.text.clear()
|
binding.contentMain.inputTeamB.text.clear()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (currentRound.isValidRound() && binding.inputTeamA.text.isNotEmpty() && binding.inputTeamB.text.isNotEmpty()) {
|
if (currentRound.isValidRound() && binding.contentMain.inputTeamA.text.isNotEmpty() && binding.contentMain.inputTeamB.text.isNotEmpty()) {
|
||||||
enableSubmitButton()
|
enableSubmitButton()
|
||||||
} else {
|
} else {
|
||||||
disableSubmitButton()
|
disableSubmitButton()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
binding.buttonAdd100.setOnClickListener {
|
binding.contentMain.buttonAdd100.setOnClickListener {
|
||||||
giveFocusToAIfNone()
|
giveFocusToAIfNone()
|
||||||
|
|
||||||
if (binding.inputTeamA.isFocused) {
|
if (binding.contentMain.inputTeamA.isFocused) {
|
||||||
|
|
||||||
currentRound.scoreA = try {
|
currentRound.scoreA = try {
|
||||||
binding.inputTeamA.text.toString().toInt() + 100
|
binding.contentMain.inputTeamA.text.toString().toInt() + 100
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
currentRound.scoreB = 0
|
currentRound.scoreB = 0
|
||||||
binding.inputTeamB.setText(currentRound.scoreB.toString())
|
binding.contentMain.inputTeamB.setText(currentRound.scoreB.toString())
|
||||||
100
|
100
|
||||||
}
|
}
|
||||||
updateOnChange = false
|
updateOnChange = false
|
||||||
binding.inputTeamA.setText(currentRound.scoreA.toString())
|
binding.contentMain.inputTeamA.setText(currentRound.scoreA.toString())
|
||||||
}
|
}
|
||||||
|
|
||||||
if (binding.inputTeamB.isFocused) {
|
if (binding.contentMain.inputTeamB.isFocused) {
|
||||||
currentRound.scoreB = try {
|
currentRound.scoreB = try {
|
||||||
binding.inputTeamB.text.toString().toInt() + 100
|
binding.contentMain.inputTeamB.text.toString().toInt() + 100
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
currentRound.scoreA = 0
|
currentRound.scoreA = 0
|
||||||
binding.inputTeamA.setText(currentRound.scoreA.toString())
|
binding.contentMain.inputTeamA.setText(currentRound.scoreA.toString())
|
||||||
100
|
100
|
||||||
|
|
||||||
}
|
}
|
||||||
updateOnChange = false
|
updateOnChange = false
|
||||||
binding.inputTeamB.setText(currentRound.scoreB.toString())
|
binding.contentMain.inputTeamB.setText(currentRound.scoreB.toString())
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
binding.buttonSub100.setOnClickListener {
|
binding.contentMain.buttonSub100.setOnClickListener {
|
||||||
giveFocusToAIfNone()
|
giveFocusToAIfNone()
|
||||||
|
|
||||||
if (binding.inputTeamA.isFocused) {
|
if (binding.contentMain.inputTeamA.isFocused) {
|
||||||
currentRound.scoreA = try {
|
currentRound.scoreA = try {
|
||||||
binding.inputTeamA.text.toString().toInt() - 100
|
binding.contentMain.inputTeamA.text.toString().toInt() - 100
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
currentRound.scoreB = 0
|
currentRound.scoreB = 0
|
||||||
binding.inputTeamB.setText(currentRound.scoreB.toString())
|
binding.contentMain.inputTeamB.setText(currentRound.scoreB.toString())
|
||||||
-100
|
-100
|
||||||
}
|
}
|
||||||
updateOnChange = false
|
updateOnChange = false
|
||||||
binding.inputTeamA.setText(currentRound.scoreA.toString())
|
binding.contentMain.inputTeamA.setText(currentRound.scoreA.toString())
|
||||||
}
|
}
|
||||||
|
|
||||||
if (binding.inputTeamB.isFocused) {
|
if (binding.contentMain.inputTeamB.isFocused) {
|
||||||
currentRound.scoreB = try {
|
currentRound.scoreB = try {
|
||||||
binding.inputTeamB.text.toString().toInt() - 100
|
binding.contentMain.inputTeamB.text.toString().toInt() - 100
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
currentRound.scoreA = 0
|
currentRound.scoreA = 0
|
||||||
binding.inputTeamA.setText(currentRound.scoreA.toString())
|
binding.contentMain.inputTeamA.setText(currentRound.scoreA.toString())
|
||||||
-100
|
-100
|
||||||
}
|
}
|
||||||
updateOnChange = false
|
updateOnChange = false
|
||||||
binding.inputTeamB.setText(currentRound.scoreB.toString())
|
binding.contentMain.inputTeamB.setText(currentRound.scoreB.toString())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
binding.button0.setOnClickListener {
|
binding.contentMain.button0.setOnClickListener {
|
||||||
giveFocusToAIfNone()
|
giveFocusToAIfNone()
|
||||||
appendToFocusedInput('0')
|
appendToFocusedInput('0')
|
||||||
}
|
}
|
||||||
|
|
||||||
binding.button1.setOnClickListener {
|
binding.contentMain.button1.setOnClickListener {
|
||||||
giveFocusToAIfNone()
|
giveFocusToAIfNone()
|
||||||
appendToFocusedInput('1')
|
appendToFocusedInput('1')
|
||||||
}
|
}
|
||||||
|
|
||||||
binding.button2.setOnClickListener {
|
binding.contentMain.button2.setOnClickListener {
|
||||||
giveFocusToAIfNone()
|
giveFocusToAIfNone()
|
||||||
appendToFocusedInput('2')
|
appendToFocusedInput('2')
|
||||||
}
|
}
|
||||||
|
|
||||||
binding.button3.setOnClickListener {
|
binding.contentMain.button3.setOnClickListener {
|
||||||
giveFocusToAIfNone()
|
giveFocusToAIfNone()
|
||||||
appendToFocusedInput('3')
|
appendToFocusedInput('3')
|
||||||
}
|
}
|
||||||
|
|
||||||
binding.button4.setOnClickListener {
|
binding.contentMain.button4.setOnClickListener {
|
||||||
giveFocusToAIfNone()
|
giveFocusToAIfNone()
|
||||||
appendToFocusedInput('4')
|
appendToFocusedInput('4')
|
||||||
}
|
}
|
||||||
|
|
||||||
binding.button5.setOnClickListener {
|
binding.contentMain.button5.setOnClickListener {
|
||||||
giveFocusToAIfNone()
|
giveFocusToAIfNone()
|
||||||
appendToFocusedInput('5')
|
appendToFocusedInput('5')
|
||||||
}
|
}
|
||||||
|
|
||||||
binding.button6.setOnClickListener {
|
binding.contentMain.button6.setOnClickListener {
|
||||||
giveFocusToAIfNone()
|
giveFocusToAIfNone()
|
||||||
appendToFocusedInput('6')
|
appendToFocusedInput('6')
|
||||||
}
|
}
|
||||||
|
|
||||||
binding.button7.setOnClickListener {
|
binding.contentMain.button7.setOnClickListener {
|
||||||
giveFocusToAIfNone()
|
giveFocusToAIfNone()
|
||||||
appendToFocusedInput('7')
|
appendToFocusedInput('7')
|
||||||
}
|
}
|
||||||
|
|
||||||
binding.button8.setOnClickListener {
|
binding.contentMain.button8.setOnClickListener {
|
||||||
giveFocusToAIfNone()
|
giveFocusToAIfNone()
|
||||||
appendToFocusedInput('8')
|
appendToFocusedInput('8')
|
||||||
}
|
}
|
||||||
|
|
||||||
binding.button9.setOnClickListener {
|
binding.contentMain.button9.setOnClickListener {
|
||||||
giveFocusToAIfNone()
|
giveFocusToAIfNone()
|
||||||
appendToFocusedInput('9')
|
appendToFocusedInput('9')
|
||||||
}
|
}
|
||||||
|
|
||||||
binding.buttonInv.setOnClickListener {
|
binding.contentMain.buttonInv.setOnClickListener {
|
||||||
val tempInt: Int
|
val tempInt: Int
|
||||||
|
|
||||||
giveFocusToAIfNone()
|
giveFocusToAIfNone()
|
||||||
|
|
||||||
if (binding.inputTeamA.isFocused) {
|
if (binding.contentMain.inputTeamA.isFocused) {
|
||||||
if (binding.inputTeamA.text.toString().equals("-")) {
|
if (binding.contentMain.inputTeamA.text.toString().equals("-")) {
|
||||||
binding.inputTeamA.text.clear()
|
binding.contentMain.inputTeamA.text.clear()
|
||||||
} else if (binding.inputTeamA.text.isNotEmpty()) {
|
} else if (binding.contentMain.inputTeamA.text.isNotEmpty()) {
|
||||||
tempInt = binding.inputTeamA.text.toString().toInt() * -1
|
tempInt = binding.contentMain.inputTeamA.text.toString().toInt() * -1
|
||||||
binding.inputTeamA.setText(tempInt.toString())
|
binding.contentMain.inputTeamA.setText(tempInt.toString())
|
||||||
} else {
|
} else {
|
||||||
updateOnChange = false
|
updateOnChange = false
|
||||||
appendToFocusedInput('-')
|
appendToFocusedInput('-')
|
||||||
@@ -267,12 +255,12 @@ class MainActivity : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
} else if (binding.inputTeamB.isFocused) {
|
} else if (binding.contentMain.inputTeamB.isFocused) {
|
||||||
if (binding.inputTeamB.text.toString().equals("-")) {
|
if (binding.contentMain.inputTeamB.text.toString().equals("-")) {
|
||||||
binding.inputTeamB.text.clear()
|
binding.contentMain.inputTeamB.text.clear()
|
||||||
} else if (binding.inputTeamB.text.isNotEmpty()) {
|
} else if (binding.contentMain.inputTeamB.text.isNotEmpty()) {
|
||||||
tempInt = binding.inputTeamB.text.toString().toInt() * -1
|
tempInt = binding.contentMain.inputTeamB.text.toString().toInt() * -1
|
||||||
binding.inputTeamB.setText(tempInt.toString())
|
binding.contentMain.inputTeamB.setText(tempInt.toString())
|
||||||
} else {
|
} else {
|
||||||
updateOnChange = false
|
updateOnChange = false
|
||||||
appendToFocusedInput('-')
|
appendToFocusedInput('-')
|
||||||
@@ -281,42 +269,42 @@ class MainActivity : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
binding.buttonBack.setOnClickListener {
|
binding.contentMain.buttonBack.setOnClickListener {
|
||||||
giveFocusToAIfNone()
|
giveFocusToAIfNone()
|
||||||
|
|
||||||
if (binding.inputTeamA.isFocused) {
|
if (binding.contentMain.inputTeamA.isFocused) {
|
||||||
if (binding.inputTeamA.text.isNotEmpty()) {
|
if (binding.contentMain.inputTeamA.text.isNotEmpty()) {
|
||||||
val string = binding.inputTeamA.text.toString()
|
val string = binding.contentMain.inputTeamA.text.toString()
|
||||||
binding.inputTeamA.setText(string.substring(0, string.length - 1))
|
binding.contentMain.inputTeamA.setText(string.substring(0, string.length - 1))
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (binding.inputTeamB.isFocused) {
|
} else if (binding.contentMain.inputTeamB.isFocused) {
|
||||||
if (binding.inputTeamB.text.isNotEmpty()) {
|
if (binding.contentMain.inputTeamB.text.isNotEmpty()) {
|
||||||
val string = binding.inputTeamB.text.toString()
|
val string = binding.contentMain.inputTeamB.text.toString()
|
||||||
binding.inputTeamB.setText(string.substring(0, string.length - 1))
|
binding.contentMain.inputTeamB.setText(string.substring(0, string.length - 1))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
binding.submit.setOnClickListener {
|
binding.contentMain.submit.setOnClickListener {
|
||||||
giveFocusToAIfNone()
|
giveFocusToAIfNone()
|
||||||
|
|
||||||
if (binding.inputTeamA.text.isNotEmpty() && binding.inputTeamB.text.isNotEmpty()) {
|
if (binding.contentMain.inputTeamA.text.isNotEmpty() && binding.contentMain.inputTeamB.text.isNotEmpty()) {
|
||||||
|
|
||||||
history.logRound(
|
history.logRound(
|
||||||
Round(
|
Round(
|
||||||
binding.inputTeamA.text.toString().toInt(),
|
binding.contentMain.inputTeamA.text.toString().toInt(),
|
||||||
binding.inputTeamB.text.toString().toInt()
|
binding.contentMain.inputTeamB.text.toString().toInt()
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
updateView()
|
updateView()
|
||||||
|
|
||||||
binding.inputTeamA.text.clear()
|
binding.contentMain.inputTeamA.text.clear()
|
||||||
binding.inputTeamB.text.clear()
|
binding.contentMain.inputTeamB.text.clear()
|
||||||
disableSubmitButton()
|
disableSubmitButton()
|
||||||
|
|
||||||
binding.scrollViewHistory.fullScroll(ScrollView.FOCUS_DOWN)
|
binding.contentMain.scrollViewHistory.fullScroll(ScrollView.FOCUS_DOWN)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -324,10 +312,10 @@ class MainActivity : AppCompatActivity() {
|
|||||||
override fun onSaveInstanceState(outState: Bundle) {
|
override fun onSaveInstanceState(outState: Bundle) {
|
||||||
super.onSaveInstanceState(outState)
|
super.onSaveInstanceState(outState)
|
||||||
|
|
||||||
val prefs = this.getSharedPreferences("Settings", Context.MODE_PRIVATE).edit()
|
val prefs = this.getSharedPreferences("Settings", MODE_PRIVATE).edit()
|
||||||
prefs.putString("history", Gson().toJson(history))
|
prefs.putString("history", Gson().toJson(history))
|
||||||
prefs.putString("nameTeamA", binding.nameTeamA.text.toString())
|
prefs.putString("nameTeamA", binding.contentMain.nameTeamA.text.toString())
|
||||||
prefs.putString("nameTeamB", binding.nameTeamB.text.toString())
|
prefs.putString("nameTeamB", binding.contentMain.nameTeamB.text.toString())
|
||||||
prefs.apply()
|
prefs.apply()
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -337,7 +325,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
menuInflater.inflate(R.menu.menu_main, menu)
|
menuInflater.inflate(R.menu.menu_main, menu)
|
||||||
|
|
||||||
menu.findItem(R.id.action_screenOn).isChecked =
|
menu.findItem(R.id.action_screenOn).isChecked =
|
||||||
this.getSharedPreferences("Settings", Context.MODE_PRIVATE)
|
this.getSharedPreferences("Settings", MODE_PRIVATE)
|
||||||
.getBoolean("Screen_On", false)
|
.getBoolean("Screen_On", false)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
@@ -389,8 +377,8 @@ class MainActivity : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun giveFocusToAIfNone() {
|
private fun giveFocusToAIfNone() {
|
||||||
if (!binding.inputTeamA.isFocused && !binding.inputTeamB.isFocused) {
|
if (!binding.contentMain.inputTeamA.isFocused && !binding.contentMain.inputTeamB.isFocused) {
|
||||||
binding.inputTeamA.requestFocus()
|
binding.contentMain.inputTeamA.requestFocus()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -400,40 +388,40 @@ class MainActivity : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun updateView() {
|
private fun updateView() {
|
||||||
binding.scoreA.text = history.getScoreA().toString()
|
binding.contentMain.scoreA.text = history.getScoreA().toString()
|
||||||
binding.scoreB.text = history.getScoreB().toString()
|
binding.contentMain.scoreB.text = history.getScoreB().toString()
|
||||||
|
|
||||||
binding.historyA.text = history.getHistoryA()
|
binding.contentMain.historyA.text = history.getHistoryA()
|
||||||
binding.historyB.text = history.getHistoryB()
|
binding.contentMain.historyB.text = history.getHistoryB()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun clearAll() {
|
private fun clearAll() {
|
||||||
binding.historyA.text = ""
|
binding.contentMain.historyA.text = ""
|
||||||
binding.historyB.text = ""
|
binding.contentMain.historyB.text = ""
|
||||||
binding.inputTeamA.text.clear()
|
binding.contentMain.inputTeamA.text.clear()
|
||||||
binding.inputTeamB.text.clear()
|
binding.contentMain.inputTeamB.text.clear()
|
||||||
binding.scoreA.text = "0"
|
binding.contentMain.scoreA.text = "0"
|
||||||
binding.scoreB.text = "0"
|
binding.contentMain.scoreB.text = "0"
|
||||||
|
|
||||||
history.clearAll()
|
history.clearAll()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun appendToFocusedInput(toAppend: Char) {
|
private fun appendToFocusedInput(toAppend: Char) {
|
||||||
if (binding.inputTeamA.isFocused) {
|
if (binding.contentMain.inputTeamA.isFocused) {
|
||||||
binding.inputTeamA.text.append(toAppend)
|
binding.contentMain.inputTeamA.text.append(toAppend)
|
||||||
} else if (binding.inputTeamB.isFocused) {
|
} else if (binding.contentMain.inputTeamB.isFocused) {
|
||||||
binding.inputTeamB.text.append(toAppend)
|
binding.contentMain.inputTeamB.text.append(toAppend)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun enableSubmitButton() {
|
private fun enableSubmitButton() {
|
||||||
binding.submit.imageAlpha = 255 // 0 being transparent and 255 being opaque
|
binding.contentMain.submit.imageAlpha = 255 // 0 being transparent and 255 being opaque
|
||||||
binding.submit.isEnabled = true
|
binding.contentMain.submit.isEnabled = true
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun disableSubmitButton() {
|
private fun disableSubmitButton() {
|
||||||
binding.submit.imageAlpha = 60 // 0 being transparent and 255 being opaque
|
binding.contentMain.submit.imageAlpha = 60 // 0 being transparent and 255 being opaque
|
||||||
binding.submit.isEnabled = false
|
binding.contentMain.submit.isEnabled = false
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun chooseThemeDialog() {
|
private fun chooseThemeDialog() {
|
||||||
@@ -443,9 +431,9 @@ class MainActivity : AppCompatActivity() {
|
|||||||
val styles = arrayOf(getString(R.string.light), getString(R.string.dark), getString(R.string.android_default_text))
|
val styles = arrayOf(getString(R.string.light), getString(R.string.dark), getString(R.string.android_default_text))
|
||||||
|
|
||||||
val checkedItem =
|
val checkedItem =
|
||||||
this.getSharedPreferences("Settings", Context.MODE_PRIVATE).getInt("Theme", 2)
|
this.getSharedPreferences("Settings", MODE_PRIVATE).getInt("Theme", 2)
|
||||||
|
|
||||||
val prefs = this.getSharedPreferences("Settings", Context.MODE_PRIVATE).edit()
|
val prefs = this.getSharedPreferences("Settings", MODE_PRIVATE).edit()
|
||||||
|
|
||||||
|
|
||||||
builder.setSingleChoiceItems(styles, checkedItem) { dialog, which ->
|
builder.setSingleChoiceItems(styles, checkedItem) { dialog, which ->
|
||||||
@@ -468,25 +456,25 @@ class MainActivity : AppCompatActivity() {
|
|||||||
builder.setTitle(getString(R.string.choose_language_text))
|
builder.setTitle(getString(R.string.choose_language_text))
|
||||||
|
|
||||||
val languages_map = mapOf(
|
val languages_map = mapOf(
|
||||||
getString(R.string.android_default_text) to systemLocale.toString(),
|
|
||||||
getString(R.string.english) to "en",
|
getString(R.string.english) to "en",
|
||||||
getString(R.string.german) to "de")
|
getString(R.string.german) to "de")
|
||||||
|
|
||||||
val languages_display_keys = languages_map.keys.toTypedArray()
|
val languages_display_keys = languages_map.keys.toTypedArray()
|
||||||
val languages_display_values = languages_map.values.toTypedArray()
|
val languages_display_values = languages_map.values.toTypedArray()
|
||||||
|
|
||||||
|
val checkedItem = AppCompatDelegate.getApplicationLocales()[0].toString()
|
||||||
|
var checkedItemIndex = languages_display_values.indexOf(checkedItem)
|
||||||
|
|
||||||
val checkedItem = this.getSharedPreferences("Settings", Context.MODE_PRIVATE).getString("Language", R.string.android_default_text.toString())
|
if(checkedItemIndex == -1)
|
||||||
val checkedItemIndex = languages_display_values.indexOf(checkedItem)
|
{
|
||||||
|
checkedItemIndex = 0
|
||||||
val prefs = this.getSharedPreferences("Settings", Context.MODE_PRIVATE).edit()
|
}
|
||||||
|
|
||||||
|
|
||||||
builder.setSingleChoiceItems(languages_display_keys, checkedItemIndex) { dialog, which ->
|
builder.setSingleChoiceItems(languages_display_keys, checkedItemIndex) { dialog, which ->
|
||||||
|
|
||||||
val temp = languages_map[languages_display_keys[which]]
|
val newLocale = LocaleListCompat.forLanguageTags(languages_map[languages_display_keys[which]])
|
||||||
prefs.putString("Language", temp)
|
|
||||||
prefs.apply()
|
AppCompatDelegate.setApplicationLocales(newLocale)
|
||||||
|
|
||||||
startActivity(Intent(this, MainActivity::class.java))
|
startActivity(Intent(this, MainActivity::class.java))
|
||||||
finish()
|
finish()
|
||||||
@@ -514,7 +502,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
window.clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
|
window.clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
|
||||||
}
|
}
|
||||||
|
|
||||||
val prefs = this.getSharedPreferences("Settings", Context.MODE_PRIVATE).edit()
|
val prefs = this.getSharedPreferences("Settings", MODE_PRIVATE).edit()
|
||||||
prefs.putBoolean("Screen_On", keepOn)
|
prefs.putBoolean("Screen_On", keepOn)
|
||||||
prefs.apply()
|
prefs.apply()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,6 +20,8 @@
|
|||||||
|
|
||||||
</com.google.android.material.appbar.AppBarLayout>
|
</com.google.android.material.appbar.AppBarLayout>
|
||||||
|
|
||||||
<include layout="@layout/content_main" />
|
<include
|
||||||
|
android:id="@+id/contentMain"
|
||||||
|
layout="@layout/content_main" />
|
||||||
|
|
||||||
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
||||||
Reference in New Issue
Block a user