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/contentkit activity add setup type #716

Merged
merged 2 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 @@ -103,6 +103,27 @@ struct ActivityDetailsView: View {
Text(hmi.description)
}
})

DisclosureGroup("**Activity Types**") {
ForEach(self.activity.types, id: \.self) { type in
let type = ActivityTypes.type(id: type)!
HStack {
Text(type.name)
Button {
self.selectedType = type
} label: {
Image(systemName: "info.circle")
}
}
}
}
.sheet(item: self.$selectedType, onDismiss: { self.selectedType = nil }, content: { type in
VStack(alignment: .leading) {
Text(type.name)
.font(.headline)
Text(type.description)
}
})
}

Section {
Expand Down Expand Up @@ -130,6 +151,7 @@ struct ActivityDetailsView: View {
@State private var selectedAuthor: Author?
@State private var selectedSkill: Skill?
@State private var selectedHMI: HMIDetails?
@State private var selectedType: ActivityType?

private let navigation: Navigation = .shared
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ hmi:
- magic_cards
- tablet_robot

types:
- one_on_one
- group

locales:
- en_US
- fr_FR
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ hmi:
- magic_cards
- tablet_robot

types:
- one_on_one
- group

locales:
- en_US
- fr_FR
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ hmi:
- magic_cards
- tablet_robot

types:
- one_on_one
- group

locales:
- en_US
- fr_FR
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ hmi:
- magic_cards
- tablet_robot

types:
- one_on_one
- group

locales:
- en_US
- fr_FR
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ hmi:
- magic_cards
- tablet_robot

types:
- one_on_one
- group

locales:
- en_US
- fr_FR
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ hmi:
- magic_cards
- tablet_robot

types:
- one_on_one
- group

locales:
- en_US
- fr_FR
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ tags:
hmi: # {{💡TO_DEFINE}}
- tablet

types: # {{💡TO_DEFINE}}
- one_on_one
- group

locales:
- en_US
- fr_FR
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Leka - iOS Monorepo
# Copyright APF France handicap
# SPDX-License-Identifier: Apache-2.0

version: 1.0.0
list:
- id: one_on_one
l10n:
- locale: fr_FR
name: Activité en tête-à-tête
description: >
Une activité en tête-à-tête est un engagement personnalisé entre un accompagnant et une seule personne accompagnée,
conçu pour favoriser une relation étroite, une attention individuelle et des expériences d'apprentissage
ou de divertissement sur mesure. Ce type d'activité permet une interaction directe, un retour immédiat
et des activités spécifiquement adaptées aux intérêts, capacités et besoins de développement de la personne accompagnée.
- locale: en_US
name: One-on-one activity
description: >
A one-on-one activity is a personalized engagement between one caregiver and one care receiver, designed to foster
a close relationship, individual attention, and tailored learning or entertainment experiences. This type of activity
allows for direct interaction, immediate feedback, and activities specifically tailored to the interests, abilities,
and developmental needs of the care receiver.

- id: group
l10n:
- locale: fr_FR
name: Activité en groupe
description: >
Une activité de groupe implique plusieurs personnes accommpagnées, supervisées par un accompagnant, s'engageant dans une tâche
ou un jeu partagé. Elle est conçue pour encourager l'interaction sociale, le travail d'équipe et la résolution de problèmes collective.
Les activités de groupe aident les personnes à apprendre à coopérer, partager et naviguer dans les dynamiques sociales tout en profitant
des avantages de perspectives diverses et d'un effort collaboratif.
- locale: en_US
name: Group activity
description: |
A group activity involves multiple care receivers, supervised by a caregiver, engaging in a shared task or game. It is designed to
encourage social interaction, teamwork, and collective problem-solving. Group activities help individuals learn to cooperate, share, and
navigate social dynamics while benefiting from diverse perspectives and collaborative effort.
3 changes: 3 additions & 0 deletions Modules/ContentKit/Sources/Activity/Activity.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
self.authors = try container.decode([String].self, forKey: .authors)
self.skills = try container.decode([String].self, forKey: .skills)
self.hmi = try container.decode([String].self, forKey: .hmi)
self.types = try container.decode([String].self, forKey: .types)
self.tags = try container.decode([String].self, forKey: .tags)

let localeStrings = try container.decode([String].self, forKey: .locales)
Expand All @@ -39,10 +40,11 @@
public let name: String
public let status: Status

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

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 author...) (todo)
public let skills: [String] // TODO: (@ladislas) - implement skills

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 skills) (todo)
public let hmi: [String] // TODO: (@ladislas) - implement hmi

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 hmi) (todo)
public let types: [String] // TODO: (@ladislas) - implement types

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

View workflow job for this annotation

GitHub Actions / swiftlint

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

Check warning on line 47 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 @@ -73,6 +75,7 @@
case authors
case skills
case hmi
case types
case tags
case status
case locales
Expand Down
4 changes: 4 additions & 0 deletions Modules/ContentKit/Sources/Mocks/Activity+Mock.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ public extension Activity {
- magic_cards
- tablet_robot

types:
- one_on_one
- group

locales:
- en_US
- fr_FR
Expand Down
108 changes: 108 additions & 0 deletions Modules/ContentKit/Sources/Models/ActivityTypes.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
// Leka - iOS Monorepo
// Copyright APF France handicap
// SPDX-License-Identifier: Apache-2.0

import Foundation
import LocalizationKit
import LogKit
import Version
import Yams

// MARK: - ActivityTypes

public class ActivityTypes: Codable {
// MARK: Lifecycle

private init() {
self.container = Self.loadTypes()
}

// MARK: Public

public static var list: [ActivityType] {
shared.container.list
}

public static func type(id: String) -> ActivityType? {
self.list.first(where: { $0.id == id })
}

// MARK: Private

private struct TypesContainer: Codable {
let list: [ActivityType]
}

private static let shared: ActivityTypes = .init()

private let container: TypesContainer

private static func loadTypes() -> TypesContainer {
if let fileURL = Bundle.module.url(forResource: "activity_types", withExtension: "yml") {
do {
let yamlString = try String(contentsOf: fileURL, encoding: .utf8)
let container = try YAMLDecoder().decode(TypesContainer.self, from: yamlString)
return container
} catch {
log.error("Failed to read YAML file: \(error)")
return TypesContainer(list: [])
}
} else {
log.error("activity_types.yml not found")
return TypesContainer(list: [])
}
}
}

// MARK: - ActivityType

public struct ActivityType: Codable, Identifiable {
// MARK: Lifecycle

public init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
self.id = try container.decode(String.self, forKey: .id)

self.l10n = try container.decode([ActivityType.Localization].self, forKey: .l10n)

let availableLocales = self.l10n.map(\.locale)

let currentLocale = availableLocales.first(where: {
$0.language.languageCode == LocalizationKit.l10n.language
}) ?? Locale(identifier: "en_US")

self.name = self.l10n.first(where: { $0.locale == currentLocale })!.name
self.description = self.l10n.first(where: { $0.locale == currentLocale })!.description
}

// MARK: Public

public let id: String
public let name: String
public let description: String

// MARK: Private

private let l10n: [Localization]
}

// MARK: ActivityType.Localization

public extension ActivityType {
struct Localization: Codable {
// MARK: Lifecycle

public init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
self.locale = try Locale(identifier: container.decode(String.self, forKey: .locale))
self.name = try container.decode(String.self, forKey: .name)
self.description = try container.decode(String.self, forKey: .description)
}

// MARK: Internal

let locale: Locale
let name: String
let description: String
}
}
8 changes: 8 additions & 0 deletions Specs/jtd/activity.jtd.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@
"ref": "$hmi"
}
},
"types": {
"elements": {
"ref": "$type"
}
},
"tags": {
"elements": {
"ref": "$tag"
Expand Down Expand Up @@ -108,6 +113,9 @@
"$skill": {
"type": "string"
},
"$type": {
"enum": ["one_on_one", "group"]
},
"$tag": {
"type": "string"
},
Expand Down
Loading