|
@@ -1,26 +1,44 @@
|
|
|
package com.tarfeef101.pwm
|
|
|
|
|
|
+import android.annotation.SuppressLint
|
|
|
import androidx.appcompat.app.AppCompatActivity
|
|
|
import android.os.Bundle
|
|
|
import android.widget.RadioButton
|
|
|
import android.widget.RadioGroup
|
|
|
+import android.widget.TextClock
|
|
|
import android.widget.TextView
|
|
|
+import androidx.appcompat.app.AppCompatDelegate
|
|
|
import kotlinx.android.synthetic.main.activity_main.*
|
|
|
|
|
|
class MainActivity : AppCompatActivity()
|
|
|
{
|
|
|
+ @SuppressLint("SetTextI18n")
|
|
|
override fun onCreate(savedInstanceState: Bundle?)
|
|
|
{
|
|
|
super.onCreate(savedInstanceState)
|
|
|
setContentView(R.layout.activity_main)
|
|
|
|
|
|
- // set textview to radio group active option
|
|
|
- fun setThemeStatus()
|
|
|
+ // define objects, set text values for em
|
|
|
+ themeRadioGroup.check(radioButtonDefault.id)
|
|
|
+ radioButtonDefault.setText("System Default")
|
|
|
+ radioButtonDark.setText("Dark")
|
|
|
+ radioButtonLight.setText("Light")
|
|
|
+
|
|
|
+ // set system theme based on active user choice
|
|
|
+ fun setTheme()
|
|
|
{
|
|
|
- var active = findViewById<RadioButton>(themeRadioGroup.checkedRadioButtonId)
|
|
|
+ val active = findViewById<RadioButton>(themeRadioGroup.checkedRadioButtonId)
|
|
|
+ when (active)
|
|
|
+ {
|
|
|
+ radioButtonDefault -> AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM)
|
|
|
+ radioButtonDark -> AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES)
|
|
|
+ radioButtonLight -> AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO)
|
|
|
+ }
|
|
|
themeStatus.setText(active.getText())
|
|
|
}
|
|
|
- setThemeStatus()
|
|
|
- themeRadioGroup.setOnCheckedChangeListener { _, _ -> setThemeStatus() }
|
|
|
+
|
|
|
+ // invoke the above on app startup, and set the listener to run from then on
|
|
|
+ setTheme()
|
|
|
+ themeRadioGroup.setOnCheckedChangeListener { _, _ -> setTheme()}
|
|
|
}
|
|
|
}
|