Formatting and cleanup

This commit is contained in:
Garth Vander Houwen 2023-09-16 13:58:04 -07:00
parent a5b86d6c14
commit 1122a5cbaf
3 changed files with 70 additions and 74 deletions

View file

@ -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")
}
}

View file

@ -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, *) {

View file

@ -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 {