2019-09-12 19:33:05 +02:00
|
|
|
//
|
|
|
|
// ShareFolderPickerController.swift
|
|
|
|
// NetNewsWire iOS Share Extension
|
|
|
|
//
|
|
|
|
// Created by Maurice Parker on 9/12/19.
|
|
|
|
// Copyright © 2019 Ranchero Software. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import UIKit
|
2019-11-17 02:44:01 +01:00
|
|
|
import RSCore
|
2019-09-12 19:33:05 +02:00
|
|
|
import Account
|
|
|
|
|
|
|
|
protocol ShareFolderPickerControllerDelegate: class {
|
2019-11-17 02:44:01 +01:00
|
|
|
func shareFolderPickerDidSelect(_ container: Container)
|
2019-09-12 19:33:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
class ShareFolderPickerController: UITableViewController {
|
|
|
|
|
|
|
|
var selectedContainer: Container?
|
2019-11-17 02:44:01 +01:00
|
|
|
var containers = [Container]()
|
|
|
|
|
2019-09-12 19:33:05 +02:00
|
|
|
weak var delegate: ShareFolderPickerControllerDelegate?
|
|
|
|
|
|
|
|
override func viewDidLoad() {
|
2019-11-17 02:44:01 +01:00
|
|
|
for account in AccountManager.shared.sortedActiveAccounts {
|
|
|
|
containers.append(account)
|
|
|
|
if let sortedFolders = account.sortedFolders {
|
|
|
|
containers.append(contentsOf: sortedFolders)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
tableView.register(UINib(nibName: "ShareFolderPickerAccountCell", bundle: Bundle.main), forCellReuseIdentifier: "AccountCell")
|
|
|
|
tableView.register(UINib(nibName: "ShareFolderPickerFolderCell", bundle: Bundle.main), forCellReuseIdentifier: "FolderCell")
|
2019-09-12 19:33:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
override func numberOfSections(in tableView: UITableView) -> Int {
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
2019-11-17 02:44:01 +01:00
|
|
|
return containers.count
|
2019-09-12 19:33:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
2019-11-17 02:44:01 +01:00
|
|
|
let container = containers[indexPath.row]
|
|
|
|
let cell: ShareFolderPickerCell = {
|
|
|
|
if container is Account {
|
|
|
|
return tableView.dequeueReusableCell(withIdentifier: "AccountCell", for: indexPath) as! ShareFolderPickerCell
|
|
|
|
} else {
|
|
|
|
return tableView.dequeueReusableCell(withIdentifier: "FolderCell", for: indexPath) as! ShareFolderPickerCell
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
|
|
|
if let account = container as? Account {
|
|
|
|
cell.icon.image = AppAssets.image(for: account.type)
|
|
|
|
} else {
|
|
|
|
cell.icon.image = AppAssets.masterFolderImage.image
|
|
|
|
}
|
|
|
|
|
|
|
|
if let displayNameProvider = container as? DisplayNameProvider {
|
|
|
|
cell.label?.text = displayNameProvider.nameForDisplay
|
|
|
|
}
|
|
|
|
|
|
|
|
if let compContainer = selectedContainer, container === compContainer {
|
2019-09-12 19:33:05 +02:00
|
|
|
cell.accessoryType = .checkmark
|
2019-09-22 23:04:21 +02:00
|
|
|
} else {
|
|
|
|
cell.accessoryType = .none
|
2019-09-12 19:33:05 +02:00
|
|
|
}
|
2019-11-17 02:44:01 +01:00
|
|
|
|
|
|
|
return cell
|
2019-09-12 19:33:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
|
2019-11-17 02:44:01 +01:00
|
|
|
let container = containers[indexPath.row]
|
|
|
|
|
|
|
|
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?.shareFolderPickerDidSelect(container)
|
|
|
|
}
|
2019-09-12 19:33:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|