iOS/Sources/App/Settings/SettingsRootDataSource.swift
Bruno Pantaleão Gonçalves 5d7f370348
Cleanup SettingsDetailsViewController (#3974)
<!-- Thank you for submitting a Pull Request and helping to improve Home
Assistant. Please complete the following sections to help the processing
and review of your changes. Please do not delete anything from this
template. -->

## Summary
<!-- Provide a brief summary of the changes you have made and most
importantly what they aim to achieve -->

## Screenshots
<!-- If this is a user-facing change not in the frontend, please include
screenshots in light and dark mode. -->

## Link to pull request in Documentation repository
<!-- Pull requests that add, change or remove functionality must have a
corresponding pull request in the Companion App Documentation repository
(https://github.com/home-assistant/companion.home-assistant). Please add
the number of this pull request after the "#" -->
Documentation: home-assistant/companion.home-assistant#

## Any other notes
<!-- If there is any other information of note, like if this Pull
Request is part of a bigger change, please include it here. -->

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2025-11-13 13:30:59 +00:00

101 lines
3.4 KiB
Swift

import Eureka
import Shared
import SwiftUI
enum SettingsRootDataSource {
static let buttonRows: [SettingsButtonRow] = {
let fakeForm = Form()
return SettingsRootDataSource.Row
.allCases.map(\.row)
.filter { row in
if case let .function(_, function) = row.hidden {
// the function returns true to hide, so invert
return !function(fakeForm)
} else {
return true
}
}
}()
enum Row: String, CaseIterable {
case location
case notifications
case actions
case complications
case nfc
var row: SettingsButtonRow {
let row = { () -> SettingsButtonRow in
switch self {
case .location: return SettingsRootDataSource.location()
case .notifications: return SettingsRootDataSource.notifications()
case .actions: return SettingsRootDataSource.actions()
case .complications: return SettingsRootDataSource.complications()
case .nfc: return SettingsRootDataSource.nfc()
}
}()
row.tag = rawValue
return row
}
}
private static func notifications() -> SettingsButtonRow {
SettingsButtonRow {
$0.title = L10n.Settings.DetailsSection.NotificationSettingsRow.title
$0.icon = .bellOutlineIcon
$0.presentationMode = .show(controllerProvider: ControllerProvider.callback {
NotificationSettingsViewController()
}, onDismiss: nil)
}
}
private static func location() -> SettingsButtonRow {
SettingsButtonRow {
$0.title = L10n.Settings.DetailsSection.LocationSettingsRow.title
$0.icon = .crosshairsGpsIcon
$0.presentationMode = .show(controllerProvider: ControllerProvider.callback {
let view = SettingsDetailViewController()
view.detailGroup = .location
return view
}, onDismiss: nil)
}
}
private static func actions() -> SettingsButtonRow {
SettingsButtonRow {
$0.title = L10n.SettingsDetails.LegacyActions.title
$0.icon = .gamepadVariantOutlineIcon
$0.presentationMode = .show(controllerProvider: ControllerProvider.callback {
let view = SettingsDetailViewController()
view.detailGroup = .actions
return view
}, onDismiss: nil)
}
}
private static func complications() -> SettingsButtonRow {
SettingsButtonRow {
$0.title = L10n.Settings.DetailsSection.WatchRowComplications.title
$0.icon = .chartDonutIcon
$0.hidden = .isCatalyst
$0.presentationMode = .show(controllerProvider: ControllerProvider.callback {
ComplicationListViewController()
}, onDismiss: { _ in
})
}
}
private static func nfc() -> SettingsButtonRow {
SettingsButtonRow {
$0.title = L10n.Nfc.List.title
$0.icon = .nfcVariantIcon
$0.hidden = .isCatalyst
$0.presentationMode = .show(controllerProvider: ControllerProvider.callback {
NFCListViewController()
}, onDismiss: nil)
}
}
}