123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644 |
- //
- // NCSelect.swift
- // Nextcloud
- //
- // Created by Marino Faggiana on 06/11/2018.
- // Copyright © 2018 Marino Faggiana. All rights reserved.
- //
- // Author Marino Faggiana <marino.faggiana@nextcloud.com>
- //
- // This program is free software: you can redistribute it and/or modify
- // it under the terms of the GNU General Public License as published by
- // the Free Software Foundation, either version 3 of the License, or
- // (at your option) any later version.
- //
- // This program is distributed in the hope that it will be useful,
- // but WITHOUT ANY WARRANTY; without even the implied warranty of
- // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- // GNU General Public License for more details.
- //
- // You should have received a copy of the GNU General Public License
- // along with this program. If not, see <http://www.gnu.org/licenses/>.
- //
- import UIKit
- import SwiftUI
- import NextcloudKit
- protocol NCSelectDelegate: AnyObject {
- func dismissSelect(serverUrl: String?, metadata: tableMetadata?, type: String, items: [Any], overwrite: Bool, copy: Bool, move: Bool, session: NCSession.Session)
- }
- class NCSelect: UIViewController, UIGestureRecognizerDelegate, UIAdaptivePresentationControllerDelegate, NCListCellDelegate, NCSectionFirstHeaderDelegate {
- @IBOutlet private var collectionView: UICollectionView!
- @IBOutlet private var buttonCancel: UIBarButtonItem!
- @IBOutlet private var bottomContraint: NSLayoutConstraint?
- private var selectCommandViewSelect: NCSelectCommandView?
- let utilityFileSystem = NCUtilityFileSystem()
- let utility = NCUtility()
- let database = NCManageDatabase.shared
- enum selectType: Int {
- case select
- case selectCreateFolder
- case copyMove
- case nothing
- }
- // ------ external settings ------------------------------------
- var delegate: NCSelectDelegate?
- var typeOfCommandView: selectType = .select
- var includeDirectoryE2EEncryption = false
- var includeImages = false
- var enableSelectFile = false
- var type = ""
- var items: [tableMetadata] = []
- var titleCurrentFolder = NCBrandOptions.shared.brand
- var serverUrl = ""
- var session: NCSession.Session!
- // -------------------------------------------------------------
- private var dataSourceTask: URLSessionTask?
- private var serverUrlPush = ""
- private var metadataFolder = tableMetadata()
- private var overwrite = true
- private var dataSource = NCCollectionViewDataSource()
- private var autoUploadFileName = ""
- private var autoUploadDirectory = ""
- private var backgroundImageView = UIImageView()
- // MARK: - View Life Cycle
- override func viewDidLoad() {
- super.viewDidLoad()
- navigationController?.setNavigationBarAppearance()
- navigationController?.navigationBar.prefersLargeTitles = true
- view.backgroundColor = .systemBackground
- collectionView.backgroundColor = .systemBackground
- selectCommandViewSelect?.separatorView.backgroundColor = .separator
- // Cell
- collectionView.register(UINib(nibName: "NCListCell", bundle: nil), forCellWithReuseIdentifier: "listCell")
- collectionView.collectionViewLayout = NCListLayout()
- // Header
- collectionView.register(UINib(nibName: "NCSectionFirstHeaderEmptyData", bundle: nil), forSupplementaryViewOfKind: UICollectionView.elementKindSectionHeader, withReuseIdentifier: "sectionFirstHeaderEmptyData")
- collectionView.register(UINib(nibName: "NCSectionFirstHeader", bundle: nil), forSupplementaryViewOfKind: UICollectionView.elementKindSectionHeader, withReuseIdentifier: "sectionFirstHeader")
- // Footer
- collectionView.register(UINib(nibName: "NCSectionFooter", bundle: nil), forSupplementaryViewOfKind: UICollectionView.elementKindSectionFooter, withReuseIdentifier: "sectionFooter")
- collectionView.alwaysBounceVertical = true
- collectionView.backgroundColor = .systemBackground
- buttonCancel.title = NSLocalizedString("_cancel_", comment: "")
- bottomContraint?.constant = UIApplication.shared.firstWindow?.rootViewController?.view.safeAreaInsets.bottom ?? 0
- // Type of command view
- if typeOfCommandView == .select || typeOfCommandView == .selectCreateFolder {
- if typeOfCommandView == .select {
- selectCommandViewSelect = Bundle.main.loadNibNamed("NCSelectCommandViewSelect", owner: self, options: nil)?.first as? NCSelectCommandView
- } else {
- selectCommandViewSelect = Bundle.main.loadNibNamed("NCSelectCommandViewSelect+CreateFolder", owner: self, options: nil)?.first as? NCSelectCommandView
- }
- self.view.addSubview(selectCommandViewSelect!)
- selectCommandViewSelect?.setColor(account: session.account)
- selectCommandViewSelect?.selectView = self
- selectCommandViewSelect?.translatesAutoresizingMaskIntoConstraints = false
- selectCommandViewSelect?.bottomAnchor.constraint(equalTo: view.bottomAnchor, constant: 0).isActive = true
- selectCommandViewSelect?.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 0).isActive = true
- selectCommandViewSelect?.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: 0).isActive = true
- selectCommandViewSelect?.heightAnchor.constraint(equalToConstant: 80).isActive = true
- bottomContraint?.constant = 80
- }
- if typeOfCommandView == .copyMove {
- selectCommandViewSelect = Bundle.main.loadNibNamed("NCSelectCommandViewCopyMove", owner: self, options: nil)?.first as? NCSelectCommandView
- self.view.addSubview(selectCommandViewSelect!)
- selectCommandViewSelect?.setColor(account: session.account)
- selectCommandViewSelect?.selectView = self
- selectCommandViewSelect?.translatesAutoresizingMaskIntoConstraints = false
- if items.contains(where: { $0.lock }) {
- selectCommandViewSelect?.moveButton?.isEnabled = false
- selectCommandViewSelect?.moveButton?.titleLabel?.isEnabled = false
- }
- selectCommandViewSelect?.bottomAnchor.constraint(equalTo: view.bottomAnchor, constant: 0).isActive = true
- selectCommandViewSelect?.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 0).isActive = true
- selectCommandViewSelect?.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: 0).isActive = true
- selectCommandViewSelect?.heightAnchor.constraint(equalToConstant: 150).isActive = true
- bottomContraint?.constant = 150
- }
- NotificationCenter.default.addObserver(self, selector: #selector(createFolder(_:)), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterCreateFolder), object: nil)
- }
- override func viewDidAppear(_ animated: Bool) {
- super.viewDidAppear(animated)
- let folderPath = utilityFileSystem.getFileNamePath("", serverUrl: serverUrl, session: session)
- if serverUrl.isEmpty || !FileNameValidator.shared.checkFolderPath(folderPath, account: session.account) {
- serverUrl = utilityFileSystem.getHomeServer(session: session)
- titleCurrentFolder = NCBrandOptions.shared.brand
- }
- autoUploadFileName = self.database.getAccountAutoUploadFileName()
- autoUploadDirectory = self.database.getAccountAutoUploadDirectory(session: session)
- self.navigationItem.title = titleCurrentFolder
- reloadDataSource()
- }
- override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
- super.viewWillTransition(to: size, with: coordinator)
- coordinator.animate(alongsideTransition: { _ in
- let animator = UIViewPropertyAnimator(duration: 0.3, curve: .easeInOut) {
- self.collectionView?.collectionViewLayout.invalidateLayout()
- }
- animator.startAnimation()
- })
- }
- func presentationControllerDidDismiss( _ presentationController: UIPresentationController) {
- // Dismission
- }
- // MARK: - NotificationCenter
- @objc func createFolder(_ notification: NSNotification) {
- guard let userInfo = notification.userInfo as NSDictionary?,
- let ocId = userInfo["ocId"] as? String,
- let serverUrl = userInfo["serverUrl"] as? String,
- let withPush = userInfo["withPush"] as? Bool,
- serverUrl == self.serverUrl,
- let metadata = self.database.getMetadataFromOcId(ocId)
- else { return }
- if withPush {
- pushMetadata(metadata)
- }
- }
- // MARK: ACTION
- @IBAction func actionCancel(_ sender: UIBarButtonItem) {
- self.dismiss(animated: true, completion: nil)
- }
- func selectButtonPressed(_ sender: UIButton) {
- delegate?.dismissSelect(serverUrl: serverUrl, metadata: metadataFolder, type: type, items: items, overwrite: overwrite, copy: false, move: false, session: session)
- self.dismiss(animated: true, completion: nil)
- }
- func copyButtonPressed(_ sender: UIButton) {
- delegate?.dismissSelect(serverUrl: serverUrl, metadata: metadataFolder, type: type, items: items, overwrite: overwrite, copy: true, move: false, session: session)
- self.dismiss(animated: true, completion: nil)
- }
- func moveButtonPressed(_ sender: UIButton) {
- delegate?.dismissSelect(serverUrl: serverUrl, metadata: metadataFolder, type: type, items: items, overwrite: overwrite, copy: false, move: true, session: session)
- self.dismiss(animated: true, completion: nil)
- }
- func createFolderButtonPressed(_ sender: UIButton) {
- let alertController = UIAlertController.createFolder(serverUrl: serverUrl, session: session)
- self.present(alertController, animated: true, completion: nil)
- }
- @IBAction func valueChangedSwitchOverwrite(_ sender: UISwitch) {
- overwrite = sender.isOn
- }
- func tapShareListItem(with ocId: String, ocIdTransfer: String, sender: Any) { }
- func tapMoreListItem(with ocId: String, ocIdTransfer: String, image: UIImage?, sender: Any) { }
- func longPressListItem(with odId: String, ocIdTransfer: String, gestureRecognizer: UILongPressGestureRecognizer) { }
- func tapRichWorkspace(_ sender: Any) { }
- // MARK: - Push metadata
- func pushMetadata(_ metadata: tableMetadata) {
- let serverUrlPush = utilityFileSystem.stringAppendServerUrl(metadata.serverUrl, addFileName: metadata.fileName)
- guard let viewController = UIStoryboard(name: "NCSelect", bundle: nil).instantiateViewController(withIdentifier: "NCSelect.storyboard") as? NCSelect else { return }
- self.serverUrlPush = serverUrlPush
- viewController.delegate = delegate
- viewController.typeOfCommandView = typeOfCommandView
- viewController.includeDirectoryE2EEncryption = includeDirectoryE2EEncryption
- viewController.includeImages = includeImages
- viewController.enableSelectFile = enableSelectFile
- viewController.type = type
- viewController.overwrite = overwrite
- viewController.items = items
- viewController.titleCurrentFolder = metadata.fileNameView
- viewController.serverUrl = serverUrlPush
- viewController.session = session
- if let fileNameError = FileNameValidator.shared.checkFileName(metadata.fileNameView, account: session.account) {
- present(UIAlertController.warning(message: "\(fileNameError.errorDescription) \(NSLocalizedString("_please_rename_file_", comment: ""))"), animated: true)
- } else {
- navigationController?.pushViewController(viewController, animated: true)
- }
- }
- }
- // MARK: - Collection View
- extension NCSelect: UICollectionViewDelegate {
- func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
- guard let metadata = self.dataSource.getMetadata(indexPath: indexPath) else { return }
- if metadata.directory {
- pushMetadata(metadata)
- } else {
- delegate?.dismissSelect(serverUrl: serverUrl, metadata: metadata, type: type, items: items, overwrite: overwrite, copy: false, move: false, session: session)
- self.dismiss(animated: true, completion: nil)
- }
- }
- }
- extension NCSelect: UICollectionViewDataSource {
- func collectionView(_ collectionView: UICollectionView, willDisplay cell: UICollectionViewCell, forItemAt indexPath: IndexPath) {
- guard let metadata = self.dataSource.getMetadata(indexPath: indexPath) else { return }
- // Thumbnail
- if !metadata.directory {
- if let image = utility.getImage(ocId: metadata.ocId, etag: metadata.etag, ext: NCGlobal.shared.previewExt512) {
- (cell as? NCCellProtocol)?.filePreviewImageView?.image = image
- } else {
- if metadata.iconName.isEmpty {
- (cell as? NCCellProtocol)?.filePreviewImageView?.image = NCImageCache.shared.getImageFile()
- } else {
- (cell as? NCCellProtocol)?.filePreviewImageView?.image = utility.loadImage(named: metadata.iconName, useTypeIconFile: true, account: metadata.account)
- }
- if metadata.hasPreview,
- metadata.status == NCGlobal.shared.metadataStatusNormal {
- for case let operation as NCCollectionViewDownloadThumbnail in NCNetworking.shared.downloadThumbnailQueue.operations where operation.metadata.ocId == metadata.ocId { return }
- NCNetworking.shared.downloadThumbnailQueue.addOperation(NCCollectionViewDownloadThumbnail(metadata: metadata, collectionView: collectionView, ext: NCGlobal.shared.previewExt256))
- }
- }
- }
- }
- func collectionView(_ collectionView: UICollectionView, didEndDisplaying cell: UICollectionViewCell, forItemAt indexPath: IndexPath) {
- }
- func numberOfSections(in collectionView: UICollectionView) -> Int {
- return self.dataSource.numberOfSections()
- }
- func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
- return self.dataSource.numberOfItemsInSection(section)
- }
- func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
- let cell = (collectionView.dequeueReusableCell(withReuseIdentifier: "listCell", for: indexPath) as? NCListCell)!
- guard let metadata = self.dataSource.getMetadata(indexPath: indexPath) else { return cell }
- var isShare = false
- var isMounted = false
- let permissions = NCPermissions()
- isShare = metadata.permissions.contains(permissions.permissionShared) && !metadataFolder.permissions.contains(permissions.permissionShared)
- isMounted = metadata.permissions.contains(permissions.permissionMounted) && !metadataFolder.permissions.contains(permissions.permissionMounted)
- cell.listCellDelegate = self
- cell.fileOcId = metadata.ocId
- cell.fileOcIdTransfer = metadata.ocIdTransfer
- cell.fileUser = metadata.ownerId
- cell.labelTitle.text = metadata.fileNameView
- cell.labelTitle.textColor = NCBrandColor.shared.textColor
- cell.imageSelect.image = nil
- cell.imageStatus.image = nil
- cell.imageLocal.image = nil
- cell.imageFavorite.image = nil
- cell.imageShared.image = nil
- cell.imageMore.image = nil
- cell.imageItem.image = nil
- cell.imageItem.backgroundColor = nil
- if metadata.directory {
- if metadata.e2eEncrypted {
- cell.imageItem.image = NCImageCache.shared.getFolderEncrypted(account: metadata.account)
- } else if isShare {
- cell.imageItem.image = NCImageCache.shared.getFolderSharedWithMe(account: metadata.account)
- } else if !metadata.shareType.isEmpty {
- metadata.shareType.contains(3) ?
- (cell.imageItem.image = NCImageCache.shared.getFolderPublic(account: metadata.account)) :
- (cell.imageItem.image = NCImageCache.shared.getFolderSharedWithMe(account: metadata.account))
- } else if metadata.mountType == "group" {
- cell.imageItem.image = NCImageCache.shared.getFolderGroup(account: metadata.account)
- } else if isMounted {
- cell.imageItem.image = NCImageCache.shared.getFolderExternal(account: metadata.account)
- } else if metadata.fileName == autoUploadFileName && metadata.serverUrl == autoUploadDirectory {
- cell.imageItem.image = NCImageCache.shared.getFolderAutomaticUpload(account: metadata.account)
- } else {
- cell.imageItem.image = NCImageCache.shared.getFolder(account: metadata.account)
- }
- cell.imageItem.image = cell.imageItem.image?.colorizeFolder(metadata: metadata)
- cell.labelInfo.text = utility.dateDiff(metadata.date as Date)
- } else {
- cell.labelInfo.text = utility.dateDiff(metadata.date as Date) + " · " + utilityFileSystem.transformedSize(metadata.size)
- // image local
- if self.database.getTableLocalFile(ocId: metadata.ocId) != nil {
- cell.imageLocal.image = NCImageCache.shared.getImageOfflineFlag()
- } else if utilityFileSystem.fileProviderStorageExists(metadata) {
- cell.imageLocal.image = NCImageCache.shared.getImageLocal()
- }
- }
- // image Favorite
- if metadata.favorite {
- cell.imageFavorite.image = NCImageCache.shared.getImageFavorite()
- }
- cell.imageSelect.isHidden = true
- cell.backgroundView = nil
- cell.hideButtonMore(true)
- cell.hideButtonShare(true)
- cell.selected(false, isEditMode: false)
- // Live Photo
- if metadata.isLivePhoto {
- cell.imageStatus.image = utility.loadImage(named: "livephoto", colors: [NCBrandColor.shared.iconImageColor2])
- }
- // Remove last separator
- if collectionView.numberOfItems(inSection: indexPath.section) == indexPath.row + 1 {
- cell.separator.isHidden = true
- } else {
- cell.separator.isHidden = false
- }
- // Add TAGS
- cell.setTags(tags: Array(metadata.tags))
- return cell
- }
- func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {
- if kind == UICollectionView.elementKindSectionHeader {
- if self.dataSource.isEmpty() {
- guard let header = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: "sectionFirstHeaderEmptyData", for: indexPath) as? NCSectionFirstHeaderEmptyData else { return NCSectionFirstHeaderEmptyData() }
- if self.dataSourceTask?.state == .running {
- header.emptyImage.image = utility.loadImage(named: "wifi", colors: [NCBrandColor.shared.getElement(account: session.account)])
- header.emptyTitle.text = NSLocalizedString("_request_in_progress_", comment: "")
- header.emptyDescription.text = ""
- } else {
- header.emptyImage.image = NCImageCache.shared.getFolder(account: session.account)
- if includeImages {
- header.emptyTitle.text = NSLocalizedString("_files_no_files_", comment: "")
- } else {
- header.emptyTitle.text = NSLocalizedString("_files_no_folders_", comment: "")
- }
- header.emptyDescription.text = ""
- }
- return header
- } else {
- return UICollectionReusableView()
- }
- } else {
- guard let footer = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: "sectionFooter", for: indexPath) as? NCSectionFooter else { return NCSectionFooter() }
- let sections = self.dataSource.numberOfSections()
- let section = indexPath.section
- footer.setTitleLabel("")
- footer.separatorIsHidden(true)
- if sections == 1 || section == sections - 1 {
- let info = self.dataSource.getFooterInformation()
- footer.setTitleLabel(directories: info.directories, files: info.files, size: info.size)
- } else {
- footer.separatorIsHidden(false)
- }
- return footer
- }
- }
- }
- extension NCSelect: UICollectionViewDelegateFlowLayout {
- func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForHeaderInSection section: Int) -> CGSize {
- var height: CGFloat = 0
- if self.dataSource.isEmpty() {
- height = utility.getHeightHeaderEmptyData(view: view, portraitOffset: 0, landscapeOffset: -20)
- }
- return CGSize(width: collectionView.frame.width, height: height)
- }
- func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForFooterInSection section: Int) -> CGSize {
- let sections = self.dataSource.numberOfSections()
- if section == sections - 1 {
- return CGSize(width: collectionView.frame.width, height: NCGlobal.shared.endHeightFooter)
- } else {
- return CGSize(width: collectionView.frame.width, height: NCGlobal.shared.heightFooter)
- }
- }
- }
- // MARK: -
- extension NCSelect {
- func reloadDataSource() {
- var predicate = NSPredicate()
- if includeDirectoryE2EEncryption {
- if includeImages {
- predicate = NSPredicate(format: "account == %@ AND serverUrl == %@ AND (directory == true OR classFile == 'image') AND NOT (status IN %@)", session.account, serverUrl, NCGlobal.shared.metadataStatusHideInView)
- } else {
- predicate = NSPredicate(format: "account == %@ AND serverUrl == %@ AND directory == true AND NOT (status IN %@)", session.account, serverUrl, NCGlobal.shared.metadataStatusHideInView)
- }
- } else {
- if includeImages {
- predicate = NSPredicate(format: "account == %@ AND serverUrl == %@ AND e2eEncrypted == false AND (directory == true OR classFile == 'image') AND NOT (status IN %@)", session.account, serverUrl, NCGlobal.shared.metadataStatusHideInView)
- } else if enableSelectFile {
- predicate = NSPredicate(format: "account == %@ AND serverUrl == %@ AND e2eEncrypted == false AND NOT (status IN %@)", session.account, serverUrl, NCGlobal.shared.metadataStatusHideInView)
- } else {
- predicate = NSPredicate(format: "account == %@ AND serverUrl == %@ AND e2eEncrypted == false AND directory == true AND NOT (status IN %@)", session.account, serverUrl, NCGlobal.shared.metadataStatusHideInView)
- }
- }
- NCNetworking.shared.readFolder(serverUrl: serverUrl,
- account: session.account,
- checkResponseDataChanged: false,
- queue: .main) { task in
- self.dataSourceTask = task
- if self.dataSource.isEmpty() {
- self.collectionView.reloadData()
- }
- } completion: { _, _, _, _, _ in
- let metadatas = self.database.getResultsMetadatasPredicate(predicate, layoutForView: NCDBLayoutForView())
- self.dataSource = NCCollectionViewDataSource(metadatas: metadatas)
- self.collectionView.reloadData()
- NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterReloadDataSource, userInfo: ["serverUrl": self.serverUrl])
- }
- }
- }
- // MARK: -
- class NCSelectCommandView: UIView {
- @IBOutlet weak var separatorView: UIView!
- @IBOutlet weak var createFolderButton: UIButton?
- @IBOutlet weak var selectButton: UIButton?
- @IBOutlet weak var copyButton: UIButton?
- @IBOutlet weak var moveButton: UIButton?
- @IBOutlet weak var overwriteSwitch: UISwitch?
- @IBOutlet weak var overwriteLabel: UILabel?
- @IBOutlet weak var separatorHeightConstraint: NSLayoutConstraint!
- var selectView: NCSelect?
- private let gradient: CAGradientLayer = CAGradientLayer()
- override func awakeFromNib() {
- separatorHeightConstraint.constant = 0.5
- separatorView.backgroundColor = .separator
- overwriteLabel?.text = NSLocalizedString("_overwrite_", comment: "")
- selectButton?.layer.cornerRadius = 15
- selectButton?.layer.masksToBounds = true
- selectButton?.setTitle(NSLocalizedString("_select_", comment: ""), for: .normal)
- createFolderButton?.layer.cornerRadius = 15
- createFolderButton?.layer.masksToBounds = true
- createFolderButton?.setTitle(NSLocalizedString("_create_folder_", comment: ""), for: .normal)
- copyButton?.layer.cornerRadius = 15
- copyButton?.layer.masksToBounds = true
- copyButton?.setTitle(NSLocalizedString("_copy_", comment: ""), for: .normal)
- moveButton?.layer.cornerRadius = 15
- moveButton?.layer.masksToBounds = true
- moveButton?.setTitle(NSLocalizedString("_move_", comment: ""), for: .normal)
- }
- func setColor(account: String) {
- overwriteSwitch?.onTintColor = NCBrandColor.shared.getElement(account: account)
- selectButton?.backgroundColor = NCBrandColor.shared.getElement(account: account)
- selectButton?.setTitleColor(UIColor(white: 1, alpha: 0.3), for: .highlighted)
- selectButton?.setTitleColor(.white, for: .normal)
- createFolderButton?.backgroundColor = NCBrandColor.shared.getElement(account: account)
- createFolderButton?.setTitleColor(UIColor(white: 1, alpha: 0.3), for: .highlighted)
- createFolderButton?.setTitleColor(NCBrandColor.shared.getText(account: account), for: .normal)
- copyButton?.backgroundColor = NCBrandColor.shared.getElement(account: account)
- copyButton?.setTitleColor(UIColor(white: 1, alpha: 0.3), for: .highlighted)
- copyButton?.setTitleColor(NCBrandColor.shared.getText(account: account), for: .normal)
- moveButton?.backgroundColor = NCBrandColor.shared.getElement(account: account)
- moveButton?.setTitleColor(UIColor(white: 1, alpha: 0.3), for: .highlighted)
- moveButton?.setTitleColor(NCBrandColor.shared.getText(account: account), for: .normal)
- }
- @IBAction func createFolderButtonPressed(_ sender: UIButton) {
- selectView?.createFolderButtonPressed(sender)
- }
- @IBAction func selectButtonPressed(_ sender: UIButton) {
- selectView?.selectButtonPressed(sender)
- }
- @IBAction func copyButtonPressed(_ sender: UIButton) {
- selectView?.copyButtonPressed(sender)
- }
- @IBAction func moveButtonPressed(_ sender: UIButton) {
- selectView?.moveButtonPressed(sender)
- }
- @IBAction func valueChangedSwitchOverwrite(_ sender: UISwitch) {
- selectView?.valueChangedSwitchOverwrite(sender)
- }
- }
- // MARK: - UIViewControllerRepresentable
- struct NCSelectViewControllerRepresentable: UIViewControllerRepresentable {
- typealias UIViewControllerType = UINavigationController
- var delegate: NCSelectDelegate
- var session: NCSession.Session!
- func makeUIViewController(context: Context) -> UINavigationController {
- let storyboard = UIStoryboard(name: "NCSelect", bundle: nil)
- let navigationController = storyboard.instantiateInitialViewController() as? UINavigationController
- let viewController = navigationController?.topViewController as? NCSelect
- viewController?.delegate = delegate
- viewController?.typeOfCommandView = .selectCreateFolder
- viewController?.includeDirectoryE2EEncryption = true
- viewController?.session = session
- return navigationController!
- }
- func updateUIViewController(_ uiViewController: UINavigationController, context: Context) { }
- }
- struct SelectView: UIViewControllerRepresentable {
- @Binding var serverUrl: String
- var session: NCSession.Session!
- class Coordinator: NSObject, NCSelectDelegate {
- var parent: SelectView
- init(_ parent: SelectView) {
- self.parent = parent
- }
- func dismissSelect(serverUrl: String?, metadata: tableMetadata?, type: String, items: [Any], overwrite: Bool, copy: Bool, move: Bool, session: NCSession.Session) {
- if let serverUrl = serverUrl {
- self.parent.serverUrl = serverUrl
- }
- }
- }
- func makeUIViewController(context: Context) -> UINavigationController {
- let storyboard = UIStoryboard(name: "NCSelect", bundle: nil)
- let navigationController = storyboard.instantiateInitialViewController() as? UINavigationController
- let viewController = navigationController?.topViewController as? NCSelect
- viewController?.delegate = context.coordinator
- viewController?.typeOfCommandView = .selectCreateFolder
- viewController?.includeDirectoryE2EEncryption = true
- viewController?.session = session
- return navigationController!
- }
- func updateUIViewController(_ uiViewController: UINavigationController, context: Context) { }
- func makeCoordinator() -> Coordinator {
- Coordinator(self)
- }
- }
|