Merge pull request #207 from meshtastic/1.3.43_Protos

Clean up message views
This commit is contained in:
Garth Vander Houwen 2022-10-15 01:01:10 -07:00 committed by GitHub
commit 6e6bf55130
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 67 additions and 84 deletions

View file

@ -45,7 +45,7 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph
var timeoutTimer: Timer?
var timeoutTimerCount = 0
var positionTimer: Timer?
let broadcastNodeNum: UInt32 = 0
let broadcastNodeNum: UInt32 = 4294967295
/* Meshtastic Service Details */
var TORADIO_characteristic: CBCharacteristic!

View file

@ -23,15 +23,14 @@ struct Contacts: View {
animation: .default)
private var nodes: FetchedResults<NodeInfoEntity>
@State private var selection: UserEntity? = nil // Nothing selected by default.
var body: some View {
NavigationView {
NavigationSplitView {
List {
Section(header: Text("Primary Channel")) {
ForEach(users) { (user: UserEntity) in
if user.num != bleManager.userSettings?.preferredNodeNum ?? 0 {
@ -40,26 +39,21 @@ struct Contacts: View {
if user.messageList.count > 0 {
let mostRecent = user.messageList.last
let lastMessageTime = Date(timeIntervalSince1970: TimeInterval(Int64((mostRecent!.messageTimestamp ))))
let mostRecent = user.num == bleManager.broadcastNodeNum ? user.messageList.last : user.messageList.last(where: { $0.toUser?.num ?? 0 != bleManager.broadcastNodeNum })
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 {
VStack {
CircleText(text: user.shortName ?? "???", color: Color.blue)
}
.padding([.leading, .trailing])
VStack {
HStack {
VStack {
Text(user.longName ?? "Unknown").font(.headline).fixedSize()
}
VStack {
if lastMessageDay == currentDay {
@ -73,11 +67,8 @@ struct Contacts: View {
.foregroundColor(.gray)
} else if lastMessageDay < (currentDay - 1) && lastMessageDay > (currentDay - 5) {
Text(lastMessageTime, style: .date)
} else {
} else if lastMessageDay < (currentDay - 1800) {
Text(lastMessageTime, style: .date)
}
}
@ -86,8 +77,7 @@ struct Contacts: View {
.listRowSeparator(.hidden).frame(height: 5)
HStack(alignment: .top) {
Text(mostRecent!.messagePayload ?? "Empty Message")
Text("\(mostRecent != nil ? mostRecent!.messagePayload! : " ")")
.frame(height: 60)
.truncationMode(.tail)
.foregroundColor(Color.gray)
@ -132,6 +122,16 @@ struct Contacts: View {
MeshtasticLogo()
)
}
.listStyle(PlainListStyle())
detail: {
if let user = selection {
MessageList(user:user)
} else {
Text("Select a user")
}
}
}
}

View file

@ -36,7 +36,7 @@ struct MessageList: View {
var body: some View {
VStack {
NavigationStack {
ScrollViewReader { scrollView in
@ -46,31 +46,25 @@ struct MessageList: View {
ForEach( user.messageList ) { (message: MessageEntity) in
if user.num != userSettings.preferredNodeNum {
let currentUser: Bool = (bleManager.connectedPeripheral == nil) ? false : ((bleManager.connectedPeripheral != nil && bleManager.connectedPeripheral.num == message.fromUser?.num) ? true : false )
let currentUser: Bool = (userSettings.preferredNodeNum == message.fromUser?.num ? true : false)
if (message.toUser!.num == Int64(bleManager.broadcastNodeNum) || userSettings.preferredNodeNum == message.fromUser?.num) {
if message.replyID > 0 {
let messageReply = user.messageList.first(where: { $0.messageId == message.replyID })
HStack {
Text(messageReply?.messagePayload ?? "EMPTY MESSAGE").foregroundColor(.blue).font(.caption2)
.padding(10)
.overlay(
RoundedRectangle(cornerRadius: 18)
.stroke(Color.blue, lineWidth: 0.5)
)
Image(systemName: "arrowshape.turn.up.left.fill")
.symbolRenderingMode(.hierarchical)
.imageScale(.large).foregroundColor(.blue)
.padding(.trailing)
if (user.num == bleManager.broadcastNodeNum || user.num != bleManager.broadcastNodeNum && message.toUser!.num != bleManager.broadcastNodeNum) {
if message.replyID > 0 {
let messageReply = user.messageList.first(where: { $0.messageId == message.replyID })
HStack {
Text(messageReply?.messagePayload ?? "EMPTY MESSAGE").foregroundColor(.blue).font(.caption2)
.padding(10)
.overlay(
RoundedRectangle(cornerRadius: 18)
.stroke(Color.blue, lineWidth: 0.5)
)
Image(systemName: "arrowshape.turn.up.left.fill")
.symbolRenderingMode(.hierarchical)
.imageScale(.large).foregroundColor(.blue)
.padding(.trailing)
}
}
}
HStack (alignment: .top) {
HStack (alignment: .top) {
if currentUser { Spacer(minLength:50) }
@ -329,37 +323,37 @@ struct MessageList: View {
Spacer(minLength:50)
}
}
.padding([.leading, .trailing])
.frame(maxWidth: .infinity)
.id(message.messageId)
.alert(isPresented: $showDeleteMessageAlert) {
Alert(title: Text("Are you sure you want to delete this message?"), message: Text("This action is permanent."),
primaryButton: .destructive(Text("Delete")) {
print("OK button tapped")
if deleteMessageId > 0 {
let message = user.messageList.first(where: { $0.messageId == deleteMessageId })
context.delete(message!)
do {
try context.save()
.padding([.leading, .trailing])
.frame(maxWidth: .infinity)
.id(message.messageId)
.alert(isPresented: $showDeleteMessageAlert) {
Alert(title: Text("Are you sure you want to delete this message?"), message: Text("This action is permanent."), primaryButton: .destructive(Text("Delete")) {
print("OK button tapped")
if deleteMessageId > 0 {
deleteMessageId = 0
let message = user.messageList.first(where: { $0.messageId == deleteMessageId })
} catch {
print("Failed to delete message \(deleteMessageId)")
context.delete(message!)
do {
try context.save()
deleteMessageId = 0
} catch {
print("Failed to delete message \(deleteMessageId)")
}
}
}
},
secondaryButton: .cancel()
)
},
secondaryButton: .cancel()
)
}
}
}
}
}
.listRowSeparator(.hidden)
}
}
.padding([.top, .bottom])
.scrollDismissesKeyboard(.immediately)
.onAppear(perform: {

View file

@ -10,13 +10,9 @@ struct MQTTConfig: View {
@Environment(\.managedObjectContext) var context
@EnvironmentObject var bleManager: BLEManager
var node: NodeInfoEntity?
@State private var isPresentingSaveConfirm: Bool = false
@State var initialLoad: Bool = true
@State var hasChanges: Bool = false
@State var enabled = false
@State var address = ""
@State var username = ""
@ -196,21 +192,14 @@ struct MQTTConfig: View {
ConnectedDevice(bluetoothOn: bleManager.isSwitchedOn, deviceConnected: bleManager.connectedPeripheral != nil, name: (bleManager.connectedPeripheral != nil) ? bleManager.connectedPeripheral.shortName : "????")
})
.onAppear {
if self.initialLoad{
self.bleManager.context = context
self.enabled = (node?.mqttConfig?.enabled ?? false)
self.address = node?.mqttConfig?.address ?? ""
self.username = node?.mqttConfig?.username ?? ""
self.password = node?.mqttConfig?.password ?? ""
self.encryptionEnabled = (node?.mqttConfig?.encryptionEnabled ?? false)
self.jsonEnabled = (node?.mqttConfig?.jsonEnabled ?? false)
self.hasChanges = false
self.initialLoad = false
}
self.bleManager.context = context
self.enabled = (node?.mqttConfig?.enabled ?? false)
self.address = node?.mqttConfig?.address ?? ""
self.username = node?.mqttConfig?.username ?? ""
self.password = node?.mqttConfig?.password ?? ""
self.encryptionEnabled = (node?.mqttConfig?.encryptionEnabled ?? false)
self.jsonEnabled = (node?.mqttConfig?.jsonEnabled ?? false)
self.hasChanges = false
}
.onChange(of: enabled) { newEnabled in