Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add First Heard and Last Heard times to node details #777

Merged
merged 2 commits into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -7365,6 +7365,9 @@
}
}
}
},
"First heard" : {

},
"Five Minutes" : {

Expand Down Expand Up @@ -10797,6 +10800,9 @@
}
}
}
},
"Last heard" : {

},
"Latitude" : {

Expand Down Expand Up @@ -21713,7 +21719,6 @@

},
"unknown" : {
"extractionState" : "migrated",
"localizations" : {
"de" : {
"stringUnit" : {
Expand Down
6 changes: 4 additions & 2 deletions Meshtastic/Persistence/UpdateCoreData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,10 @@ func upsertNodeInfoPacket (packet: MeshPacket, context: NSManagedObjectContext)
let newNode = NodeInfoEntity(context: context)
newNode.id = Int64(packet.from)
newNode.num = Int64(packet.from)
newNode.firstHeard = Date(timeIntervalSince1970: TimeInterval(Int64(packet.rxTime)))
newNode.lastHeard = Date(timeIntervalSince1970: TimeInterval(Int64(packet.rxTime)))
if packet.rxTime != 0 {
newNode.firstHeard = Date(timeIntervalSince1970: TimeInterval(Int64(packet.rxTime)))
newNode.lastHeard = Date(timeIntervalSince1970: TimeInterval(Int64(packet.rxTime)))
}
newNode.snr = packet.rxSnr
newNode.rssi = packet.rxRssi
newNode.viaMqtt = packet.viaMqtt
Expand Down
7 changes: 3 additions & 4 deletions Meshtastic/Views/Helpers/LastHeardText.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import SwiftUI
//
struct LastHeardText: View {
var lastHeard: Date?
let sixMonthsAgo = Calendar.current.date(byAdding: .month, value: -6, to: Date())

static let formatter: RelativeDateTimeFormatter = {
let formatter = RelativeDateTimeFormatter()
Expand All @@ -16,10 +15,10 @@ struct LastHeardText: View {
}()

var body: some View {
if lastHeard != nil && lastHeard! >= sixMonthsAgo! {
Text(lastHeard?.formatted() ?? "unknown.age".localized)
if let lastHeard, lastHeard.timeIntervalSince1970 > 0, let text = Self.formatter.string(for: lastHeard) {
Text(text)
} else {
Text("unknown.age")
Text("unknown")
}
}
}
Expand Down
44 changes: 37 additions & 7 deletions Meshtastic/Views/Nodes/Helpers/NodeDetail.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ struct NodeDetail: View {

// The node the device is currently connected to
var connectedNode: NodeInfoEntity?

// The node information being displayed on the detail screen
@ObservedObject
var node: NodeInfoEntity

var columnVisibility = NavigationSplitViewVisibility.all

var favoriteNodeAction: some View {
Expand Down Expand Up @@ -96,6 +96,20 @@ struct NodeDetail: View {
.textSelection(.enabled)
}

if let metadata = node.metadata {
HStack {
Label {
Text("firmware.version")
} icon: {
Image(systemName: "memorychip")
.symbolRenderingMode(.multicolor)
}
Spacer()

Text(metadata.firmwareVersion ?? "unknown".localized)
}
}

if let dm = node.telemetries?.filtered(using: NSPredicate(format: "metricsType == 0")).lastObject as? TelemetryEntity, dm.uptimeSeconds > 0 {
HStack {
Label {
Expand All @@ -111,21 +125,37 @@ struct NodeDetail: View {
let later = now + TimeInterval(dm.uptimeSeconds)
let uptime = (now..<later).formatted(.components(style: .narrow))
Text(uptime)
.textSelection(.enabled)
.textSelection(.enabled)
}
}

if let metadata = node.metadata {
if let firstHeard = node.firstHeard {
HStack {
Label {
Text("firmware.version")
Text("First heard")
} icon: {
Image(systemName: "memorychip")
Image(systemName: "clock")
.symbolRenderingMode(.multicolor)
}
Spacer()

Text(metadata.firmwareVersion ?? "unknown".localized)
LastHeardText(lastHeard: firstHeard)
.textSelection(.enabled)
}
}

if let lastHeard = node.lastHeard {
HStack {
Label {
Text("Last heard")
} icon: {
Image(systemName: "clock.arrow.circlepath")
.symbolRenderingMode(.multicolor)
}
Spacer()

LastHeardText(lastHeard: lastHeard)
.textSelection(.enabled)
}
}
}
Expand Down
Loading