iOS/Sources/App/Settings/TemplateEditViewController.swift
Bruno Pantaleão Gonçalves e9c85b3f7a
Drop iOS 12, 13 and 14 support (#2469)
<!-- 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 -->
Drop support for iOS 12 and 13.

## 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. -->
2023-12-27 16:50:11 +01:00

85 lines
2.2 KiB
Swift

import Eureka
import Foundation
import HAKit
import Shared
class TemplateEditViewController: HAFormViewController, RowControllerType {
var onDismissCallback: ((UIViewController) -> Void)?
var saveHandler: (Server, String) -> Void
private var server: Server {
didSet {
templateSection?.server = server
}
}
private let initialValue: String
private var templateSection: TemplateSection?
init(
server: Server,
initial: String,
saveHandler: @escaping (Server, String) -> Void
) {
self.server = server
self.saveHandler = saveHandler
self.initialValue = initial
super.init()
isModalInPresentation = true
self.title = L10n.Settings.TemplateEdit.title
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
_ = templateSection?.inputRow.cell.textView.becomeFirstResponder()
}
override func viewDidLoad() {
super.viewDidLoad()
navigationItem.leftBarButtonItems = [
UIBarButtonItem(barButtonSystemItem: .cancel, target: self, action: #selector(cancel)),
]
navigationItem.rightBarButtonItems = [
UIBarButtonItem(barButtonSystemItem: .save, target: self, action: #selector(save)),
]
let section = TemplateSection(
header: nil,
footer: nil,
server: server,
initializeInput: {
$0.value = initialValue
$0.placeholder = "{{ now() }}"
}, initializeSection: { _ in
}
)
section <<< ServerSelectRow {
$0.value = .server(server)
$0.onChange { [weak self] row in
if case let .server(server) = row.value {
self?.server = server
}
}
}
form +++ section
templateSection = section
}
@objc private func cancel() {
onDismissCallback?(self)
}
@objc private func save() {
if let section = templateSection {
saveHandler(server, section.inputRow.value ?? "")
}
onDismissCallback?(self)
}
}