reworked preference saving

This commit is contained in:
Jannik 2019-12-13 14:54:51 +01:00
parent 9907d083e9
commit 8f5a4dd1b3
Signed by: Seil0
GPG Key ID: E8459F3723C52C24
3 changed files with 59 additions and 19 deletions

View File

@ -64,37 +64,81 @@ class PreferencesController {
apply() apply()
} }
// save the course }
/**
* save the course locally
*/
fun saveCourse(context: Context, course: Course) {
val sharedPref = context.getSharedPreferences(
context.getString(R.string.preference_file_key),
Context.MODE_PRIVATE
)
with (sharedPref.edit()) { with (sharedPref.edit()) {
putString(context.getString(R.string.save_key_course), cCourse.courseName) putString(context.getString(R.string.save_key_course), course.courseName)
putString(context.getString(R.string.save_key_courseTTLink), cCourse.courseLink) putString(context.getString(R.string.save_key_courseTTLink), course.courseLink)
apply() apply()
} }
// save the primary color 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
)
with (sharedPref.edit()) { with (sharedPref.edit()) {
putInt(context.getString(R.string.save_key_colorPrimary), putInt(context.getString(R.string.save_key_colorPrimary),
cColorPrimary colorPrimary
) )
apply() apply()
} }
// save the accent color 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
)
with (sharedPref.edit()) { with (sharedPref.edit()) {
putInt(context.getString(R.string.save_key_colorAccent), putInt(context.getString(R.string.save_key_colorAccent),
cColorAccent colorAccent
) )
apply() apply()
} }
// save showBuffet cColorAccent = colorAccent
}
/**
* save showBuffet
*/
fun saveShowBuffet(context: Context, showBuffet: Boolean) {
val sharedPref = context.getSharedPreferences(
context.getString(R.string.preference_file_key),
Context.MODE_PRIVATE
)
with (sharedPref.edit()) { with (sharedPref.edit()) {
putBoolean(context.getString(R.string.save_key_showBuffet), putBoolean(context.getString(R.string.save_key_showBuffet),
cShowBuffet showBuffet
) )
apply() apply()
} }
cShowBuffet = showBuffet
} }
// the load function // the load function

View File

@ -182,6 +182,7 @@ class SettingsFragment : Fragment() {
2 -> activityTheme(R.style.AppTheme_Black) 2 -> activityTheme(R.style.AppTheme_Black)
else -> activityTheme(R.style.AppTheme_Light) else -> activityTheme(R.style.AppTheme_Light)
} }
apply()
} }
} }
} }
@ -199,8 +200,7 @@ class SettingsFragment : Fragment() {
apply() apply()
} }
cColorPrimary = color PreferencesController.saveColorPrimary(context!!, color)
PreferencesController.save(context!!)
} }
.positiveButton(R.string.select) .positiveButton(R.string.select)
.show() .show()
@ -217,17 +217,14 @@ class SettingsFragment : Fragment() {
apply() apply()
} }
cColorAccent = color PreferencesController.saveColorAccent(context!!, color)
PreferencesController.save(context!!)
} }
.positiveButton(R.string.select) .positiveButton(R.string.select)
.show() .show()
} }
switchBuffet.setOnClickListener { switchBuffet.setOnClickListener {
cShowBuffet = switchBuffet.isChecked PreferencesController.saveShowBuffet(context!!, switchBuffet.isChecked)
PreferencesController.save(context!!)
println(switchBuffet.isChecked)
} }
} }
@ -249,8 +246,7 @@ class SettingsFragment : Fragment() {
dialog.show() dialog.show()
doAsync { doAsync {
cCourse = coursesList[index] // set the course PreferencesController.saveCourse(context, coursesList[index]) // save the course
PreferencesController.save(context)
// update current & next weeks timetable // update current & next weeks timetable
TCoRAPIController.getTimetable(cCourse.courseName, 0, context).get() // blocking since we want the new data TCoRAPIController.getTimetable(cCourse.courseName, 0, context).get() // blocking since we want the new data

View File

@ -7,7 +7,7 @@ buildscript {
jcenter() jcenter()
} }
dependencies { dependencies {
classpath 'com.android.tools.build:gradle:3.5.2' classpath 'com.android.tools.build:gradle:3.5.3'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong // NOTE: Do not place your application dependencies here; they belong