Sesame-iOS/Sesame-Watch Watch App/HistoryItemDetail.swift
2023-08-09 16:29:18 +02:00

68 lines
1.9 KiB
Swift

import SwiftUI
import SFSafeSymbols
private let df: DateFormatter = {
let df = DateFormatter()
df.dateStyle = .short
df.timeStyle = .short
df.doesRelativeDateFormatting = true
return df
}()
struct HistoryItemDetail: View {
let item: HistoryItem
private var entryTime: String {
df.string(from: item.requestDate)
}
var counterText: String {
let sentCounter = item.request.id
let startText = "\(sentCounter)"
guard let rCounter = item.responseMessage?.id else {
return startText
}
guard sentCounter + 1 != rCounter && sentCounter != rCounter else {
return startText
}
return "\(sentCounter) -> \(rCounter)"
}
var body: some View {
List {
SettingsListTextItem(
title: "Status",
value: item.response?.description ?? "No response")
SettingsListTextItem(
title: "Date",
value: entryTime)
SettingsListTextItem(
title: "Connection",
value: item.usedLocalConnection ? "Local" : "Remote")
SettingsListTextItem(
title: "Device ID",
value: "\(item.request.deviceId!)")
SettingsListTextItem(
title: "Message Counter",
value: counterText)
if let time = item.roundTripTime {
SettingsListTextItem(
title: "Round Trip Time",
value: "\(Int(time * 1000)) ms")
}
if let offset = item.clockOffset {
SettingsListTextItem(
title: "Clock offset",
value: "\(offset) seconds")
}
}.navigationTitle("Details")
}
}
struct HistoryItemDetail_Previews: PreviewProvider {
static var previews: some View {
HistoryItemDetail(item: .mock)
}
}