Route color

This commit is contained in:
Garth Vander Houwen 2023-11-22 00:36:05 -08:00
parent 926ea1ea67
commit 787b7907a6
3 changed files with 35 additions and 8 deletions

View file

@ -37,5 +37,13 @@ extension UIColor {
private func add(_ value: CGFloat, toComponent: CGFloat) -> CGFloat {
return max(0, min(1, toComponent + value))
}
static var random: UIColor {
return UIColor(
red: .random(in: 0...1),
green: .random(in: 0...1),
blue: .random(in: 0...1),
alpha: 1.0
)
}
}

View file

@ -285,8 +285,9 @@
<relationship name="rangeTestConfigNode" optional="YES" maxCount="1" deletionRule="Nullify" destinationEntity="NodeInfoEntity" inverseName="rangeTestConfig" inverseEntity="NodeInfoEntity"/>
</entity>
<entity name="RouteEntity" representedClassName="RouteEntity" syncable="YES" codeGenerationType="class">
<attribute name="color" optional="YES" attributeType="Integer 32" defaultValueString="0" usesScalarValueType="YES"/>
<attribute name="color" optional="YES" attributeType="Integer 64" defaultValueString="0" usesScalarValueType="YES"/>
<attribute name="date" optional="YES" attributeType="Date" usesScalarValueType="NO"/>
<attribute name="enabled" optional="YES" attributeType="Boolean" defaultValueString="NO" usesScalarValueType="YES"/>
<attribute name="id" optional="YES" attributeType="Integer 32" defaultValueString="0" usesScalarValueType="YES"/>
<attribute name="name" optional="YES" attributeType="String"/>
<attribute name="notes" optional="YES" attributeType="String"/>

View file

@ -26,6 +26,10 @@ struct Routes: View {
Button("Import Route") {
importing = true
}
.buttonStyle(.bordered)
.buttonBorderShape(.capsule)
.controlSize(.large)
.padding()
.fileImporter(
isPresented: $importing,
allowedContentTypes: [.commaSeparatedText],
@ -54,9 +58,9 @@ struct Routes: View {
}
if latIndex >= 0 && longIndex >= 0 {
let newRoute = RouteEntity(context: context)
newRoute.name = ("\(String(routeName)) - \(Date().formatted())")
newRoute.name = String(routeName)
newRoute.id = Int32.random(in: Int32(Int8.max) ... Int32.max)
newRoute.color = 12
newRoute.color = Int64(UIColor.random.hex)
newRoute.date = Date()
var newLocations = [LocationEntity]()
lines.dropFirst().forEach { line in
@ -90,8 +94,22 @@ struct Routes: View {
VStack {
List(routes, id: \.self, selection: $selectedRoute) { route in
Text(route.name ?? "No Name Route")
.font(.title)
Label {
VStack (alignment: .leading) {
Text("\(route.name ?? "No Name Route")")
.padding(.top)
.foregroundStyle(.primary)
Text("\(route.date?.formatted() ?? "Unknown Time")")
.padding(.bottom)
.font(.callout)
.foregroundColor(.gray)
}
} icon: {
RoundedRectangle(cornerRadius: 10)
.fill(Color(UIColor(hex: route.color >= 0 ? UInt32(route.color) : 0)))
.frame(width: 20, height: 20)
}
}
.listStyle(.plain)
}
@ -128,11 +146,11 @@ struct Routes: View {
lineCap: .round, lineJoin: .round, dash: [7, 10]
)
MapPolyline(coordinates: lineCoords)
.stroke(.green, style: dashed)
.stroke(Color(UIColor(hex: UInt32(selectedRoute?.color ?? 0))), style: dashed)
}
.frame(maxWidth: .infinity, maxHeight: .infinity)
}
}.navigationTitle(" \(selectedRoute?.name ?? "Unknown Route") Map")
}.navigationTitle(" \(selectedRoute?.name ?? "Unknown Route") \(selectedRoute?.locations?.count ?? 0) points")
}
}
}