2019-11-16 19:02:58 +01:00
|
|
|
//
|
2020-08-12 00:04:11 +02:00
|
|
|
// AddFeedFolderViewController.swift
|
2019-11-16 19:02:58 +01:00
|
|
|
// NetNewsWire-iOS
|
|
|
|
//
|
|
|
|
// Created by Maurice Parker on 11/16/19.
|
|
|
|
// Copyright © 2019 Ranchero Software. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import UIKit
|
|
|
|
import RSCore
|
|
|
|
import Account
|
|
|
|
|
2020-08-12 00:04:11 +02:00
|
|
|
protocol AddFeedFolderViewControllerDelegate {
|
2019-11-16 19:02:58 +01:00
|
|
|
func didSelect(container: Container)
|
|
|
|
}
|
|
|
|
|
2020-08-12 00:04:11 +02:00
|
|
|
class AddFeedFolderViewController: UITableViewController {
|
2019-11-16 19:02:58 +01:00
|
|
|
|
2020-08-12 00:04:11 +02:00
|
|
|
var delegate: AddFeedFolderViewControllerDelegate?
|
2020-08-12 00:33:48 +02:00
|
|
|
var addFeedType = AddFeedType.web
|
2019-11-16 19:02:58 +01:00
|
|
|
var initialContainer: Container?
|
|
|
|
|
|
|
|
var containers = [Container]()
|
|
|
|
|
|
|
|
override func viewDidLoad() {
|
|
|
|
super.viewDidLoad()
|
|
|
|
|
2020-08-12 00:33:48 +02:00
|
|
|
var sortedActiveAccounts: [Account]
|
|
|
|
if addFeedType == .web {
|
|
|
|
sortedActiveAccounts = AccountManager.shared.sortedActiveAccounts
|
|
|
|
} else {
|
|
|
|
sortedActiveAccounts = AccountManager.shared.sortedActiveAccounts.filter { $0.type == .onMyMac || $0.type == .cloudKit }
|
|
|
|
}
|
|
|
|
|
|
|
|
for account in sortedActiveAccounts {
|
2019-11-16 19:02:58 +01:00
|
|
|
containers.append(account)
|
|
|
|
if let sortedFolders = account.sortedFolders {
|
|
|
|
containers.append(contentsOf: sortedFolders)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// MARK: - Table view data source
|
|
|
|
|
|
|
|
override func numberOfSections(in tableView: UITableView) -> Int {
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
|
|
|
return containers.count
|
|
|
|
}
|
|
|
|
|
|
|
|
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
|
|
|
let container = containers[indexPath.row]
|
2020-04-23 11:00:51 +02:00
|
|
|
let cell: AddComboTableViewCell = {
|
2019-11-16 19:02:58 +01:00
|
|
|
if container is Account {
|
2020-04-23 11:00:51 +02:00
|
|
|
return tableView.dequeueReusableCell(withIdentifier: "AccountCell", for: indexPath) as! AddComboTableViewCell
|
2019-11-16 19:02:58 +01:00
|
|
|
} else {
|
2020-04-23 11:00:51 +02:00
|
|
|
return tableView.dequeueReusableCell(withIdentifier: "FolderCell", for: indexPath) as! AddComboTableViewCell
|
2019-11-16 19:02:58 +01:00
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
|
|
|
if let smallIconProvider = container as? SmallIconProvider {
|
|
|
|
cell.icon?.image = smallIconProvider.smallIcon?.image
|
|
|
|
}
|
|
|
|
|
|
|
|
if let displayNameProvider = container as? DisplayNameProvider {
|
|
|
|
cell.label?.text = displayNameProvider.nameForDisplay
|
|
|
|
}
|
|
|
|
|
|
|
|
if let compContainer = initialContainer, container === compContainer {
|
|
|
|
cell.accessoryType = .checkmark
|
2019-11-17 02:44:01 +01:00
|
|
|
} else {
|
|
|
|
cell.accessoryType = .none
|
2019-11-16 19:02:58 +01:00
|
|
|
}
|
2019-11-17 02:44:01 +01:00
|
|
|
|
2019-11-16 19:02:58 +01:00
|
|
|
return cell
|
|
|
|
}
|
|
|
|
|
|
|
|
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
|
2019-11-16 20:25:55 +01:00
|
|
|
let container = containers[indexPath.row]
|
2019-11-16 19:02:58 +01:00
|
|
|
|
2019-11-16 20:25:55 +01:00
|
|
|
if let account = container as? Account, account.behaviors.contains(.disallowFeedInRootFolder) {
|
|
|
|
tableView.selectRow(at: nil, animated: false, scrollPosition: .none)
|
|
|
|
} else {
|
|
|
|
let cell = tableView.cellForRow(at: indexPath)
|
|
|
|
cell?.accessoryType = .checkmark
|
|
|
|
delegate?.didSelect(container: container)
|
2019-11-16 21:19:51 +01:00
|
|
|
dismiss()
|
2019-11-16 20:25:55 +01:00
|
|
|
}
|
2019-11-16 19:02:58 +01:00
|
|
|
}
|
|
|
|
|
2019-11-16 21:19:51 +01:00
|
|
|
// MARK: Actions
|
|
|
|
|
|
|
|
@IBAction func cancel(_ sender: Any) {
|
|
|
|
dismiss()
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-08-12 00:04:11 +02:00
|
|
|
private extension AddFeedFolderViewController {
|
2019-11-16 21:19:51 +01:00
|
|
|
|
|
|
|
func dismiss() {
|
|
|
|
dismiss(animated: true)
|
|
|
|
}
|
|
|
|
|
2019-11-16 19:02:58 +01:00
|
|
|
}
|