Skip to content

Commit

Permalink
IAQ legend popower
Browse files Browse the repository at this point in the history
  • Loading branch information
garthvh committed Jul 11, 2024
1 parent 3a248b6 commit cdf260e
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 45 deletions.
3 changes: 3 additions & 0 deletions Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -8530,6 +8530,9 @@
},
"Indoor Air Quality" : {

},
"Indoor Air Quality (IAQ)" : {

},
"inputevent.back" : {
"extractionState" : "migrated",
Expand Down
2 changes: 1 addition & 1 deletion Meshtastic.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -603,8 +603,8 @@
DD5E523E298F5A9E00D21B61 /* AirQualityIndex.swift */,
DDFEB3BA29900C1200EE7472 /* CurrentConditionsCompact.swift */,
DDA9515D2BC6F56F00CEA535 /* IndoorAirQuality.swift */,
DD41A61429AB0035003C5A37 /* NodeWeatherForecast.swift */,
DD354FD82BD96A0B0061A25F /* IAQScale.swift */,
DD41A61429AB0035003C5A37 /* NodeWeatherForecast.swift */,
);
path = Weather;
sourceTree = "<group>";
Expand Down
7 changes: 2 additions & 5 deletions Meshtastic/Views/Helpers/Weather/IAQScale.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ struct IAQScale: View {

var body: some View {
VStack(alignment: .leading) {
Text("Indoor Air Quality (IAQ)")
.font(.title3)
ForEach(Iaq.allCases) { iaq in
HStack {
RoundedRectangle(cornerRadius: 5)
Expand All @@ -22,11 +24,6 @@ struct IAQScale: View {
}
}
.padding()
.background(.thinMaterial, in: RoundedRectangle(cornerRadius: 20, style: .continuous))
// .overlay(
// RoundedRectangle(cornerRadius: 20)
// .stroke(.secondary, lineWidth: 5)
// )
}
}

Expand Down
87 changes: 49 additions & 38 deletions Meshtastic/Views/Helpers/Weather/IndoorAirQuality.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,59 +20,70 @@ enum IaqDisplayMode: Int, CaseIterable, Identifiable {
}

struct IndoorAirQuality: View {
@State var isLegendOpen = false
var iaq: Int = 0
var displayMode: IaqDisplayMode = .pill
let gradient = Gradient(colors: [.green, .mint, .yellow, .orange, .red, .purple, .purple, .brown, .brown, .brown, .brown])

var body: some View {
let iaqEnum = Iaq.getIaq(for: iaq)
switch displayMode {
case .pill:
ZStack(alignment: .leading) {
RoundedRectangle(cornerRadius: 10)
.fill(iaqEnum.color)
.frame(width: 125, height: 30)
Label("IAQ \(iaq)", systemImage: iaq < 100 ? "aqi.low" : ((iaq > 100 && iaq < 201) ? "aqi.medium" : "aqi.high"))
.padding(.leading, 4)
}
case .dot:
VStack {
HStack {
Text("\(iaq)")
Circle()
VStack {
switch displayMode {
case .pill:
ZStack(alignment: .leading) {
RoundedRectangle(cornerRadius: 10)
.fill(iaqEnum.color)
.frame(width: 10, height: 10)
.frame(width: 125, height: 30)
Label("IAQ \(iaq)", systemImage: iaq < 100 ? "aqi.low" : ((iaq > 100 && iaq < 201) ? "aqi.medium" : "aqi.high"))
.padding(.leading, 4)
}
}
case .text:
Text(iaqEnum.description)
.font(.caption)
case .gauge:
Gauge(value: Double(iaq), in: 0...500) {

case .dot:
VStack {
HStack {
Text("\(iaq)")
Circle()
.fill(iaqEnum.color)
.frame(width: 10, height: 10)
}
}
case .text:
Text(iaqEnum.description)
.font(.caption)
case .gauge:
Gauge(value: Double(iaq), in: 0...500) {
Text("IAQ")
.foregroundColor(iaqEnum.color)
} currentValueLabel: {
Text("\(Int(iaq))")
}
.tint(gradient)
.gaugeStyle(.accessoryCircular)
case .gradient:
HStack {
Gauge(value: Double(iaq), in: 0...500) {
Text("IAQ")
.foregroundColor(iaqEnum.color)
} currentValueLabel: {
Text("\(Int(iaq))")
Text("IAQ ")+Text("\(Int(iaq))")
.foregroundColor(.gray)
}
.tint(gradient)
.gaugeStyle(.accessoryCircular)
case .gradient:
HStack {
Gauge(value: Double(iaq), in: 0...500) {
Text("IAQ")
.foregroundColor(iaqEnum.color)
} currentValueLabel: {
Text("IAQ ")+Text("\(Int(iaq))")
.foregroundColor(.gray)
}
.tint(gradient)
.gaugeStyle(.accessoryLinear)
Text(iaqEnum.description)
.font(.caption)
.gaugeStyle(.accessoryLinear)
Text(iaqEnum.description)
.font(.caption)
}
.padding([.leading, .trailing])
}
.padding([.leading, .trailing])
}
.onTapGesture {
isLegendOpen.toggle()
}
.popover(isPresented: self.$isLegendOpen, arrowEdge: .bottom, content: {
VStack(spacing: 0.5) {
IAQScale()
}
.presentationCompactAdaptation(.popover)
})
}
}

Expand Down
2 changes: 2 additions & 0 deletions Meshtastic/Views/Nodes/Helpers/NodeInfoItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ struct NodeInfoItem: View {

var body: some View {
HStack {
Spacer()
CircleText(
text: node.user?.shortName ?? "?",
color: Color(UIColor(hex: UInt32(node.num))),
Expand Down Expand Up @@ -68,6 +69,7 @@ struct NodeInfoItem: View {
BatteryGauge(node: node)
.padding()
}
Spacer()
}
.padding(.leading)
}
Expand Down
2 changes: 1 addition & 1 deletion protobufs

0 comments on commit cdf260e

Please sign in to comment.