Merge branch 'master' into preference-refactoring

This commit is contained in:
y20k 2021-07-05 11:12:49 +02:00 committed by GitHub
commit 5639a42a30
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 14 additions and 4 deletions

View file

@ -51,7 +51,7 @@ class MainActivity : AppCompatActivity() {
super.onCreate(savedInstanceState)
// todo: remove after testing finished
if (BuildConfig.DEBUG && Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
if (BuildConfig.DEBUG && Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
StrictMode.setVmPolicy(
VmPolicy.Builder()
.detectNonSdkApiUsage()

View file

@ -39,6 +39,7 @@ class Trackbook: Application() {
override fun onCreate() {
super.onCreate()
LogHelper.v(TAG, "Trackbook application started.")
// initialize single sharedPreferences object when app is launched
initPreferences()
// set Dark / Light theme state
AppThemeHelper.setTheme(PreferencesHelper.loadThemeSelection())

View file

@ -98,9 +98,7 @@ class TrackerService: Service(), SensorEventListener {
currentBestLocation = LocationHelper.getLastKnownLocation(this)
track = FileHelper.readTrack(this, FileHelper.getTempFileUri(this))
altitudeValues.capacity = PreferencesHelper.loadAltitudeSmoothingValue()
PreferencesHelper.registerPreferenceChangeListener(
sharedPreferenceChangeListener
)
PreferencesHelper.registerPreferenceChangeListener(sharedPreferenceChangeListener)
}

View file

@ -44,7 +44,16 @@ object PreferencesHelper {
/* Define log tag */
private val TAG: String = LogHelper.makeLogTag(PreferencesHelper::class.java)
/* The sharedPreferences object to be initialized */
private lateinit var sharedPreferences: SharedPreferences
/* Initialize a single sharedPreferences object when the app is launched */
fun Context.initPreferences() {
sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this)
}
/* Loads zoom level of map */
fun loadZoomLevel(): Double {
// load zoom level
@ -129,6 +138,7 @@ object PreferencesHelper {
altitude = sharedPreferences.getDouble(Keys.PREF_CURRENT_BEST_LOCATION_ALTITUDE, Keys.DEFAULT_ALTITUDE)
time = sharedPreferences.getLong(Keys.PREF_CURRENT_BEST_LOCATION_TIME, Keys.DEFAULT_TIME)
}
}
@ -160,6 +170,7 @@ object PreferencesHelper {
/* Saves state of housekeeping */
fun saveHouseKeepingNecessaryState(state: Boolean = false) {
sharedPreferences.edit { putBoolean(Keys.PREF_ONE_TIME_HOUSEKEEPING_NECESSARY, state) }
}
/* Start watching for changes in shared preferences - context must implement OnSharedPreferenceChangeListener */