Browse Source

clear code

Signed-off-by: Marino Faggiana <marino@marinofaggiana.com>
Marino Faggiana 1 year ago
parent
commit
be21726bc3

+ 5 - 0
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 != "" {

+ 14 - 0
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: "")
+    }
 }

+ 1 - 1
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)

+ 0 - 6
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

+ 20 - 19
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)
     }