2019-04-16 20:38:07 +02:00
|
|
|
//
|
|
|
|
// AddFolderViewController.swift
|
|
|
|
// NetNewsWire
|
|
|
|
//
|
|
|
|
// Created by Maurice Parker on 4/16/19.
|
|
|
|
// Copyright © 2019 Ranchero Software, LLC. All rights reserved.
|
|
|
|
//
|
2019-04-15 22:03:05 +02:00
|
|
|
|
|
|
|
import UIKit
|
|
|
|
import Account
|
|
|
|
import RSCore
|
|
|
|
|
2019-04-16 23:03:30 +02:00
|
|
|
class AddFolderViewController: UITableViewController, AddContainerViewControllerChild {
|
2019-04-15 22:03:05 +02:00
|
|
|
|
|
|
|
@IBOutlet weak var nameTextField: UITextField!
|
|
|
|
@IBOutlet weak var accountLabel: UILabel!
|
|
|
|
@IBOutlet weak var accountPickerView: UIPickerView!
|
|
|
|
|
|
|
|
private var accounts: [Account]!
|
|
|
|
|
2019-04-26 01:06:53 +02:00
|
|
|
weak var delegate: AddContainerViewControllerChildDelegate?
|
2019-04-16 23:03:30 +02:00
|
|
|
|
2019-04-15 22:03:05 +02:00
|
|
|
override func viewDidLoad() {
|
|
|
|
|
|
|
|
super.viewDidLoad()
|
|
|
|
|
|
|
|
accounts = AccountManager.shared.sortedAccounts
|
|
|
|
accountLabel.text = (accounts[0] as DisplayNameProvider).nameForDisplay
|
|
|
|
|
|
|
|
accountPickerView.dataSource = self
|
|
|
|
accountPickerView.delegate = self
|
|
|
|
|
2019-04-16 20:38:07 +02:00
|
|
|
// I couldn't figure out the gap at the top of the UITableView, so I took a hammer to it.
|
|
|
|
tableView.contentInset = UIEdgeInsets(top: -28, left: 0, bottom: 0, right: 0)
|
2019-04-16 23:03:30 +02:00
|
|
|
|
|
|
|
NotificationCenter.default.addObserver(self, selector: #selector(textDidChange(_:)), name: UITextField.textDidChangeNotification, object: nameTextField)
|
|
|
|
|
2019-04-15 22:03:05 +02:00
|
|
|
}
|
|
|
|
|
2019-04-16 23:03:30 +02:00
|
|
|
func cancel() {
|
|
|
|
delegate?.processingDidEnd()
|
2019-04-15 22:03:05 +02:00
|
|
|
}
|
|
|
|
|
2019-04-16 23:03:30 +02:00
|
|
|
func add() {
|
2019-04-15 22:03:05 +02:00
|
|
|
let account = accounts[accountPickerView.selectedRow(inComponent: 0)]
|
|
|
|
if let folderName = nameTextField.text {
|
|
|
|
account.ensureFolder(with: folderName)
|
|
|
|
}
|
2019-04-16 23:03:30 +02:00
|
|
|
delegate?.processingDidEnd()
|
|
|
|
}
|
|
|
|
|
|
|
|
@objc func textDidChange(_ note: Notification) {
|
|
|
|
delegate?.readyToAdd(state: !(nameTextField.text?.isEmpty ?? false))
|
2019-04-15 22:03:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
extension AddFolderViewController: UIPickerViewDataSource, UIPickerViewDelegate {
|
|
|
|
|
|
|
|
func numberOfComponents(in pickerView: UIPickerView) ->Int {
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
|
|
|
|
return accounts.count
|
|
|
|
}
|
|
|
|
|
|
|
|
func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
|
|
|
|
return (accounts[row] as DisplayNameProvider).nameForDisplay
|
|
|
|
}
|
|
|
|
|
|
|
|
func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
|
|
|
|
accountLabel.text = (accounts[row] as DisplayNameProvider).nameForDisplay
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|