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)
|
super.onCreate(savedInstanceState)
|
||||||
|
|
||||||
// todo: remove after testing finished
|
// 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(
|
StrictMode.setVmPolicy(
|
||||||
VmPolicy.Builder()
|
VmPolicy.Builder()
|
||||||
.detectNonSdkApiUsage()
|
.detectNonSdkApiUsage()
|
||||||
|
|
|
@ -39,6 +39,7 @@ class Trackbook: Application() {
|
||||||
override fun onCreate() {
|
override fun onCreate() {
|
||||||
super.onCreate()
|
super.onCreate()
|
||||||
LogHelper.v(TAG, "Trackbook application started.")
|
LogHelper.v(TAG, "Trackbook application started.")
|
||||||
|
// initialize single sharedPreferences object when app is launched
|
||||||
initPreferences()
|
initPreferences()
|
||||||
// set Dark / Light theme state
|
// set Dark / Light theme state
|
||||||
AppThemeHelper.setTheme(PreferencesHelper.loadThemeSelection())
|
AppThemeHelper.setTheme(PreferencesHelper.loadThemeSelection())
|
||||||
|
|
|
@ -98,9 +98,7 @@ class TrackerService: Service(), SensorEventListener {
|
||||||
currentBestLocation = LocationHelper.getLastKnownLocation(this)
|
currentBestLocation = LocationHelper.getLastKnownLocation(this)
|
||||||
track = FileHelper.readTrack(this, FileHelper.getTempFileUri(this))
|
track = FileHelper.readTrack(this, FileHelper.getTempFileUri(this))
|
||||||
altitudeValues.capacity = PreferencesHelper.loadAltitudeSmoothingValue()
|
altitudeValues.capacity = PreferencesHelper.loadAltitudeSmoothingValue()
|
||||||
PreferencesHelper.registerPreferenceChangeListener(
|
PreferencesHelper.registerPreferenceChangeListener(sharedPreferenceChangeListener)
|
||||||
sharedPreferenceChangeListener
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -44,6 +44,15 @@ object PreferencesHelper {
|
||||||
/* Define log tag */
|
/* Define log tag */
|
||||||
private val TAG: String = LogHelper.makeLogTag(PreferencesHelper::class.java)
|
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 */
|
/* Loads zoom level of map */
|
||||||
fun loadZoomLevel(): Double {
|
fun loadZoomLevel(): Double {
|
||||||
|
@ -129,6 +138,7 @@ object PreferencesHelper {
|
||||||
altitude = sharedPreferences.getDouble(Keys.PREF_CURRENT_BEST_LOCATION_ALTITUDE, Keys.DEFAULT_ALTITUDE)
|
altitude = sharedPreferences.getDouble(Keys.PREF_CURRENT_BEST_LOCATION_ALTITUDE, Keys.DEFAULT_ALTITUDE)
|
||||||
time = sharedPreferences.getLong(Keys.PREF_CURRENT_BEST_LOCATION_TIME, Keys.DEFAULT_TIME)
|
time = sharedPreferences.getLong(Keys.PREF_CURRENT_BEST_LOCATION_TIME, Keys.DEFAULT_TIME)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -160,6 +170,7 @@ object PreferencesHelper {
|
||||||
/* Saves state of housekeeping */
|
/* Saves state of housekeeping */
|
||||||
fun saveHouseKeepingNecessaryState(state: Boolean = false) {
|
fun saveHouseKeepingNecessaryState(state: Boolean = false) {
|
||||||
sharedPreferences.edit { putBoolean(Keys.PREF_ONE_TIME_HOUSEKEEPING_NECESSARY, state) }
|
sharedPreferences.edit { putBoolean(Keys.PREF_ONE_TIME_HOUSEKEEPING_NECESSARY, state) }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Start watching for changes in shared preferences - context must implement OnSharedPreferenceChangeListener */
|
/* Start watching for changes in shared preferences - context must implement OnSharedPreferenceChangeListener */
|
||||||
|
|
Loading…
Reference in a new issue