Bigger QR code, hide disabled channels

This commit is contained in:
Garth Vander Houwen 2022-10-15 20:22:13 -07:00
parent 2fbfe0375e
commit acf544aa09
2 changed files with 63 additions and 88 deletions

View file

@ -17,6 +17,7 @@ struct MessageList: View {
enum Field: Hashable {
case messageText
}
// Keyboard State
@State var typingMessage: String = ""
@State private var totalBytes = 0
@ -24,12 +25,10 @@ struct MessageList: View {
@FocusState var focusedField: Field?
@ObservedObject var user: UserEntity
@State var showDeleteMessageAlert = false
@State private var deleteMessageId: Int64 = 0
@State private var replyMessageId: Int64 = 0
@State private var sendPositionWithMessage: Bool = false
@State private var messageCount = 0
@State private var refreshId = UUID()
@ -37,13 +36,9 @@ struct MessageList: View {
var body: some View {
NavigationStack {
ScrollViewReader { scrollView in
ScrollView {
if user.messageList.count > 0 {
ForEach( user.messageList ) { (message: MessageEntity) in
if user.num != userSettings.preferredNodeNum {
let currentUser: Bool = (userSettings.preferredNodeNum == message.fromUser?.num ? true : false)
@ -70,17 +65,13 @@ struct MessageList: View {
.padding(.all, 5)
.offset(y: -5)
}
VStack(alignment: currentUser ? .trailing : .leading) {
Text(message.messagePayload ?? "EMPTY MESSAGE")
.padding(10)
.foregroundColor(.white)
.background(currentUser ? Color.blue : Color(.darkGray))
.cornerRadius(15)
.contextMenu {
Menu("Tapback response") {
Button(action: {
@ -151,28 +142,20 @@ struct MessageList: View {
Image(uiImage: image!)
}
Button(action: {
if bleManager.sendMessage(message: "", toUserNum: user.num, isEmoji: true, replyID: message.messageId) {
print("Sent ❓ Tapback")
self.context.refresh(user, mergeChanges: true)
print("Sent ❓ Tapback")
} else { print("❓ Tapback Failed") }
}) {
Text("Question Mark")
let image = "".image()
Image(uiImage: image!)
}
Button(action: {
if bleManager.sendMessage(message: "💩", toUserNum: user.num, isEmoji: true, replyID: message.messageId) {
print("Sent 💩 Tapback")
self.context.refresh(user, mergeChanges: true)
print("Sent 💩 Tapback")
} else { print("💩 Tapback Failed") }
}) {
Text("Poop")
let image = "💩".image()
@ -195,14 +178,10 @@ struct MessageList: View {
Image(systemName: "doc.on.doc")
}
Menu("Message Details") {
VStack {
let messageDate = Date(timeIntervalSince1970: TimeInterval(message.messageTimestamp))
Text("Date \(messageDate, style: .date) \(messageDate.formattedDate(format: "h:mm:ss a"))").font(.caption2).foregroundColor(.gray)
}
if currentUser && message.receivedACK {
VStack {
@ -290,19 +269,13 @@ struct MessageList: View {
}
HStack {
if currentUser && message.receivedACK {
// Ack Received
Text("Acknowledged").font(.caption2).foregroundColor(.gray)
} else if currentUser && message.ackError == 0 {
// Empty Error
Text("Waiting to be acknowledged. . .").font(.caption2).foregroundColor(.orange)
} else if currentUser && message.ackError > 0 {
let ackErrorVal = RoutingError(rawValue: Int(message.ackError))
Text("\(ackErrorVal?.display ?? "No Error" )").fixedSize(horizontal: false, vertical: true)
.font(.caption2).foregroundColor(.red)
@ -312,7 +285,6 @@ struct MessageList: View {
.padding(.bottom)
.id(user.messageList.firstIndex(of: message))
if !currentUser {
Spacer(minLength:50)
}
}
@ -323,15 +295,11 @@ struct MessageList: View {
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()
deleteMessageId = 0
} catch {
print("Failed to delete message \(deleteMessageId)")
}
@ -465,16 +433,13 @@ struct MessageList: View {
.navigationBarTitleDisplayMode(.inline)
.toolbar {
ToolbarItem(placement: .principal) {
HStack {
CircleText(text: user.shortName ?? "???", color: .blue, circleSize: 42, fontSize: 16).fixedSize()
Text(user.longName ?? "Unknown").font(.headline).fixedSize()
}
}
ToolbarItem(placement: .navigationBarTrailing) {
ZStack {
ConnectedDevice(
bluetoothOn: bleManager.isSwitchedOn,
deviceConnected: bleManager.connectedPeripheral != nil,

View file

@ -69,7 +69,6 @@ struct ShareChannels: View {
Text("Encrypted")
.font(.caption)
.fontWeight(.bold)
Spacer()
}
ForEach(node!.myInfo!.channels?.array as! [ChannelEntity], id: \.self) { (channel: ChannelEntity) in
GridRow {
@ -80,97 +79,108 @@ struct ShareChannels: View {
.labelsHidden()
.disabled(channel.role == 1)
Text((channel.name!.isEmpty ? "Primary" : channel.name) ?? "Primary")
} else if channel.index == 1 {
Image(systemName: "lock.fill")
.foregroundColor(.green)
} else if channel.index == 1 && channel.role > 0 {
Toggle("Channel 1 Included", isOn: $includeChannel1)
.toggleStyle(.switch)
.labelsHidden()
.disabled(channel.role == 0)
Text((channel.name!.isEmpty ? "Channel\(channel.index)" : channel.name) ?? "Channel\(channel.index)")
} else if channel.index == 2 {
Image(systemName: "lock.fill")
.foregroundColor(.green)
} else if channel.index == 2 && channel.role > 0 {
Toggle("Channel 2 Included", isOn: $includeChannel2)
.toggleStyle(.switch)
.labelsHidden()
.disabled(channel.role == 0)
Text((channel.name!.isEmpty ? "Channel\(channel.index)" : channel.name) ?? "Channel\(channel.index)")
} else if channel.index == 3 {
Image(systemName: "lock.fill")
.foregroundColor(.green)
} else if channel.index == 3 && channel.role > 0 {
Toggle("Channel 3 Included", isOn: $includeChannel3)
.toggleStyle(.switch)
.labelsHidden()
.disabled(channel.role == 0)
Text((channel.name!.isEmpty ? "Channel\(channel.index)" : channel.name) ?? "Channel\(channel.index)")
} else if channel.index == 4 {
Image(systemName: "lock.fill")
.foregroundColor(.green)
} else if channel.index == 4 && channel.role > 0 {
Toggle("Channel 4 Included", isOn: $includeChannel4)
.toggleStyle(.switch)
.labelsHidden()
.disabled(channel.role == 0)
Text((channel.name!.isEmpty ? "Channel\(channel.index)" : channel.name) ?? "Channel\(channel.index)")
} else if channel.index == 5 {
Image(systemName: "lock.fill")
.foregroundColor(.green)
} else if channel.index == 5 && channel.role > 0 {
Toggle("Channel 5 Included", isOn: $includeChannel5)
.toggleStyle(.switch)
.labelsHidden()
.disabled(channel.role == 0)
Text((channel.name!.isEmpty ? "Channel\(channel.index)" : channel.name) ?? "Channel\(channel.index)")
} else if channel.index == 6 {
Image(systemName: "lock.fill")
.foregroundColor(.green)
} else if channel.index == 6 && channel.role > 0 {
Toggle("Channel 6 Included", isOn: $includeChannel6)
.toggleStyle(.switch)
.labelsHidden()
.disabled(channel.role == 0)
Text((channel.name!.isEmpty ? "Channel\(channel.index)" : channel.name) ?? "Channel\(channel.index)")
} else if channel.index == 7 {
Image(systemName: "lock.fill")
.foregroundColor(.green)
} else if channel.index == 7 && channel.role > 0 {
Toggle("Channel 7 Included", isOn: $includeChannel7)
.toggleStyle(.switch)
.labelsHidden()
.disabled(channel.role == 0)
Text((channel.name!.isEmpty ? "Channel\(channel.index)" : channel.name) ?? "Channel\(channel.index)")
}
if channel.role == 0 {
Image(systemName: "lock.slash")
.foregroundColor(.gray)
}
else if channel.role > 0 {
Image(systemName: "lock.fill")
.foregroundColor(.green)
}
Spacer()
}
.padding(0)
}
}
let qrImage = qrCodeImage.generateQRCode(from: channelsUrl)
VStack {
if node != nil {
ShareLink("Share QR Code & Link",
item: Image(uiImage: qrImage),
subject: Text("Meshtastic Node \(node?.user?.shortName ?? "????") has shared channels with you"),
message: Text(channelsUrl),
preview: SharePreview("Meshtastic Node \(node?.user?.shortName ?? "????") has shared channels with you",
image: Image(uiImage: qrImage))
)
.buttonStyle(.bordered)
.buttonBorderShape(.capsule)
.controlSize(.large)
.padding(.bottom)
Image(uiImage: qrImage)
.resizable()
.scaledToFit()
.frame(
minWidth: smallest * 0.95,
maxWidth: smallest * 0.95,
minHeight: smallest * 0.95,
maxHeight: smallest * 0.95,
alignment: .top
)
Button {
isPresentingHelp = true
} label: {
Label("Help Me!", systemImage: "lifepreserver")
}
.buttonStyle(.bordered)
.buttonBorderShape(.capsule)
.controlSize(.small)
}
}
}
}
let qrImage = qrCodeImage.generateQRCode(from: channelsUrl)
VStack {
if node != nil {
ShareLink("Share QR Code & Link",
item: Image(uiImage: qrImage),
subject: Text("Meshtastic Node \(node?.user?.shortName ?? "????") has shared channels with you"),
message: Text(channelsUrl),
preview: SharePreview("Meshtastic Node \(node?.user?.shortName ?? "????") has shared channels with you",
image: Image(uiImage: qrImage))
)
.buttonStyle(.bordered)
.buttonBorderShape(.capsule)
.controlSize(.large)
Image(uiImage: qrImage)
.resizable()
.scaledToFit()
.frame(
minWidth: smallest * 0.65,
maxWidth: smallest * 0.65,
minHeight: smallest * 0.65,
maxHeight: smallest * 0.65,
alignment: .top
)
Button {
isPresentingHelp = true
} label: {
Label("Help Me!", systemImage: "lifepreserver")
}
.buttonStyle(.bordered)
.buttonBorderShape(.capsule)
.controlSize(.small)
}
}
}
.sheet(isPresented: $isPresentingHelp) {
@ -207,7 +217,7 @@ struct ShareChannels: View {
ConnectedDevice(bluetoothOn: bleManager.isSwitchedOn, deviceConnected: bleManager.connectedPeripheral != nil, name: (bleManager.connectedPeripheral != nil) ? bleManager.connectedPeripheral.shortName : "????")
})
.onAppear {
self.bleManager.context = context
bleManager.context = context
GenerateChannelSet()
}
.onChange(of: includeChannel1) { includeCh1 in GenerateChannelSet() }