Skip to content

Commit

Permalink
🔀 Merge branch 'ladislas/feature/gek-refactor-activity-view'
Browse files Browse the repository at this point in the history
  • Loading branch information
ladislas committed Feb 22, 2024
2 parents bd15514 + 8af7515 commit f6506ce
Show file tree
Hide file tree
Showing 13 changed files with 81 additions and 78 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,7 @@ struct MainView: View {
.fullScreenCover(item: self.$navigation.currentActivity) {
self.navigation.currentActivity = nil
} content: { activity in
Text("Activity: \(activity.details.title)")
// TODO: (@ladislas) switch back to activity view
// ActivityView(activity: activity)
ActivityView(activity: activity)
}
.sheet(isPresented: self.$rootOwnerViewModel.isSettingsViewPresented) {
SettingsView()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,10 +238,10 @@ exercises_payload:
type: sfsymbol
- value: cloud.sun
type: sfsymbol
- value: cloud.bolt.rain.fill
- value: cloud.bolt.rain
type: sfsymbol
isRightAnswer: true
- value: cloud.rain
- value: cloud.snow
type: sfsymbol

- instructions:
Expand All @@ -260,5 +260,5 @@ exercises_payload:
type: sfsymbol
- value: airplane
type: sfsymbol
- value: boat
- value: sailboat
type: sfsymbol
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ exercises_payload:
type: sfsymbol
- value: cloud.sun
type: sfsymbol
- value: cloud.bolt.rain.fill
- value: cloud.bolt.rain
type: sfsymbol
isRightAnswer: true
- value: cloud.rain
Expand All @@ -260,5 +260,5 @@ exercises_payload:
type: sfsymbol
- value: airplane
type: sfsymbol
- value: boat
- value: sailboat
type: sfsymbol
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ exercises_payload:
type: sfsymbol
- value: cloud.sun
type: sfsymbol
- value: cloud.bolt.rain.fill
- value: cloud.bolt.rain
type: sfsymbol
isRightAnswer: true
- value: cloud.rain
Expand All @@ -260,5 +260,5 @@ exercises_payload:
type: sfsymbol
- value: airplane
type: sfsymbol
- value: boat
- value: sailboat
type: sfsymbol
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ exercises_payload:
type: sfsymbol
- value: cloud.sun
type: sfsymbol
- value: cloud.bolt.rain.fill
- value: cloud.bolt.rain
type: sfsymbol
isRightAnswer: true
- value: cloud.rain
Expand All @@ -260,5 +260,5 @@ exercises_payload:
type: sfsymbol
- value: airplane
type: sfsymbol
- value: boat
- value: sailboat
type: sfsymbol
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ exercises_payload:
type: sfsymbol
- value: cloud.sun
type: sfsymbol
- value: cloud.bolt.rain.fill
- value: cloud.bolt.rain
type: sfsymbol
isRightAnswer: true
- value: cloud.rain
Expand All @@ -260,5 +260,5 @@ exercises_payload:
type: sfsymbol
- value: airplane
type: sfsymbol
- value: boat
- value: sailboat
type: sfsymbol
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ exercises_payload:
type: sfsymbol
- value: cloud.sun
type: sfsymbol
- value: cloud.bolt.rain.fill
- value: cloud.bolt.rain
type: sfsymbol
isRightAnswer: true
- value: cloud.rain
Expand All @@ -260,5 +260,5 @@ exercises_payload:
type: sfsymbol
- value: airplane
type: sfsymbol
- value: boat
- value: sailboat
type: sfsymbol
6 changes: 3 additions & 3 deletions Modules/ContentKit/Sources/Activity/Activity.swift
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,10 @@ public extension Activity {

public extension Activity {
struct ExercisesPayload: Decodable {
// MARK: Internal
// MARK: Public

let options: Options
var exerciseGroups: [ExerciseGroup]
public let options: Options
public var exerciseGroups: [ExerciseGroup]

// MARK: Private

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Copyright APF France handicap
// SPDX-License-Identifier: Apache-2.0

public class ActivityExerciseManager {
public class CurrentActivityManager {
// MARK: Lifecycle

public init(activity: Activity) {
Expand All @@ -26,6 +26,8 @@ public class ActivityExerciseManager {
public var currentGroupIndex: Int = 0
public var currentExerciseIndexInCurrentGroup: Int = 0

public let activity: Activity

public var totalGroups: Int {
self.activity.exercisePayload.exerciseGroups.count
}
Expand Down Expand Up @@ -64,8 +66,4 @@ public class ActivityExerciseManager {
self.currentExerciseIndexInCurrentGroup = self.activity.exercisePayload.exerciseGroups[self.currentGroupIndex].exercises.count - 1
}
}

// MARK: Private

private let activity: Activity
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,22 @@ import SwiftUI
public class ExerciseSharedData: ObservableObject {
// MARK: Lifecycle

public init(sequenceIndex: Int, exerciseIndex: Int) {
self.sequenceIndex = sequenceIndex
public init(groupIndex: Int, exerciseIndex: Int) {
self.groupIndex = groupIndex
self.exerciseIndex = exerciseIndex
}

public init() {
self.exerciseIndex = 0
self.sequenceIndex = 0
self.groupIndex = 0
}

// MARK: Internal

// TODO: (@HPezz): Add state setter function, and makes it private
@Published var state: ExerciseState = .idle

let sequenceIndex: Int
let groupIndex: Int
let exerciseIndex: Int

var completionLevel: ExerciseState.CompletionLevel? {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,23 @@ struct ActivityProgressBar: View {
// MARK: Internal

@ObservedObject var viewModel: ActivityViewViewModel
let height: CGFloat = 30

var body: some View {
HStack(spacing: 0) {
Spacer()
ForEach(0..<self.viewModel.totalSequences, id: \.self) { sequenceIndex in
ForEach(0..<self.viewModel.totalGroups, id: \.self) { groupIndex in
HStack(spacing: 0) {
ForEach(0..<self.viewModel.totalExercisesInCurrentSequence, id: \.self) { exerciseIndex in
let markerColor = self.progressBarMarkerColor(sequence: sequenceIndex, exercise: exerciseIndex)
ForEach(0..<self.viewModel.groupSizeEnumeration[groupIndex], id: \.self) { exerciseIndex in
let markerColor = self.progressBarMarkerColor(group: groupIndex, exercise: exerciseIndex)

let isCurrentSequence = sequenceIndex == self.viewModel.currentSequenceIndex
let isCurrentExercise = isCurrentSequence && exerciseIndex == self.viewModel.currentExerciseIndexInSequence
let isCurrentGroup = groupIndex == self.viewModel.currentGroupIndex
let isCurrentExercise = isCurrentGroup && exerciseIndex == self.viewModel.currentExerciseIndexInCurrentGroup
let isNotYetCompleted = self.viewModel.currentExerciseSharedData.isExerciseNotYetCompleted

let isCurrentlyPlaying = isCurrentExercise && isNotYetCompleted

ActivityProgressBarMarker(
color: (isCurrentSequence && isCurrentExercise)
color: (isCurrentGroup && isCurrentExercise)
? self.$currentColor : .constant(markerColor),
isCurrentlyPlaying: .constant(isCurrentlyPlaying)
)
Expand All @@ -39,15 +38,15 @@ struct ActivityProgressBar: View {
}
}

if exerciseIndex < self.viewModel.totalExercisesInCurrentSequence - 1 {
if exerciseIndex < self.viewModel.groupSizeEnumeration[groupIndex] - 1 {
Spacer().frame(maxWidth: 100)
}
}
}
.frame(height: self.height)
.background(DesignKitAsset.Colors.progressBar.swiftUIColor, in: Capsule())

if sequenceIndex < self.viewModel.totalSequences - 1 {
if groupIndex < self.viewModel.totalGroups - 1 {
Spacer().frame(minWidth: 20, maxWidth: 60)
}
}
Expand All @@ -57,6 +56,8 @@ struct ActivityProgressBar: View {

// MARK: Private

private let height: CGFloat = 30

@State private var currentColor: Color = .white

private func completionLevelToColor(level: ExerciseState.CompletionLevel?) -> Color {
Expand All @@ -75,9 +76,9 @@ struct ActivityProgressBar: View {
}
}

private func progressBarMarkerColor(sequence: Int, exercise: Int) -> Color {
private func progressBarMarkerColor(group: Int, exercise: Int) -> Color {
if let completedExerciseSharedData = self.viewModel.completedExercisesSharedData.first(where: {
$0.sequenceIndex == sequence
$0.groupIndex == group
&& $0.exerciseIndex == exercise
}) {
self.completionLevelToColor(level: completedExerciseSharedData.completionLevel)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import SwiftUI
public struct ActivityView: View {
// MARK: Lifecycle

public init(viewModel: ActivityViewViewModel) {
self.viewModel = viewModel
public init(activity: Activity) {
self._viewModel = StateObject(wrappedValue: ActivityViewViewModel(activity: activity))
}

// MARK: Public
Expand All @@ -32,7 +32,7 @@ public struct ActivityView: View {
}

if self.viewModel.isExerciseInstructionsButtonVisible {
ExerciseInstructionsButton(instructions: self.viewModel.currentExercise.instructions)
ExerciseInstructionsButton(instructions: self.viewModel.currentExercise.instructions!)
}
}

Expand All @@ -42,7 +42,7 @@ public struct ActivityView: View {
Spacer()
}
}
.id(self.viewModel.currentExerciseIndexInSequence)
.id(self.viewModel.currentExerciseIndexInCurrentGroup)
.blur(radius: self.blurRadius)
.opacity(self.opacity)
.onChange(of: self.viewModel.isReinforcerAnimationVisible) {
Expand Down Expand Up @@ -146,7 +146,8 @@ public struct ActivityView: View {

@Environment(\.dismiss) var dismiss

@ObservedObject var viewModel: ActivityViewViewModel
// TODO: (@ladislas) was @ObservedObject, check why
@StateObject var viewModel: ActivityViewViewModel

// MARK: Private

Expand Down Expand Up @@ -301,6 +302,7 @@ public struct ActivityView: View {
// swiftlint:enable cyclomatic_complexity void_function_in_ternary function_body_length

#Preview {
let activity = ContentKit.decodeActivityDeprecated("activity-sample")
return ActivityView(viewModel: ActivityViewViewModel(activity: activity))
NavigationStack {
ActivityView(activity: Activity.mock)
}
}
Loading

0 comments on commit f6506ce

Please sign in to comment.