mycode/myApp/Keging/KegingWidgets/KegingWidgetsLiveActivity.swift
songyc macbook 06d13b2f3d feat(keging): 준비 시간(0~10초, 기본 3초) — 시작 버튼 후 카운트다운 뒤 첫 수축
- KegelPhase에 prepare 국면 추가(무진동 — 첫 수축 진동이 시작 신호), 준비 0초면 즉시 수축
- 세팅에 '준비' 스테퍼(0~10초), 워치 자동 동기화, 구버전 설정 decodeIfPresent 보존
- 진행 화면: 준비=회그린 원이 작게 시작해 천천히 부풀며 첫 수축으로 연결(기존 그래픽 문법 유지),
  진행 링 0·카운터 색 연동. 워치·Live Activity도 준비 국면 색/표시 대응
- 기록·건강의 시작 시각은 준비를 뺀 첫 수축 기준. Live Activity는 sync 단일 진입점으로 정리
- 도움말·세팅 푸터 문구 갱신, 신규 문자열 번역(en/ja)·stale 정리 — 전 카탈로그 0/0
- 검증: Debug·Release·워치 빌드 그린, 준비→수축 전환·세팅 화면 QA

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UPmp29DQHY6Ahfss5SRopT
2026-08-29 20:55:10 +09:00

89 lines
3.5 KiB
Swift

//
// KegingWidgetsLiveActivity.swift
// KegingWidgets
//
// · Live Activity /
//
import ActivityKit
import WidgetKit
import SwiftUI
struct KegingLiveActivity: Widget {
var body: some WidgetConfiguration {
ActivityConfiguration(for: KegingActivityAttributes.self) { context in
// ·
HStack(spacing: 12) {
phaseIcon(context.state)
VStack(alignment: .leading, spacing: 2) {
Text(context.state.phase.label)
.font(.headline)
.foregroundStyle(phaseColor(context.state))
Text("\(context.state.rep) / \(context.state.totalReps)")
.font(.subheadline)
.monospacedDigit()
.foregroundStyle(.secondary)
}
Spacer()
Text(timerInterval: context.state.phaseStart...context.state.phaseEnd, countsDown: true)
.font(.title2.weight(.semibold))
.monospacedDigit()
.frame(maxWidth: 64)
.multilineTextAlignment(.trailing)
}
.padding(14)
} dynamicIsland: { context in
DynamicIsland {
DynamicIslandExpandedRegion(.leading) {
HStack(spacing: 6) {
phaseIcon(context.state)
Text(context.state.phase.label)
.font(.headline)
.foregroundStyle(phaseColor(context.state))
}
.padding(.leading, 4)
}
DynamicIslandExpandedRegion(.trailing) {
Text("\(context.state.rep) / \(context.state.totalReps)")
.font(.headline)
.monospacedDigit()
.padding(.trailing, 4)
}
DynamicIslandExpandedRegion(.bottom) {
VStack(spacing: 6) {
Text(timerInterval: context.state.phaseStart...context.state.phaseEnd, countsDown: true)
.font(.title.weight(.semibold))
.monospacedDigit()
.multilineTextAlignment(.center)
ProgressView(value: Double(context.state.rep), total: Double(max(1, context.state.totalReps)))
.tint(phaseColor(context.state))
}
}
} compactLeading: {
phaseIcon(context.state)
} compactTrailing: {
Text("\(context.state.rep)/\(context.state.totalReps)")
.font(.caption2)
.monospacedDigit()
.foregroundStyle(phaseColor(context.state))
} minimal: {
phaseIcon(context.state)
}
}
}
private func phaseColor(_ state: KegingActivityAttributes.ContentState) -> Color {
switch state.phase {
case .prepare: Color(hex: "#9AA8A0")
case .contract: Color(hex: "#7FBF9E")
case .relax: Color(hex: "#E8C558")
}
}
private func phaseIcon(_ state: KegingActivityAttributes.ContentState) -> some View {
Image(systemName: state.phase.symbolName)
.font(.body.weight(.semibold))
.foregroundStyle(phaseColor(state))
}
}