Merge branch 'master' into preference-refactoring
This commit is contained in:
commit
5639a42a30
4 changed files with 14 additions and 4 deletions
|
@ -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()
|
||||
|
|
|
@ -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())
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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 */
|
||||
|
|
Loading…
Reference in a new issue