Repository navigation
feat: 이전 운동 기록 API 연동 #185
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
GYMUP/Sources/Features/WorkoutSession/WorkoutSessionComponents.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
138 changes: 138 additions & 0 deletions
138
GYMUP/Sources/Features/WorkoutSession/WorkoutSessionView+Actions.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,138 @@ | ||
| import SwiftUI | ||
| import UIKit | ||
|
|
||
| extension WorkoutSessionView { | ||
| func loadPreviousRecord(for exerciseID: String) async { | ||
| await viewModel.loadPreviousRecord(for: exerciseID) | ||
| guard viewModel.currentExercise?.id == exerciseID else { return } | ||
| showFirstExercisePromptIfNeeded() | ||
| } | ||
|
|
||
| func handleRestTick(at date: Date) async { | ||
| if let activityState = WorkoutRestActivityController.shared.currentState(sessionID: liveActivitySessionID) { | ||
| if activityState.isSkipped { | ||
| viewModel.skipRest() | ||
| settings.cancelRestNotification(sessionID: liveActivitySessionID) | ||
| await WorkoutRestActivityController.shared.end(sessionID: liveActivitySessionID) | ||
| return | ||
| } | ||
| viewModel.synchronizeRestTimer( | ||
| endsAt: activityState.restEndsAt, | ||
| durationSeconds: activityState.restDurationSeconds, | ||
| at: date | ||
| ) | ||
| } | ||
| guard viewModel.refreshClock(at: date) else { return } | ||
| isShowingRestFinishedAlert = settings.preferences.restTimerEnabled | ||
| if settings.preferences.hapticsEnabled { | ||
| UINotificationFeedbackGenerator().notificationOccurred(.success) | ||
| } | ||
| await WorkoutRestActivityController.shared.end(sessionID: liveActivitySessionID) | ||
| } | ||
|
|
||
| func completeCurrentSet(at date: Date) { | ||
| guard let currentSetIndex = viewModel.currentSetIndex else { return } | ||
| viewModel.toggleSetCompletion( | ||
| exerciseIndex: viewModel.currentExerciseIndex, | ||
| setIndex: currentSetIndex, | ||
| at: date | ||
| ) | ||
| if settings.preferences.hapticsEnabled { | ||
| UIImpactFeedbackGenerator(style: .light).impactOccurred() | ||
| } | ||
| syncRestActivity() | ||
| if viewModel.currentExerciseIndex == viewModel.plan.exercises.count - 1, | ||
| viewModel.currentExercise?.isComplete == true { | ||
| showWorkoutProcessing() | ||
| } | ||
| } | ||
|
|
||
| func formattedDuration(_ seconds: Int) -> String { | ||
| String(format: "%02d:%02d", seconds / 60, seconds % 60) | ||
| } | ||
|
|
||
| func finishWorkout() { | ||
| settings.cancelRestNotification(sessionID: liveActivitySessionID) | ||
| Task { await WorkoutRestActivityController.shared.end(sessionID: liveActivitySessionID) } | ||
| guard !didSaveHistoryRecord else { | ||
| dismiss() | ||
| return | ||
| } | ||
|
|
||
| if let completedAt = viewModel.finishedAt { | ||
| var record = WorkoutSessionCompletionDataFactory.makeHistoryRecord( | ||
| plan: viewModel.plan, | ||
| elapsedSeconds: viewModel.elapsedSeconds(at: completedAt), | ||
| completedAt: completedAt | ||
| ) | ||
| record.earnedExperience = viewModel.completionData?.earnedXP | ||
| if record.setCount > 0 { | ||
| historyStore.add(record) | ||
| } | ||
| didSaveHistoryRecord = true | ||
| } | ||
| dismiss() | ||
| } | ||
|
|
||
| func syncRestActivity() { | ||
| guard settings.preferences.restTimerEnabled, viewModel.isResting, | ||
| let exercise = viewModel.currentExercise, | ||
| let setIndex = viewModel.currentSetIndex, | ||
| let restEndsAt = viewModel.activeRestEndsAt else { | ||
| settings.cancelRestNotification(sessionID: liveActivitySessionID) | ||
| Task { await WorkoutRestActivityController.shared.end(sessionID: liveActivitySessionID) } | ||
| return | ||
| } | ||
|
|
||
| settings.scheduleRestNotification(sessionID: liveActivitySessionID, endsAt: restEndsAt) | ||
| let nextSet = exercise.sets[setIndex] | ||
| let duration = viewModel.activeRestDurationSeconds | ||
| let state = WorkoutRestActivityAttributes.ContentState( | ||
| restStartedAt: restEndsAt.addingTimeInterval(TimeInterval(-duration)), | ||
| restEndsAt: restEndsAt, | ||
| restDurationSeconds: duration, | ||
| routineName: viewModel.plan.title, | ||
| exerciseName: exercise.name, | ||
| exerciseIndex: viewModel.currentExerciseIndex + 1, | ||
| totalExerciseCount: viewModel.plan.exercises.count, | ||
| completedSetCount: exercise.completedSetCount, | ||
| nextSetNumber: setIndex + 1, | ||
| nextSetWeightKilograms: nextSet.weightKilograms, | ||
| nextSetRepetitions: nextSet.repetitions, | ||
| isSkipped: false, | ||
| nextSetIsTimed: exercise.measure == .seconds | ||
| ) | ||
| Task { | ||
| await WorkoutRestActivityController.shared.startOrUpdate(sessionID: liveActivitySessionID, state: state) | ||
| } | ||
| } | ||
|
|
||
| func showWorkoutProcessing() { | ||
| isShowingWorkoutProcessing = true | ||
| Task { @MainActor in | ||
| do { | ||
| try await Task.sleep(for: .milliseconds(1_800)) | ||
| } catch { | ||
| return | ||
| } | ||
| isShowingWorkoutProcessing = false | ||
| viewModel.finish() | ||
| } | ||
| } | ||
|
|
||
| func showFirstExercisePromptIfNeeded() { | ||
| guard let exercise = viewModel.currentExercise, | ||
| !exercise.hasPreviousPerformance, | ||
| !promptedExerciseIDs.contains(exercise.id) else { return } | ||
| promptedExerciseIDs.insert(exercise.id) | ||
| isShowingFirstExercisePrompt = true | ||
| } | ||
|
|
||
| static func makePreviousRecordService() -> ExerciseReadAPIService? { | ||
| #if DEBUG | ||
| DebugOnboardingNetworking.makeExerciseReadService() | ||
| #else | ||
| nil | ||
| #endif | ||
| } | ||
| } |
96 changes: 96 additions & 0 deletions
96
GYMUP/Sources/Features/WorkoutSession/WorkoutSessionView+Content.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| import SwiftUI | ||
|
|
||
| extension WorkoutSessionView { | ||
| var preparationContent: some View { | ||
| WorkoutSessionPreparationView( | ||
| plan: viewModel.plan, | ||
| selectedExerciseIndex: $guideIndex, | ||
| onBack: dismiss.callAsFunction, | ||
| onStart: { viewModel.start(at: Date()) } | ||
| ) | ||
| } | ||
|
|
||
| var sessionContent: some View { | ||
| Group { | ||
| if let exercise = viewModel.currentExercise, | ||
| exercise.isComplete, | ||
| viewModel.plan.exercises.indices.contains(viewModel.currentExerciseIndex + 1) { | ||
| WorkoutExerciseCompleteScreen( | ||
| exercise: exercise, | ||
| nextExercise: viewModel.plan.exercises[viewModel.currentExerciseIndex + 1], | ||
| nextExerciseIndex: viewModel.currentExerciseIndex + 1, | ||
| totalExerciseCount: viewModel.plan.exercises.count, | ||
| onContinue: { _ = viewModel.moveToNextExercise() }, | ||
| onFinish: { isConfirmingFinish = true } | ||
| ) | ||
| } else if viewModel.isResting, | ||
| let exercise = viewModel.currentExercise, | ||
| let nextSetIndex = viewModel.currentSetIndex { | ||
| WorkoutSessionRestTimerScreen( | ||
| exercise: exercise, | ||
| completedSetCount: exercise.completedSetCount, | ||
| nextSetIndex: nextSetIndex, | ||
| remainingSeconds: viewModel.restSecondsRemaining, | ||
| totalSeconds: viewModel.activeRestDurationSeconds, | ||
| onExtend: { | ||
| viewModel.extendRest(by: 15) | ||
| syncRestActivity() | ||
| }, | ||
| onSkip: { | ||
| viewModel.skipRest() | ||
| settings.cancelRestNotification(sessionID: liveActivitySessionID) | ||
| Task { await WorkoutRestActivityController.shared.end(sessionID: liveActivitySessionID) } | ||
| }, | ||
| previousRecordError: viewModel.previousRecordError(for: exercise.id), | ||
| isLoadingPreviousRecord: viewModel.isLoadingPreviousRecord(for: exercise.id), | ||
| onRetryPreviousRecord: { Task { await loadPreviousRecord(for: exercise.id) } } | ||
| ) | ||
| } else if let exercise = viewModel.currentExercise { | ||
| WorkoutTrainModeScreen( | ||
| routineTitle: viewModel.plan.title, | ||
| elapsedTime: formattedDuration(viewModel.elapsedSeconds), | ||
| exercise: exercise, | ||
| exerciseIndex: viewModel.currentExerciseIndex, | ||
| totalExerciseCount: viewModel.plan.exercises.count, | ||
| currentSetIndex: viewModel.currentSetIndex, | ||
| isResting: viewModel.isResting || viewModel.isPaused, | ||
| isPaused: viewModel.isPaused, | ||
| restSecondsRemaining: viewModel.restSecondsRemaining, | ||
| onQuit: { isConfirmingFinish = true }, | ||
| onMusic: { isShowingPlaylist = true }, | ||
| onToggleGuide: { | ||
| withAnimation(.easeInOut(duration: 0.2)) { | ||
| isShowingCurrentGuide.toggle() | ||
| } | ||
| }, | ||
| onToggleSet: { setIndex in | ||
| viewModel.toggleSetCompletion( | ||
| exerciseIndex: viewModel.currentExerciseIndex, | ||
| setIndex: setIndex, | ||
| at: Date() | ||
| ) | ||
| syncRestActivity() | ||
| }, | ||
| onAdjustWeight: viewModel.adjustCurrentWeight, | ||
| onInputWeight: { | ||
| weightInputSetIndex = viewModel.currentSetIndex | ||
| isShowingWeightInput = weightInputSetIndex != nil | ||
| }, | ||
| onAdjustRepetitions: viewModel.adjustCurrentRepetitions, | ||
| onSetDone: { completeCurrentSet(at: Date()) }, | ||
| onSkipRest: { | ||
| viewModel.skipRest() | ||
| syncRestActivity() | ||
| }, | ||
| onNextExercise: { _ = viewModel.moveToNextExercise() }, | ||
| onFinish: { isConfirmingFinish = true }, | ||
| previousRecordError: viewModel.previousRecordError(for: exercise.id), | ||
| isLoadingPreviousRecord: viewModel.isLoadingPreviousRecord(for: exercise.id), | ||
| onRetryPreviousRecord: { Task { await loadPreviousRecord(for: exercise.id) } } | ||
| ) | ||
| } else { | ||
| GymupEmptyState(symbol: "dumbbell", title: "운동을 찾을 수 없어요", message: "루틴으로 돌아가 운동을 확인해 주세요.") | ||
| } | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[P1] 날짜·이전 기록 표시와 ViewModel의 성공/기록 없음/실패/재시도 동작을 검증하는 회귀 테스트를 추가해 주세요. Issue #184의 검증 조건인데 현재 PR에는 테스트가 없고, 이번 CI도 SwiftLint 실패 때문에 XCTest를 건너뛰었습니다.