Better handle expires on waypoints, update waypoint annotations

This commit is contained in:
Garth Vander Houwen 2023-02-05 20:23:31 -08:00
parent 1cd9c8d350
commit fda42ecc15
4 changed files with 31 additions and 8 deletions

View file

@ -759,7 +759,8 @@ class BLEManager: NSObject, CBPeripheralDelegate, ObservableObject {
wayPointEntity.icon = Int64(waypoint.icon)
wayPointEntity.latitudeI = waypoint.latitudeI
wayPointEntity.longitudeI = waypoint.longitudeI
if waypoint.expire > 0 {
if waypoint.expire > 1 {
wayPointEntity.expire = Date.init(timeIntervalSince1970: Double(waypoint.expire))
} else {
wayPointEntity.expire = nil
@ -769,6 +770,11 @@ class BLEManager: NSObject, CBPeripheralDelegate, ObservableObject {
} else {
wayPointEntity.locked = 0
}
if wayPointEntity.created == nil {
wayPointEntity.created = Date()
} else {
wayPointEntity.lastUpdated = Date()
}
do {
try context!.save()
print("💾 Updated Waypoint from Waypoint App Packet From: \(fromNodeNum)")

View file

@ -806,9 +806,10 @@ func waypointPacket (packet: MeshPacket, context: NSManagedObjectContext) {
waypoint.locked = Int64(waypointMessage.lockedTo)
if waypointMessage.expire > 0 {
waypoint.expire = Date(timeIntervalSince1970: TimeInterval(Int64(waypointMessage.expire)))
}else {
waypoint.expire = nil
}
waypoint.created = Date()
waypoint.lastUpdated = Date()
do {
try context.save()
print("💾 Updated Node Waypoint App Packet For: \(waypoint.id)")
@ -825,8 +826,10 @@ func waypointPacket (packet: MeshPacket, context: NSManagedObjectContext) {
fetchedWaypoint[0].longitudeI = waypointMessage.longitudeI
fetchedWaypoint[0].icon = Int64(waypointMessage.icon)
fetchedWaypoint[0].locked = Int64(waypointMessage.lockedTo)
if waypointMessage.expire > 0 {
if waypointMessage.expire > 1 {
fetchedWaypoint[0].expire = Date(timeIntervalSince1970: TimeInterval(Int64(waypointMessage.expire)))
} else {
fetchedWaypoint[0].expire = nil
}
fetchedWaypoint[0].lastUpdated = Date()
do {

View file

@ -174,7 +174,21 @@ struct MapViewSwiftUI: UIViewRepresentable {
leftIcon.backgroundColor = UIColor(.accentColor)
annotationView.leftCalloutAccessoryView = leftIcon
let subtitle = UILabel()
subtitle.text = waypointAnnotation.longDescription
if subtitle.text?.count ?? 0 > 0 {
subtitle.text = (waypointAnnotation.longDescription ?? "") + "\n"
}
else {
subtitle.text = ""
}
if waypointAnnotation.created != nil {
subtitle.text! += "Created: \(waypointAnnotation.created?.formatted() ?? "Unknown") \n"
}
if waypointAnnotation.lastUpdated != nil {
subtitle.text! += "Updated: \(waypointAnnotation.lastUpdated?.formatted() ?? "Unknown") \n"
}
if waypointAnnotation.expire != nil {
subtitle.text! += "Expires: \(waypointAnnotation.expire?.formatted() ?? "Unknown") \n"
}
subtitle.numberOfLines = 0
annotationView.detailCalloutAccessoryView = subtitle
let editIcon = UIButton(type: .detailDisclosure)

View file

@ -151,8 +151,10 @@ struct WaypointFormView: View {
newWaypoint.lockedTo = UInt32(lockedTo)
}
}
if expire.timeIntervalSince1970 > 0 {
if expires {
newWaypoint.expire = UInt32(expire.timeIntervalSince1970)
} else {
newWaypoint.expire = 0
}
if bleManager.sendWaypoint(waypoint: newWaypoint) {
waypointId = 0
@ -198,9 +200,7 @@ struct WaypointFormView: View {
if waypointId > 0 {
newWaypoint.id = UInt32(waypointId)
} else {
newWaypoint.id = UInt32.random(in: UInt32(UInt8.max)..<UInt32.max)
}
}
newWaypoint.name = name.count > 0 ? name : "Dropped Pin"
newWaypoint.description_p = description
newWaypoint.latitudeI = Int32(coordinate.latitude * 1e7)