2019-02-17 15:05:03 +01:00
/ * *
* ProjectLaogai
*
2020-01-15 15:00:05 +01:00
* Copyright 2019 - 2020 < seil0 @mosad . xyz >
2019-02-17 15:05:03 +01:00
*
* 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 .
*
* /
2019-03-17 18:12:36 +01:00
package org.mosad.seil0.projectlaogai.controller
2019-02-17 15:05:03 +01:00
import android.content.Context
import android.graphics.Color
2019-03-17 18:12:36 +01:00
import org.mosad.seil0.projectlaogai.R
2019-02-17 15:05:03 +01:00
import org.mosad.seil0.projectlaogai.hsoparser.Course
/ * *
* The PreferencesController class
* contains all preferences and global variables that exist in this app
* /
class PreferencesController {
companion object {
2019-03-17 18:12:36 +01:00
var coursesCacheTime : Long = 0
var mensaCacheTime : Long = 0
var timetableCacheTime : Long = 0
2019-03-09 22:15:53 +01:00
var cColorPrimary : Int = Color . BLACK
2019-03-17 18:38:31 +01:00
var cColorAccent : Int = Color . parseColor ( " #3F51B5 " )
2019-02-17 15:05:03 +01:00
var cCourse = Course ( " https://www.hs-offenburg.de/index.php?id=6627&class=class&iddV=DA64F6FE-9DDB-429E-A677-05D0D40CB636&week=0 " , " AI3 " )
2019-03-10 13:37:13 +01:00
var cShowBuffet = true
2019-08-18 22:09:33 +02:00
var oGiants = false
2019-02-17 15:05:03 +01:00
// the save function
fun save ( context : Context ) {
2019-10-17 19:19:47 +02:00
val sharedPref = context . getSharedPreferences (
context . getString ( R . string . preference _file _key ) ,
Context . MODE _PRIVATE
)
2019-03-17 18:12:36 +01:00
// save the update times (cache)
with ( sharedPref . edit ( ) ) {
putLong ( context . getString ( R . string . save _key _coursesCacheTime ) ,
coursesCacheTime
)
putLong ( context . getString ( R . string . save _key _mensaCacheTime ) ,
mensaCacheTime
)
putLong ( context . getString ( R . string . save _key _timetableCacheTime ) ,
timetableCacheTime
)
apply ( )
}
2019-12-13 14:54:51 +01:00
}
/ * *
* save the course locally
* /
fun saveCourse ( context : Context , course : Course ) {
val sharedPref = context . getSharedPreferences (
context . getString ( R . string . preference _file _key ) ,
Context . MODE _PRIVATE
)
2019-02-17 15:05:03 +01:00
with ( sharedPref . edit ( ) ) {
2019-12-13 14:54:51 +01:00
putString ( context . getString ( R . string . save _key _course ) , course . courseName )
putString ( context . getString ( R . string . save _key _courseTTLink ) , course . courseLink )
2019-02-17 15:05:03 +01:00
apply ( )
}
2019-12-13 14:54:51 +01:00
cCourse = course
}
/ * *
* save the primary color
* /
fun saveColorPrimary ( context : Context , colorPrimary : Int ) {
val sharedPref = context . getSharedPreferences (
context . getString ( R . string . preference _file _key ) ,
Context . MODE _PRIVATE
)
2019-02-17 15:05:03 +01:00
with ( sharedPref . edit ( ) ) {
2019-03-17 18:12:36 +01:00
putInt ( context . getString ( R . string . save _key _colorPrimary ) ,
2019-12-13 14:54:51 +01:00
colorPrimary
2019-03-17 18:12:36 +01:00
)
2019-03-09 22:15:53 +01:00
apply ( )
}
2019-12-13 14:54:51 +01:00
cColorPrimary = colorPrimary
}
/ * *
* save the accent color
* /
fun saveColorAccent ( context : Context , colorAccent : Int ) {
val sharedPref = context . getSharedPreferences (
context . getString ( R . string . preference _file _key ) ,
Context . MODE _PRIVATE
)
2019-03-09 22:15:53 +01:00
with ( sharedPref . edit ( ) ) {
2019-03-17 18:12:36 +01:00
putInt ( context . getString ( R . string . save _key _colorAccent ) ,
2019-12-13 14:54:51 +01:00
colorAccent
2019-03-17 18:12:36 +01:00
)
2019-02-17 15:05:03 +01:00
apply ( )
}
2019-12-13 14:54:51 +01:00
cColorAccent = colorAccent
}
/ * *
* save showBuffet
* /
fun saveShowBuffet ( context : Context , showBuffet : Boolean ) {
val sharedPref = context . getSharedPreferences (
context . getString ( R . string . preference _file _key ) ,
Context . MODE _PRIVATE
)
2019-03-10 13:37:13 +01:00
with ( sharedPref . edit ( ) ) {
2019-03-17 18:12:36 +01:00
putBoolean ( context . getString ( R . string . save _key _showBuffet ) ,
2019-12-13 14:54:51 +01:00
showBuffet
2019-03-17 18:12:36 +01:00
)
2019-03-10 13:37:13 +01:00
apply ( )
}
2019-12-13 14:54:51 +01:00
cShowBuffet = showBuffet
2019-02-17 15:05:03 +01:00
}
// the load function
fun load ( context : Context ) {
2019-10-17 19:19:47 +02:00
val sharedPref = context . getSharedPreferences (
context . getString ( R . string . preference _file _key ) ,
Context . MODE _PRIVATE
)
2019-03-17 18:12:36 +01:00
// load the update times (cache)
coursesCacheTime = sharedPref . getLong ( context . getString (
R . string . save _key _coursesCacheTime
) , 0 )
mensaCacheTime = sharedPref . getLong ( context . getString (
R . string . save _key _mensaCacheTime
) , 0 )
timetableCacheTime = sharedPref . getLong ( context . getString (
R . string . save _key _timetableCacheTime
) , 0 )
// load saved course
2019-02-17 15:05:03 +01:00
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 " ) !!
)
2019-03-09 22:15:53 +01:00
// load saved colors
2019-03-17 18:12:36 +01:00
cColorPrimary = sharedPref . getInt ( context . getString (
R . string . save _key _colorPrimary
) , Color . BLACK )
cColorAccent = sharedPref . getInt ( context . getString (
R . string . save _key _colorAccent
2019-03-17 18:38:31 +01:00
) , Color . parseColor ( " #3F51B5 " ) )
2019-03-10 13:37:13 +01:00
// load showBuffet
2019-03-17 18:12:36 +01:00
cShowBuffet = sharedPref . getBoolean ( context . getString (
R . string . save _key _showBuffet
) , true )
2019-02-17 15:05:03 +01:00
}
}
}