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
|
|
|
|
import Account
|
2024-07-08 19:07:26 +02:00
|
|
|
import Core
|
2019-09-12 19:33:05 +02:00
|
|
|
|
2021-02-06 00:06:45 +01:00
|
|
|
protocol ShareFolderPickerControllerDelegate: AnyObject {
|
2024-05-04 07:55:29 +02:00
|
|
|
|
|
|
|
@MainActor func shareFolderPickerDidSelect(_ container: ExtensionContainer)
|
2019-09-12 19:33:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
class ShareFolderPickerController: UITableViewController {
|
|
|
|
|
2020-02-09 22:08:11 +01:00
|
|
|
var containers: [ExtensionContainer]?
|
|
|
|
var selectedContainerID: ContainerIdentifier?
|
2019-11-17 02:44:01 +01:00
|
|
|
|
2019-09-12 19:33:05 +02:00
|
|
|
weak var delegate: ShareFolderPickerControllerDelegate?
|
|
|
|
|
|
|
|
override func viewDidLoad() {
|
2019-11-17 02:44:01 +01:00
|
|
|
tableView.register(UINib(nibName: "ShareFolderPickerAccountCell", bundle: Bundle.main), forCellReuseIdentifier: "AccountCell")
|
|
|
|
tableView.register(UINib(nibName: "ShareFolderPickerFolderCell", bundle: Bundle.main), forCellReuseIdentifier: "FolderCell")
|
2020-02-09 22:08:11 +01:00
|
|
|
|
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 {
|
2020-02-09 22:08:11 +01:00
|
|
|
return containers?.count ?? 0
|
2019-09-12 19:33:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
2020-02-09 22:08:11 +01:00
|
|
|
let container = containers?[indexPath.row]
|
2019-11-17 02:44:01 +01:00
|
|
|
let cell: ShareFolderPickerCell = {
|
2020-02-09 22:08:11 +01:00
|
|
|
if container is ExtensionAccount {
|
2019-11-17 02:44:01 +01:00
|
|
|
return tableView.dequeueReusableCell(withIdentifier: "AccountCell", for: indexPath) as! ShareFolderPickerCell
|
|
|
|
} else {
|
|
|
|
return tableView.dequeueReusableCell(withIdentifier: "FolderCell", for: indexPath) as! ShareFolderPickerCell
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
2020-02-09 22:08:11 +01:00
|
|
|
if let account = container as? ExtensionAccount {
|
2024-10-01 07:16:54 +02:00
|
|
|
cell.icon.image = AppAsset.accountImage(for: account.type)
|
2019-11-17 02:44:01 +01:00
|
|
|
} else {
|
2024-10-01 07:16:54 +02:00
|
|
|
cell.icon.image = AppAsset.folderIcon.image
|
2019-11-17 02:44:01 +01:00
|
|
|
}
|
2020-02-09 22:08:11 +01:00
|
|
|
|
|
|
|
cell.label?.text = container?.name ?? ""
|
|
|
|
|
|
|
|
if let containerID = container?.containerID, containerID == selectedContainerID {
|
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) {
|
2020-02-09 22:08:11 +01:00
|
|
|
guard let container = containers?[indexPath.row] else { return }
|
2019-11-17 02:44:01 +01:00
|
|
|
|
2020-02-09 22:08:11 +01:00
|
|
|
if let account = container as? ExtensionAccount, account.disallowFeedInRootFolder {
|
2019-11-17 02:44:01 +01:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
}
|