Improve final headphones checks and fix IllegalStateException if data changes between the final two checks.

This commit is contained in:
darken
2023-04-05 13:13:42 +02:00
committed by Matthias Urhahn
parent d3257d6c5e
commit 85900e5bff
@@ -174,8 +174,14 @@ class TroubleShooterFragmentVM @Inject constructor(
run {
progress("Checking all closeby headphones.")
var otherDevices = withTimeoutOrNull(STEP_TIME) {
podMonitor.devices.take(10).toList().flatten()
val otherDevices = withTimeoutOrNull(STEP_TIME) {
val start = System.currentTimeMillis()
podMonitor.devices
.take(10)
.takeWhile { System.currentTimeMillis() - start < STEP_TIME - 1000 }
.toList()
.flatten()
.distinctBy { it.address }
} ?: emptyList()
if (otherDevices.isEmpty()) {
@@ -189,18 +195,6 @@ class TroubleShooterFragmentVM @Inject constructor(
generalSettings.mainDeviceAddress.value = null
generalSettings.minimumSignalQuality.value = 0.25f
otherDevices = withTimeoutOrNull(STEP_TIME) {
withTimeoutOrNull(STEP_TIME) {
val start = System.currentTimeMillis()
podMonitor.devices
.take(10)
.takeWhile { System.currentTimeMillis() - start < STEP_TIME - 1000 }
.toList()
.flatten()
.distinctBy { it.address }
} ?: emptyList()
} ?: emptyList()
progress("Setting headphone with strongest signal as yours.")
generalSettings.mainDeviceModel.value = otherDevices.maxBy { it.signalQuality }.model