-
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.
🔀 Merge branch 'ladislas/feature/contentkit-add-activity-hmi'
- Loading branch information
Showing
11 changed files
with
234 additions
and
24 deletions.
There are no files selected for viewing
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
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 |
---|---|---|
|
@@ -29,6 +29,10 @@ identifier_name: | |
- BLE | ||
- cmd | ||
- g | ||
- hmi | ||
- HMI | ||
- hmis | ||
- HMIs | ||
- i | ||
- i18n | ||
- id | ||
|
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 |
---|---|---|
|
@@ -25,6 +25,11 @@ locales: | |
- en_US | ||
- fr_FR | ||
|
||
hmi: | ||
- robot | ||
- magic_cards | ||
- tablet_robot | ||
|
||
l10n: | ||
- locale: fr_FR | ||
details: | ||
|
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
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,49 @@ | ||
# Leka - iOS Monorepo | ||
# Copyright APF France handicap | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
version: 1.0.0 | ||
list: | ||
- id: robot | ||
l10n: | ||
- locale: fr_FR | ||
name: Robot seul | ||
description: | | ||
L'utilisateur interagit directement avec le robot. | ||
- locale: en_US | ||
name: Robot alone | ||
description: | | ||
The user interacts directly with the robot. | ||
- id: magic_cards | ||
l10n: | ||
- locale: fr_FR | ||
name: Robot et cartes magiques | ||
description: | | ||
L'utilisateur interagit avec le robot en utilisant les cartes magiques. | ||
- locale: en_US | ||
name: Robot and magic cards | ||
description: | | ||
The user interacts with the robot by using magic cards. | ||
- id: tablet_robot | ||
l10n: | ||
- locale: fr_FR | ||
name: iPad et robot | ||
description: | | ||
L'utilisateur interagit avec l'iPad, le robot agit en tant que support pour observer avant de répondre. | ||
- locale: en_US | ||
name: iPad and robot | ||
description: | | ||
The user interacts with the iPad, and the robot serves as support for observation before providing answers. | ||
- id: tablet | ||
l10n: | ||
- locale: fr_FR | ||
name: iPad (robot en renforçateur) | ||
description: | | ||
L'utilisateur interagit avec l'iPad, le robot agit en tant que renforçateur. | ||
- locale: en_US | ||
name: iPad (robot as reinforcer) | ||
description: | | ||
The user interacts with the iPad, and the robot serves as reinforcer. |
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
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,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: - HMI | ||
|
||
public class HMI: Codable { | ||
// MARK: Lifecycle | ||
|
||
private init() { | ||
self.container = Self.loadHMI() | ||
} | ||
|
||
// MARK: Public | ||
|
||
public static var list: [HMIDetails] { | ||
shared.container.list | ||
} | ||
|
||
public static func hmi(id: String) -> HMIDetails? { | ||
self.list.first(where: { $0.id == id }) | ||
} | ||
|
||
// MARK: Private | ||
|
||
private struct HMIContainer: Codable { | ||
let list: [HMIDetails] | ||
} | ||
|
||
private static let shared: HMI = .init() | ||
|
||
private let container: HMIContainer | ||
|
||
private static func loadHMI() -> HMIContainer { | ||
if let fileURL = Bundle.module.url(forResource: "hmi", withExtension: "yml") { | ||
do { | ||
let yamlString = try String(contentsOf: fileURL, encoding: .utf8) | ||
let container = try YAMLDecoder().decode(HMIContainer.self, from: yamlString) | ||
return container | ||
} catch { | ||
log.error("Failed to read YAML file: \(error)") | ||
return HMIContainer(list: []) | ||
} | ||
} else { | ||
log.error("hmi.yml not found") | ||
return HMIContainer(list: []) | ||
} | ||
} | ||
} | ||
|
||
// MARK: - HMIDetails | ||
|
||
public struct HMIDetails: 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([HMIDetails.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: HMIDetails.Localization | ||
|
||
public extension HMIDetails { | ||
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 | ||
} | ||
} |
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
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
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
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