AeroToss: исправлен поиск после потери связи + убрана лишняя кнопка

- onBroadcastReceived: обновляет device если IP/name изменились
- Убрана FAB 'Обновить' внизу (осталась TextButton 'Обновить' справа)
- Устройства снова видят друг друга после переподключения
This commit is contained in:
2026-08-20 11:45:13 +03:00
parent 982419f37d
commit 32e4e6698e
2 changed files with 18 additions and 16 deletions
@@ -151,10 +151,20 @@ class TcpDiscovery(
if (remoteId == deviceId) return if (remoteId == deviceId) return
if (remoteServicePort == myServicePort) return if (remoteServicePort == myServicePort) return
// Skip if already known
if (discoveredDevices.containsKey(remoteId)) return
val host = pkt.address.hostAddress ?: return val host = pkt.address.hostAddress ?: return
// Update existing device if IP or name changed (e.g. after reconnect)
val existing = discoveredDevices[remoteId]
if (existing != null) {
if (existing.hostAddress != host || existing.name != remoteName) {
val updated = existing.copy(hostAddress = host, name = remoteName)
discoveredDevices[remoteId] = updated
_devices.value = discoveredDevices.values.toList()
}
return
}
// New device - query it
val device = queryRemote(host, remoteTcpPort) val device = queryRemote(host, remoteTcpPort)
if (device != null) { if (device != null) {
discoveredDevices[device.id] = device discoveredDevices[device.id] = device
@@ -35,19 +35,11 @@ fun HomeScreen(
) )
}, },
floatingActionButton = { floatingActionButton = {
Row(horizontalArrangement = Arrangement.spacedBy(16.dp)) { FloatingActionButton(
FloatingActionButton( onClick = onReceiveClick,
onClick = { manager.rescan() }, containerColor = MaterialTheme.colorScheme.secondaryContainer
containerColor = MaterialTheme.colorScheme.tertiaryContainer ) {
) { Text("Получить", style = MaterialTheme.typography.labelLarge)
Text("Обновить", style = MaterialTheme.typography.labelLarge)
}
FloatingActionButton(
onClick = onReceiveClick,
containerColor = MaterialTheme.colorScheme.secondaryContainer
) {
Text("Получить", style = MaterialTheme.typography.labelLarge)
}
} }
} }
) { padding -> ) { padding ->