From 0b4eb76eb4349f106b798afcb37428960ffd2baa Mon Sep 17 00:00:00 2001 From: Garth Vander Houwen Date: Sat, 19 Nov 2022 13:21:24 -0800 Subject: [PATCH] Make node list layout match contact list --- Meshtastic/Helpers/BLEManager.swift | 8 +-- .../Views/Messages/ChannelMessageList.swift | 2 +- Meshtastic/Views/Messages/Contacts.swift | 8 +-- Meshtastic/Views/Nodes/NodeList.swift | 71 ++++++++++--------- 4 files changed, 45 insertions(+), 44 deletions(-) diff --git a/Meshtastic/Helpers/BLEManager.swift b/Meshtastic/Helpers/BLEManager.swift index 6781cfac..2051809c 100644 --- a/Meshtastic/Helpers/BLEManager.swift +++ b/Meshtastic/Helpers/BLEManager.swift @@ -45,7 +45,7 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph var timeoutTimer: Timer? var timeoutTimerCount = 0 var positionTimer: Timer? - let broadcastNodeNum: UInt32 = 4294967295 + let emptyNodeNum: UInt32 = 4294967295 /* Meshtastic Service Details */ var TORADIO_characteristic: CBCharacteristic! @@ -606,7 +606,7 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph // MARK: Check for an All / Broadcast User and delete it as a transition to multi channel let fetchBCUserRequest: NSFetchRequest = NSFetchRequest.init(entityName: "UserEntity") - fetchBCUserRequest.predicate = NSPredicate(format: "num == %lld", Int64(broadcastNodeNum)) + fetchBCUserRequest.predicate = NSPredicate(format: "num == %lld", Int64(emptyNodeNum)) do { let fetchedUser = try context?.fetch(fetchBCUserRequest) as! [UserEntity] @@ -724,7 +724,7 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph if toUserNum > 0 { meshPacket.to = UInt32(toUserNum) } else { - meshPacket.to = 4294967295 + meshPacket.to = emptyNodeNum } meshPacket.channel = UInt32(channel) meshPacket.from = UInt32(fromUserNum) @@ -830,7 +830,7 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph var dataMessage = DataMessage() dataMessage.payload = try! positionPacket.serializedData() dataMessage.portnum = PortNum.positionApp - if destNum != broadcastNodeNum { + if destNum != emptyNodeNum { dataMessage.wantResponse = true } meshPacket.decoded = dataMessage diff --git a/Meshtastic/Views/Messages/ChannelMessageList.swift b/Meshtastic/Views/Messages/ChannelMessageList.swift index 8ed8fd43..aa8cfacc 100644 --- a/Meshtastic/Views/Messages/ChannelMessageList.swift +++ b/Meshtastic/Views/Messages/ChannelMessageList.swift @@ -35,7 +35,7 @@ struct ChannelMessageList: View { NavigationStack { ScrollViewReader { scrollView in ScrollView { - LazyVStack { + LazyVStack { ForEach( channel.allPrivateMessages ) { (message: MessageEntity) in let currentUser: Bool = (userSettings.preferredNodeNum == message.fromUser?.num ? true : false) if message.replyID > 0 { diff --git a/Meshtastic/Views/Messages/Contacts.swift b/Meshtastic/Views/Messages/Contacts.swift index 1e2bfed3..0832e3eb 100644 --- a/Meshtastic/Views/Messages/Contacts.swift +++ b/Meshtastic/Views/Messages/Contacts.swift @@ -35,11 +35,11 @@ struct Contacts: View { VStack { NavigationLink(destination: ChannelMessageList(channel: channel)) { - let mostRecent = channel.allPrivateMessages.last + let mostRecent = channel.allPrivateMessages.last(where: { $0.channel == channel.index }) let lastMessageTime = Date(timeIntervalSince1970: TimeInterval(Int64((mostRecent?.messageTimestamp ?? 0 )))) let lastMessageDay = Calendar.current.dateComponents([.day], from: lastMessageTime).day ?? 0 let currentDay = Calendar.current.dateComponents([.day], from: Date()).day ?? 0 - HStack { + //HStack { VStack(alignment: .leading) { HStack { CircleText(text: String(channel.index), color: .gray, circleSize: 52, fontSize: 40) @@ -80,7 +80,7 @@ struct Contacts: View { .frame(maxWidth: .infinity, alignment: .leading) } } - } + // } } } .frame(maxWidth: .infinity, maxHeight: 80, alignment: .leading) @@ -94,7 +94,7 @@ struct Contacts: View { ForEach(users) { (user: UserEntity) in if user.num != bleManager.userSettings?.preferredNodeNum ?? 0 { NavigationLink(destination: UserMessageList(user: user)) { - let mostRecent = user.num == bleManager.broadcastNodeNum ? user.messageList.last : user.messageList.last(where: { $0.toUser?.num ?? 0 != bleManager.broadcastNodeNum }) + let mostRecent = user.messageList.last let lastMessageTime = Date(timeIntervalSince1970: TimeInterval(Int64((mostRecent?.messageTimestamp ?? 0 )))) let lastMessageDay = Calendar.current.dateComponents([.day], from: lastMessageTime).day ?? 0 let currentDay = Calendar.current.dateComponents([.day], from: Date()).day ?? 0 diff --git a/Meshtastic/Views/Nodes/NodeList.swift b/Meshtastic/Views/Nodes/NodeList.swift index cfb81235..f15a2202 100644 --- a/Meshtastic/Views/Nodes/NodeList.swift +++ b/Meshtastic/Views/Nodes/NodeList.swift @@ -42,46 +42,47 @@ struct NodeList: View { let connected: Bool = (bleManager.connectedPeripheral != nil && bleManager.connectedPeripheral.num == node.num) VStack(alignment: .leading) { HStack { - CircleText(text: node.user?.shortName ?? "???", color: .gray, circleSize: 52, fontSize: 16).offset(y: 1).padding(.trailing, 5) - .offset(x: -15) - - Text(node.user?.longName ?? "Unknown").font(.headline).offset(x: -15) - } - .padding(.bottom, 5) - if connected { - HStack(alignment: .bottom) { - Image(systemName: "repeat.circle.fill") - .font(.title2) - .symbolRenderingMode(.hierarchical) - Text("Currently Connected").font(.callout) - } - .padding(.bottom, 2) - } - if node.positions?.count ?? 0 > 0 && (bleManager.connectedPeripheral != nil && bleManager.connectedPeripheral.num != node.num) { - HStack(alignment: .bottom) { - let lastPostion = node.positions!.reversed()[0] as! PositionEntity - let myCoord = CLLocation(latitude: LocationHelper.currentLocation.latitude, longitude: LocationHelper.currentLocation.longitude) - if lastPostion.coordinate != nil { - let nodeCoord = CLLocation(latitude: lastPostion.coordinate!.latitude, longitude: lastPostion.coordinate!.longitude) - let metersAway = nodeCoord.distance(from: myCoord) - Image(systemName: "lines.measurement.horizontal") - .font(.title3) + CircleText(text: node.user?.shortName ?? "???", color: .gray, circleSize: 52, fontSize: 16) + .padding(.trailing, 5) + VStack(alignment: .leading) { + Text(node.user?.longName ?? "Unknown").font(.headline) + .padding(.bottom, 2) + if connected { + HStack(alignment: .bottom) { + Image(systemName: "repeat.circle.fill") + .font(.title2) + .symbolRenderingMode(.hierarchical) + Text("Currently Connected").font(.callout) + } + .padding(.bottom, 2) + } + if node.positions?.count ?? 0 > 0 && (bleManager.connectedPeripheral != nil && bleManager.connectedPeripheral.num != node.num) { + HStack(alignment: .bottom) { + let lastPostion = node.positions!.reversed()[0] as! PositionEntity + let myCoord = CLLocation(latitude: LocationHelper.currentLocation.latitude, longitude: LocationHelper.currentLocation.longitude) + if lastPostion.coordinate != nil { + let nodeCoord = CLLocation(latitude: lastPostion.coordinate!.latitude, longitude: lastPostion.coordinate!.longitude) + let metersAway = nodeCoord.distance(from: myCoord) + Image(systemName: "lines.measurement.horizontal") + .font(.title3) + .symbolRenderingMode(.hierarchical) + + DistanceText(meters: metersAway).font(.subheadline) + } + } + .padding(.bottom, 2) + } + HStack(alignment: .bottom) { + Image(systemName: "clock.badge.checkmark.fill") + .font(.headline) .symbolRenderingMode(.hierarchical) - - DistanceText(meters: metersAway).font(.subheadline) + LastHeardText(lastHeard: node.lastHeard) + .font(.subheadline) } } - .padding(.bottom, 2) - } - HStack(alignment: .bottom) { - Image(systemName: "clock.badge.checkmark.fill") - .font(.headline) - .symbolRenderingMode(.hierarchical) - LastHeardText(lastHeard: node.lastHeard) - .font(.subheadline) + .frame(maxWidth: .infinity, alignment: .leading) } } - .padding([.leading, .top, .bottom]) } } }