mirror of
https://github.com/meshtastic/Meshtastic-Apple.git
synced 2026-04-20 22:13:56 +00:00
Merge pull request #180 from meshtastic/add_share_channels
Add share channels view back
This commit is contained in:
commit
2eafaad8e1
3 changed files with 123 additions and 0 deletions
|
|
@ -25,6 +25,7 @@
|
|||
DD2E65262767A01F00E45FC5 /* NodeDetail.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD2E65252767A01F00E45FC5 /* NodeDetail.swift */; };
|
||||
DD3501892852FC3B000FC853 /* Settings.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD3501882852FC3B000FC853 /* Settings.swift */; };
|
||||
DD35018B2852FC79000FC853 /* UserSettings.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD35018A2852FC79000FC853 /* UserSettings.swift */; };
|
||||
DD3CC6B528E33FD100FA9159 /* ShareChannels.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD3CC6B428E33FD100FA9159 /* ShareChannels.swift */; };
|
||||
DD4033C228B286B70096A444 /* Onboarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD4033C128B286B70096A444 /* Onboarding.swift */; };
|
||||
DD41582628582E9B009B0E59 /* DeviceConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD41582528582E9B009B0E59 /* DeviceConfig.swift */; };
|
||||
DD415828285859C4009B0E59 /* TelemetryConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD415827285859C4009B0E59 /* TelemetryConfig.swift */; };
|
||||
|
|
@ -135,6 +136,7 @@
|
|||
DD2E65252767A01F00E45FC5 /* NodeDetail.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NodeDetail.swift; sourceTree = "<group>"; };
|
||||
DD3501882852FC3B000FC853 /* Settings.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Settings.swift; sourceTree = "<group>"; };
|
||||
DD35018A2852FC79000FC853 /* UserSettings.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserSettings.swift; sourceTree = "<group>"; };
|
||||
DD3CC6B428E33FD100FA9159 /* ShareChannels.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShareChannels.swift; sourceTree = "<group>"; };
|
||||
DD4033C128B286B70096A444 /* Onboarding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Onboarding.swift; sourceTree = "<group>"; };
|
||||
DD4033C328B405A60096A444 /* MeshtasticDataModel v 8.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = "MeshtasticDataModel v 8.xcdatamodel"; sourceTree = "<group>"; };
|
||||
DD41582528582E9B009B0E59 /* DeviceConfig.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DeviceConfig.swift; sourceTree = "<group>"; };
|
||||
|
|
@ -302,6 +304,7 @@
|
|||
DDCE4E2B2869F92900BE9F8F /* UserConfig.swift */,
|
||||
DD0F791A28713C8A00A6FDAD /* AdminMessageList.swift */,
|
||||
DD61937A2863876A00E59241 /* Config */,
|
||||
DD3CC6B428E33FD100FA9159 /* ShareChannels.swift */,
|
||||
);
|
||||
path = Settings;
|
||||
sourceTree = "<group>";
|
||||
|
|
@ -725,6 +728,7 @@
|
|||
DD9D8F2F2764403B00080993 /* Meshtastic.xcdatamodeld in Sources */,
|
||||
DD6193772862F90F00E59241 /* CannedMessagesConfig.swift in Sources */,
|
||||
DD41582628582E9B009B0E59 /* DeviceConfig.swift in Sources */,
|
||||
DD3CC6B528E33FD100FA9159 /* ShareChannels.swift in Sources */,
|
||||
DD1BF2F92776FE2E008C8D2F /* UserMessageList.swift in Sources */,
|
||||
DDB6ABE628B1406100384BA1 /* LoraConfigEnums.swift in Sources */,
|
||||
DDB2CC6E27F3EB47009C5FCC /* telemetry.pb.swift in Sources */,
|
||||
|
|
|
|||
|
|
@ -37,6 +37,15 @@ struct Settings: View {
|
|||
|
||||
Section("Radio Configuration") {
|
||||
|
||||
NavigationLink {
|
||||
ShareChannels(node: nodes.first(where: { $0.num == connectedNodeNum }))
|
||||
} label: {
|
||||
Image(systemName: "qrcode")
|
||||
.symbolRenderingMode(.hierarchical)
|
||||
Text("Share Channels QR Code")
|
||||
}
|
||||
.disabled(bleManager.connectedPeripheral == nil)
|
||||
|
||||
NavigationLink {
|
||||
UserConfig(node: nodes.first(where: { $0.num == connectedNodeNum }))
|
||||
} label: {
|
||||
|
|
|
|||
110
Meshtastic/Views/Settings/ShareChannels.swift
Normal file
110
Meshtastic/Views/Settings/ShareChannels.swift
Normal file
|
|
@ -0,0 +1,110 @@
|
|||
//
|
||||
// ShareChannel.swift
|
||||
// MeshtasticApple
|
||||
//
|
||||
// Created by Garth Vander Houwen on 4/8/22.
|
||||
//
|
||||
import SwiftUI
|
||||
import CoreData
|
||||
import CoreImage.CIFilterBuiltins
|
||||
|
||||
|
||||
struct QrCodeImage {
|
||||
let context = CIContext()
|
||||
|
||||
func generateQRCode(from text: String) -> UIImage {
|
||||
var qrImage = UIImage(systemName: "xmark.circle") ?? UIImage()
|
||||
let data = Data(text.utf8)
|
||||
let filter = CIFilter.qrCodeGenerator()
|
||||
filter.setValue(data, forKey: "inputMessage")
|
||||
|
||||
let transform = CGAffineTransform(scaleX: 20, y: 20)
|
||||
if let outputImage = filter.outputImage?.transformed(by: transform) {
|
||||
if let image = context.createCGImage(
|
||||
outputImage,
|
||||
from: outputImage.extent) {
|
||||
qrImage = UIImage(cgImage: image)
|
||||
}
|
||||
}
|
||||
return qrImage
|
||||
}
|
||||
}
|
||||
struct ShareChannels: View {
|
||||
|
||||
@Environment(\.managedObjectContext) var context
|
||||
@EnvironmentObject var bleManager: BLEManager
|
||||
@EnvironmentObject var userSettings: UserSettings
|
||||
|
||||
var node: NodeInfoEntity?
|
||||
|
||||
@State private var text = "https://meshtastic.org/E/#test"
|
||||
var qrCodeImage = QrCodeImage()
|
||||
|
||||
var body: some View {
|
||||
|
||||
VStack {
|
||||
|
||||
GeometryReader { bounds in
|
||||
|
||||
let smallest = min(bounds.size.width, bounds.size.height)
|
||||
|
||||
ScrollView {
|
||||
|
||||
VStack {
|
||||
Text("Scan the QR code below with the Apple or Android device you would like to share your channel settings with.")
|
||||
.fixedSize(horizontal: false, vertical: true)
|
||||
.font(.callout)
|
||||
|
||||
let image = qrCodeImage.generateQRCode(from: text)
|
||||
Image(uiImage: image)
|
||||
.resizable()
|
||||
.scaledToFit()
|
||||
.frame(
|
||||
minWidth: smallest * 0.8,
|
||||
maxWidth: smallest * 0.8,
|
||||
minHeight: smallest * 0.8,
|
||||
maxHeight: smallest * 0.8,
|
||||
alignment: .center
|
||||
)
|
||||
|
||||
if node != nil && node!.loRaConfig != nil {
|
||||
|
||||
HStack {
|
||||
|
||||
let preset = ModemPresets(rawValue: Int(node!.loRaConfig!.modemPreset))
|
||||
Text("Modem Preset \(preset!.description)").font(.title3)
|
||||
}
|
||||
}
|
||||
VStack {
|
||||
|
||||
Text("Number of Channels: \(node!.myInfo!.maxChannels)").font(.title2)
|
||||
|
||||
ForEach(node!.myInfo!.channels?.array.sorted(by: { ($0 as! ChannelEntity).index < ($1 as! ChannelEntity).index }) as! [ChannelEntity], id: \.self) { (channel: ChannelEntity) in
|
||||
|
||||
VStack {
|
||||
|
||||
|
||||
Text("Channel: \(channel.index) Name: \(channel.name ?? "")")
|
||||
}
|
||||
}
|
||||
}
|
||||
.frame(width: bounds.size.width, height: bounds.size.height)
|
||||
}
|
||||
}
|
||||
.navigationTitle("Share Channel")
|
||||
.navigationBarTitleDisplayMode(.automatic)
|
||||
.navigationBarItems(trailing:
|
||||
|
||||
ZStack {
|
||||
|
||||
ConnectedDevice(bluetoothOn: bleManager.isSwitchedOn, deviceConnected: bleManager.connectedPeripheral != nil, name: (bleManager.connectedPeripheral != nil) ? bleManager.connectedPeripheral.shortName : "????")
|
||||
})
|
||||
.onAppear {
|
||||
|
||||
self.bleManager.context = context
|
||||
}
|
||||
}
|
||||
.navigationViewStyle(StackNavigationViewStyle())
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue