NetNewsWire/iOS/Account/LocalAccountViewController.swift

66 lines
1.9 KiB
Swift
Raw Normal View History

//
// LocalAccountViewController.swift
// NetNewsWire-iOS
//
// Created by Maurice Parker on 5/19/19.
// Copyright © 2019 Ranchero Software. All rights reserved.
//
import UIKit
import Account
class LocalAccountViewController: UITableViewController {
@IBOutlet weak var nameTextField: UITextField!
2020-11-09 14:41:05 +01:00
@IBOutlet weak var footerLabel: UILabel!
weak var delegate: AddAccountDismissDelegate?
override func viewDidLoad() {
super.viewDidLoad()
2020-11-09 14:41:05 +01:00
setupFooter()
navigationItem.title = Account.defaultLocalAccountName
nameTextField.delegate = self
tableView.register(ImageHeaderView.self, forHeaderFooterViewReuseIdentifier: "SectionHeader")
}
2020-11-09 14:41:05 +01:00
private func setupFooter() {
footerLabel.text = NSLocalizedString("Local accounts do not sync your feeds across devices.", comment: "Local")
2020-11-09 14:41:05 +01:00
}
@IBAction func cancel(_ sender: Any) {
dismiss(animated: true, completion: nil)
}
@IBAction func add(_ sender: Any) {
let account = AccountManager.shared.createAccount(type: .onMyMac)
account.name = nameTextField.text
dismiss(animated: true, completion: nil)
delegate?.dismiss()
}
override func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return section == 0 ? ImageHeaderView.rowHeight : super.tableView(tableView, heightForHeaderInSection: section)
}
override func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
if section == 0 {
let headerView = tableView.dequeueReusableHeaderFooterView(withIdentifier: "SectionHeader") as! ImageHeaderView
headerView.imageView.image = AppAssets.image(for: .onMyMac)
return headerView
} else {
return super.tableView(tableView, viewForHeaderInSection: section)
}
}
}
extension LocalAccountViewController: UITextFieldDelegate {
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
textField.resignFirstResponder()
return true
}
}