fix: Throw no error on connection error
This commit is contained in:
parent
bb9a497a73
commit
b5e9601065
2 changed files with 42 additions and 11 deletions
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue