-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ (ContentKit): Add new ActivityExerciseManager to replace ActivitySe…
…quenceManager
- Loading branch information
Showing
2 changed files
with
73 additions
and
2 deletions.
There are no files selected for viewing
71 changes: 71 additions & 0 deletions
71
Modules/ContentKit/Sources/Activity/ActivityExerciseManager.swift
This file contains 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,71 @@ | ||
// Leka - iOS Monorepo | ||
// Copyright APF France handicap | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
public class ActivityExerciseManager { | ||
// MARK: Lifecycle | ||
|
||
public init(activity: Activity) { | ||
var copyOfActivity = activity | ||
|
||
if copyOfActivity.exercisePayload.options.shuffleExercises { | ||
copyOfActivity.exercisePayload.exerciseGroups = copyOfActivity.exercisePayload.exerciseGroups.map { | ||
Activity.ExercisesPayload.ExerciseGroup(exercises: $0.exercises.shuffled()) | ||
} | ||
} | ||
|
||
if copyOfActivity.exercisePayload.options.shuffleGroups { | ||
copyOfActivity.exercisePayload.exerciseGroups.shuffle() | ||
} | ||
|
||
self.activity = copyOfActivity | ||
} | ||
|
||
// MARK: Public | ||
|
||
public var currentGroupIndex: Int = 0 | ||
public var currentExerciseIndexInCurrentGroup: Int = 0 | ||
|
||
public var totalGroups: Int { | ||
self.activity.exercisePayload.exerciseGroups.count | ||
} | ||
|
||
public var totalExercisesInCurrentGroup: Int { | ||
self.activity.exercisePayload.exerciseGroups[self.currentGroupIndex].exercises.count | ||
} | ||
|
||
public var currentExercise: Exercise { | ||
self.activity.exercisePayload.exerciseGroups[self.currentGroupIndex].exercises[self.currentExerciseIndexInCurrentGroup] | ||
} | ||
|
||
public var isFirstExercise: Bool { | ||
self.currentExerciseIndexInCurrentGroup == 0 && self.currentGroupIndex == 0 | ||
} | ||
|
||
public var isLastExercise: Bool { | ||
self.currentExerciseIndexInCurrentGroup == self.activity.exercisePayload.exerciseGroups[self.currentGroupIndex].exercises.count - 1 | ||
&& self.currentGroupIndex == self.activity.exercisePayload.exerciseGroups.count - 1 | ||
} | ||
|
||
public func moveToNextExercise() { | ||
if self.currentExerciseIndexInCurrentGroup < self.activity.exercisePayload.exerciseGroups[self.currentGroupIndex].exercises.count - 1 { | ||
self.currentExerciseIndexInCurrentGroup += 1 | ||
} else if self.currentGroupIndex < self.activity.exercisePayload.exerciseGroups.count - 1 { | ||
self.currentGroupIndex += 1 | ||
self.currentExerciseIndexInCurrentGroup = 0 | ||
} | ||
} | ||
|
||
public func moveToPreviousExercise() { | ||
if self.currentExerciseIndexInCurrentGroup > 0 { | ||
self.currentExerciseIndexInCurrentGroup -= 1 | ||
} else if self.currentGroupIndex > 0 { | ||
self.currentGroupIndex -= 1 | ||
self.currentExerciseIndexInCurrentGroup = self.activity.exercisePayload.exerciseGroups[self.currentGroupIndex].exercises.count - 1 | ||
} | ||
} | ||
|
||
// MARK: Private | ||
|
||
private let activity: Activity | ||
} |
This file contains 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