HealthImport/HealthImport/ActivityDetailView.swift
2024-01-25 13:48:00 +01:00

60 lines
1.9 KiB
Swift

import SwiftUI
struct ActivityDetailView: View {
@EnvironmentObject
var database: HealthDatabase
let activity: WorkoutActivity
@State var locations: [LocationSample] = []
var body: some View {
List {
DetailRow("UUID", value: activity.uuid)
DetailRow("Primary Activity", value: activity.isPrimaryActivity)
DetailRow("Activity", value: activity.activityType)
DetailRow("Location", value: activity.locationType)
DetailRow("Swimming Location", value: activity.swimmingLocationType)
DetailRow("Lap Length", value: activity.lapLength)
DetailRow("Start", date: activity.startDate)
DetailRow("End", date: activity.endDate)
DetailRow("Duration", duration: activity.duration)
DetailRow("Metadata", value: activity.metadata)
if !locations.isEmpty {
NavigationLink(value: locations) {
DetailRow("Locations", value: "\(locations.count)")
}
} else {
DetailRow("Locations", value: "0")
}
}
.navigationTitle("Activity")
.navigationDestination(for: [LocationSample].self) { locations in
LocationSampleListView(samples: locations)
}
.onAppear(perform: load)
}
private func load() {
Task {
do {
let samples = try database.locationSamples(for: activity)
.sorted { $0.timestamp }
DispatchQueue.main.async {
self.locations = samples
}
} catch {
print("Failed to load location samples for activity: \(error)")
}
}
}
}
#Preview {
NavigationStack {
ActivityDetailView(activity: .mock1)
.environmentObject(HealthDatabase.mock())
}
}