Satellite tracker and pass predictor for Android, inspired by Gpredict
Kotlin amsatcelestrakgpsham-radiohamlibhamradiokotlinnasaradiosatellitesatellite-datasatellite-positionsatellite-predictionsatellitessatnogssdrspacespacexstarlink
Refactor "Disconnect" and "Track" logic
Rui Oliveiraf9b1a97a37ed
diff --git a/core/data/src/main/java/com/rtbishop/look4sat/core/data/framework/Ic705Controller.kt b/core/data/src/main/java/com/rtbishop/look4sat/core/data/framework/Ic705Controller.ktindex 860df4d5..4641e11f 100644--- a/core/data/src/main/java/com/rtbishop/look4sat/core/data/framework/Ic705Controller.kt+++ b/core/data/src/main/java/com/rtbishop/look4sat/core/data/framework/Ic705Controller.kt@@ -84,19 +84,21 @@ class Ic705Controller(}}- override suspend fun disconnect() = withContext(Dispatchers.IO) {- try {- inputStream?.close()- outputStream?.close()- socket?.close()- } catch (e: Exception) {- Log.e(tag, "Disconnect error: ${e.message}")- } finally {- inputStream = null- outputStream = null- socket = null- isConnected = false- Log.i(tag, "Disconnected from $deviceAddress")+ override suspend fun disconnect() {+ withContext(Dispatchers.IO) {+ try {+ inputStream?.close()+ outputStream?.close()+ socket?.close()+ } catch (e: Exception) {+ Log.e(tag, "Disconnect error: ${e.message}")+ } finally {+ inputStream = null+ outputStream = null+ socket = null+ isConnected = false+ Log.i(tag, "Disconnected from $deviceAddress")+ }}}diff --git a/core/data/src/main/java/com/rtbishop/look4sat/core/data/framework/RadioTrackingService.kt b/core/data/src/main/java/com/rtbishop/look4sat/core/data/framework/RadioTrackingService.ktindex 37d05d47..42ae5a5e 100644--- a/core/data/src/main/java/com/rtbishop/look4sat/core/data/framework/RadioTrackingService.kt+++ b/core/data/src/main/java/com/rtbishop/look4sat/core/data/framework/RadioTrackingService.kt@@ -31,6 +31,7 @@ import com.rtbishop.look4sat.core.domain.repository.RadioTrackingStateimport com.rtbishop.look4sat.core.domain.utility.TransponderMapperimport kotlinx.coroutines.CoroutineScopeimport kotlinx.coroutines.Job+import kotlinx.coroutines.currentCoroutineContextimport kotlinx.coroutines.delayimport kotlinx.coroutines.flow.MutableStateFlowimport kotlinx.coroutines.flow.StateFlow@@ -189,7 +190,7 @@ class RadioTrackingService(var lastReadFreq = 0Lvar stableCount = 0- while (isActive) {+ while (currentCoroutineContext().isActive) {val currentState = _state.valueif (!currentState.isActive) break@@ -360,7 +361,7 @@ class RadioTrackingService(// After initial setup we never change VFO or band.// We only update the active-VFO frequency using CMD 0x25 sub 0x00.// The IC-705 automatically makes VFO-B active while PTT is pressed.- while (isActive) {+ while (currentCoroutineContext().isActive) {val currentState = _state.valueif (!currentState.isActive) breakdiff --git a/feature/settings/src/main/java/com/rtbishop/look4sat/feature/settings/SettingsDialog.kt b/feature/settings/src/main/java/com/rtbishop/look4sat/feature/settings/SettingsDialog.ktindex 385f7a84..1dab7436 100644--- a/feature/settings/src/main/java/com/rtbishop/look4sat/feature/settings/SettingsDialog.kt+++ b/feature/settings/src/main/java/com/rtbishop/look4sat/feature/settings/SettingsDialog.kt@@ -473,12 +473,14 @@ fun RadioControlDialog(// If current baud rate is not in the new list, default to the first availableif (baudRate.intValue !in baudRates) baudRate.intValue = baudRates.first()- val pairedDevices = remember {- try {- val manager = context.getSystemService(Context.BLUETOOTH_SERVICE) as BluetoothManager- manager.adapter?.bondedDevices?.map { it.name ?: "Unknown" to it.address } ?: emptyList()- } catch (_: SecurityException) {- emptyList()+ val pairedDevices: List<Pair<String, String>> = remember {+ buildList {+ try {+ val manager = context.getSystemService(Context.BLUETOOTH_SERVICE) as BluetoothManager+ manager.adapter?.bondedDevices?.forEach {+ add(Pair(it.name ?: "Unknown", it.address ?: ""))+ }+ } catch (_: SecurityException) { }}}