fix: Throw no error on connection error

This commit is contained in:
Piotr Dec 2024-07-14 18:47:47 +02:00
parent bb9a497a73
commit b5e9601065
Signed by: stawros
GPG key ID: F89F27AD8F881A91
2 changed files with 42 additions and 11 deletions

View file

@ -10,7 +10,6 @@ import java.io.IOException
import java.util.*
import java.util.concurrent.SynchronousQueue
@SuppressLint("MissingPermission")
class Garmin(
val context: MainActivity,
@ -100,14 +99,26 @@ class Garmin(
// Cancel discovery because it otherwise slows down the connection.
context.checkBt()
adapter.cancelDiscovery()
socket?.connect()
sleep(3000)
readAll()
while (true) {
val newCurrent = Optional.ofNullable(queue.poll()).orElse(current)
current = newCurrent
send(current)
sleep(900)
try {
socket?.connect()
context.setConnectionStatus(true)
sleep(3000)
readAll()
while (true) {
val newCurrent = Optional.ofNullable(queue.poll()).orElse(current)
current = newCurrent
send(current)
sleep(900)
}
} catch (e: IOException) {
Log.d(TAG, "Not connected", e)
context.setConnectionStatus(false)
while (true) {
// Just dequeue
// TODO: Add option to reconnect
queue.poll()
sleep(900)
}
}
}