Skip to content
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

ladislas/feature/gek refactor activity view #707

Merged
merged 6 commits into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
}
.frame(maxWidth: .infinity)
}
// TODO: (@ladislas) remove if not necessary

Check warning on line 79 in Apps/LekaApp/Sources/_NEWCodeBase/Views/MainView/MainView.swift

View workflow job for this annotation

GitHub Actions / swiftlint

TODOs should be resolved ((@ladislas) remove if not nece...) (todo)
// .disabled(navigation.disableUICompletly)
} detail: {
NavigationStack(path: self.$navigation.path) {
Expand Down Expand Up @@ -125,7 +125,7 @@
.fullScreenCover(isPresented: self.$viewModel.isRobotConnectionPresented) {
RobotConnectionView(viewModel: RobotConnectionViewModel())
}
// TODO: (@team) - Update this onReceive when caregiver are managed by AccountKit

Check warning on line 128 in Apps/LekaApp/Sources/_NEWCodeBase/Views/MainView/MainView.swift

View workflow job for this annotation

GitHub Actions / swiftlint

TODOs should be resolved ((@team) - Update this onReceiv...) (todo)
.onReceive(self.rootOwnerViewModel.$currentCaregiver) { caregiver in
if !self.authManagerViewModel.isUserLoggedOut {
self.isCaregiverPickerPresented = (caregiver == nil)
Expand All @@ -137,9 +137,7 @@
.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 @@ -39,10 +39,10 @@
public let name: String
public let status: Status

public let authors: [String] // TODO: (@ladislas) - implement authors

Check warning on line 42 in Modules/ContentKit/Sources/Activity/Activity.swift

View workflow job for this annotation

GitHub Actions / swiftlint

TODOs should be resolved ((@ladislas) - implement author...) (todo)
public let skills: [String] // TODO: (@ladislas) - implement skills

Check warning on line 43 in Modules/ContentKit/Sources/Activity/Activity.swift

View workflow job for this annotation

GitHub Actions / swiftlint

TODOs should be resolved ((@ladislas) - implement skills) (todo)
public let hmi: [String] // TODO: (@ladislas) - implement hmi

Check warning on line 44 in Modules/ContentKit/Sources/Activity/Activity.swift

View workflow job for this annotation

GitHub Actions / swiftlint

TODOs should be resolved ((@ladislas) - implement hmi) (todo)
public let tags: [String] // TODO: (@ladislas) - implement tags

Check warning on line 45 in Modules/ContentKit/Sources/Activity/Activity.swift

View workflow job for this annotation

GitHub Actions / swiftlint

TODOs should be resolved ((@ladislas) - implement tags) (todo)

public let locales: [Locale]
public let l10n: [LocalizedDetails]
Expand Down Expand Up @@ -142,10 +142,10 @@

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 @@
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

Check warning on line 22 in Modules/GameEngineKit/Sources/_NewSystem/Exercises/ExerciseSharedData.swift

View workflow job for this annotation

GitHub Actions / swiftlint

TODOs should be resolved ((@HPezz): Add state setter fun...) (todo)
@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 @@
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 @@
}

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

Expand All @@ -42,7 +42,7 @@
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 @@ -125,7 +125,7 @@
}
}
.sheet(isPresented: self.$isInfoSheetPresented) {
// TODO: (@team) - Add YAML description of activities

Check warning on line 128 in Modules/GameEngineKit/Sources/_NewSystem/Views/Activity/ActivityView.swift

View workflow job for this annotation

GitHub Actions / swiftlint

TODOs should be resolved ((@team) - Add YAML description...) (todo)
Text("Info related to the activity ")
}
.fullScreenCover(isPresented: self.$viewModel.isCurrentActivityCompleted) {
Expand All @@ -146,7 +146,8 @@

@Environment(\.dismiss) var dismiss

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

Check warning on line 149 in Modules/GameEngineKit/Sources/_NewSystem/Views/Activity/ActivityView.swift

View workflow job for this annotation

GitHub Actions / swiftlint

TODOs should be resolved ((@ladislas) was @ObservedObjec...) (todo)
@StateObject var viewModel: ActivityViewViewModel

// MARK: Private

Expand All @@ -173,7 +174,7 @@
speed: 0.2
)
.onAppear {
// TODO(@ladislas/@hugo): Use reinforcer children choice

Check warning on line 177 in Modules/GameEngineKit/Sources/_NewSystem/Views/Activity/ActivityView.swift

View workflow job for this annotation

GitHub Actions / swiftlint

TODOs should be resolved ((@ladislas/@hugo): Use reinfor...) (todo)
self.robot.run(.fire)
}
.transition(
Expand Down Expand Up @@ -301,6 +302,7 @@
// 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
Loading