Navigation state & location observer
This commit is contained in:
parent
b5cc580cf8
commit
9a553cf563
5 changed files with 70 additions and 21 deletions
|
@ -5,10 +5,12 @@ import android.bluetooth.BluetoothAdapter
|
|||
import android.bluetooth.BluetoothDevice
|
||||
import android.bluetooth.BluetoothSocket
|
||||
import android.util.Log
|
||||
import com.mapbox.navigation.core.trip.session.LocationMatcherResult
|
||||
import com.mapbox.navigation.core.trip.session.NavigationSessionState
|
||||
import com.mapbox.navigation.ui.maneuver.model.Maneuver
|
||||
import eu.ztsh.garmin.data.DataCache
|
||||
import eu.ztsh.garmin.data.GarminMapper
|
||||
import eu.ztsh.garmin.data.ManeuverMapper
|
||||
import eu.ztsh.garmin.data.MapboxMapper
|
||||
import java.io.IOException
|
||||
import java.util.*
|
||||
import java.util.concurrent.SynchronousQueue
|
||||
|
@ -34,44 +36,56 @@ class Garmin(
|
|||
}
|
||||
|
||||
fun process(maneuver: Maneuver) {
|
||||
processing = ProcessingThread(maneuver)
|
||||
processing = ManeuverProcessingThread(maneuver)
|
||||
processing.start()
|
||||
processing.join()
|
||||
}
|
||||
|
||||
fun process(location: LocationMatcherResult) {
|
||||
processing = LocationProcessingThread(location)
|
||||
processing.start()
|
||||
processing.join()
|
||||
|
||||
}
|
||||
|
||||
private inner class ProcessingThread(val maneuver: Maneuver) : Thread() {
|
||||
fun process(navigationSessionState: NavigationSessionState) {
|
||||
cache.update(navigationSessionState)
|
||||
}
|
||||
|
||||
private inner class ManeuverProcessingThread(val maneuver: Maneuver) : ProcessingThread() {
|
||||
|
||||
override fun run() {
|
||||
if (cache.hasChanged(maneuver)) {
|
||||
cache.update(maneuver)
|
||||
send(ManeuverMapper.apply(maneuver))
|
||||
send(MapboxMapper.apply(maneuver))
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private inner class LocationProcessingThread(val location: LocationMatcherResult) : ProcessingThread() {
|
||||
|
||||
override fun run() {
|
||||
if (cache.hasChanged(location)) {
|
||||
cache.update(location)
|
||||
send(MapboxMapper.apply(location))
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private open inner class ProcessingThread : Thread() {
|
||||
|
||||
fun send(incoming: eu.ztsh.garmin.data.State) {
|
||||
if (cache.hasChanged(incoming.distance)) {
|
||||
setDistance(incoming)
|
||||
connection.enqueue(GarminMapper.setDistance(incoming))
|
||||
}
|
||||
if (cache.hasChanged(incoming.direction)) {
|
||||
setDirection(incoming)
|
||||
connection.enqueue(GarminMapper.setDirection(incoming))
|
||||
}
|
||||
cache.update(incoming)
|
||||
}
|
||||
|
||||
private fun setLines(state: eu.ztsh.garmin.data.State) {
|
||||
|
||||
}
|
||||
|
||||
private fun setDistance(state: eu.ztsh.garmin.data.State) {
|
||||
connection.enqueue(GarminMapper.setDistance(state))
|
||||
}
|
||||
|
||||
private fun setDirection(direction: eu.ztsh.garmin.data.State) {
|
||||
connection.enqueue(GarminMapper.setDirection(direction))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private inner class ConnectThread : Thread() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue