mirror of
https://github.com/atsunatsu/Look4Sat.git
synced 2026-10-02 03:15:37 +00:00
Cleaned up SharedPreferences keys and values
This commit is contained in:
1 parent
e100484810
commit
b9ade5f243
14 files changed
+239
-326
No files matched your search
@@ -55,7 +55,6 @@ dependencies {
|
||||
implementation("org.osmdroid:osmdroid-android:6.1.16")
|
||||
debugImplementation("androidx.compose.ui:ui-tooling:1.5.0")
|
||||
debugImplementation("androidx.compose.ui:ui-test-manifest:1.5.0")
|
||||
debugImplementation("com.squareup.leakcanary:leakcanary-android:2.12")
|
||||
|
||||
testImplementation("junit:junit:4.13.2")
|
||||
testImplementation("io.mockk:mockk:1.13.7")
|
||||
|
||||
@@ -40,8 +40,8 @@ class MainApplication : Application() {
|
||||
|
||||
private suspend fun checkAutoUpdate() {
|
||||
val settingsRepo = container.settingsRepo
|
||||
if (settingsRepo.otherSettings.value.updateState) {
|
||||
val timeDelta = System.currentTimeMillis() - settingsRepo.databaseState.value.timestamp
|
||||
if (settingsRepo.otherSettings.value.stateOfAutoUpdate) {
|
||||
val timeDelta = System.currentTimeMillis() - settingsRepo.databaseState.value.updateTimestamp
|
||||
if (timeDelta > AUTO_UPDATE_DELTA_MS) {
|
||||
val sdf = SimpleDateFormat("d MMM yyyy - HH:mm:ss", Locale.getDefault())
|
||||
println("Started periodic data update on ${sdf.format(Date())}")
|
||||
|
||||
@@ -99,8 +99,11 @@ class MainContainer(private val context: Context) {
|
||||
|
||||
private fun provideSettingsRepo(): ISettingsRepo {
|
||||
val manager = context.getSystemService(Context.LOCATION_SERVICE) as LocationManager
|
||||
val preferences = context.getSharedPreferences("default", Context.MODE_PRIVATE)
|
||||
Configuration.getInstance().load(context, preferences)
|
||||
return SettingsRepo(manager, preferences)
|
||||
val appPrefsFileName = "${context.packageName}_preferences"
|
||||
val appPreferences = context.getSharedPreferences(appPrefsFileName, Context.MODE_PRIVATE)
|
||||
val mapPrefsFileName = "${context.packageName}_osmdroid"
|
||||
val mapPreferences = context.getSharedPreferences(mapPrefsFileName, Context.MODE_PRIVATE)
|
||||
Configuration.getInstance().load(context, mapPreferences)
|
||||
return SettingsRepo(manager, appPreferences)
|
||||
}
|
||||
}
|
||||
@@ -98,7 +98,7 @@ class PassesViewModel(
|
||||
fun calculatePasses(timeRef: Long, hoursAhead: Int, minElev: Double) = viewModelScope.launch {
|
||||
_passes.emit(DataState.Loading)
|
||||
passesProcessing?.cancelAndJoin()
|
||||
settingsRepo.savePassesSettings(PassesSettings(hoursAhead, minElev))
|
||||
settingsRepo.updatePassesSettings(PassesSettings(hoursAhead, minElev))
|
||||
satelliteRepo.calculatePasses(timeRef, hoursAhead, minElev)
|
||||
}
|
||||
|
||||
|
||||
@@ -61,7 +61,7 @@ class RadarViewModel(
|
||||
val orientation = mutableStateOf(sensorSource.orientation.value)
|
||||
|
||||
init {
|
||||
if (settingsRepo.otherSettings.value.sensorState) {
|
||||
if (settingsRepo.otherSettings.value.stateOfSensors) {
|
||||
viewModelScope.launch {
|
||||
sensorSource.enableSensor()
|
||||
sensorSource.orientation.collect { data ->
|
||||
@@ -117,8 +117,8 @@ class RadarViewModel(
|
||||
satellite, stationPos, satPass.aosTime, satPass.losTime
|
||||
)
|
||||
}
|
||||
if (settingsRepo.getRotatorEnabled()) {
|
||||
val server = settingsRepo.getRotatorServer()
|
||||
if (settingsRepo.getRotatorState()) {
|
||||
val server = settingsRepo.getRotatorAddress()
|
||||
val port = settingsRepo.getRotatorPort().toInt()
|
||||
val azimuth = satPos.azimuth.toDegrees().round(1)
|
||||
val elevation = satPos.elevation.toDegrees().round(1)
|
||||
@@ -130,10 +130,10 @@ class RadarViewModel(
|
||||
|
||||
private fun sendPassDataBT(satPos: SatPos) {
|
||||
viewModelScope.launch {
|
||||
if (settingsRepo.getBTEnabled()) {
|
||||
val btDevice = settingsRepo.getBTDeviceAddr()
|
||||
if (settingsRepo.getBluetoothState()) {
|
||||
val btDevice = settingsRepo.getBluetoothAddress()
|
||||
if (bluetoothReporter.isConnected()) {
|
||||
val format = settingsRepo.getBTFormat()
|
||||
val format = settingsRepo.getBluetoothFormat()
|
||||
val azimuth = satPos.azimuth.toDegrees().round(0).toInt()
|
||||
val elevation = satPos.elevation.toDegrees().round(0).toInt()
|
||||
bluetoothReporter.reportRotation(format, azimuth, elevation)
|
||||
|
||||
@@ -367,7 +367,7 @@ private fun DataCard(
|
||||
@Preview(showBackground = true)
|
||||
@Composable
|
||||
private fun OtherCardPreview() = MainTheme {
|
||||
val values = OtherSettings(utcState = false, updateState = true, sweepState = true, sensorState = true)
|
||||
val values = OtherSettings(stateOfAutoUpdate = true, stateOfSensors = true, stateOfSweep = true, stateOfUtc = false)
|
||||
OtherCard(settings = values, {}, {}, {}, {})
|
||||
}
|
||||
|
||||
@@ -387,7 +387,7 @@ private fun OtherCard(
|
||||
modifier = Modifier.fillMaxWidth()
|
||||
) {
|
||||
Text(text = stringResource(id = R.string.other_switch_utc))
|
||||
Switch(checked = settings.utcState, onCheckedChange = { toggleUtc(it) })
|
||||
Switch(checked = settings.stateOfUtc, onCheckedChange = { toggleUtc(it) })
|
||||
}
|
||||
Row(
|
||||
horizontalArrangement = Arrangement.SpaceBetween,
|
||||
@@ -395,7 +395,7 @@ private fun OtherCard(
|
||||
modifier = Modifier.fillMaxWidth()
|
||||
) {
|
||||
Text(text = stringResource(id = R.string.other_switch_update))
|
||||
Switch(checked = settings.updateState, onCheckedChange = { toggleUpdate(it) })
|
||||
Switch(checked = settings.stateOfAutoUpdate, onCheckedChange = { toggleUpdate(it) })
|
||||
}
|
||||
Row(
|
||||
horizontalArrangement = Arrangement.SpaceBetween,
|
||||
@@ -403,7 +403,7 @@ private fun OtherCard(
|
||||
modifier = Modifier.fillMaxWidth()
|
||||
) {
|
||||
Text(text = stringResource(id = R.string.other_switch_sweep))
|
||||
Switch(checked = settings.sweepState, onCheckedChange = { toggleSweep(it) })
|
||||
Switch(checked = settings.stateOfSweep, onCheckedChange = { toggleSweep(it) })
|
||||
}
|
||||
Row(
|
||||
horizontalArrangement = Arrangement.SpaceBetween,
|
||||
@@ -411,7 +411,7 @@ private fun OtherCard(
|
||||
modifier = Modifier.fillMaxWidth()
|
||||
) {
|
||||
Text(text = stringResource(id = R.string.other_switch_sensors))
|
||||
Switch(checked = settings.sensorState, onCheckedChange = { toggleSensor(it) })
|
||||
Switch(checked = settings.stateOfSensors, onCheckedChange = { toggleSensor(it) })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+10
-10
@@ -57,9 +57,9 @@ class SettingsViewModel(
|
||||
settingsRepo.databaseState.collect { state ->
|
||||
_dataSettings.value = _dataSettings.value.copy(
|
||||
isUpdating = false,
|
||||
entriesTotal = state.entriesTotal,
|
||||
radiosTotal = state.radiosTotal,
|
||||
timestamp = state.timestamp
|
||||
entriesTotal = state.numberOfSatellites,
|
||||
radiosTotal = state.numberOfRadios,
|
||||
timestamp = state.updateTimestamp
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -69,7 +69,7 @@ class SettingsViewModel(
|
||||
}
|
||||
|
||||
fun setGpsPosition() {
|
||||
if (settingsRepo.setGpsPosition()) {
|
||||
if (settingsRepo.setStationPositionGps()) {
|
||||
val messageResId = R.string.location_success
|
||||
_positionSettings.value =
|
||||
_positionSettings.value.copy(isUpdating = true, messageResId = messageResId)
|
||||
@@ -80,7 +80,7 @@ class SettingsViewModel(
|
||||
}
|
||||
|
||||
fun setGeoPosition(latitude: Double, longitude: Double) {
|
||||
if (settingsRepo.setGeoPosition(latitude, longitude)) {
|
||||
if (settingsRepo.setStationPositionGeo(latitude, longitude, 0.0)) {
|
||||
val messageResId = R.string.location_success
|
||||
_positionSettings.value = _positionSettings.value.copy(messageResId = messageResId)
|
||||
} else {
|
||||
@@ -90,7 +90,7 @@ class SettingsViewModel(
|
||||
}
|
||||
|
||||
fun setQthPosition(locator: String) {
|
||||
if (settingsRepo.setQthPosition(locator)) {
|
||||
if (settingsRepo.setStationPositionQth(locator)) {
|
||||
val messageResId = R.string.location_success
|
||||
_positionSettings.value = _positionSettings.value.copy(messageResId = messageResId)
|
||||
} else {
|
||||
@@ -125,10 +125,10 @@ class SettingsViewModel(
|
||||
|
||||
fun clearAllData() = viewModelScope.launch { databaseRepo.clearAllData() }
|
||||
|
||||
fun toggleUtc(value: Boolean) = settingsRepo.toggleUtc(value)
|
||||
fun toggleUpdate(value: Boolean) = settingsRepo.toggleUpdate(value)
|
||||
fun toggleSweep(value: Boolean) = settingsRepo.toggleSweep(value)
|
||||
fun toggleSensor(value: Boolean) = settingsRepo.toggleSensor(value)
|
||||
fun toggleUtc(value: Boolean) = settingsRepo.setStateOfUtc(value)
|
||||
fun toggleUpdate(value: Boolean) = settingsRepo.setStateOfAutoUpdate(value)
|
||||
fun toggleSweep(value: Boolean) = settingsRepo.setStateOfSweep(value)
|
||||
fun toggleSensor(value: Boolean) = settingsRepo.setStateOfSensors(value)
|
||||
|
||||
// fun getRotatorEnabled(): Boolean = settings.getRotatorEnabled()
|
||||
// fun setRotatorEnabled(value: Boolean) = settings.setRotatorEnabled(value)
|
||||
|
||||
Reference in new issue
Block a user