Skip to content

Commit

Permalink
Update copy and add "show in watch" option
Browse files Browse the repository at this point in the history
  • Loading branch information
bgoncal committed Jan 18, 2024
1 parent 0313b81 commit 738b25b
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 18 deletions.
5 changes: 3 additions & 2 deletions Sources/App/Resources/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,8 @@ Home Assistant is free and open source home automation software with a focus on
"settings_details.actions.scenes.select_all" = "Select All";
"settings_details.actions.scenes.title" = "Scene Actions";
"settings_details.actions.title" = "Actions";
"settings_details.actions.carPlay.available.title" = "CarPlay";
"settings_details.actions.carPlay.available.title" = "Show in CarPlay";
"settings_details.actions.watch.available.title" = "Show in Watch";
"settings_details.general.app_icon.enum.beta" = "Beta";
"settings_details.general.app_icon.enum.black" = "Black";
"settings_details.general.app_icon.enum.blue" = "Blue";
Expand Down Expand Up @@ -809,4 +810,4 @@ Home Assistant is free and open source home automation software with a focus on
"widgets.open_page.description" = "Open a frontend page in Home Assistant.";
"widgets.open_page.not_configured" = "No Pages Available";
"widgets.open_page.title" = "Open Page";
"yes_label" = "Yes";
"yes_label" = "Yes";
26 changes: 20 additions & 6 deletions Sources/App/Settings/ActionConfigurator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,21 @@ class ActionConfigurator: HAFormViewController, TypedRowControllerType {
if !Current.isCatalyst {
firstSection <<< SwitchRow {
$0.title = L10n.SettingsDetails.Actions.CarPlay.Available.title
$0.value = action.CarPlayAvailable
$0.disabled = .init(booleanLiteral: !action.canConfigure(\Action.CarPlayAvailable))
$0.value = action.showInCarPlay
$0.disabled = .init(booleanLiteral: !action.canConfigure(\Action.showInCarPlay))
}.onChange { row in
if let value = row.value {
self.action.CarPlayAvailable = value
self.action.showInCarPlay = value
}
}

firstSection <<< SwitchRow("showInWatch") {
$0.title = L10n.SettingsDetails.Actions.Watch.Available.title
$0.value = action.showInWatch
$0.disabled = .init(booleanLiteral: !action.canConfigure(\Action.showInWatch))
}.onChange { row in
if let value = row.value {
self.action.showInWatch = value
}
}
}
Expand Down Expand Up @@ -251,11 +261,15 @@ class ActionConfigurator: HAFormViewController, TypedRowControllerType {
form.append(visuals)
}

form +++ ViewRow<ActionPreview>("preview").cellSetup { cell, _ in
form +++ ViewRow<ActionPreview>("preview") { [weak self] row in
row.hidden = Condition.function(["showInWatch"], { form in
return !(self?.action.showInWatch ?? true)
})
}.cellSetup { [weak self] cell, row in
cell.backgroundColor = UIColor.clear
cell.preservesSuperviewLayoutMargins = false
self.updatePreviews()
cell.view = self.preview
self?.updatePreviews()
cell.view = self?.preview
}

form +++ YamlSection(
Expand Down
2 changes: 1 addition & 1 deletion Sources/Extensions/Watch/InterfaceController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class InterfaceController: WKInterfaceController {

noActionsLabel.setText(L10n.Watch.Labels.noAction)

let actions = realm.objects(Action.self).sorted(byKeyPath: "Position")
let actions = realm.objects(Action.self).sorted(byKeyPath: "Position").filter("showInWatch == true")
self.actions = actions

notificationToken = actions.observe { (changes: RealmCollectionChange) in
Expand Down
21 changes: 17 additions & 4 deletions Sources/Shared/API/Models/Action.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ public final class Action: Object, ImmutableMappable, UpdatableModel {
@objc public dynamic var Scene: RLMScene?
@objc public dynamic var isServerControlled: Bool = false
@objc public dynamic var serverIdentifier: String = ""
@objc public dynamic var CarPlayAvailable: Bool = true
@objc public dynamic var showInCarPlay: Bool = true
@objc public dynamic var showInWatch: Bool = true

static func primaryKey(sourceIdentifier: String, serverIdentifier: String) -> String {
#warning("multiserver - primary key duplication")
Expand Down Expand Up @@ -69,7 +70,9 @@ public final class Action: Object, ImmutableMappable, UpdatableModel {
return Scene == nil
case \Action.serverIdentifier:
return Scene == nil
case \Action.CarPlayAvailable:
case \Action.showInCarPlay:
return Scene == nil
case \Action.showInWatch:
return Scene == nil
default:
return true
Expand All @@ -89,7 +92,8 @@ public final class Action: Object, ImmutableMappable, UpdatableModel {
self.CreatedAt = try map.value("CreatedAt", using: DateTransform())
self.isServerControlled = try map.value("isServerControlled")
self.serverIdentifier = try map.value("serverIdentifier")
self.CarPlayAvailable = try map.value("CarPlayAvailable")
self.showInCarPlay = try map.value("showInCarPlay")
self.showInWatch = try map.value("showInWatch")
super.init()
}

Expand All @@ -105,7 +109,8 @@ public final class Action: Object, ImmutableMappable, UpdatableModel {
CreatedAt >>> (map["CreatedAt"], DateTransform())
isServerControlled >>> map["isServerControlled"]
serverIdentifier >>> map["serverIdentifier"]
CarPlayAvailable >>> map["CarPlayAvailable"]
showInCarPlay >>> map["showInCarPlay"]
showInWatch >>> map["showInWatch"]
}

static func didUpdate(objects: [Action], server: Server, realm: Realm) {
Expand Down Expand Up @@ -158,6 +163,14 @@ public final class Action: Object, ImmutableMappable, UpdatableModel {
TextColor = textColor
}

if let showInCarPlay = object.showInCarPlay {
self.showInCarPlay = showInCarPlay
}

if let showInWatch = object.showInWatch {
self.showInWatch = showInWatch
}

return true
}

Expand Down
6 changes: 4 additions & 2 deletions Sources/Shared/API/Responses/MobileAppConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ public struct MobileAppConfigAction: ImmutableMappable, UpdatableModelSource {
var labelColor: String?
var iconIcon: String?
var iconColor: String?
var carPlayAvailable: Bool?
var showInCarPlay: Bool?
var showInWatch: Bool?

public init(map: Map) throws {
self.name = try map.value("name")
Expand All @@ -17,7 +18,8 @@ public struct MobileAppConfigAction: ImmutableMappable, UpdatableModelSource {
self.labelColor = try? map.value("label.color")
self.iconIcon = try? map.value("icon.icon")
self.iconColor = try? map.value("icon.color")
self.carPlayAvailable = try? map.value("carplay_available")
self.showInCarPlay = try? map.value("show_in_carplay")
self.showInWatch = try? map.value("show_in_watch")
}

public var primaryKey: String { name }
Expand Down
3 changes: 2 additions & 1 deletion Sources/Shared/Common/Extensions/Realm+Initialization.swift
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,8 @@ public extension Realm {

if oldVersion < 27 {
migration.enumerateObjects(ofType: Action.className()) { _, newObject in
newObject?["CarPlayAvailable"] = true
newObject?["showInCarPlay"] = true
newObject?["showInWatch"] = true
}
}

Expand Down
8 changes: 7 additions & 1 deletion Sources/Shared/Resources/Swiftgen/Strings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1339,7 +1339,7 @@ public enum L10n {
}
public enum CarPlay {
public enum Available {
/// CarPlay
/// Show in CarPlay
public static var title: String { return L10n.tr("Localizable", "settings_details.actions.carPlay.available.title") }
}
}
Expand All @@ -1355,6 +1355,12 @@ public enum L10n {
/// Scene Actions
public static var title: String { return L10n.tr("Localizable", "settings_details.actions.scenes.title") }
}
public enum Watch {
public enum Available {
/// Show in Watch
public static var title: String { return L10n.tr("Localizable", "settings_details.actions.watch.available.title") }
}
}
}
public enum General {
/// General
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ final class CarPlayActionsViewModel {
func update() {
let actions = Current.realm().objects(Action.self)
.sorted(byKeyPath: "Position")
.filter("Scene == nil AND CarPlayAvailable == true")
.filter("Scene == nil AND showInCarPlay == true")

actionsToken?.invalidate()
actionsToken = actions.observe { [weak self] _ in
Expand Down

0 comments on commit 738b25b

Please sign in to comment.