Use correct binding. Remove unneeded code.
This commit is contained in:
@@ -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.os.Bundle
|
||||
import android.text.InputType
|
||||
import android.view.Menu
|
||||
import android.view.MenuItem
|
||||
import android.view.WindowManager
|
||||
import android.view.*
|
||||
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 me.zobrist.tichucounter.databinding.ContentMainBinding
|
||||
import me.zobrist.tichucounter.databinding.ActivityMainBinding
|
||||
import java.util.*
|
||||
|
||||
class MainActivity : AppCompatActivity() {
|
||||
@@ -26,43 +25,32 @@ class MainActivity : AppCompatActivity() {
|
||||
private var currentRound = Round()
|
||||
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?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
binding = ContentMainBinding.inflate(layoutInflater)
|
||||
binding = ActivityMainBinding.inflate(layoutInflater)
|
||||
setContentView(binding.root)
|
||||
|
||||
setContentView(R.layout.activity_main)
|
||||
setSupportActionBar(findViewById(R.id.toolbar))
|
||||
setSupportActionBar(binding.toolbar)
|
||||
|
||||
binding.inputTeamA.setRawInputType(InputType.TYPE_NULL)
|
||||
binding.inputTeamB.setRawInputType(InputType.TYPE_NULL)
|
||||
binding.inputTeamA.requestFocus()
|
||||
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)
|
||||
binding.nameTeamA.setText(this.getSharedPreferences("Settings", Context.MODE_PRIVATE).getString("nameTeamA", "TeamA"))
|
||||
binding.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()
|
||||
@@ -72,21 +60,21 @@ class MainActivity : AppCompatActivity() {
|
||||
|
||||
private fun setListenes()
|
||||
{
|
||||
binding.inputTeamA.setOnFocusChangeListener { _, b ->
|
||||
binding.contentMain.inputTeamA.setOnFocusChangeListener { _, b ->
|
||||
if (b) {
|
||||
hideKeyboard()
|
||||
}
|
||||
}
|
||||
|
||||
binding.inputTeamB.setOnFocusChangeListener { _, b ->
|
||||
binding.contentMain.inputTeamB.setOnFocusChangeListener { _, b ->
|
||||
if (b) {
|
||||
hideKeyboard()
|
||||
}
|
||||
}
|
||||
|
||||
binding.inputTeamA.doOnTextChanged { text, _, _, _ ->
|
||||
if (binding.inputTeamA.isFocused) {
|
||||
if (binding.inputTeamA.text.isNotEmpty()) {
|
||||
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)
|
||||
@@ -94,26 +82,26 @@ class MainActivity : AppCompatActivity() {
|
||||
} catch (e: java.lang.Exception) {
|
||||
Round(1, 1)
|
||||
}
|
||||
binding.inputTeamB.setText(currentRound.scoreB.toString())
|
||||
binding.contentMain.inputTeamB.setText(currentRound.scoreB.toString())
|
||||
} else {
|
||||
updateOnChange = true
|
||||
}
|
||||
} else {
|
||||
binding.inputTeamA.text.clear()
|
||||
binding.inputTeamB.text.clear()
|
||||
binding.contentMain.inputTeamA.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()
|
||||
} else {
|
||||
disableSubmitButton()
|
||||
}
|
||||
}
|
||||
|
||||
binding.inputTeamB.doOnTextChanged { text, _, _, _ ->
|
||||
if (binding.inputTeamB.isFocused) {
|
||||
if (binding.inputTeamB.text.isNotEmpty()) {
|
||||
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)
|
||||
@@ -121,145 +109,145 @@ class MainActivity : AppCompatActivity() {
|
||||
} catch (e: java.lang.Exception) {
|
||||
Round(1, 1)
|
||||
}
|
||||
binding.inputTeamA.setText(currentRound.scoreA.toString())
|
||||
binding.contentMain.inputTeamA.setText(currentRound.scoreA.toString())
|
||||
|
||||
} else {
|
||||
updateOnChange = true
|
||||
}
|
||||
|
||||
} else {
|
||||
binding.inputTeamA.text.clear()
|
||||
binding.inputTeamB.text.clear()
|
||||
binding.contentMain.inputTeamA.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()
|
||||
} else {
|
||||
disableSubmitButton()
|
||||
}
|
||||
}
|
||||
|
||||
binding.buttonAdd100.setOnClickListener {
|
||||
binding.contentMain.buttonAdd100.setOnClickListener {
|
||||
giveFocusToAIfNone()
|
||||
|
||||
if (binding.inputTeamA.isFocused) {
|
||||
if (binding.contentMain.inputTeamA.isFocused) {
|
||||
|
||||
currentRound.scoreA = try {
|
||||
binding.inputTeamA.text.toString().toInt() + 100
|
||||
binding.contentMain.inputTeamA.text.toString().toInt() + 100
|
||||
} catch (e: Exception) {
|
||||
currentRound.scoreB = 0
|
||||
binding.inputTeamB.setText(currentRound.scoreB.toString())
|
||||
binding.contentMain.inputTeamB.setText(currentRound.scoreB.toString())
|
||||
100
|
||||
}
|
||||
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 {
|
||||
binding.inputTeamB.text.toString().toInt() + 100
|
||||
binding.contentMain.inputTeamB.text.toString().toInt() + 100
|
||||
} catch (e: Exception) {
|
||||
currentRound.scoreA = 0
|
||||
binding.inputTeamA.setText(currentRound.scoreA.toString())
|
||||
binding.contentMain.inputTeamA.setText(currentRound.scoreA.toString())
|
||||
100
|
||||
|
||||
}
|
||||
updateOnChange = false
|
||||
binding.inputTeamB.setText(currentRound.scoreB.toString())
|
||||
binding.contentMain.inputTeamB.setText(currentRound.scoreB.toString())
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
binding.buttonSub100.setOnClickListener {
|
||||
binding.contentMain.buttonSub100.setOnClickListener {
|
||||
giveFocusToAIfNone()
|
||||
|
||||
if (binding.inputTeamA.isFocused) {
|
||||
if (binding.contentMain.inputTeamA.isFocused) {
|
||||
currentRound.scoreA = try {
|
||||
binding.inputTeamA.text.toString().toInt() - 100
|
||||
binding.contentMain.inputTeamA.text.toString().toInt() - 100
|
||||
} catch (e: Exception) {
|
||||
currentRound.scoreB = 0
|
||||
binding.inputTeamB.setText(currentRound.scoreB.toString())
|
||||
binding.contentMain.inputTeamB.setText(currentRound.scoreB.toString())
|
||||
-100
|
||||
}
|
||||
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 {
|
||||
binding.inputTeamB.text.toString().toInt() - 100
|
||||
binding.contentMain.inputTeamB.text.toString().toInt() - 100
|
||||
} catch (e: Exception) {
|
||||
currentRound.scoreA = 0
|
||||
binding.inputTeamA.setText(currentRound.scoreA.toString())
|
||||
binding.contentMain.inputTeamA.setText(currentRound.scoreA.toString())
|
||||
-100
|
||||
}
|
||||
updateOnChange = false
|
||||
binding.inputTeamB.setText(currentRound.scoreB.toString())
|
||||
binding.contentMain.inputTeamB.setText(currentRound.scoreB.toString())
|
||||
}
|
||||
}
|
||||
|
||||
binding.button0.setOnClickListener {
|
||||
binding.contentMain.button0.setOnClickListener {
|
||||
giveFocusToAIfNone()
|
||||
appendToFocusedInput('0')
|
||||
}
|
||||
|
||||
binding.button1.setOnClickListener {
|
||||
binding.contentMain.button1.setOnClickListener {
|
||||
giveFocusToAIfNone()
|
||||
appendToFocusedInput('1')
|
||||
}
|
||||
|
||||
binding.button2.setOnClickListener {
|
||||
binding.contentMain.button2.setOnClickListener {
|
||||
giveFocusToAIfNone()
|
||||
appendToFocusedInput('2')
|
||||
}
|
||||
|
||||
binding.button3.setOnClickListener {
|
||||
binding.contentMain.button3.setOnClickListener {
|
||||
giveFocusToAIfNone()
|
||||
appendToFocusedInput('3')
|
||||
}
|
||||
|
||||
binding.button4.setOnClickListener {
|
||||
binding.contentMain.button4.setOnClickListener {
|
||||
giveFocusToAIfNone()
|
||||
appendToFocusedInput('4')
|
||||
}
|
||||
|
||||
binding.button5.setOnClickListener {
|
||||
binding.contentMain.button5.setOnClickListener {
|
||||
giveFocusToAIfNone()
|
||||
appendToFocusedInput('5')
|
||||
}
|
||||
|
||||
binding.button6.setOnClickListener {
|
||||
binding.contentMain.button6.setOnClickListener {
|
||||
giveFocusToAIfNone()
|
||||
appendToFocusedInput('6')
|
||||
}
|
||||
|
||||
binding.button7.setOnClickListener {
|
||||
binding.contentMain.button7.setOnClickListener {
|
||||
giveFocusToAIfNone()
|
||||
appendToFocusedInput('7')
|
||||
}
|
||||
|
||||
binding.button8.setOnClickListener {
|
||||
binding.contentMain.button8.setOnClickListener {
|
||||
giveFocusToAIfNone()
|
||||
appendToFocusedInput('8')
|
||||
}
|
||||
|
||||
binding.button9.setOnClickListener {
|
||||
binding.contentMain.button9.setOnClickListener {
|
||||
giveFocusToAIfNone()
|
||||
appendToFocusedInput('9')
|
||||
}
|
||||
|
||||
binding.buttonInv.setOnClickListener {
|
||||
binding.contentMain.buttonInv.setOnClickListener {
|
||||
val tempInt: Int
|
||||
|
||||
giveFocusToAIfNone()
|
||||
|
||||
if (binding.inputTeamA.isFocused) {
|
||||
if (binding.inputTeamA.text.toString().equals("-")) {
|
||||
binding.inputTeamA.text.clear()
|
||||
} else if (binding.inputTeamA.text.isNotEmpty()) {
|
||||
tempInt = binding.inputTeamA.text.toString().toInt() * -1
|
||||
binding.inputTeamA.setText(tempInt.toString())
|
||||
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('-')
|
||||
@@ -267,12 +255,12 @@ class MainActivity : AppCompatActivity() {
|
||||
}
|
||||
|
||||
|
||||
} else if (binding.inputTeamB.isFocused) {
|
||||
if (binding.inputTeamB.text.toString().equals("-")) {
|
||||
binding.inputTeamB.text.clear()
|
||||
} else if (binding.inputTeamB.text.isNotEmpty()) {
|
||||
tempInt = binding.inputTeamB.text.toString().toInt() * -1
|
||||
binding.inputTeamB.setText(tempInt.toString())
|
||||
} 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('-')
|
||||
@@ -281,42 +269,42 @@ class MainActivity : AppCompatActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
binding.buttonBack.setOnClickListener {
|
||||
binding.contentMain.buttonBack.setOnClickListener {
|
||||
giveFocusToAIfNone()
|
||||
|
||||
if (binding.inputTeamA.isFocused) {
|
||||
if (binding.inputTeamA.text.isNotEmpty()) {
|
||||
val string = binding.inputTeamA.text.toString()
|
||||
binding.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 (binding.inputTeamB.isFocused) {
|
||||
if (binding.inputTeamB.text.isNotEmpty()) {
|
||||
val string = binding.inputTeamB.text.toString()
|
||||
binding.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))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
binding.submit.setOnClickListener {
|
||||
binding.contentMain.submit.setOnClickListener {
|
||||
giveFocusToAIfNone()
|
||||
|
||||
if (binding.inputTeamA.text.isNotEmpty() && binding.inputTeamB.text.isNotEmpty()) {
|
||||
if (binding.contentMain.inputTeamA.text.isNotEmpty() && binding.contentMain.inputTeamB.text.isNotEmpty()) {
|
||||
|
||||
history.logRound(
|
||||
Round(
|
||||
binding.inputTeamA.text.toString().toInt(),
|
||||
binding.inputTeamB.text.toString().toInt()
|
||||
binding.contentMain.inputTeamA.text.toString().toInt(),
|
||||
binding.contentMain.inputTeamB.text.toString().toInt()
|
||||
)
|
||||
)
|
||||
|
||||
updateView()
|
||||
|
||||
binding.inputTeamA.text.clear()
|
||||
binding.inputTeamB.text.clear()
|
||||
binding.contentMain.inputTeamA.text.clear()
|
||||
binding.contentMain.inputTeamB.text.clear()
|
||||
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) {
|
||||
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", binding.nameTeamA.text.toString())
|
||||
prefs.putString("nameTeamB", binding.nameTeamB.text.toString())
|
||||
prefs.putString("nameTeamA", binding.contentMain.nameTeamA.text.toString())
|
||||
prefs.putString("nameTeamB", binding.contentMain.nameTeamB.text.toString())
|
||||
prefs.apply()
|
||||
|
||||
}
|
||||
@@ -337,7 +325,7 @@ class MainActivity : AppCompatActivity() {
|
||||
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
|
||||
}
|
||||
@@ -389,8 +377,8 @@ class MainActivity : AppCompatActivity() {
|
||||
}
|
||||
|
||||
private fun giveFocusToAIfNone() {
|
||||
if (!binding.inputTeamA.isFocused && !binding.inputTeamB.isFocused) {
|
||||
binding.inputTeamA.requestFocus()
|
||||
if (!binding.contentMain.inputTeamA.isFocused && !binding.contentMain.inputTeamB.isFocused) {
|
||||
binding.contentMain.inputTeamA.requestFocus()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -400,40 +388,40 @@ class MainActivity : AppCompatActivity() {
|
||||
}
|
||||
|
||||
private fun updateView() {
|
||||
binding.scoreA.text = history.getScoreA().toString()
|
||||
binding.scoreB.text = history.getScoreB().toString()
|
||||
binding.contentMain.scoreA.text = history.getScoreA().toString()
|
||||
binding.contentMain.scoreB.text = history.getScoreB().toString()
|
||||
|
||||
binding.historyA.text = history.getHistoryA()
|
||||
binding.historyB.text = history.getHistoryB()
|
||||
binding.contentMain.historyA.text = history.getHistoryA()
|
||||
binding.contentMain.historyB.text = history.getHistoryB()
|
||||
}
|
||||
|
||||
private fun clearAll() {
|
||||
binding.historyA.text = ""
|
||||
binding.historyB.text = ""
|
||||
binding.inputTeamA.text.clear()
|
||||
binding.inputTeamB.text.clear()
|
||||
binding.scoreA.text = "0"
|
||||
binding.scoreB.text = "0"
|
||||
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 (binding.inputTeamA.isFocused) {
|
||||
binding.inputTeamA.text.append(toAppend)
|
||||
} else if (binding.inputTeamB.isFocused) {
|
||||
binding.inputTeamB.text.append(toAppend)
|
||||
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() {
|
||||
binding.submit.imageAlpha = 255 // 0 being transparent and 255 being opaque
|
||||
binding.submit.isEnabled = true
|
||||
binding.contentMain.submit.imageAlpha = 255 // 0 being transparent and 255 being opaque
|
||||
binding.contentMain.submit.isEnabled = true
|
||||
}
|
||||
|
||||
private fun disableSubmitButton() {
|
||||
binding.submit.imageAlpha = 60 // 0 being transparent and 255 being opaque
|
||||
binding.submit.isEnabled = false
|
||||
binding.contentMain.submit.imageAlpha = 60 // 0 being transparent and 255 being opaque
|
||||
binding.contentMain.submit.isEnabled = false
|
||||
}
|
||||
|
||||
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 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 ->
|
||||
@@ -468,25 +456,25 @@ class MainActivity : AppCompatActivity() {
|
||||
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 = 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())
|
||||
val checkedItemIndex = languages_display_values.indexOf(checkedItem)
|
||||
|
||||
val prefs = this.getSharedPreferences("Settings", Context.MODE_PRIVATE).edit()
|
||||
|
||||
if(checkedItemIndex == -1)
|
||||
{
|
||||
checkedItemIndex = 0
|
||||
}
|
||||
|
||||
builder.setSingleChoiceItems(languages_display_keys, checkedItemIndex) { dialog, which ->
|
||||
|
||||
val temp = languages_map[languages_display_keys[which]]
|
||||
prefs.putString("Language", temp)
|
||||
prefs.apply()
|
||||
val newLocale = LocaleListCompat.forLanguageTags(languages_map[languages_display_keys[which]])
|
||||
|
||||
AppCompatDelegate.setApplicationLocales(newLocale)
|
||||
|
||||
startActivity(Intent(this, MainActivity::class.java))
|
||||
finish()
|
||||
@@ -514,7 +502,7 @@ class MainActivity : AppCompatActivity() {
|
||||
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()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user