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

88 lines
3.3 KiB
Kotlin

/**
* ProjectLaogai
*
* Copyright 2019 <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.content.Context
import android.graphics.Color
import org.jetbrains.anko.defaultSharedPreferences
import org.mosad.seil0.projectlaogai.hsoparser.Course
import org.mosad.seil0.projectlaogai.hsoparser.Meal
import org.mosad.seil0.projectlaogai.hsoparser.TimeTable
/**
* The PreferencesController class
* contains all preferences and global variables that exist in this app
*/
class PreferencesController {
companion object {
var cCourseTTLinkList = ArrayList<Course>()
var cMenusCurrentWeek = ArrayList<Meal>()
var cMenusNextWeek = ArrayList<Meal>()
var cTimeTableCurrentWeek = TimeTable()
var cTimeTableNextWeek = TimeTable()
var cColorPrimary: Int = Color.BLACK
var cColorAccent: Int = Color.BLACK
var cCourse = Course("https://www.hs-offenburg.de/index.php?id=6627&class=class&iddV=DA64F6FE-9DDB-429E-A677-05D0D40CB636&week=0", "AI3")
// the save function
fun save(context: Context) {
//println(cCourse.courseLink)
// save the course
val sharedPref = context.defaultSharedPreferences
with (sharedPref.edit()) {
putString(context.getString(R.string.save_key_course), cCourse.courseName)
putString(context.getString(R.string.save_key_courseTTLink), cCourse.courseLink)
apply()
}
// save the primary color
with (sharedPref.edit()) {
putInt(context.getString(R.string.save_key_colorPrimary), cColorPrimary)
apply()
}
// save the accent color
with (sharedPref.edit()) {
putInt(context.getString(R.string.save_key_colorAccent), cColorAccent)
apply()
}
}
// the load function
fun load(context: Context) {
// load saved course
val sharedPref = context.defaultSharedPreferences
cCourse = Course(
sharedPref.getString(context.getString(R.string.save_key_courseTTLink), "https://www.hs-offenburg.de/index.php?id=6627&class=class&iddV=DA64F6FE-9DDB-429E-A677-05D0D40CB636&week=0")!!,
sharedPref.getString(context.getString(R.string.save_key_course), "AI3")!!
)
// load saved colors
cColorPrimary = sharedPref.getInt(context.getString(R.string.save_key_colorPrimary), Color.BLACK)
cColorAccent = sharedPref.getInt(context.getString(R.string.save_key_colorAccent), Color.parseColor("#FF1744"))
}
}
}