Skip to content

Commit 386b401

Browse files
authored
Merge pull request #10 from nbschultz97/codex/convert-fetchflightdata-to-suspend-function-wocofw
2 parents 3211f9a + 28fb5ac commit 386b401

1 file changed

Lines changed: 16 additions & 1 deletion

File tree

app/src/main/java/com/example/dronedetect/DroneSignalDetector.kt

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,34 @@ import android.content.Intent
66
import android.net.wifi.WifiManager
77
import android.os.Handler
88
import android.os.Looper
9+
import kotlinx.coroutines.CoroutineScope
10+
import kotlinx.coroutines.Dispatchers
11+
import kotlinx.coroutines.SupervisorJob
12+
import kotlinx.coroutines.cancel
13+
import kotlinx.coroutines.launch
14+
import kotlinx.coroutines.withContext
915

1016
class DroneSignalDetector(private val context: Context) {
1117
private val handler = Handler(Looper.getMainLooper())
1218
private val wifiManager = context.applicationContext.getSystemService(Context.WIFI_SERVICE) as WifiManager
1319
private val receiver = WifiScanReceiver()
20+
private val scope = CoroutineScope(SupervisorJob() + Dispatchers.IO)
1421

1522
fun startScan() {
16-
// TODO: implement scanning logic
23+
scope.launch {
24+
fetchFlightData()
25+
// TODO: implement scanning logic
26+
}
27+
}
28+
29+
suspend fun fetchFlightData() = withContext(Dispatchers.IO) {
30+
// TODO: implement fetching flight data
1731
}
1832

1933
fun stopScan() {
2034
handler.removeCallbacksAndMessages(null)
2135
context.unregisterReceiver(receiver)
36+
scope.cancel()
2237
}
2338
}
2439

0 commit comments

Comments
 (0)