Browse Source

reworked preference saving

tags/0.5.1
Jannik Seiler 2 months ago
parent
commit
8f5a4dd1b3
Signed by: Seil0 <seil0@mosad.xyz> GPG Key ID: E8459F3723C52C24
3 changed files with 59 additions and 19 deletions
  1. +53
    -9
      app/src/main/java/org/mosad/seil0/projectlaogai/controller/PreferencesController.kt
  2. +5
    -9
      app/src/main/java/org/mosad/seil0/projectlaogai/fragments/SettingsFragment.kt
  3. +1
    -1
      build.gradle

+ 53
- 9
app/src/main/java/org/mosad/seil0/projectlaogai/controller/PreferencesController.kt View File

@@ -64,37 +64,81 @@ class PreferencesController {
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()) {
putString(context.getString(R.string.save_key_course), cCourse.courseName)
putString(context.getString(R.string.save_key_courseTTLink), cCourse.courseLink)
putString(context.getString(R.string.save_key_course), course.courseName)
putString(context.getString(R.string.save_key_courseTTLink), course.courseLink)
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()) {
putInt(context.getString(R.string.save_key_colorPrimary),
cColorPrimary
colorPrimary
)
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()) {
putInt(context.getString(R.string.save_key_colorAccent),
cColorAccent
colorAccent
)
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()) {
putBoolean(context.getString(R.string.save_key_showBuffet),
cShowBuffet
showBuffet
)
apply()
}

cShowBuffet = showBuffet
}

// the load function


+ 5
- 9
app/src/main/java/org/mosad/seil0/projectlaogai/fragments/SettingsFragment.kt View File

@@ -182,6 +182,7 @@ class SettingsFragment : Fragment() {
2 -> activityTheme(R.style.AppTheme_Black)
else -> activityTheme(R.style.AppTheme_Light)
}
apply()
}
}
}
@@ -199,8 +200,7 @@ class SettingsFragment : Fragment() {
apply()
}

cColorPrimary = color
PreferencesController.save(context!!)
PreferencesController.saveColorPrimary(context!!, color)
}
.positiveButton(R.string.select)
.show()
@@ -217,17 +217,14 @@ class SettingsFragment : Fragment() {
apply()
}

cColorAccent = color
PreferencesController.save(context!!)
PreferencesController.saveColorAccent(context!!, color)
}
.positiveButton(R.string.select)
.show()
}

switchBuffet.setOnClickListener {
cShowBuffet = switchBuffet.isChecked
PreferencesController.save(context!!)
println(switchBuffet.isChecked)
PreferencesController.saveShowBuffet(context!!, switchBuffet.isChecked)
}

}
@@ -249,8 +246,7 @@ class SettingsFragment : Fragment() {
dialog.show()

doAsync {
cCourse = coursesList[index] // set the course
PreferencesController.save(context)
PreferencesController.saveCourse(context, coursesList[index]) // save the course

// update current & next weeks timetable
TCoRAPIController.getTimetable(cCourse.courseName, 0, context).get() // blocking since we want the new data


+ 1
- 1
build.gradle View File

@@ -7,7 +7,7 @@ buildscript {
jcenter()
}
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"

// NOTE: Do not place your application dependencies here; they belong


Loading…
Cancel
Save