148 lines
5.9 KiB
Swift
148 lines
5.9 KiB
Swift
//
|
|
// SettingsView.swift
|
|
// Workouts
|
|
//
|
|
// Copyright 2025 Rouslan Zenetl. All Rights Reserved.
|
|
//
|
|
|
|
import SwiftUI
|
|
import SwiftData
|
|
import IndieAbout
|
|
|
|
struct SettingsView: View {
|
|
@Environment(SyncEngine.self) private var sync
|
|
@Environment(\.modelContext) private var modelContext
|
|
@Environment(AppServices.self) private var services
|
|
|
|
@Query(sort: \Split.order) private var splits: [Split]
|
|
|
|
@AppStorage("restSeconds") private var restSeconds: Int = 45
|
|
@AppStorage("doneCountdownSeconds") private var doneCountdownSeconds: Int = 5
|
|
@State private var showingAddSplitSheet = false
|
|
|
|
var body: some View {
|
|
NavigationStack {
|
|
Form {
|
|
// MARK: - Workout Section
|
|
Section {
|
|
Stepper(value: $restSeconds, in: 10...180, step: 5) {
|
|
HStack {
|
|
Text("Rest Between Sets")
|
|
Spacer()
|
|
Text("\(restSeconds)s").foregroundColor(.secondary)
|
|
}
|
|
}
|
|
|
|
Stepper(value: $doneCountdownSeconds, in: 3...20, step: 1) {
|
|
HStack {
|
|
Text("Auto-Finish Countdown")
|
|
Spacer()
|
|
Text("\(doneCountdownSeconds)s").foregroundColor(.secondary)
|
|
}
|
|
}
|
|
} header: {
|
|
Text("Workout")
|
|
} footer: {
|
|
Text("How long the watch waits on the finish screen before completing an exercise automatically.")
|
|
}
|
|
|
|
// MARK: - Splits Section
|
|
Section(header: Text("Splits")) {
|
|
if splits.isEmpty {
|
|
HStack {
|
|
Spacer()
|
|
VStack(spacing: 8) {
|
|
Image(systemName: "dumbbell.fill")
|
|
.font(.largeTitle)
|
|
.foregroundColor(.secondary)
|
|
Text("No Splits Yet")
|
|
.font(.headline)
|
|
.foregroundColor(.secondary)
|
|
Text("Create a split to organize your workout routine.")
|
|
.font(.caption)
|
|
.foregroundColor(.secondary)
|
|
.multilineTextAlignment(.center)
|
|
}
|
|
.padding(.vertical)
|
|
Spacer()
|
|
}
|
|
} else {
|
|
ForEach(splits) { split in
|
|
NavigationLink {
|
|
SplitDetailView(split: split)
|
|
} label: {
|
|
HStack {
|
|
Image(systemName: split.systemImage)
|
|
.foregroundColor(Color.color(from: split.color))
|
|
.frame(width: 24)
|
|
Text(split.name)
|
|
Spacer()
|
|
Text("\(split.exercisesArray.count)")
|
|
.foregroundColor(.secondary)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
Button {
|
|
showingAddSplitSheet = true
|
|
} label: {
|
|
HStack {
|
|
Image(systemName: "plus.circle.fill")
|
|
.foregroundColor(.accentColor)
|
|
Text("Add Split")
|
|
}
|
|
}
|
|
|
|
Button {
|
|
Task { await SplitSeeder.seedDefaults(into: modelContext, using: sync) }
|
|
} label: {
|
|
HStack {
|
|
Image(systemName: "wand.and.sparkles")
|
|
.foregroundColor(.accentColor)
|
|
Text("Add Starter Splits")
|
|
}
|
|
}
|
|
}
|
|
|
|
// MARK: - iCloud Sync Section
|
|
Section {
|
|
switch sync.iCloudStatus {
|
|
case .checking:
|
|
Label("Connecting…", systemImage: "arrow.triangle.2.circlepath.icloud")
|
|
.foregroundStyle(.secondary)
|
|
case .available:
|
|
Label("Connected", systemImage: "checkmark.icloud")
|
|
.foregroundStyle(.secondary)
|
|
case .unavailable:
|
|
Label("iCloud unavailable", systemImage: "xmark.icloud")
|
|
.foregroundStyle(.orange)
|
|
}
|
|
if let error = sync.lastSyncError {
|
|
Label(error, systemImage: "exclamationmark.icloud.fill")
|
|
.foregroundStyle(.orange)
|
|
}
|
|
} header: {
|
|
Text("iCloud Sync")
|
|
}
|
|
|
|
// MARK: - About Section
|
|
Section {
|
|
IndieAbout(configuration: AppInfoConfiguration(
|
|
documents: [
|
|
.license(extension: "md")
|
|
],
|
|
changelogDocument: .changelog()
|
|
))
|
|
}
|
|
}
|
|
.navigationTitle("Settings")
|
|
.sheet(isPresented: $showingAddSplitSheet) {
|
|
SplitAddEditView(split: nil)
|
|
}
|
|
.onChange(of: restSeconds) { _, _ in services.watchBridge.pushAll() }
|
|
.onChange(of: doneCountdownSeconds) { _, _ in services.watchBridge.pushAll() }
|
|
}
|
|
}
|
|
}
|