From 1122a5cbaf25de8d90d04b5f0a2cbea4817d2474 Mon Sep 17 00:00:00 2001 From: Garth Vander Houwen Date: Sat, 16 Sep 2023 13:58:04 -0700 Subject: [PATCH] Formatting and cleanup --- Meshtastic/Views/Messages/UserList.swift | 124 +++++++++--------- .../Views/Nodes/Helpers/NodeDetail.swift | 2 +- .../Views/Nodes/Helpers/NodeMapSwiftUI.swift | 18 +-- 3 files changed, 70 insertions(+), 74 deletions(-) diff --git a/Meshtastic/Views/Messages/UserList.swift b/Meshtastic/Views/Messages/UserList.swift index 8f8d2c04..4cf0f135 100644 --- a/Meshtastic/Views/Messages/UserList.swift +++ b/Meshtastic/Views/Messages/UserList.swift @@ -21,7 +21,7 @@ struct UserList: View { searchText = newValue users.nsPredicate = newValue.isEmpty ? nil : NSPredicate(format: "longName CONTAINS[c] %@ OR shortName CONTAINS[c] %@", newValue, newValue) } - } + } @FetchRequest( sortDescriptors: [NSSortDescriptor(key: "lastMessage", ascending: false), NSSortDescriptor(key: "vip", ascending: false), NSSortDescriptor(key: "longName", ascending: true)], animation: .default) @@ -35,70 +35,67 @@ struct UserList: View { var body: some View { let localeDateFormat = DateFormatter.dateFormat(fromTemplate: "yyMMdd", options: 0, locale: Locale.current) let dateFormatString = (localeDateFormat ?? "MM/dd/YY") - VStack { List { ForEach(users) { (user: UserEntity) in - 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 if user.num != bleManager.connectedPeripheral?.num ?? 0 { + NavigationLink(destination: UserMessageList(user: user)) { + ZStack { + Image(systemName: "circle.fill") + .opacity(user.unreadMessages > 0 ? 1 : 0) + .font(.system(size: 10)) + .foregroundColor(.accentColor) + .brightness(0.2) + } - NavigationLink(destination: UserMessageList(user: user)) { - ZStack { - Image(systemName: "circle.fill") - .opacity(user.unreadMessages > 0 ? 1 : 0) - .font(.system(size: 10)) - .foregroundColor(.accentColor) - .brightness(0.2) - } - - CircleText(text: user.shortName ?? "?", color: Color(UIColor(hex: UInt32(user.num)))) - - VStack(alignment: .leading){ - HStack{ - Text(user.longName ?? "unknown".localized) - - Spacer() - if user.vip { - Image(systemName: "star.fill") - .foregroundColor(.secondary) - } - if user.messageList.count > 0 { - if lastMessageDay == currentDay { - Text(lastMessageTime, style: .time ) - .font(.system(size: 16)) - .foregroundColor(.secondary) - } else if lastMessageDay == (currentDay - 1) { - Text("Yesterday") - .font(.system(size: 16)) - .foregroundColor(.secondary) - } else if lastMessageDay < (currentDay - 1) && lastMessageDay > (currentDay - 5) { - Text(lastMessageTime.formattedDate(format: dateFormatString)) - .font(.system(size: 16)) - .foregroundColor(.secondary) - } else if lastMessageDay < (currentDay - 1800) { - Text(lastMessageTime.formattedDate(format: dateFormatString)) - .font(.system(size: 16)) - .foregroundColor(.secondary) - } - } - // Image(systemName: "chevron.forward") - // .font(.caption) - // .foregroundColor(.secondary) - } + CircleText(text: user.shortName ?? "?", color: Color(UIColor(hex: UInt32(user.num)))) + + VStack(alignment: .leading){ + HStack{ + Text(user.longName ?? "unknown".localized) + Spacer() + if user.vip { + Image(systemName: "star.fill") + .foregroundColor(.secondary) + } if user.messageList.count > 0 { - HStack(alignment: .top) { - Text("\(mostRecent != nil ? mostRecent!.messagePayload! : " ")") + if lastMessageDay == currentDay { + Text(lastMessageTime, style: .time ) + .font(.system(size: 16)) + .foregroundColor(.secondary) + } else if lastMessageDay == (currentDay - 1) { + Text("Yesterday") + .font(.system(size: 16)) + .foregroundColor(.secondary) + } else if lastMessageDay < (currentDay - 1) && lastMessageDay > (currentDay - 5) { + Text(lastMessageTime.formattedDate(format: dateFormatString)) + .font(.system(size: 16)) + .foregroundColor(.secondary) + } else if lastMessageDay < (currentDay - 1800) { + Text(lastMessageTime.formattedDate(format: dateFormatString)) .font(.system(size: 16)) .foregroundColor(.secondary) } } + // Image(systemName: "chevron.forward") + // .font(.caption) + // .foregroundColor(.secondary) + } + + if user.messageList.count > 0 { + HStack(alignment: .top) { + Text("\(mostRecent != nil ? mostRecent!.messagePayload! : " ")") + .font(.system(size: 16)) + .foregroundColor(.secondary) + } } } + } .frame(height: 62) .contextMenu { Button { @@ -145,28 +142,27 @@ struct UserList: View { isPresented: $isPresentingTraceRouteSentAlert ) { Button("OK", role: .cancel) { } + } message: { + Text("This could take a while, response will appear in the mesh log.") } - message: { - Text("This could take a while, response will appear in the mesh log.") - } - .confirmationDialog( - "This conversation will be deleted.", - isPresented: $isPresentingDeleteUserMessagesConfirm, - titleVisibility: .visible - ) { - Button(role: .destructive) { - deleteUserMessages(user: userSelection!, context: context) - context.refresh(node!.user!, mergeChanges: true) - UIApplication.shared.applicationIconBadgeNumber = appState.unreadChannelMessages + appState.unreadDirectMessages - } label: { - Text("delete") + .confirmationDialog( + "This conversation will be deleted.", + isPresented: $isPresentingDeleteUserMessagesConfirm, + titleVisibility: .visible + ) { + Button(role: .destructive) { + deleteUserMessages(user: userSelection!, context: context) + context.refresh(node!.user!, mergeChanges: true) + UIApplication.shared.applicationIconBadgeNumber = appState.unreadChannelMessages + appState.unreadDirectMessages + } label: { + Text("delete") + } } } - } } } .listStyle(.plain) - .navigationTitle(String.localizedStringWithFormat("contacts %@".localized, String(users.count))) + .navigationTitle(String.localizedStringWithFormat("contacts %@".localized, String(users.count == 0 ? 0 : users.count - 1))) .searchable(text: usersQuery, prompt: "Find a contact") } } diff --git a/Meshtastic/Views/Nodes/Helpers/NodeDetail.swift b/Meshtastic/Views/Nodes/Helpers/NodeDetail.swift index a5b45aa9..4c889031 100644 --- a/Meshtastic/Views/Nodes/Helpers/NodeDetail.swift +++ b/Meshtastic/Views/Nodes/Helpers/NodeDetail.swift @@ -12,7 +12,6 @@ struct NodeDetail: View { @Environment(\.managedObjectContext) var context @EnvironmentObject var bleManager: BLEManager - @Environment(\.colorScheme) var colorScheme: ColorScheme @State private var showingShutdownConfirm: Bool = false @State private var showingRebootConfirm: Bool = false @@ -39,6 +38,7 @@ struct NodeDetail: View { .font(.title3) } .disabled(!node.hasDeviceMetrics) + Divider() NavigationLink { if #available (iOS 17, macOS 14, *) { diff --git a/Meshtastic/Views/Nodes/Helpers/NodeMapSwiftUI.swift b/Meshtastic/Views/Nodes/Helpers/NodeMapSwiftUI.swift index e7cd33cf..26c45a0a 100644 --- a/Meshtastic/Views/Nodes/Helpers/NodeMapSwiftUI.swift +++ b/Meshtastic/Views/Nodes/Helpers/NodeMapSwiftUI.swift @@ -46,7 +46,7 @@ struct NodeMapSwiftUI: View { if node.hasPositions { ZStack { - Map(position: $position, bounds: MapCameraBounds(minimumDistance: 100, maximumDistance: .infinity), scope: mapScope) { + Map(position: $position, bounds: MapCameraBounds(minimumDistance: 1, maximumDistance: .infinity), scope: mapScope) { /// Route Lines if showRouteLines { let gradient = LinearGradient( @@ -79,10 +79,10 @@ struct NodeMapSwiftUI: View { .background(Color(UIColor(hex: UInt32(node.num)).darker())) .clipShape(Circle()) .rotationEffect(.degrees(Double(position.heading))) - .onTapGesture { - selected = (selected == position ? nil : position) // <-- here - print("tapity tap tap \(position.time)") - } +// .onTapGesture { +// selected = (selected == position ? nil : position) // <-- here +// print("tapity tap tap \(position.time)") +// } } else { Image(systemName: "flipphone") .symbolEffect(.pulse.byLayer) @@ -90,10 +90,10 @@ struct NodeMapSwiftUI: View { .foregroundStyle(Color(nodeColor).isLight() ? .black : .white) .background(Color(UIColor(hex: UInt32(node.num)).darker())) .clipShape(Circle()) - .onTapGesture { - selected = (selected == position ? nil : position) // <-- here - print("tapity tap tap \(position.time)") - } +// .onTapGesture { +// selected = (selected == position ? nil : position) // <-- here +// print("tapity tap tap \(position.time)") +// } } } else { if showNodeHistory {