mirror of
https://github.com/meshtastic/Meshtastic-Apple.git
synced 2026-04-20 22:13:56 +00:00
Delete button for waypoints
This commit is contained in:
parent
338cfa946f
commit
c819d21d89
4 changed files with 33 additions and 19 deletions
|
|
@ -9,7 +9,7 @@ import MapKit
|
|||
|
||||
struct MapViewSwiftUI: UIViewRepresentable {
|
||||
|
||||
var onLongPress: (_ waypointCoordinate: CLLocationCoordinate2D?, _ tag: Int ) -> Void
|
||||
var onLongPress: (_ waypointCoordinate: CLLocationCoordinate2D) -> Void
|
||||
var onWaypointEdit: (_ waypointId: Int ) -> Void
|
||||
let mapView = MKMapView()
|
||||
let positions: [PositionEntity]
|
||||
|
|
@ -172,7 +172,7 @@ struct MapViewSwiftUI: UIViewRepresentable {
|
|||
annotation.coordinate = coordinate
|
||||
parent.mapView.addAnnotation(annotation)
|
||||
UINotificationFeedbackGenerator().notificationOccurred(.success)
|
||||
parent.onLongPress(coordinate, 0)
|
||||
parent.onLongPress(coordinate)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ struct WaypointFormView: View {
|
|||
@State private var locked: Bool = false
|
||||
|
||||
var body: some View {
|
||||
|
||||
Form {
|
||||
let distance = CLLocation(latitude: LocationHelper.currentLocation.latitude, longitude: LocationHelper.currentLocation.longitude).distance(from: CLLocation(latitude: coordinate.latitude, longitude: coordinate.longitude))
|
||||
Section(header: Text((waypointId > 0) ? "Editing Waypoint" : "Create Waypoint")) {
|
||||
|
|
@ -132,7 +133,7 @@ struct WaypointFormView: View {
|
|||
} else {
|
||||
newWaypoint.id = UInt32.random(in: UInt32(UInt8.max)..<UInt32.max)
|
||||
}
|
||||
newWaypoint.name = name
|
||||
newWaypoint.name = name.count > 0 ? name : "Dropped Pin"
|
||||
newWaypoint.description_p = description
|
||||
newWaypoint.latitudeI = Int32(coordinate.latitude * 1e7)
|
||||
newWaypoint.longitudeI = Int32(coordinate.longitude * 1e7)
|
||||
|
|
@ -160,17 +161,36 @@ struct WaypointFormView: View {
|
|||
.buttonBorderShape(.capsule)
|
||||
.controlSize(.large)
|
||||
.disabled(bleManager.connectedPeripheral == nil)
|
||||
.padding()
|
||||
.padding(.bottom)
|
||||
|
||||
Button {
|
||||
Button(role:.cancel) {
|
||||
dismiss()
|
||||
} label: {
|
||||
Label("cancel", systemImage: "xmark")
|
||||
Label("cancel", systemImage: "x.circle")
|
||||
}
|
||||
.buttonStyle(.bordered)
|
||||
.buttonBorderShape(.capsule)
|
||||
.controlSize(.large)
|
||||
.padding()
|
||||
.padding(.bottom)
|
||||
|
||||
if waypointId > 0 {
|
||||
Button(role: .destructive) {
|
||||
let waypoint = getWaypoint(id: Int64(waypointId), context: bleManager.context!)
|
||||
bleManager.context!.delete(waypoint)
|
||||
do {
|
||||
try bleManager.context!.save()
|
||||
} catch {
|
||||
bleManager.context!.rollback()
|
||||
}
|
||||
dismiss()
|
||||
} label: {
|
||||
Label("delete", systemImage: "trash")
|
||||
}
|
||||
.buttonStyle(.bordered)
|
||||
.buttonBorderShape(.capsule)
|
||||
.controlSize(.large)
|
||||
.padding(.bottom)
|
||||
}
|
||||
}
|
||||
.onChange(of: waypointId) { newId in
|
||||
print(newId)
|
||||
|
|
|
|||
|
|
@ -48,13 +48,10 @@ struct NodeDetail: View {
|
|||
ZStack {
|
||||
let annotations = node.positions?.array as! [PositionEntity]
|
||||
ZStack {
|
||||
MapViewSwiftUI(onLongPress: { coord, id in
|
||||
MapViewSwiftUI(onLongPress: { coord in
|
||||
waypointCoordinate = coord
|
||||
|
||||
if waypointCoordinate != nil {
|
||||
editingWaypoint = 0
|
||||
presentingWaypointForm = true
|
||||
}
|
||||
editingWaypoint = 0
|
||||
presentingWaypointForm = true
|
||||
}, onWaypointEdit: { wpId in
|
||||
if wpId > 0 {
|
||||
editingWaypoint = wpId
|
||||
|
|
|
|||
|
|
@ -55,13 +55,10 @@ struct NodeMap: View {
|
|||
NavigationStack {
|
||||
ZStack {
|
||||
|
||||
MapViewSwiftUI(onLongPress: { coord, id in
|
||||
MapViewSwiftUI(onLongPress: { coord in
|
||||
waypointCoordinate = coord
|
||||
|
||||
if waypointCoordinate != nil {
|
||||
editingWaypoint = 0
|
||||
presentingWaypointForm = true
|
||||
}
|
||||
editingWaypoint = 0
|
||||
presentingWaypointForm = true
|
||||
}, onWaypointEdit: { wpId in
|
||||
if wpId > 0 {
|
||||
editingWaypoint = wpId
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue