@ -51,6 +51,7 @@ import org.mosad.seil0.projectlaogai.controller.TCoRAPIController
import org.mosad.seil0.projectlaogai.hsoparser.DataTypes
import java.util.*
import android.util.TypedValue
import com.afollestad.materialdialogs.list.listItemsSingleChoice
/ * *
* The settings controller class
@ -61,6 +62,7 @@ class SettingsFragment : Fragment() {
private lateinit var linLayoutUser : LinearLayout
private lateinit var linLayoutCourse : LinearLayout
private lateinit var linLayoutAbout : LinearLayout
private lateinit var linLayoutTheme : LinearLayout
private lateinit var linLayoutPrimaryColor : LinearLayout
private lateinit var linLayoutAccentColor : LinearLayout
private lateinit var switchBuffet : Switch
@ -72,6 +74,7 @@ class SettingsFragment : Fragment() {
linLayoutUser = view . findViewById ( R . id . linLayout _User )
linLayoutCourse = view . findViewById ( R . id . linLayout _Course )
linLayoutAbout = view . findViewById ( R . id . linLayout _About )
linLayoutTheme = view . findViewById ( R . id . linLayout _Theme )
linLayoutPrimaryColor = view . findViewById ( R . id . linLayout _PrimaryColor )
linLayoutAccentColor = view . findViewById ( R . id . linLayout _AccentColor )
switchBuffet = view . findViewById ( R . id . switch _buffet )
@ -85,17 +88,28 @@ class SettingsFragment : Fragment() {
override fun onViewCreated ( view : View , savedInstanceState : Bundle ? ) {
super . onViewCreated ( view , savedInstanceState )
// initialize the settings gui
txtView _Course . text = cCourse . courseName
txtView _AboutDesc . text = resources . getString ( R . string . about _version , BuildConfig . VERSION _NAME , getString ( R . string . build _time ) )
switch _buffet . isChecked = cShowBuffet // init switch
val outValue = TypedValue ( )
activity !! . theme . resolveAttribute ( R . attr . themeName , outValue , true )
if ( outValue . string == " dark " ) {
switch _buffet . setTextColor ( activity !! . resources . getColor ( R . color . textPrimaryDark , activity !! . theme ) )
} else {
switch _buffet . setTextColor ( activity !! . resources . getColor ( R . color . textPrimaryLight , activity !! . theme ) )
when ( outValue . string ) {
" light " -> {
switch _buffet . setTextColor ( activity !! . resources . getColor ( R . color . textPrimaryLight , activity !! . theme ) )
txtView _SelectedTheme . text = resources . getString ( R . string . themeLight )
}
" dark " -> {
switch _buffet . setTextColor ( activity !! . resources . getColor ( R . color . textPrimaryDark , activity !! . theme ) )
txtView _SelectedTheme . text = resources . getString ( R . string . themeDark )
}
" black " -> {
switch _buffet . setTextColor ( activity !! . resources . getColor ( R . color . textPrimaryDark , activity !! . theme ) )
txtView _SelectedTheme . text = resources . getString ( R . string . themeBlack )
}
}
}
/ * *
@ -104,19 +118,6 @@ class SettingsFragment : Fragment() {
private fun initActions ( ) {
linLayoutUser . setOnClickListener {
// open a new dialog
// TODO move and save
// val outValue = TypedValue()
// activity!!.theme.resolveAttribute(R.attr.themeName, outValue, true)
// if (outValue.string == "dark") {
// Aesthetic.config {
// activityTheme(R.style.AppTheme_Light)
// }
// } else {
// Aesthetic.config {
// activityTheme(R.style.AppTheme_Dark)
// }
// }
}
linLayoutCourse . setOnClickListener {
@ -132,6 +133,26 @@ class SettingsFragment : Fragment() {
. show ( )
}
linLayoutTheme . setOnClickListener {
val themes = listOf (
resources . getString ( R . string . themeLight ) ,
resources . getString ( R . string . themeDark ) ,
resources . getString ( R . string . themeBlack )
)
MaterialDialog ( context !! ) . show {
listItemsSingleChoice ( items = themes ) { _ , index , _ ->
Aesthetic . config {
when ( index ) {
0 -> activityTheme ( R . style . AppTheme _Light )
1 -> activityTheme ( R . style . AppTheme _Dark )
2 -> activityTheme ( R . style . AppTheme _Black )
else -> activityTheme ( R . style . AppTheme _Light )
}
}
}
}
}
linLayoutPrimaryColor . setOnClickListener {
// open a new color chooser dialog
MaterialDialog ( context !! )