NetNewsWire/iOS/Settings/AddAccountViewController.swift

81 lines
2.5 KiB
Swift
Raw Normal View History

//
// AddAccountViewController.swift
// NetNewsWire-iOS
//
// Created by Maurice Parker on 5/16/19.
// Copyright © 2019 Ranchero Software. All rights reserved.
//
import Account
import UIKit
protocol AddAccountDismissDelegate: UIViewController {
func dismiss()
}
class AddAccountViewController: UITableViewController, AddAccountDismissDelegate {
2019-10-23 20:52:07 +02:00
@IBOutlet private weak var localAccountImageView: UIImageView!
@IBOutlet private weak var localAccountNameLabel: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
2019-10-23 20:52:07 +02:00
localAccountImageView.image = AppAssets.image(for: .onMyMac)
localAccountNameLabel.text = Account.defaultLocalAccountName
}
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
switch indexPath.row {
case 0:
let navController = UIStoryboard.account.instantiateViewController(withIdentifier: "AddLocalAccountNavigationViewController") as! UINavigationController
navController.modalPresentationStyle = .currentContext
let addViewController = navController.topViewController as! LocalAccountViewController
addViewController.delegate = self
present(navController, animated: true)
case 1:
let navController = UIStoryboard.account.instantiateViewController(withIdentifier: "FeedbinAccountNavigationViewController") as! UINavigationController
navController.modalPresentationStyle = .currentContext
let addViewController = navController.topViewController as! FeedbinAccountViewController
addViewController.delegate = self
present(navController, animated: true)
case 2:
let addAccount = OAuthAccountAuthorizationOperation(accountType: .feedly)
addAccount.delegate = self
addAccount.presentationAnchor = self.view.window!
OperationQueue.main.addOperation(addAccount)
default:
break
}
}
func dismiss() {
navigationController?.popViewController(animated: false)
}
}
extension AddAccountViewController: OAuthAccountAuthorizationOperationDelegate {
func oauthAccountAuthorizationOperation(_ operation: OAuthAccountAuthorizationOperation, didCreate account: Account) {
let rootViewController = view.window?.rootViewController
account.refreshAll { result in
switch result {
case .success:
break
case .failure(let error):
guard let viewController = rootViewController else {
return
}
viewController.presentError(error)
}
}
dismiss()
}
func oauthAccountAuthorizationOperation(_ operation: OAuthAccountAuthorizationOperation, didFailWith error: Error) {
presentError(error)
}
}