Add icon, set device time
This commit is contained in:
@ -67,119 +67,132 @@ struct DeviceInfoView: View {
|
||||
}
|
||||
|
||||
func sensorView(_ sensor: TemperatureSensor?, id: Int) -> some View {
|
||||
VStack(alignment: .leading, spacing: 5) {
|
||||
Text("Sensor \(id)")
|
||||
.font(.headline)
|
||||
if let sensor {
|
||||
HStack {
|
||||
Image(systemSymbol: sensor.temperatureIcon)
|
||||
.frame(width: 30)
|
||||
Text(sensor.temperatureText)
|
||||
}
|
||||
HStack {
|
||||
Image(systemSymbol: .arrowTriangle2Circlepath)
|
||||
.frame(width: 30)
|
||||
Text(sensor.updateText)
|
||||
Spacer()
|
||||
}
|
||||
HStack {
|
||||
Image(systemSymbol: .tag)
|
||||
.frame(width: 30)
|
||||
Text(sensor.hexAddress)
|
||||
}
|
||||
} else {
|
||||
HStack {
|
||||
Image(systemSymbol: .thermometerMediumSlash)
|
||||
.frame(width: 30)
|
||||
Text("Not connected")
|
||||
VStack(alignment: .leading, spacing: 5) {
|
||||
Text("Sensor \(id)")
|
||||
.font(.headline)
|
||||
if let sensor {
|
||||
HStack {
|
||||
Image(systemSymbol: sensor.temperatureIcon)
|
||||
.frame(width: 30)
|
||||
Text(sensor.temperatureText)
|
||||
}
|
||||
HStack {
|
||||
Image(systemSymbol: .arrowTriangle2Circlepath)
|
||||
.frame(width: 30)
|
||||
Text(sensor.updateText)
|
||||
Spacer()
|
||||
}
|
||||
HStack {
|
||||
Image(systemSymbol: .tag)
|
||||
.frame(width: 30)
|
||||
Text(sensor.hexAddress)
|
||||
}
|
||||
} else {
|
||||
HStack {
|
||||
Image(systemSymbol: .thermometerMediumSlash)
|
||||
.frame(width: 30)
|
||||
Text("Not connected")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
var updateText: String {
|
||||
guard info.receivedDate.secondsToNow > 3 else {
|
||||
return "Updated Now"
|
||||
}
|
||||
return "Updated \(info.receivedDate.timePassedText)"
|
||||
}
|
||||
|
||||
var clockOffsetText: String {
|
||||
guard info.hasDeviceStartTimeSet else {
|
||||
return "Clock not synchronized"
|
||||
}
|
||||
let offset = info.clockOffset.roundedInt
|
||||
guard abs(offset) > 1 else {
|
||||
return "No clock offset"
|
||||
}
|
||||
return "Offset: \(offset) seconds"
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
VStack(alignment: .leading, spacing: 5) {
|
||||
HStack {
|
||||
Text("Device Info").font(.title2).bold()
|
||||
Spacer()
|
||||
Button(action: { isPresented = false }) {
|
||||
Image(systemSymbol: .xmarkCircleFill)
|
||||
.foregroundColor(.gray)
|
||||
.font(.system(size: 26))
|
||||
}
|
||||
}
|
||||
.padding(.bottom)
|
||||
NavigationView {
|
||||
VStack(alignment: .leading, spacing: 5) {
|
||||
Text("Recording")
|
||||
.font(.headline)
|
||||
HStack {
|
||||
Image(systemSymbol: .power)
|
||||
.frame(width: 30)
|
||||
Text(df.string(from: info.deviceStartTime))
|
||||
Spacer()
|
||||
VStack(alignment: .leading, spacing: 5) {
|
||||
Text("Recording")
|
||||
.font(.headline)
|
||||
HStack {
|
||||
Image(systemSymbol: .power)
|
||||
.frame(width: 30)
|
||||
Text(df.string(from: info.deviceStartTime))
|
||||
Spacer()
|
||||
}
|
||||
HStack {
|
||||
Image(systemSymbol: .clock)
|
||||
.frame(width: 30)
|
||||
Text("\(runTimeString)")
|
||||
}
|
||||
HStack {
|
||||
Image(systemSymbol: .clockBadgeExclamationmark)
|
||||
.frame(width: 30)
|
||||
Text(clockOffsetText)
|
||||
}
|
||||
HStack {
|
||||
Image(systemSymbol: .stopwatch)
|
||||
.frame(width: 30)
|
||||
Text("Every \(info.measurementInterval) seconds")
|
||||
Spacer()
|
||||
}
|
||||
HStack {
|
||||
Image(systemSymbol: .arrowTriangle2Circlepath)
|
||||
.frame(width: 30)
|
||||
Text(nextUpdateText)
|
||||
Spacer()
|
||||
}
|
||||
}
|
||||
HStack {
|
||||
Image(systemSymbol: .clock)
|
||||
.frame(width: 30)
|
||||
Text("\(runTimeString)")
|
||||
VStack(alignment: .leading, spacing: 5) {
|
||||
Text("Storage")
|
||||
.font(.headline)
|
||||
HStack {
|
||||
Image(systemSymbol: .speedometer)
|
||||
.frame(width: 30)
|
||||
Text("\(info.numberOfStoredMeasurements) Measurements (\(info.totalNumberOfMeasurements) total)")
|
||||
}
|
||||
HStack {
|
||||
Image(systemSymbol: storageIcon)
|
||||
.frame(width: 30)
|
||||
Text(storageText)
|
||||
}
|
||||
HStack {
|
||||
Image(systemSymbol: .iphoneAndArrowForward)
|
||||
.frame(width: 30)
|
||||
Text("\(info.transferBlockSize) Byte Block Size")
|
||||
}
|
||||
}
|
||||
HStack {
|
||||
Image(systemSymbol: .stopwatch)
|
||||
.frame(width: 30)
|
||||
Text("Every \(info.measurementInterval) seconds")
|
||||
Spacer()
|
||||
}
|
||||
HStack {
|
||||
Image(systemSymbol: .arrowTriangle2Circlepath)
|
||||
.frame(width: 30)
|
||||
Text(nextUpdateText)
|
||||
Spacer()
|
||||
}
|
||||
}
|
||||
VStack(alignment: .leading, spacing: 5) {
|
||||
Text("Storage")
|
||||
.font(.headline)
|
||||
HStack {
|
||||
Image(systemSymbol: .speedometer)
|
||||
.frame(width: 30)
|
||||
Text("\(info.numberOfMeasurements) Measurements")
|
||||
}
|
||||
HStack {
|
||||
Image(systemSymbol: storageIcon)
|
||||
.frame(width: 30)
|
||||
Text(storageText)
|
||||
}
|
||||
HStack {
|
||||
Image(systemSymbol: .iphoneAndArrowForward)
|
||||
.frame(width: 30)
|
||||
Text("\(info.transferBlockSize) Byte Block Size")
|
||||
}
|
||||
}
|
||||
sensorView(info.sensor0, id: 0)
|
||||
sensorView(info.sensor1, id: 1)
|
||||
Spacer()
|
||||
HStack {
|
||||
sensorView(info.sensor0, id: 0)
|
||||
sensorView(info.sensor1, id: 1)
|
||||
Spacer()
|
||||
TimelineView(.periodic(from: Date(), by: 1)) { context in
|
||||
Text(updateText)
|
||||
.font(.footnote)
|
||||
.textCase(.uppercase)
|
||||
HStack {
|
||||
Spacer()
|
||||
TimelineView(.periodic(from: Date(), by: 1)) { context in
|
||||
Text(updateText)
|
||||
.font(.footnote)
|
||||
.textCase(.uppercase)
|
||||
}
|
||||
Spacer()
|
||||
}
|
||||
Spacer()
|
||||
}
|
||||
}.padding()
|
||||
.padding()
|
||||
.navigationTitle("Device Info")
|
||||
.navigationBarTitleDisplayMode(.large)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct DeviceInfoView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
DeviceInfoView(info: .mock, isPresented: .constant(true))
|
||||
.previewLayout(.fixed(width: 375, height: 600))
|
||||
.previewLayout(.fixed(width: 375, height: 650))
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user