ProjectLaogai/app/src/main/java/org/mosad/seil0/projectlaogai/SettingsFragment.kt

110 lines
3.7 KiB
Kotlin

/**
* 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
import android.graphics.Color
import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.LinearLayout
import com.afollestad.materialdialogs.MaterialDialog
import com.afollestad.materialdialogs.color.colorChooser
import com.afollestad.materialdialogs.list.listItems
import kotlinx.android.synthetic.main.fragment_settings.*
/**
* The settings controller class
* contains all needed parts to display and the settings screen
*/
class SettingsFragment : Fragment() {
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
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
val view: View = inflater.inflate(R.layout.fragment_settings, container, false)
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()
// Inflate the layout for this fragment
return view
}
/**
* initialize some actions for SettingsFragment elements
*/
private fun initActions() {
linLayoutUser.setOnClickListener {
// open a new dialog
}
linLayoutCourse.setOnClickListener {
// open a new dialog
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()
}
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()
}
}
}