2018-10-25 18:52:33 +02:00
/ * *
* ProjectLaogai
*
* Copyright 2018 < seil0 @mosad . xyz >
*
* This program is free software ; you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation ; either version 3 of the License , or
* ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
* along with this program ; if not , write to the Free Software
* Foundation , Inc . , 51 Franklin Street , Fifth Floor , Boston ,
* MA 02110 - 1301 , USA .
*
* /
package org.mosad.seil0.projectlaogai
2018-10-26 00:50:37 +02:00
import android.graphics.Color
2018-10-25 18:52:33 +02:00
import android.os.Bundle
2018-10-26 00:50:37 +02:00
import androidx.fragment.app.Fragment
2018-10-25 18:52:33 +02:00
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
2018-10-26 00:50:37 +02:00
import android.widget.LinearLayout
import com.afollestad.materialdialogs.MaterialDialog
import com.afollestad.materialdialogs.color.colorChooser
2018-10-27 00:39:56 +02:00
import com.afollestad.materialdialogs.list.listItems
2018-10-26 00:50:37 +02:00
import kotlinx.android.synthetic.main.fragment_settings.*
2018-10-25 18:52:33 +02:00
/ * *
* The settings controller class
* contains all needed parts to display and the settings screen
* /
class SettingsFragment : Fragment ( ) {
2018-10-26 00:50:37 +02:00
private lateinit var linLayoutUser : LinearLayout
private lateinit var linLayoutCourse : LinearLayout
private lateinit var linLayoutInfo : LinearLayout
private lateinit var linLayoutMainColor : LinearLayout
private lateinit var viewPrimaryColor : View
2018-10-25 18:52:33 +02:00
override fun onCreateView ( inflater : LayoutInflater , container : ViewGroup ? , savedInstanceState : Bundle ? ) : View ? {
val view : View = inflater . inflate ( R . layout . fragment _settings , container , false )
2018-10-26 00:50:37 +02:00
linLayoutUser = view . findViewById ( R . id . linLayout _User )
linLayoutCourse = view . findViewById ( R . id . linLayout _Course )
linLayoutInfo = view . findViewById ( R . id . linLayout _Info )
linLayoutMainColor = view . findViewById ( R . id . linLayout _MainColor )
viewPrimaryColor = view . findViewById ( R . id . view _PrimaryColor )
initActions ( )
2018-10-25 18:52:33 +02:00
// Inflate the layout for this fragment
return view
}
2018-10-26 00:50:37 +02:00
/ * *
* initialize some actions for SettingsFragment elements
* /
private fun initActions ( ) {
linLayoutUser . setOnClickListener {
// open a new dialog
}
linLayoutCourse . setOnClickListener {
// open a new dialog
2018-10-27 00:39:56 +02:00
val courses = listOf ( " AI1 " , " AI2 " , " AI3 " , " AI4 " , " AI5 " , " AI6 " , " AI7 " )
MaterialDialog ( context !! )
. listItems ( items = courses ) { dialog , index , text ->
// TODO save selected course
// update txtView
txtView _Course . text = text
}
. show ( )
2018-10-26 00:50:37 +02:00
}
linLayoutInfo . setOnClickListener {
// open a new info dialog
MaterialDialog ( context !! )
. title ( R . string . about )
. message ( R . string . about _text )
. show ( )
}
linLayoutMainColor . setOnClickListener {
// open a new color chooser dialog
val colors = intArrayOf ( Color . parseColor ( " #3F51B5 " ) , Color . RED , Color . GREEN , Color . BLUE )
MaterialDialog ( context !! )
. title ( R . string . primary _color )
. colorChooser ( colors , initialSelection = Color . parseColor ( " #3F51B5 " ) ) { dialog , color ->
viewPrimaryColor . setBackgroundColor ( color )
}
. positiveButton ( R . string . select )
. show ( )
}
}
2018-10-25 18:52:33 +02:00
}