refactor: extract NsdManager methods

This commit is contained in:
andrekir 2023-11-18 05:50:57 -03:00
parent f29d4e2309
commit e5a20c9665
3 changed files with 72 additions and 66 deletions

View file

@ -154,9 +154,6 @@ class BTScanModel @Inject constructor(
}
fun stopScan() {
// Stop Network Service Discovery (for TCP)
networkDiscovery?.cancel()
if (scanJob != null) {
debug("stopping scan")
try {
@ -170,14 +167,9 @@ class BTScanModel @Inject constructor(
} else _spinner.value = false
}
private var networkDiscovery: Job? = null
fun startScan(context: Context?) {
_spinner.value = true
// Start Network Service Discovery (find TCP devices)
networkDiscovery = networkRepository.networkDiscoveryFlow()
.launchIn(viewModelScope)
if (context != null) startCompanionScan(context) else startClassicScan()
}