From be21726bc35ff190f655f39b644a3b2c671e67b1 Mon Sep 17 00:00:00 2001 From: Marino Faggiana Date: Tue, 9 May 2023 17:10:48 +0200 Subject: [PATCH] clear code Signed-off-by: Marino Faggiana --- Brand/NCBrand.swift | 5 +++ ExternalResources/NCApplicationHandle.swift | 14 ++++++++ iOSClient/Main/NCActionCenter.swift | 2 +- iOSClient/NCGlobal.swift | 6 ---- iOSClient/Share/NCSharePaging.swift | 39 +++++++++++---------- 5 files changed, 40 insertions(+), 26 deletions(-) diff --git a/Brand/NCBrand.swift b/Brand/NCBrand.swift index 45d7bc94d2..789686b170 100755 --- a/Brand/NCBrand.swift +++ b/Brand/NCBrand.swift @@ -82,6 +82,11 @@ import UIKit // Internal option behaviour @objc public var cleanUpDay: Int = 0 // Set default "Delete, in the cache, all files older than" possible days value are: 0, 1, 7, 30, 90, 180, 365 + // Info Paging + enum NCInfoPagingIndex: Int, CaseIterable { + case activity, sharing + } + override init() { if folderBrandAutoUpload != "" { diff --git a/ExternalResources/NCApplicationHandle.swift b/ExternalResources/NCApplicationHandle.swift index ed10ff5116..60bec0c9c6 100644 --- a/ExternalResources/NCApplicationHandle.swift +++ b/ExternalResources/NCApplicationHandle.swift @@ -23,6 +23,8 @@ import Foundation import NextcloudKit +import UIKit +import Parchment class NCApplicationHandle: NSObject { @@ -59,4 +61,16 @@ class NCApplicationHandle: NSObject { // func: tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) func didSelectItem(_ item: NKExternalSite, viewController: UIViewController) { } + + // class: NCSharePaging + // func pagingViewController(_: PagingViewController, viewControllerAt index: Int) -> UIViewController + func pagingViewController(_: PagingViewController, viewControllerAt index: Int) -> UIViewController { + return UIViewController() + } + + // class: NCSharePaging + // func pagingViewController(_: PagingViewController, pagingItemAt index: Int) -> PagingItem + func pagingViewController(_: PagingViewController, pagingItemAt index: Int) -> PagingItem { + return PagingIndexItem(index: index, title: "") + } } diff --git a/iOSClient/Main/NCActionCenter.swift b/iOSClient/Main/NCActionCenter.swift index 26404c38c3..085d7e5e58 100644 --- a/iOSClient/Main/NCActionCenter.swift +++ b/iOSClient/Main/NCActionCenter.swift @@ -188,7 +188,7 @@ class NCActionCenter: NSObject, UIDocumentInteractionControllerDelegate, NCSelec // MARK: - - func openShare(viewController: UIViewController, metadata: tableMetadata, indexPage: NCGlobal.NCSharePagingIndex) { + func openShare(viewController: UIViewController, metadata: tableMetadata, indexPage: NCBrandOptions.NCInfoPagingIndex) { let serverUrlFileName = metadata.serverUrl + "/" + metadata.fileName NCActivityIndicator.shared.start(backgroundView: viewController.view) diff --git a/iOSClient/NCGlobal.swift b/iOSClient/NCGlobal.swift index 9899cbb6c4..3fa1d21758 100644 --- a/iOSClient/NCGlobal.swift +++ b/iOSClient/NCGlobal.swift @@ -135,12 +135,6 @@ class NCGlobal: NSObject { let maxHTTPCache: Int64 = 10000000000 // 10 GB let fileNameVideoEncoded: String = "video_encoded.mp4" - // NCSharePaging - // - enum NCSharePagingIndex: Int, CaseIterable { - case activity, sharing - } - // NCViewerProviderContextMenu // let maxAutoDownload: UInt64 = 50000000 // 50MB diff --git a/iOSClient/Share/NCSharePaging.swift b/iOSClient/Share/NCSharePaging.swift index a742e25e71..98509258af 100644 --- a/iOSClient/Share/NCSharePaging.swift +++ b/iOSClient/Share/NCSharePaging.swift @@ -41,9 +41,10 @@ class NCSharePaging: UIViewController { private var commentsEnabled = true private var sharingEnabled = true private var currentVC: NCSharePagingContent? + private let applicationHandle = NCApplicationHandle() @objc var metadata = tableMetadata() - var indexPage = NCGlobal.NCSharePagingIndex.activity + var indexPage = NCBrandOptions.NCInfoPagingIndex.activity // MARK: - View Life Cycle @@ -139,7 +140,7 @@ class NCSharePaging: UIViewController { } pagingViewController.menuItemSize = .fixed( - width: self.view.bounds.width / CGFloat(NCGlobal.NCSharePagingIndex.allCases.count), + width: self.view.bounds.width / CGFloat(NCBrandOptions.NCInfoPagingIndex.allCases.count), height: 40) } @@ -158,7 +159,7 @@ class NCSharePaging: UIViewController { coordinator.animate(alongsideTransition: nil) { _ in self.pagingViewController.menuItemSize = .fixed( - width: self.view.bounds.width / CGFloat(NCGlobal.NCSharePagingIndex.allCases.count), + width: self.view.bounds.width / CGFloat(NCBrandOptions.NCInfoPagingIndex.allCases.count), height: 40) self.currentVC?.textField?.resignFirstResponder() } @@ -197,7 +198,7 @@ extension NCSharePaging: PagingViewControllerDelegate { guard let item = pagingItem as? PagingIndexItem, - let itemIndex = NCGlobal.NCSharePagingIndex(rawValue: item.index) + let itemIndex = NCBrandOptions.NCInfoPagingIndex(rawValue: item.index) else { return } if itemIndex == .activity && !activityEnabled || itemIndex == .sharing && !sharingEnabled { @@ -219,7 +220,7 @@ extension NCSharePaging: PagingViewControllerDataSource { let height = pagingViewController.options.menuHeight + NCSharePagingView.headerHeight + NCSharePagingView.tagHeaderHeight - switch NCGlobal.NCSharePagingIndex(rawValue: index) { + switch NCBrandOptions.NCInfoPagingIndex(rawValue: index) { case .activity: guard let viewController = UIStoryboard(name: "NCActivity", bundle: nil).instantiateInitialViewController() as? NCActivity else { return UIViewController() @@ -239,29 +240,29 @@ extension NCSharePaging: PagingViewControllerDataSource { viewController.height = height return viewController default: - return UIViewController() + return applicationHandle.pagingViewController(pagingViewController, viewControllerAt: index) } } func pagingViewController(_: PagingViewController, pagingItemAt index: Int) -> PagingItem { - if sharingEnabled { - switch NCGlobal.NCSharePagingIndex(rawValue: index) { - case .activity: - return PagingIndexItem(index: index, title: NSLocalizedString("_activity_", comment: "")) - case .sharing: - return PagingIndexItem(index: index, title: NSLocalizedString("_sharing_", comment: "")) - default: - return PagingIndexItem(index: index, title: "") - } - } else { + if NCBrandOptions.NCInfoPagingIndex.allCases.count == 2 && !sharingEnabled { self.title = NSLocalizedString("_activity_", comment: "") return PagingIndexItem(index: index, title: "") } + + switch NCBrandOptions.NCInfoPagingIndex(rawValue: index) { + case .activity: + return PagingIndexItem(index: index, title: NSLocalizedString("_activity_", comment: "")) + case .sharing: + return PagingIndexItem(index: index, title: NSLocalizedString("_sharing_", comment: "")) + default: + return applicationHandle.pagingViewController(pagingViewController, pagingItemAt: index) + } } func numberOfViewControllers(in pagingViewController: PagingViewController) -> Int { - return 2 + return NCBrandOptions.NCInfoPagingIndex.allCases.count } } @@ -286,8 +287,8 @@ class NCShareHeaderViewController: PagingViewController { } override func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { - guard NCGlobal.NCSharePagingIndex(rawValue: indexPath.item) != .activity || activityEnabled, - NCGlobal.NCSharePagingIndex(rawValue: indexPath.item) != .sharing || sharingEnabled + guard NCBrandOptions.NCInfoPagingIndex(rawValue: indexPath.item) != .activity || activityEnabled, + NCBrandOptions.NCInfoPagingIndex(rawValue: indexPath.item) != .sharing || sharingEnabled else { return } super.collectionView(collectionView, didSelectItemAt: indexPath) }