2019-10-21 18:51:33 +02:00
|
|
|
//
|
2019-10-24 02:58:18 +02:00
|
|
|
// LocalAccountViewController.swift
|
2019-10-21 18:51:33 +02:00
|
|
|
// NetNewsWire-iOS
|
|
|
|
//
|
|
|
|
// Created by Maurice Parker on 5/19/19.
|
|
|
|
// Copyright © 2019 Ranchero Software. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import UIKit
|
|
|
|
import Account
|
|
|
|
|
2019-10-24 02:58:18 +02:00
|
|
|
class LocalAccountViewController: UITableViewController {
|
2019-10-21 18:51:33 +02:00
|
|
|
|
|
|
|
@IBOutlet weak var nameTextField: UITextField!
|
2020-11-09 14:41:05 +01:00
|
|
|
@IBOutlet weak var footerLabel: UILabel!
|
2020-04-29 00:53:24 +02:00
|
|
|
|
|
|
|
weak var delegate: AddAccountDismissDelegate?
|
2019-10-21 18:51:33 +02:00
|
|
|
|
|
|
|
override func viewDidLoad() {
|
|
|
|
super.viewDidLoad()
|
2020-11-09 14:41:05 +01:00
|
|
|
setupFooter()
|
2019-10-22 03:28:50 +02:00
|
|
|
navigationItem.title = Account.defaultLocalAccountName
|
2019-10-21 18:51:33 +02:00
|
|
|
nameTextField.delegate = self
|
2019-11-16 22:47:12 +01:00
|
|
|
tableView.register(ImageHeaderView.self, forHeaderFooterViewReuseIdentifier: "SectionHeader")
|
2019-10-21 18:51:33 +02:00
|
|
|
}
|
2020-11-09 14:41:05 +01:00
|
|
|
|
|
|
|
private func setupFooter() {
|
|
|
|
footerLabel.text = NSLocalizedString("Local accounts do not sync your subscriptions across devices.", comment: "Local")
|
|
|
|
}
|
2019-10-21 18:51:33 +02:00
|
|
|
|
|
|
|
@IBAction func cancel(_ sender: Any) {
|
|
|
|
dismiss(animated: true, completion: nil)
|
|
|
|
}
|
|
|
|
|
2019-10-22 03:28:50 +02:00
|
|
|
@IBAction func add(_ sender: Any) {
|
2019-10-21 18:51:33 +02:00
|
|
|
let account = AccountManager.shared.createAccount(type: .onMyMac)
|
|
|
|
account.name = nameTextField.text
|
|
|
|
dismiss(animated: true, completion: nil)
|
2020-04-29 00:53:24 +02:00
|
|
|
delegate?.dismiss()
|
2019-10-21 18:51:33 +02:00
|
|
|
}
|
|
|
|
|
2019-11-16 22:47:12 +01:00
|
|
|
override func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
|
2019-11-22 22:11:15 +01:00
|
|
|
return section == 0 ? ImageHeaderView.rowHeight : super.tableView(tableView, heightForHeaderInSection: section)
|
2019-11-16 22:47:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-21 18:51:33 +02:00
|
|
|
}
|
|
|
|
|
2019-10-24 02:58:18 +02:00
|
|
|
extension LocalAccountViewController: UITextFieldDelegate {
|
2019-10-21 18:51:33 +02:00
|
|
|
|
|
|
|
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
|
|
|
|
textField.resignFirstResponder()
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|