Meshtastic-Apple/Meshtastic/Views/Nodes/Helpers/NodeInfo.swift
Blake McAnally 4d547e48db This change fixes several lint errors throughout the project, and moves the SwiftLint build phase to before compilation.
After this change, a developer can now clone the project and run without the build failing due to lint errors! 😃

* I ran `swiftlint --fix` to resolve many auto-correctable issues (mostly whitespace)
* Excluded the `Meshtastic/Protobufs` directory from lint, since that code is automatically generated.
* Converted some single letter method parameters to lowercase.
* Converted several instances `force_cast` to instead use `guard` or `if let` to unwrap optional values. During this change, some of the SwiftUI views became "too complex to be solved in a reasonable time", so I broke up the views into distinct sub-expressions.

I was able to build and run the app on an iOS simulator.
2024-05-31 21:48:50 -05:00

93 lines
2.4 KiB
Swift

//
// NodeInfoItem.swift
// Meshtastic
//
// Copyright(c) Garth Vander Houwen 9/9/23.
//
import SwiftUI
import CoreLocation
import MapKit
struct NodeInfoItem: View {
@ObservedObject var node: NodeInfoEntity
var body: some View {
Divider()
HStack {
VStack(alignment: .center) {
CircleText(text: node.user?.shortName ?? "?", color: Color(UIColor(hex: UInt32(node.num))), circleSize: 65)
}
if node.user != nil {
Divider()
VStack {
Image(node.user!.hwModel ?? "unset".localized)
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width: 75, height: 75)
.cornerRadius(5)
Text(String(node.user!.hwModel ?? "unset".localized))
.font(.caption2).fixedSize()
}
}
if node.snr != 0 {
Divider()
VStack(alignment: .center) {
let signalStrength = getLoRaSignalStrength(snr: node.snr, rssi: node.rssi, preset: ModemPresets.longModerate)
LoRaSignalStrengthIndicator(signalStrength: signalStrength)
Text("Signal \(signalStrength.description)").font(.footnote)
Text("SNR \(String(format: "%.2f", node.snr))dB")
.foregroundColor(getSnrColor(snr: node.snr, preset: ModemPresets.longModerate))
.font(.caption2)
Text("RSSI \(node.rssi)dB")
.foregroundColor(getRssiColor(rssi: node.rssi))
.font(.caption2)
}
}
let deviceMetrics = node.telemetries?.filtered(using: NSPredicate(format: "metricsType == 0"))
if deviceMetrics?.count ?? 0 >= 1 {
Divider()
let mostRecent = deviceMetrics?.lastObject as? TelemetryEntity
VStack(alignment: .center) {
BatteryGauge(batteryLevel: Double(mostRecent?.batteryLevel ?? 0))
if mostRecent?.voltage ?? 0 > 0 {
Text(String(format: "%.2f", mostRecent?.voltage ?? 0) + " V")
.font(.callout)
.foregroundColor(.gray)
.fixedSize()
}
}
}
}
Divider()
HStack(alignment: .center) {
VStack {
HStack {
Image(systemName: "number")
.font(.title2)
.foregroundColor(.accentColor)
.symbolRenderingMode(.hierarchical)
Text("Node Number:").font(.title2)
}
Text(String(node.num)).font(.title3).foregroundColor(.gray)
}
Divider()
VStack {
HStack {
Image(systemName: "person")
.font(.title2)
.foregroundColor(.accentColor)
.symbolRenderingMode(.hierarchical)
Text("User Id:").font(.title2)
}
Text(node.user?.userId ?? "?").font(.title3).foregroundColor(.gray)
}
}
Divider()
}
}