From 069bc1f11bb612c13a33fdc0962a1ddc960b586e Mon Sep 17 00:00:00 2001 From: Garth Vander Houwen Date: Thu, 18 Jul 2024 11:26:17 -0700 Subject: [PATCH] Improved layout for phone single table cell --- Localizable.xcstrings | 17 ++--- Meshtastic.xcodeproj/project.pbxproj | 6 +- Meshtastic/Views/Helpers/BatteryCompact.swift | 68 +++++++++++++++++++ .../Views/Helpers/BatteryLevelCompact.swift | 56 +-------------- Meshtastic/Views/Nodes/DeviceMetricsLog.swift | 20 +++--- 5 files changed, 92 insertions(+), 75 deletions(-) create mode 100644 Meshtastic/Views/Helpers/BatteryCompact.swift diff --git a/Localizable.xcstrings b/Localizable.xcstrings index 014a5128..2227c21f 100644 --- a/Localizable.xcstrings +++ b/Localizable.xcstrings @@ -679,7 +679,7 @@ "Airtime" : { }, - "AirTm %@%%" : { + "Airtime %@%%" : { }, "Alert" : { @@ -1427,9 +1427,6 @@ }, "Barometric Pressure" : { - }, - "Batt %@%%" : { - }, "Battery Level %" : { @@ -2791,6 +2788,9 @@ }, "Channel Role" : { + }, + "Channel Utilization %@%% " : { + }, "channel.role.disabled" : { "extractionState" : "migrated", @@ -3090,9 +3090,6 @@ }, "CHG" : { - }, - "ChUtil %@%% " : { - }, "Clear" : { @@ -22291,9 +22288,6 @@ }, "Via Mqtt" : { - }, - "Volt %@ " : { - }, "voltage" : { "localizations" : { @@ -22352,6 +22346,9 @@ } } } + }, + "Voltage %@ " : { + }, "waiting" : { "localizations" : { diff --git a/Meshtastic.xcodeproj/project.pbxproj b/Meshtastic.xcodeproj/project.pbxproj index 6c090d2f..49bf08ef 100644 --- a/Meshtastic.xcodeproj/project.pbxproj +++ b/Meshtastic.xcodeproj/project.pbxproj @@ -68,6 +68,7 @@ DD3501892852FC3B000FC853 /* Settings.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD3501882852FC3B000FC853 /* Settings.swift */; }; DD354FD92BD96A0B0061A25F /* IAQScale.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD354FD82BD96A0B0061A25F /* IAQScale.swift */; }; DD3619152B1EF9F900C41C8C /* LocationsHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD3619142B1EF9F900C41C8C /* LocationsHandler.swift */; }; + DD3CC24C2C498D6C001BD3A2 /* BatteryCompact.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD3CC24B2C498D6C001BD3A2 /* BatteryCompact.swift */; }; DD3CC6B528E33FD100FA9159 /* ShareChannels.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD3CC6B428E33FD100FA9159 /* ShareChannels.swift */; }; DD3CC6BC28E366DF00FA9159 /* Meshtastic.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = DD3CC6BA28E366DF00FA9159 /* Meshtastic.xcdatamodeld */; }; DD3CC6BE28E4CD9800FA9159 /* BatteryGauge.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD3CC6BD28E4CD9800FA9159 /* BatteryGauge.swift */; }; @@ -248,12 +249,12 @@ 2519268F2C3CB44900249DF5 /* ClientHistoryButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ClientHistoryButton.swift; sourceTree = ""; }; 251926912C3CB52300249DF5 /* DeleteNodeButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DeleteNodeButton.swift; sourceTree = ""; }; 25AECD4E2C2F723200862C8E /* Localizable.xcstrings */ = {isa = PBXFileReference; lastKnownFileType = text.json.xcstrings; path = Localizable.xcstrings; sourceTree = ""; }; + 25C49D8F2C471AEA0024FBD1 /* Constants.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Constants.swift; sourceTree = ""; }; 25F5D5BD2C3F6D87008036E3 /* NavigationState.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NavigationState.swift; sourceTree = ""; }; 25F5D5BF2C3F6DA6008036E3 /* Router.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Router.swift; sourceTree = ""; }; 25F5D5C12C3F6E4B008036E3 /* AppState.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppState.swift; sourceTree = ""; }; 25F5D5C72C4375A8008036E3 /* MeshtasticTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = MeshtasticTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 25F5D5D02C4375DF008036E3 /* RouterTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RouterTests.swift; sourceTree = ""; }; - 25C49D8F2C471AEA0024FBD1 /* Constants.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Constants.swift; sourceTree = ""; }; 6D825E612C34786C008DBEE4 /* CommonRegex.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CommonRegex.swift; sourceTree = ""; }; 6DA39D8D2A92DC52007E311C /* MeshtasticAppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MeshtasticAppDelegate.swift; sourceTree = ""; }; 6DEDA5592A957B8E00321D2E /* DetectionSensorLog.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DetectionSensorLog.swift; sourceTree = ""; }; @@ -307,6 +308,7 @@ DD3619132B1EE20700C41C8C /* MeshtasticDataModelV21.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = MeshtasticDataModelV21.xcdatamodel; sourceTree = ""; }; DD3619142B1EF9F900C41C8C /* LocationsHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LocationsHandler.swift; sourceTree = ""; }; DD398EBD2B93F640002B4C51 /* MeshtasticDataModelV 29.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = "MeshtasticDataModelV 29.xcdatamodel"; sourceTree = ""; }; + DD3CC24B2C498D6C001BD3A2 /* BatteryCompact.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BatteryCompact.swift; sourceTree = ""; }; DD3CC6B428E33FD100FA9159 /* ShareChannels.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShareChannels.swift; sourceTree = ""; }; DD3CC6BB28E366DF00FA9159 /* MeshtasticDataModel.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = MeshtasticDataModel.xcdatamodel; sourceTree = ""; }; DD3CC6BD28E4CD9800FA9159 /* BatteryGauge.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BatteryGauge.swift; sourceTree = ""; }; @@ -882,6 +884,7 @@ isa = PBXGroup; children = ( DD3CC6BD28E4CD9800FA9159 /* BatteryGauge.swift */, + DD3CC24B2C498D6C001BD3A2 /* BatteryCompact.swift */, DDB75A222A13CDA9006ED576 /* BatteryLevelCompact.swift */, DD457187293C7E63000C49FB /* BLESignalStrengthIndicator.swift */, DD47E3D526F17ED900029299 /* CircleText.swift */, @@ -1320,6 +1323,7 @@ DDB75A112A059258006ED576 /* Url.swift in Sources */, DDAD49ED2AFB39DC00B4425D /* MeshMap.swift in Sources */, DD8169FB271F1F3A00F4AB02 /* MeshLog.swift in Sources */, + DD3CC24C2C498D6C001BD3A2 /* BatteryCompact.swift in Sources */, DD1B8F402B35E2F10022AABC /* GPSStatus.swift in Sources */, DD8ED9C52898D51F00B3B0AB /* NetworkConfig.swift in Sources */, DDC3B274283F411B00AC321C /* LastHeardText.swift in Sources */, diff --git a/Meshtastic/Views/Helpers/BatteryCompact.swift b/Meshtastic/Views/Helpers/BatteryCompact.swift new file mode 100644 index 00000000..d12d37e0 --- /dev/null +++ b/Meshtastic/Views/Helpers/BatteryCompact.swift @@ -0,0 +1,68 @@ +// +// BatteryCompact.swift +// Meshtastic +// +// Created by Garth Vander Houwen on 7/18/24. +// +import SwiftUI + +struct BatteryCompact: View { + @State var batteryLevel: Int32 + var font: Font + var iconFont: Font + var color: Color + + var body: some View { + HStack(alignment: .center, spacing: 0) { + if batteryLevel == 100 { + Image(systemName: "battery.100.bolt") + .font(iconFont) + .foregroundColor(color) + .symbolRenderingMode(.hierarchical) + } else if batteryLevel < 100 && batteryLevel > 74 { + Image(systemName: "battery.75") + .font(iconFont) + .foregroundColor(color) + .symbolRenderingMode(.hierarchical) + } else if batteryLevel < 75 && batteryLevel > 49 { + Image(systemName: "battery.50") + .font(iconFont) + .foregroundColor(color) + .symbolRenderingMode(.hierarchical) + } else if batteryLevel < 50 && batteryLevel > 14 { + Image(systemName: "battery.25") + .font(iconFont) + .foregroundColor(color) + .symbolRenderingMode(.hierarchical) + } else if batteryLevel < 15 && batteryLevel > 0 { + Image(systemName: "battery.0") + .font(iconFont) + .foregroundColor(color) + .symbolRenderingMode(.hierarchical) + } else if batteryLevel == 0 { + Image(systemName: "battery.0") + .font(iconFont) + .foregroundColor(.red) + .symbolRenderingMode(.hierarchical) + } else if batteryLevel > 100 { + Image(systemName: "powerplug") + .font(iconFont) + .foregroundColor(color) + .symbolRenderingMode(.hierarchical) + } + if batteryLevel > 100 { + Text("PWD") + .foregroundStyle(.gray) + .font(font) + } else if batteryLevel == 100 { + Text("CHG") + .foregroundStyle(.gray) + .font(font) + } else { + Text("\(batteryLevel)%") + .foregroundStyle(.gray) + .font(font) + } + } + } +} diff --git a/Meshtastic/Views/Helpers/BatteryLevelCompact.swift b/Meshtastic/Views/Helpers/BatteryLevelCompact.swift index 7bb2542c..e1354e23 100644 --- a/Meshtastic/Views/Helpers/BatteryLevelCompact.swift +++ b/Meshtastic/Views/Helpers/BatteryLevelCompact.swift @@ -19,61 +19,7 @@ struct BatteryLevelCompact: View { let mostRecent = deviceMetrics?.lastObject as? TelemetryEntity let batteryLevel = mostRecent?.batteryLevel ?? 0 if deviceMetrics?.count ?? 0 > 0 { - HStack(alignment: .center, spacing: 0) { - if batteryLevel == 100 { - Image(systemName: "battery.100.bolt") - .font(iconFont) - .foregroundColor(color) - .symbolRenderingMode(.hierarchical) - } else if batteryLevel < 100 && batteryLevel > 74 { - - Image(systemName: "battery.75") - .font(iconFont) - .foregroundColor(color) - .symbolRenderingMode(.hierarchical) - } else if batteryLevel < 75 && batteryLevel > 49 { - - Image(systemName: "battery.50") - .font(iconFont) - .foregroundColor(color) - .symbolRenderingMode(.hierarchical) - } else if batteryLevel < 50 && batteryLevel > 14 { - - Image(systemName: "battery.25") - .font(iconFont) - .foregroundColor(color) - .symbolRenderingMode(.hierarchical) - } else if batteryLevel < 15 && batteryLevel > 0 { - - Image(systemName: "battery.0") - .font(iconFont) - .foregroundColor(color) - .symbolRenderingMode(.hierarchical) - } else if batteryLevel == 0 { - Image(systemName: "battery.0") - .font(iconFont) - .foregroundColor(.red) - .symbolRenderingMode(.hierarchical) - } else if batteryLevel > 100 { - Image(systemName: "powerplug") - .font(iconFont) - .foregroundColor(color) - .symbolRenderingMode(.hierarchical) - } - if batteryLevel > 100 { - Text("PWD") - .foregroundStyle(.gray) - .font(font) - } else if batteryLevel == 100 { - Text("CHG") - .foregroundStyle(.gray) - .font(font) - } else { - Text("\(batteryLevel)%") - .foregroundStyle(.gray) - .font(font) - } - } + BatteryCompact(batteryLevel: batteryLevel, font: font, iconFont: iconFont, color: color) } } } diff --git a/Meshtastic/Views/Nodes/DeviceMetricsLog.swift b/Meshtastic/Views/Nodes/DeviceMetricsLog.swift index c14ff162..cd3163b8 100644 --- a/Meshtastic/Views/Nodes/DeviceMetricsLog.swift +++ b/Meshtastic/Views/Nodes/DeviceMetricsLog.swift @@ -35,7 +35,6 @@ struct DeviceMetricsLog: View { .sorted { $0.time! < $1.time! } if chartData.count > 0 { GroupBox(label: Label("\(deviceMetrics.count) Readings Total", systemImage: "chart.xyaxis.line")) { - Chart { ForEach(chartData, id: \.self) { point in Plot { @@ -104,18 +103,21 @@ struct DeviceMetricsLog: View { TableColumn("battery.level") { dm in HStack { Text(dm.time?.formattedDate(format: dateFormatString) ?? "unknown.age".localized) + .fontWeight(.semibold) Spacer() + Image(systemName: "bolt") + .symbolRenderingMode(.multicolor) + .foregroundStyle(.yellow) + Text("Voltage \(String(format: "%.2f", dm.voltage)) ") + .foregroundStyle(.gray) + BatteryCompact(batteryLevel: dm.batteryLevel, font: .caption, iconFont: .callout, color: .accentColor) } .font(.caption) HStack { - if dm.batteryLevel > 100 { - Text("PWD") - } else { - Text("Batt \(String(dm.batteryLevel))%") - } - Text("Volt \(String(format: "%.2f", dm.voltage)) ") - Text("ChUtil \(String(format: "%.2f", dm.channelUtilization))% ") - Text("AirTm \(String(format: "%.2f", dm.airUtilTx))%") + Text("Channel Utilization \(String(format: "%.2f", dm.channelUtilization))% ") + .foregroundColor(dm.channelUtilization < 25 ? .gray : (dm.channelUtilization > 50 ? .red : .orange)) + Text("Airtime \(String(format: "%.2f", dm.airUtilTx))%") + .foregroundColor(.gray) Spacer() } .font(.caption)