2019-05-18 00:25:47 +02:00
|
|
|
//
|
|
|
|
// DetailAccountViewController.swift
|
|
|
|
// NetNewsWire-iOS
|
|
|
|
//
|
|
|
|
// Created by Maurice Parker on 5/17/19.
|
|
|
|
// Copyright © 2019 Ranchero Software. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import UIKit
|
|
|
|
import Account
|
|
|
|
|
|
|
|
class DetailAccountViewController: UITableViewController {
|
|
|
|
|
|
|
|
@IBOutlet weak var nameTextField: UITextField!
|
|
|
|
@IBOutlet weak var activeSwitch: UISwitch!
|
|
|
|
|
|
|
|
weak var account: Account?
|
|
|
|
|
|
|
|
override func viewDidLoad() {
|
|
|
|
super.viewDidLoad()
|
|
|
|
|
|
|
|
guard let account = account else { return }
|
2019-05-23 02:42:06 +02:00
|
|
|
|
|
|
|
nameTextField.placeholder = account.defaultName
|
2019-05-18 00:25:47 +02:00
|
|
|
nameTextField.text = account.name
|
2019-05-19 23:01:14 +02:00
|
|
|
nameTextField.delegate = self
|
2019-05-18 00:25:47 +02:00
|
|
|
activeSwitch.isOn = account.isActive
|
|
|
|
}
|
|
|
|
|
|
|
|
override func viewWillDisappear(_ animated: Bool) {
|
|
|
|
account?.name = nameTextField.text
|
|
|
|
account?.isActive = activeSwitch.isOn
|
|
|
|
}
|
2019-05-19 23:01:14 +02:00
|
|
|
|
|
|
|
}
|
2019-05-18 00:25:47 +02:00
|
|
|
|
2019-05-20 02:03:50 +02:00
|
|
|
extension DetailAccountViewController {
|
2019-05-18 00:25:47 +02:00
|
|
|
|
2019-05-20 01:04:32 +02:00
|
|
|
override func numberOfSections(in tableView: UITableView) -> Int {
|
2019-06-03 12:04:03 +02:00
|
|
|
|
|
|
|
guard let account = account else { return 0 }
|
|
|
|
|
2019-05-20 01:04:32 +02:00
|
|
|
if account == AccountManager.shared.defaultAccount {
|
|
|
|
return 1
|
2019-06-03 12:04:03 +02:00
|
|
|
} else if account.type == .onMyMac {
|
|
|
|
return 2
|
2019-05-20 01:04:32 +02:00
|
|
|
} else {
|
|
|
|
return super.numberOfSections(in: tableView)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
2019-06-03 12:04:03 +02:00
|
|
|
|
|
|
|
let cell: UITableViewCell
|
|
|
|
if indexPath.section == 1, let account = account, account.type == .onMyMac {
|
|
|
|
cell = super.tableView(tableView, cellForRowAt: IndexPath(row: 0, section: 2))
|
|
|
|
} else {
|
|
|
|
cell = super.tableView(tableView, cellForRowAt: indexPath)
|
|
|
|
}
|
2019-05-20 01:04:32 +02:00
|
|
|
|
|
|
|
let bgView = UIView()
|
2019-06-19 01:31:37 +02:00
|
|
|
bgView.backgroundColor = AppAssets.netNewsWireBlueColor
|
2019-05-20 01:04:32 +02:00
|
|
|
cell.selectedBackgroundView = bgView
|
|
|
|
return cell
|
|
|
|
}
|
|
|
|
|
2019-05-20 02:08:49 +02:00
|
|
|
override func tableView(_ tableView: UITableView, shouldHighlightRowAt indexPath: IndexPath) -> Bool {
|
2019-06-03 12:04:03 +02:00
|
|
|
if indexPath.section > 0 {
|
2019-05-20 02:08:49 +02:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2019-05-20 01:04:32 +02:00
|
|
|
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
|
2019-06-03 12:04:03 +02:00
|
|
|
if let account = account, account.type == .onMyMac {
|
|
|
|
if indexPath.section == 1 {
|
|
|
|
deleteAccount()
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
switch indexPath.section {
|
|
|
|
case 1:
|
|
|
|
credentials()
|
|
|
|
case 2:
|
|
|
|
deleteAccount()
|
|
|
|
default:
|
|
|
|
break
|
|
|
|
}
|
2019-05-20 01:04:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
tableView.selectRow(at: nil, animated: true, scrollPosition: .none)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
private extension DetailAccountViewController {
|
|
|
|
|
2019-06-03 12:04:03 +02:00
|
|
|
func credentials() {
|
|
|
|
guard let account = account else { return }
|
|
|
|
switch account.type {
|
|
|
|
case .feedbin:
|
|
|
|
let navController = UIStoryboard.settings.instantiateViewController(withIdentifier: "FeedbinAccountNavigationViewController") as! UINavigationController
|
|
|
|
let addViewController = navController.topViewController as! FeedbinAccountViewController
|
|
|
|
addViewController.account = account
|
|
|
|
present(navController, animated: true)
|
|
|
|
default:
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-20 01:04:32 +02:00
|
|
|
func deleteAccount() {
|
|
|
|
let title = NSLocalizedString("Delete Account", comment: "Delete Account")
|
|
|
|
let message = NSLocalizedString("Are you sure you want to delete this account? This can not be undone.", comment: "Delete Account")
|
|
|
|
let alertController = UIAlertController(title: title, message: message, preferredStyle: .alert)
|
|
|
|
|
|
|
|
let cancelTitle = NSLocalizedString("Cancel", comment: "Cancel")
|
|
|
|
let cancelAction = UIAlertAction(title: cancelTitle, style: .cancel)
|
|
|
|
alertController.addAction(cancelAction)
|
2019-05-19 23:01:14 +02:00
|
|
|
|
2019-05-20 01:04:32 +02:00
|
|
|
let markTitle = NSLocalizedString("Delete", comment: "Delete")
|
|
|
|
let markAction = UIAlertAction(title: markTitle, style: .default) { [weak self] (action) in
|
|
|
|
guard let account = self?.account else { return }
|
|
|
|
AccountManager.shared.deleteAccount(account)
|
|
|
|
self?.navigationController?.popViewController(animated: true)
|
|
|
|
}
|
|
|
|
alertController.addAction(markAction)
|
|
|
|
|
|
|
|
present(alertController, animated: true)
|
|
|
|
}
|
|
|
|
|
2019-05-18 00:25:47 +02:00
|
|
|
}
|
2019-05-20 02:03:50 +02:00
|
|
|
|
|
|
|
extension DetailAccountViewController: UITextFieldDelegate {
|
|
|
|
|
2019-05-19 23:01:14 +02:00
|
|
|
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
|
2019-05-19 23:14:23 +02:00
|
|
|
textField.resignFirstResponder()
|
2019-05-19 23:01:14 +02:00
|
|
|
return true
|
|
|
|
}
|
2019-05-20 02:03:50 +02:00
|
|
|
|
2019-05-18 00:25:47 +02:00
|
|
|
}
|