mirror of
https://github.com/rt-bishop/Look4Sat.git
synced 2026-10-02 03:15:37 +00:00
Added remote data output sections to SettingsScreen.kt
This commit is contained in:
1 parent
a68e466040
commit
a835ac4e07
8 files changed
+246
-129
No files matched your search
@@ -150,10 +150,10 @@ class RadarViewModel(
|
|||||||
|
|
||||||
private fun sendPassDataBT(orbitalPos: OrbitalPos) {
|
private fun sendPassDataBT(orbitalPos: OrbitalPos) {
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
if (settingsRepo.getBluetoothState()) {
|
if (settingsRepo.rcSettings.value.bluetoothState) {
|
||||||
val btDevice = settingsRepo.getBluetoothAddress()
|
val btDevice = settingsRepo.rcSettings.value.bluetoothAddress
|
||||||
if (bluetoothReporter.isConnected()) {
|
if (bluetoothReporter.isConnected()) {
|
||||||
val format = settingsRepo.getBluetoothFormat()
|
val format = settingsRepo.rcSettings.value.bluetoothFormat
|
||||||
val azimuth = orbitalPos.azimuth.toDegrees().round(0).toInt()
|
val azimuth = orbitalPos.azimuth.toDegrees().round(0).toInt()
|
||||||
val elevation = orbitalPos.elevation.toDegrees().round(0).toInt()
|
val elevation = orbitalPos.elevation.toDegrees().round(0).toInt()
|
||||||
bluetoothReporter.reportRotation(format, azimuth, elevation)
|
bluetoothReporter.reportRotation(format, azimuth, elevation)
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ import androidx.compose.material3.ElevatedCard
|
|||||||
import androidx.compose.material3.Icon
|
import androidx.compose.material3.Icon
|
||||||
import androidx.compose.material3.LinearProgressIndicator
|
import androidx.compose.material3.LinearProgressIndicator
|
||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
||||||
|
import androidx.compose.material3.OutlinedTextField
|
||||||
import androidx.compose.material3.Switch
|
import androidx.compose.material3.Switch
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
@@ -42,6 +43,7 @@ import androidx.navigation.NavGraphBuilder
|
|||||||
import androidx.navigation.compose.composable
|
import androidx.navigation.compose.composable
|
||||||
import com.rtbishop.look4sat.R
|
import com.rtbishop.look4sat.R
|
||||||
import com.rtbishop.look4sat.domain.model.OtherSettings
|
import com.rtbishop.look4sat.domain.model.OtherSettings
|
||||||
|
import com.rtbishop.look4sat.domain.model.RCSettings
|
||||||
import com.rtbishop.look4sat.domain.predict.GeoPos
|
import com.rtbishop.look4sat.domain.predict.GeoPos
|
||||||
import com.rtbishop.look4sat.presentation.MainTheme
|
import com.rtbishop.look4sat.presentation.MainTheme
|
||||||
import com.rtbishop.look4sat.presentation.Screen
|
import com.rtbishop.look4sat.presentation.Screen
|
||||||
@@ -76,8 +78,10 @@ private fun SettingsScreen(uiState: SettingsState) {
|
|||||||
else -> Manifest.permission.BLUETOOTH_CONNECT
|
else -> Manifest.permission.BLUETOOTH_CONNECT
|
||||||
}
|
}
|
||||||
val bluetoothRequest = rememberLauncherForActivityResult(bluetoothContract) { isGranted ->
|
val bluetoothRequest = rememberLauncherForActivityResult(bluetoothContract) { isGranted ->
|
||||||
uiState.sendRCAction(RCAction.SetBluetoothState(isGranted))
|
if (!isGranted) {
|
||||||
if (!isGranted) uiState.sendSystemAction(SystemAction.ShowToast(bluetoothError))
|
uiState.sendRCAction(RCAction.SetBluetoothState(false))
|
||||||
|
uiState.sendSystemAction(SystemAction.ShowToast(bluetoothError))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
val locationContract = ActivityResultContracts.RequestMultiplePermissions()
|
val locationContract = ActivityResultContracts.RequestMultiplePermissions()
|
||||||
val locationError = stringResource(R.string.location_gps_error)
|
val locationError = stringResource(R.string.location_gps_error)
|
||||||
@@ -123,6 +127,18 @@ private fun SettingsScreen(uiState: SettingsState) {
|
|||||||
val updateFromFile = { contentRequest.launch("*/*") }
|
val updateFromFile = { contentRequest.launch("*/*") }
|
||||||
val clearAllData: () -> Unit = { uiState.sendAction(SettingsAction.ClearAllData) }
|
val clearAllData: () -> Unit = { uiState.sendAction(SettingsAction.ClearAllData) }
|
||||||
|
|
||||||
|
// RC settings
|
||||||
|
val rcSettings = uiState.rcSettings
|
||||||
|
val setRotatorState = { value: Boolean -> uiState.sendRCAction(RCAction.SetRotatorState(value)) }
|
||||||
|
val setRotatorAddress = { value: String -> uiState.sendRCAction(RCAction.SetRotatorAddress(value)) }
|
||||||
|
val setRotatorPort = { value: String -> uiState.sendRCAction(RCAction.SetRotatorPort(value)) }
|
||||||
|
val setBluetoothState = { value: Boolean ->
|
||||||
|
bluetoothRequest.launch(bluetoothPerm)
|
||||||
|
uiState.sendRCAction(RCAction.SetBluetoothState(value))
|
||||||
|
}
|
||||||
|
val setBluetoothAddress = { value: String -> uiState.sendRCAction(RCAction.SetBluetoothAddress(value)) }
|
||||||
|
val setBluetoothFormat = { value: String -> uiState.sendRCAction(RCAction.SetBluetoothFormat(value)) }
|
||||||
|
|
||||||
// Other settings
|
// Other settings
|
||||||
val otherSettings = uiState.otherSettings
|
val otherSettings = uiState.otherSettings
|
||||||
val toggleUtc = { value: Boolean -> uiState.sendAction(SettingsAction.ToggleUtc(value)) }
|
val toggleUtc = { value: Boolean -> uiState.sendAction(SettingsAction.ToggleUtc(value)) }
|
||||||
@@ -177,6 +193,8 @@ private fun SettingsScreen(uiState: SettingsState) {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
item { DataCard(dataSettings, updateFromWeb, updateFromFile, clearAllData) }
|
item { DataCard(dataSettings, updateFromWeb, updateFromFile, clearAllData) }
|
||||||
|
item { NetworkOutputCard(rcSettings, setRotatorState, setRotatorAddress, setRotatorPort) }
|
||||||
|
item { BluetoothOutputCard(rcSettings, setBluetoothState, setBluetoothAddress, setBluetoothFormat) }
|
||||||
item {
|
item {
|
||||||
OtherCard(
|
OtherCard(
|
||||||
otherSettings,
|
otherSettings,
|
||||||
@@ -329,51 +347,132 @@ private fun DataCard(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//private fun setupRemoteCard() {
|
@Preview(showBackground = true)
|
||||||
// binding.run {
|
@Composable
|
||||||
// settingsRemote.remoteSwitch.apply {
|
private fun NetworkOutputCardPreview() = MainTheme {
|
||||||
// isChecked = viewModel.getRotatorEnabled()
|
val settings = RCSettings(
|
||||||
// settingsRemote.remoteIp.isEnabled = isChecked
|
rotatorState = false,
|
||||||
// settingsRemote.remoteIpEdit.setText(viewModel.getRotatorServer())
|
rotatorAddress = "127.0.0.1",
|
||||||
// settingsRemote.remotePort.isEnabled = isChecked
|
rotatorPort = "4533",
|
||||||
// settingsRemote.remotePortEdit.setText(viewModel.getRotatorPort())
|
bluetoothState = false,
|
||||||
// setOnCheckedChangeListener { _, isChecked ->
|
bluetoothFormat = $$"W$AZ $EL",
|
||||||
// viewModel.setRotatorEnabled(isChecked)
|
bluetoothName = "Name",
|
||||||
// settingsRemote.remoteIp.isEnabled = isChecked
|
bluetoothAddress = "00:0C:BF:13:80:5D"
|
||||||
// settingsRemote.remotePort.isEnabled = isChecked
|
)
|
||||||
// }
|
NetworkOutputCard(settings)
|
||||||
// }
|
}
|
||||||
// settingsRemote.remoteIpEdit.doOnTextChanged { text, _, _, _ ->
|
|
||||||
// if (text.toString().isValidIPv4()) viewModel.setRotatorServer(text.toString())
|
@Composable
|
||||||
// }
|
private fun NetworkOutputCard(
|
||||||
// settingsRemote.remotePortEdit.doOnTextChanged { text, _, _, _ ->
|
settings: RCSettings,
|
||||||
// if (text.toString().isValidPort()) viewModel.setRotatorPort(text.toString())
|
setRotatorState: (Boolean) -> Unit = {},
|
||||||
// }
|
setRotatorAddress: (String) -> Unit = {},
|
||||||
// }
|
setRotatorPort: (String) -> Unit = {}
|
||||||
//}
|
) {
|
||||||
//
|
ElevatedCard(modifier = Modifier.fillMaxWidth()) {
|
||||||
//private fun setupBTCard() {
|
Column(modifier = Modifier.padding(horizontal = 8.dp, vertical = 4.dp)) {
|
||||||
// binding.run {
|
Text(
|
||||||
// settingsBtremote.BTremoteSwitch.apply {
|
text = stringResource(id = R.string.remote_title),
|
||||||
// isChecked = viewModel.getBTEnabled()
|
color = MaterialTheme.colorScheme.primary
|
||||||
// settingsBtremote.BTremoteAddress.isEnabled = isChecked
|
)
|
||||||
// settingsBtremote.BTAddressEdit.setText(viewModel.getBTDeviceAddr())
|
Row(
|
||||||
// settingsBtremote.BTremoteFormat.isEnabled = isChecked
|
horizontalArrangement = Arrangement.SpaceBetween,
|
||||||
// settingsBtremote.BTFormatEdit.setText(viewModel.getBTFormat())
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
// setOnCheckedChangeListener { _, isChecked ->
|
modifier = Modifier.fillMaxWidth()
|
||||||
// toggleBTstate(isChecked)
|
) {
|
||||||
// bluetoothRequest.launch(bluetooth)
|
Text(text = stringResource(R.string.remote_switch))
|
||||||
// }
|
Switch(checked = settings.rotatorState, onCheckedChange = { setRotatorState(it) })
|
||||||
// }
|
}
|
||||||
// settingsBtremote.BTAddressEdit.doOnTextChanged { text, _, _, _ ->
|
Row(
|
||||||
// viewModel.setBTDeviceAddr(text.toString())
|
horizontalArrangement = Arrangement.spacedBy(8.dp),
|
||||||
// }
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
// settingsBtremote.BTFormatEdit.doOnTextChanged { text, _, _, _ ->
|
modifier = Modifier.fillMaxWidth()
|
||||||
// viewModel.setBTFormat(text.toString())
|
) {
|
||||||
// }
|
OutlinedTextField(
|
||||||
// }
|
value = settings.rotatorAddress,
|
||||||
//}
|
singleLine = true,
|
||||||
//
|
label = { Text(text = stringResource(R.string.remote_ip_hint)) },
|
||||||
|
onValueChange = { setRotatorAddress(it) },
|
||||||
|
modifier = Modifier.weight(1.5f),
|
||||||
|
enabled = settings.rotatorState
|
||||||
|
)
|
||||||
|
OutlinedTextField(
|
||||||
|
value = settings.rotatorPort,
|
||||||
|
onValueChange = { setRotatorPort(it) },
|
||||||
|
label = { Text(text = stringResource(R.string.remote_port_hint)) },
|
||||||
|
singleLine = true,
|
||||||
|
modifier = Modifier.weight(1f),
|
||||||
|
enabled = settings.rotatorState
|
||||||
|
)
|
||||||
|
}
|
||||||
|
Spacer(modifier = Modifier.height(4.dp))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Preview(showBackground = true)
|
||||||
|
@Composable
|
||||||
|
private fun BluetoothOutputCardPreview() = MainTheme {
|
||||||
|
val settings = RCSettings(
|
||||||
|
rotatorState = false,
|
||||||
|
rotatorAddress = "127.0.0.1",
|
||||||
|
rotatorPort = "4533",
|
||||||
|
bluetoothState = false,
|
||||||
|
bluetoothFormat = $$"W$AZ $EL",
|
||||||
|
bluetoothName = "Name",
|
||||||
|
bluetoothAddress = "00:0C:BF:13:80:5D"
|
||||||
|
)
|
||||||
|
BluetoothOutputCard(settings)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
private fun BluetoothOutputCard(
|
||||||
|
settings: RCSettings,
|
||||||
|
setBluetoothState: (Boolean) -> Unit = {},
|
||||||
|
setBluetoothAddress: (String) -> Unit = {},
|
||||||
|
setBluetoothFormat: (String) -> Unit = {}
|
||||||
|
) {
|
||||||
|
ElevatedCard(modifier = Modifier.fillMaxWidth()) {
|
||||||
|
Column(modifier = Modifier.padding(horizontal = 8.dp, vertical = 4.dp)) {
|
||||||
|
Text(
|
||||||
|
text = stringResource(id = R.string.BTremote_title),
|
||||||
|
color = MaterialTheme.colorScheme.primary
|
||||||
|
)
|
||||||
|
Row(
|
||||||
|
horizontalArrangement = Arrangement.SpaceBetween,
|
||||||
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
|
modifier = Modifier.fillMaxWidth()
|
||||||
|
) {
|
||||||
|
Text(text = stringResource(R.string.BTremote_switch))
|
||||||
|
Switch(checked = settings.bluetoothState, onCheckedChange = { setBluetoothState(it) })
|
||||||
|
}
|
||||||
|
Row(
|
||||||
|
horizontalArrangement = Arrangement.spacedBy(8.dp),
|
||||||
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
|
modifier = Modifier.fillMaxWidth()
|
||||||
|
) {
|
||||||
|
OutlinedTextField(
|
||||||
|
value = settings.bluetoothAddress,
|
||||||
|
singleLine = true,
|
||||||
|
label = { Text(text = stringResource(R.string.BTremote_device_hint)) },
|
||||||
|
onValueChange = { setBluetoothAddress(it) },
|
||||||
|
modifier = Modifier.weight(1.5f),
|
||||||
|
enabled = settings.bluetoothState
|
||||||
|
)
|
||||||
|
OutlinedTextField(
|
||||||
|
value = settings.bluetoothFormat,
|
||||||
|
onValueChange = { setBluetoothFormat(it) },
|
||||||
|
label = { Text(text = stringResource(R.string.BTremote_output_hint)) },
|
||||||
|
singleLine = true,
|
||||||
|
modifier = Modifier.weight(1f),
|
||||||
|
enabled = settings.bluetoothState
|
||||||
|
)
|
||||||
|
}
|
||||||
|
Spacer(modifier = Modifier.height(4.dp))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Preview(showBackground = true)
|
@Preview(showBackground = true)
|
||||||
@Composable
|
@Composable
|
||||||
private fun OtherCardPreview() = MainTheme {
|
private fun OtherCardPreview() = MainTheme {
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package com.rtbishop.look4sat.presentation.settings
|
package com.rtbishop.look4sat.presentation.settings
|
||||||
|
|
||||||
import com.rtbishop.look4sat.domain.model.OtherSettings
|
import com.rtbishop.look4sat.domain.model.OtherSettings
|
||||||
|
import com.rtbishop.look4sat.domain.model.RCSettings
|
||||||
import com.rtbishop.look4sat.domain.predict.GeoPos
|
import com.rtbishop.look4sat.domain.predict.GeoPos
|
||||||
import com.rtbishop.look4sat.domain.predict.OrbitalPass
|
import com.rtbishop.look4sat.domain.predict.OrbitalPass
|
||||||
|
|
||||||
@@ -12,16 +13,6 @@ data class DataSettings(
|
|||||||
val isUpdating: Boolean, val entriesTotal: Int, val radiosTotal: Int, val timestamp: Long
|
val isUpdating: Boolean, val entriesTotal: Int, val radiosTotal: Int, val timestamp: Long
|
||||||
)
|
)
|
||||||
|
|
||||||
data class RCSettings(
|
|
||||||
val rotatorState: Boolean,
|
|
||||||
val rotatorAddress: String,
|
|
||||||
val rotatorPort: String,
|
|
||||||
val bluetoothState: Boolean,
|
|
||||||
val bluetoothFormat: String,
|
|
||||||
val bluetoothName: String,
|
|
||||||
val bluetoothAddress: String,
|
|
||||||
)
|
|
||||||
|
|
||||||
data class SettingsState(
|
data class SettingsState(
|
||||||
val nextPass: OrbitalPass,
|
val nextPass: OrbitalPass,
|
||||||
val nextTime: String,
|
val nextTime: String,
|
||||||
@@ -52,9 +43,6 @@ sealed class SettingsAction {
|
|||||||
}
|
}
|
||||||
|
|
||||||
sealed class SystemAction {
|
sealed class SystemAction {
|
||||||
data object OpenGitHub : SystemAction()
|
|
||||||
data object OpenDonate : SystemAction()
|
|
||||||
data object OpenFDroid : SystemAction()
|
|
||||||
data class ShowToast(val message: String) : SystemAction()
|
data class ShowToast(val message: String) : SystemAction()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -51,15 +51,6 @@ class SettingsViewModel(
|
|||||||
|
|
||||||
private val defaultPosSettings = PositionSettings(false, settingsRepo.stationPosition.value, 0)
|
private val defaultPosSettings = PositionSettings(false, settingsRepo.stationPosition.value, 0)
|
||||||
private val defaultDataSettings = DataSettings(false, 0, 0, 0L)
|
private val defaultDataSettings = DataSettings(false, 0, 0, 0L)
|
||||||
private val defaultRCSettings = RCSettings(
|
|
||||||
rotatorState = settingsRepo.getRotatorState(),
|
|
||||||
rotatorAddress = settingsRepo.getRotatorAddress(),
|
|
||||||
rotatorPort = settingsRepo.getRotatorPort(),
|
|
||||||
bluetoothState = settingsRepo.getBluetoothState(),
|
|
||||||
bluetoothFormat = settingsRepo.getBluetoothFormat(),
|
|
||||||
bluetoothName = settingsRepo.getBluetoothName(),
|
|
||||||
bluetoothAddress = settingsRepo.getBluetoothAddress()
|
|
||||||
)
|
|
||||||
private val _uiState = MutableStateFlow(
|
private val _uiState = MutableStateFlow(
|
||||||
SettingsState(
|
SettingsState(
|
||||||
nextTime = "00:00:00",
|
nextTime = "00:00:00",
|
||||||
@@ -69,7 +60,7 @@ class SettingsViewModel(
|
|||||||
positionSettings = defaultPosSettings,
|
positionSettings = defaultPosSettings,
|
||||||
dataSettings = defaultDataSettings,
|
dataSettings = defaultDataSettings,
|
||||||
otherSettings = settingsRepo.otherSettings.value,
|
otherSettings = settingsRepo.otherSettings.value,
|
||||||
rcSettings = defaultRCSettings,
|
rcSettings = settingsRepo.rcSettings.value,
|
||||||
sendAction = ::handleAction,
|
sendAction = ::handleAction,
|
||||||
sendRCAction = ::handleAction,
|
sendRCAction = ::handleAction,
|
||||||
sendSystemAction = ::handleAction
|
sendSystemAction = ::handleAction
|
||||||
@@ -112,6 +103,11 @@ class SettingsViewModel(
|
|||||||
_uiState.update { it.copy(dataSettings = newDataSettings) }
|
_uiState.update { it.copy(dataSettings = newDataSettings) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
viewModelScope.launch {
|
||||||
|
settingsRepo.rcSettings.collect { settings ->
|
||||||
|
_uiState.update { it.copy(rcSettings = settings) }
|
||||||
|
}
|
||||||
|
}
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
settingsRepo.otherSettings.collect { settings ->
|
settingsRepo.otherSettings.collect { settings ->
|
||||||
_uiState.update { it.copy(otherSettings = settings) }
|
_uiState.update { it.copy(otherSettings = settings) }
|
||||||
@@ -151,7 +147,6 @@ class SettingsViewModel(
|
|||||||
private fun handleAction(action: SystemAction) {
|
private fun handleAction(action: SystemAction) {
|
||||||
when (action) {
|
when (action) {
|
||||||
is SystemAction.ShowToast -> showToast(action.message)
|
is SystemAction.ShowToast -> showToast(action.message)
|
||||||
else -> {}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ import androidx.core.location.LocationManagerCompat
|
|||||||
import com.rtbishop.look4sat.domain.model.DatabaseState
|
import com.rtbishop.look4sat.domain.model.DatabaseState
|
||||||
import com.rtbishop.look4sat.domain.model.OtherSettings
|
import com.rtbishop.look4sat.domain.model.OtherSettings
|
||||||
import com.rtbishop.look4sat.domain.model.PassesSettings
|
import com.rtbishop.look4sat.domain.model.PassesSettings
|
||||||
|
import com.rtbishop.look4sat.domain.model.RCSettings
|
||||||
import com.rtbishop.look4sat.domain.predict.GeoPos
|
import com.rtbishop.look4sat.domain.predict.GeoPos
|
||||||
import com.rtbishop.look4sat.domain.repository.ISettingsRepo
|
import com.rtbishop.look4sat.domain.repository.ISettingsRepo
|
||||||
import com.rtbishop.look4sat.domain.utility.positionToQth
|
import com.rtbishop.look4sat.domain.utility.positionToQth
|
||||||
@@ -33,6 +34,7 @@ import com.rtbishop.look4sat.domain.utility.qthToPosition
|
|||||||
import com.rtbishop.look4sat.domain.utility.round
|
import com.rtbishop.look4sat.domain.utility.round
|
||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
import kotlinx.coroutines.flow.StateFlow
|
import kotlinx.coroutines.flow.StateFlow
|
||||||
|
import kotlinx.coroutines.flow.update
|
||||||
|
|
||||||
class SettingsRepo(
|
class SettingsRepo(
|
||||||
private val locationManager: LocationManager,
|
private val locationManager: LocationManager,
|
||||||
@@ -126,6 +128,10 @@ class SettingsRepo(
|
|||||||
private val providerNet = LocationManager.NETWORK_PROVIDER
|
private val providerNet = LocationManager.NETWORK_PROVIDER
|
||||||
override val stationPosition: StateFlow<GeoPos> = _stationPosition
|
override val stationPosition: StateFlow<GeoPos> = _stationPosition
|
||||||
|
|
||||||
|
override fun onLocationChanged(location: Location) {
|
||||||
|
setStationPosition(location.latitude, location.longitude, location.altitude)
|
||||||
|
}
|
||||||
|
|
||||||
override fun setStationPosition(latitude: Double, longitude: Double, altitude: Double): Boolean {
|
override fun setStationPosition(latitude: Double, longitude: Double, altitude: Double): Boolean {
|
||||||
val newLongitude = if (longitude > 180.0) longitude - 180 else longitude
|
val newLongitude = if (longitude > 180.0) longitude - 180 else longitude
|
||||||
val locator = positionToQth(latitude, newLongitude) ?: return false
|
val locator = positionToQth(latitude, newLongitude) ?: return false
|
||||||
@@ -225,43 +231,93 @@ class SettingsRepo(
|
|||||||
}
|
}
|
||||||
//endregion
|
//endregion
|
||||||
|
|
||||||
|
//region # RC settings
|
||||||
|
private val _rcSettings = MutableStateFlow(getRCSettings())
|
||||||
|
override val rcSettings: StateFlow<RCSettings> = _rcSettings
|
||||||
|
|
||||||
|
override fun setBluetoothAddress(value: String) {
|
||||||
|
preferences.edit { putString(keyBluetoothAddress, value) }
|
||||||
|
_rcSettings.update { it.copy(bluetoothAddress = value) }
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun setBluetoothFormat(value: String) {
|
||||||
|
preferences.edit { putString(keyBluetoothFormat, value) }
|
||||||
|
_rcSettings.update { it.copy(bluetoothFormat = value) }
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun setBluetoothName(value: String) {
|
||||||
|
preferences.edit { putString(keyBluetoothName, value) }
|
||||||
|
_rcSettings.update { it.copy(bluetoothName = value) }
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun setBluetoothState(value: Boolean) {
|
||||||
|
preferences.edit { putBoolean(keyBluetoothState, value) }
|
||||||
|
_rcSettings.update { it.copy(bluetoothState = value) }
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun setRotatorAddress(value: String) {
|
||||||
|
preferences.edit { putString(keyRotatorAddress, value) }
|
||||||
|
_rcSettings.update { it.copy(rotatorAddress = value) }
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun setRotatorPort(value: String) {
|
||||||
|
preferences.edit { putString(keyRotatorPort, value) }
|
||||||
|
_rcSettings.update { it.copy(rotatorPort = value) }
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun setRotatorState(value: Boolean) {
|
||||||
|
preferences.edit { putBoolean(keyRotatorState, value) }
|
||||||
|
_rcSettings.update { it.copy(rotatorState = value) }
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun getRCSettings(): RCSettings = RCSettings(
|
||||||
|
rotatorState = preferences.getBoolean(keyRotatorState, false),
|
||||||
|
rotatorAddress = preferences.getString(keyRotatorAddress, null) ?: "127.0.0.1",
|
||||||
|
rotatorPort = preferences.getString(keyRotatorPort, null) ?: "4533",
|
||||||
|
bluetoothState = preferences.getBoolean(keyBluetoothState, false),
|
||||||
|
bluetoothFormat = preferences.getString(keyBluetoothFormat, null) ?: $$"W$AZ $EL",
|
||||||
|
bluetoothName = preferences.getString(keyBluetoothName, null) ?: "Default",
|
||||||
|
bluetoothAddress = preferences.getString(keyBluetoothAddress, null) ?: "00:0C:BF:13:80:5D"
|
||||||
|
)
|
||||||
|
//endregion
|
||||||
|
|
||||||
//region # Other settings
|
//region # Other settings
|
||||||
private val _otherSettings = MutableStateFlow(getOtherSettings())
|
private val _otherSettings = MutableStateFlow(getOtherSettings())
|
||||||
override val otherSettings: StateFlow<OtherSettings> = _otherSettings
|
override val otherSettings: StateFlow<OtherSettings> = _otherSettings
|
||||||
|
|
||||||
override fun setStateOfAutoUpdate(value: Boolean) {
|
override fun setStateOfAutoUpdate(value: Boolean) {
|
||||||
preferences.edit { putBoolean(keyStateOfAutoUpdate, value) }
|
preferences.edit { putBoolean(keyStateOfAutoUpdate, value) }
|
||||||
_otherSettings.value = otherSettings.value.copy(stateOfAutoUpdate = value)
|
_otherSettings.update { it.copy(stateOfAutoUpdate = value) }
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun setStateOfSensors(value: Boolean) {
|
override fun setStateOfSensors(value: Boolean) {
|
||||||
preferences.edit { putBoolean(keyStateOfSensors, value) }
|
preferences.edit { putBoolean(keyStateOfSensors, value) }
|
||||||
_otherSettings.value = otherSettings.value.copy(stateOfSensors = value)
|
_otherSettings.update { it.copy(stateOfSensors = value) }
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun setStateOfSweep(value: Boolean) {
|
override fun setStateOfSweep(value: Boolean) {
|
||||||
preferences.edit { putBoolean(keyStateOfSweep, value) }
|
preferences.edit { putBoolean(keyStateOfSweep, value) }
|
||||||
_otherSettings.value = otherSettings.value.copy(stateOfSweep = value)
|
_otherSettings.update { it.copy(stateOfSweep = value) }
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun setStateOfUtc(value: Boolean) {
|
override fun setStateOfUtc(value: Boolean) {
|
||||||
preferences.edit { putBoolean(keyStateOfUtc, value) }
|
preferences.edit { putBoolean(keyStateOfUtc, value) }
|
||||||
_otherSettings.value = otherSettings.value.copy(stateOfUtc = value)
|
_otherSettings.update { it.copy(stateOfUtc = value) }
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun setStateOfLightTheme(value: Boolean){
|
override fun setStateOfLightTheme(value: Boolean){
|
||||||
preferences.edit { putBoolean(keyStateOfLightTheme, value) }
|
preferences.edit { putBoolean(keyStateOfLightTheme, value) }
|
||||||
_otherSettings.value = otherSettings.value.copy(stateOfLightTheme = value)
|
_otherSettings.update { it.copy(stateOfLightTheme = value) }
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun setWarningDismissed() {
|
override fun setWarningDismissed() {
|
||||||
preferences.edit { putBoolean(keyShouldSeeWarning, false) }
|
preferences.edit { putBoolean(keyShouldSeeWarning, false) }
|
||||||
_otherSettings.value = otherSettings.value.copy(shouldSeeWarning = false)
|
_otherSettings.update { it.copy(shouldSeeWarning = false) }
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun setWelcomeDismissed() {
|
override fun setWelcomeDismissed() {
|
||||||
preferences.edit { putBoolean(keyShouldSeeWelcome, false) }
|
preferences.edit { putBoolean(keyShouldSeeWelcome, false) }
|
||||||
_otherSettings.value = otherSettings.value.copy(shouldSeeWelcome = false)
|
_otherSettings.update { it.copy(shouldSeeWelcome = false) }
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getOtherSettings(): OtherSettings = OtherSettings(
|
private fun getOtherSettings(): OtherSettings = OtherSettings(
|
||||||
@@ -274,30 +330,4 @@ class SettingsRepo(
|
|||||||
shouldSeeWelcome = preferences.getBoolean(keyShouldSeeWelcome, true)
|
shouldSeeWelcome = preferences.getBoolean(keyShouldSeeWelcome, true)
|
||||||
)
|
)
|
||||||
//endregion
|
//endregion
|
||||||
|
|
||||||
//region # Undefined settings
|
|
||||||
override fun getBluetoothAddress(): String = preferences.getString(keyBluetoothAddress, null) ?: "00:0C:BF:13:80:5D"
|
|
||||||
override fun setBluetoothAddress(value: String) = preferences.edit { putString(keyBluetoothAddress, value) }
|
|
||||||
|
|
||||||
override fun getBluetoothFormat(): String = preferences.getString(keyBluetoothFormat, null) ?: $$"W$AZ $EL"
|
|
||||||
override fun setBluetoothFormat(value: String) = preferences.edit { putString(keyBluetoothFormat, value) }
|
|
||||||
|
|
||||||
override fun getBluetoothName(): String = preferences.getString(keyBluetoothName, null) ?: "Default"
|
|
||||||
override fun setBluetoothName(value: String) = preferences.edit { putString(keyBluetoothName, value) }
|
|
||||||
|
|
||||||
override fun getBluetoothState(): Boolean = preferences.getBoolean(keyBluetoothState, false)
|
|
||||||
override fun setBluetoothState(value: Boolean) = preferences.edit { putBoolean(keyBluetoothState, value) }
|
|
||||||
|
|
||||||
override fun getRotatorAddress(): String = preferences.getString(keyRotatorAddress, null) ?: "127.0.0.1"
|
|
||||||
override fun setRotatorAddress(value: String) = preferences.edit { putString(keyRotatorAddress, value) }
|
|
||||||
|
|
||||||
override fun getRotatorPort(): String = preferences.getString(keyRotatorPort, null) ?: "4533"
|
|
||||||
override fun setRotatorPort(value: String) = preferences.edit { putString(keyRotatorPort, value) }
|
|
||||||
|
|
||||||
override fun getRotatorState(): Boolean = preferences.getBoolean(keyRotatorState, false)
|
|
||||||
override fun setRotatorState(value: Boolean) = preferences.edit { putBoolean(keyRotatorState, value) }
|
|
||||||
override fun onLocationChanged(location: Location) {
|
|
||||||
setStationPosition(location.latitude, location.longitude, location.altitude)
|
|
||||||
}
|
|
||||||
//endregion
|
|
||||||
}
|
}
|
||||||
@@ -12,6 +12,16 @@ data class PassesSettings(
|
|||||||
val selectedModes: List<String>
|
val selectedModes: List<String>
|
||||||
)
|
)
|
||||||
|
|
||||||
|
data class RCSettings(
|
||||||
|
val rotatorState: Boolean,
|
||||||
|
val rotatorAddress: String,
|
||||||
|
val rotatorPort: String,
|
||||||
|
val bluetoothState: Boolean,
|
||||||
|
val bluetoothFormat: String,
|
||||||
|
val bluetoothName: String,
|
||||||
|
val bluetoothAddress: String,
|
||||||
|
)
|
||||||
|
|
||||||
data class OtherSettings(
|
data class OtherSettings(
|
||||||
val stateOfAutoUpdate: Boolean,
|
val stateOfAutoUpdate: Boolean,
|
||||||
val stateOfSensors: Boolean,
|
val stateOfSensors: Boolean,
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ package com.rtbishop.look4sat.domain.repository
|
|||||||
import com.rtbishop.look4sat.domain.model.DatabaseState
|
import com.rtbishop.look4sat.domain.model.DatabaseState
|
||||||
import com.rtbishop.look4sat.domain.model.OtherSettings
|
import com.rtbishop.look4sat.domain.model.OtherSettings
|
||||||
import com.rtbishop.look4sat.domain.model.PassesSettings
|
import com.rtbishop.look4sat.domain.model.PassesSettings
|
||||||
|
import com.rtbishop.look4sat.domain.model.RCSettings
|
||||||
import com.rtbishop.look4sat.domain.predict.GeoPos
|
import com.rtbishop.look4sat.domain.predict.GeoPos
|
||||||
import kotlinx.coroutines.flow.StateFlow
|
import kotlinx.coroutines.flow.StateFlow
|
||||||
|
|
||||||
@@ -51,6 +52,17 @@ interface ISettingsRepo {
|
|||||||
fun updateDatabaseState(state: DatabaseState)
|
fun updateDatabaseState(state: DatabaseState)
|
||||||
//endregion
|
//endregion
|
||||||
|
|
||||||
|
//region # RC settings
|
||||||
|
val rcSettings: StateFlow<RCSettings>
|
||||||
|
fun setBluetoothAddress(value: String)
|
||||||
|
fun setBluetoothFormat(value: String)
|
||||||
|
fun setBluetoothName(value: String)
|
||||||
|
fun setBluetoothState(value: Boolean)
|
||||||
|
fun setRotatorAddress(value: String)
|
||||||
|
fun setRotatorPort(value: String)
|
||||||
|
fun setRotatorState(value: Boolean)
|
||||||
|
//endregion
|
||||||
|
|
||||||
//region # Other settings
|
//region # Other settings
|
||||||
val otherSettings: StateFlow<OtherSettings>
|
val otherSettings: StateFlow<OtherSettings>
|
||||||
fun setStateOfAutoUpdate(value: Boolean)
|
fun setStateOfAutoUpdate(value: Boolean)
|
||||||
@@ -61,21 +73,4 @@ interface ISettingsRepo {
|
|||||||
fun setWarningDismissed()
|
fun setWarningDismissed()
|
||||||
fun setWelcomeDismissed()
|
fun setWelcomeDismissed()
|
||||||
//endregion
|
//endregion
|
||||||
|
|
||||||
//region # Undefined settings
|
|
||||||
fun getBluetoothAddress(): String
|
|
||||||
fun setBluetoothAddress(value: String)
|
|
||||||
fun getBluetoothFormat(): String
|
|
||||||
fun setBluetoothFormat(value: String)
|
|
||||||
fun getBluetoothName(): String
|
|
||||||
fun setBluetoothName(value: String)
|
|
||||||
fun getBluetoothState(): Boolean
|
|
||||||
fun setBluetoothState(value: Boolean)
|
|
||||||
fun getRotatorAddress(): String
|
|
||||||
fun setRotatorAddress(value: String)
|
|
||||||
fun getRotatorPort(): String
|
|
||||||
fun setRotatorPort(value: String)
|
|
||||||
fun getRotatorState(): Boolean
|
|
||||||
fun setRotatorState(value: Boolean)
|
|
||||||
//endregion
|
|
||||||
}
|
}
|
||||||
@@ -5,16 +5,16 @@ kotlin = "2.2.21"
|
|||||||
|
|
||||||
androidx-core-ktx = "1.17.0"
|
androidx-core-ktx = "1.17.0"
|
||||||
androidx-core-splashscreen = "1.2.0"
|
androidx-core-splashscreen = "1.2.0"
|
||||||
androidx-room = "2.8.3"
|
androidx-room = "2.8.4"
|
||||||
|
|
||||||
compose-bom = "2025.11.00"
|
compose-bom = "2025.11.01"
|
||||||
compose-activity = "1.11.0"
|
compose-activity = "1.12.0"
|
||||||
compose-lifecycle = "2.9.4"
|
compose-lifecycle = "2.10.0"
|
||||||
compose-navigation = "2.9.6"
|
compose-navigation = "2.9.6"
|
||||||
|
|
||||||
other-coroutines = "1.10.2"
|
other-coroutines = "1.10.2"
|
||||||
other-json = "20250517"
|
other-json = "20250517"
|
||||||
other-okhttp = "5.3.0"
|
other-okhttp = "5.3.2"
|
||||||
other-osmdroid = "6.1.20"
|
other-osmdroid = "6.1.20"
|
||||||
|
|
||||||
test-junit4 = "4.13.2"
|
test-junit4 = "4.13.2"
|
||||||
|
|||||||
Reference in new issue
Block a user