Marino Faggiana 1 tahun lalu
induk
melakukan
2dd7847085

+ 1 - 1
Brand/NCBrand.swift

@@ -83,7 +83,7 @@ import UIKit
     @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 {
+    enum NCInfoPagingTab: Int, CaseIterable {
         case activity, sharing
     }
 

+ 1 - 1
iOSClient/Main/Collection Common/NCCollectionViewCommon.swift

@@ -892,7 +892,7 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
         if isEditMode { return }
         guard let metadata = NCManageDatabase.shared.getMetadataFromOcId(objectId) else { return }
 
-        NCActionCenter.shared.openShare(viewController: self, metadata: metadata, indexPage: .sharing)
+        NCActionCenter.shared.openShare(viewController: self, metadata: metadata, page: .sharing)
     }
 
     func tapMoreGridItem(with objectId: String, namedButtonMore: String, image: UIImage?, sender: Any) {

+ 31 - 2
iOSClient/Main/NCActionCenter.swift

@@ -188,18 +188,47 @@ class NCActionCenter: NSObject, UIDocumentInteractionControllerDelegate, NCSelec
 
     // MARK: -
 
-    func openShare(viewController: UIViewController, metadata: tableMetadata, indexPage: NCBrandOptions.NCInfoPagingIndex) {
+    func openShare(viewController: UIViewController, metadata: tableMetadata, page: NCBrandOptions.NCInfoPagingTab) {
 
         let serverUrlFileName = metadata.serverUrl + "/" + metadata.fileName
+
         NCActivityIndicator.shared.start(backgroundView: viewController.view)
         NCNetworking.shared.readFile(serverUrlFileName: serverUrlFileName, queue: .main) { _, metadata, error in
+
             NCActivityIndicator.shared.stop()
+
             if let metadata = metadata, error == .success {
+
+                var pages: [NCBrandOptions.NCInfoPagingTab] = []
+
                 let shareNavigationController = UIStoryboard(name: "NCShare", bundle: nil).instantiateInitialViewController() as? UINavigationController
                 let shareViewController = shareNavigationController?.topViewController as? NCSharePaging
 
+                // let serverVersionMajor = NCManageDatabase.shared.getCapabilitiesServerInt(account: metadata.account, elements: NCElementsJSON.shared.capabilitiesVersionMajor)
+                // let comments = NCManageDatabase.shared.getCapabilitiesServerBool(account: metadata.account, elements: NCElementsJSON.shared.capabilitiesFilesComments, exists: false)
+                let activity = NCManageDatabase.shared.getCapabilitiesServerArray(account: metadata.account, elements: NCElementsJSON.shared.capabilitiesActivity)
+
+                for value in NCBrandOptions.NCInfoPagingTab.allCases {
+                    pages.append(value)
+                }
+
+                if activity == nil, let idx = pages.firstIndex(of: .activity) {
+                    pages.remove(at: idx)
+                }
+                if !metadata.isSharable, let idx = pages.firstIndex(of: .sharing) {
+                    pages.remove(at: idx)
+                }
+
                 shareViewController?.metadata = metadata
-                shareViewController?.indexPage = indexPage
+                shareViewController?.pages = pages
+
+                if pages.contains(page) {
+                    shareViewController?.page = page
+                } else if let page = pages.first {
+                    shareViewController?.page = page
+                } else {
+                    return
+                }
 
                 shareNavigationController?.modalPresentationStyle = .formSheet
                 if let shareNavigationController = shareNavigationController {

+ 1 - 1
iOSClient/Menu/NCCollectionViewCommon+Menu.swift

@@ -82,7 +82,7 @@ extension NCCollectionViewCommon {
                     icon: NCUtility.shared.loadImage(named: "info"),
                     order: 10,
                     action: { _ in
-                        NCActionCenter.shared.openShare(viewController: self, metadata: metadata, indexPage: .activity)
+                        NCActionCenter.shared.openShare(viewController: self, metadata: metadata, page: .activity)
                     }
                 )
             )

+ 1 - 1
iOSClient/Menu/NCContextMenu.swift

@@ -53,7 +53,7 @@ class NCContextMenu: NSObject {
 
         let detail = UIAction(title: NSLocalizedString("_details_", comment: ""),
                               image: UIImage(systemName: "info")) { _ in
-            NCActionCenter.shared.openShare(viewController: viewController, metadata: metadata, indexPage: .activity)
+            NCActionCenter.shared.openShare(viewController: viewController, metadata: metadata, page: .activity)
         }
 
         let favorite = UIAction(title: metadata.favorite ?

+ 1 - 1
iOSClient/Menu/NCViewer+Menu.swift

@@ -46,7 +46,7 @@ extension NCViewer {
                     title: NSLocalizedString("_details_", comment: ""),
                     icon: NCUtility.shared.loadImage(named: "info"),
                     action: { _ in
-                        NCActionCenter.shared.openShare(viewController: viewController, metadata: metadata, indexPage: .activity)
+                        NCActionCenter.shared.openShare(viewController: viewController, metadata: metadata, page: .activity)
                     }
                 )
             )

+ 1 - 1
iOSClient/RichWorkspace/NCViewerRichWorkspaceWebView.swift

@@ -83,7 +83,7 @@ class NCViewerRichWorkspaceWebView: UIViewController, WKNavigationDelegate, WKSc
 
             if message.body as? String == "share" {
                 if metadata != nil {
-                    NCActionCenter.shared.openShare(viewController: self, metadata: metadata!, indexPage: .sharing)
+                    NCActionCenter.shared.openShare(viewController: self, metadata: metadata!, page: .sharing)
                 }
             }
 

+ 1 - 1
iOSClient/Share/NCShare.swift

@@ -94,7 +94,7 @@ class NCShare: UIViewController, NCShareNetworkingDelegate, NCSharePagingContent
 
         networking = NCShareNetworking(metadata: metadata, view: self.view, delegate: self)
         if sharingEnabled {
-            let isVisible = (self.navigationController?.topViewController as? NCSharePaging)?.indexPage == .sharing
+            let isVisible = (self.navigationController?.topViewController as? NCSharePaging)?.page == .sharing
             networking?.readShare(showLoadingIndicator: isVisible)
         }
     }

+ 16 - 66
iOSClient/Share/NCSharePaging.swift

@@ -37,14 +37,12 @@ class NCSharePaging: UIViewController {
     private let pagingViewController = NCShareHeaderViewController()
     private weak var appDelegate = UIApplication.shared.delegate as? AppDelegate
 
-    private var activityEnabled = true
-    private var commentsEnabled = true
-    private var sharingEnabled = true
     private var currentVC: NCSharePagingContent?
     private let applicationHandle = NCApplicationHandle()
 
-    @objc var metadata = tableMetadata()
-    var indexPage = NCBrandOptions.NCInfoPagingIndex.activity
+    var metadata = tableMetadata()
+    var pages: [NCBrandOptions.NCInfoPagingTab] = []
+    var page: NCBrandOptions.NCInfoPagingTab = .activity
 
     // MARK: - View Life Cycle
 
@@ -57,14 +55,8 @@ class NCSharePaging: UIViewController {
         NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillShow(notification:)), name: UIResponder.keyboardWillShowNotification, object: nil)
         NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillHide(notification:)), name: UIResponder.keyboardWillHideNotification, object: nil)
 
-        setupCapabilities()
-
         // *** MUST BE THE FIRST ONE ***
         pagingViewController.metadata = metadata
-
-        pagingViewController.activityEnabled = activityEnabled
-        pagingViewController.commentsEnabled = commentsEnabled
-        pagingViewController.sharingEnabled = sharingEnabled
         pagingViewController.backgroundColor = .systemBackground
         pagingViewController.menuBackgroundColor = .systemBackground
         pagingViewController.selectedBackgroundColor = .systemBackground
@@ -95,39 +87,14 @@ class NCSharePaging: UIViewController {
 
         pagingViewController.dataSource = self
         pagingViewController.delegate = self
-        pagingViewController.select(index: indexPage.rawValue)
-        let pagingIndexItem = self.pagingViewController(pagingViewController, pagingItemAt: indexPage.rawValue) as? PagingIndexItem
+        pagingViewController.select(index: page.rawValue)
+        let pagingIndexItem = self.pagingViewController(pagingViewController, pagingItemAt: page.rawValue) as? PagingIndexItem
         self.title = pagingIndexItem?.title
 
-        if sharingEnabled {
-            pagingViewController.indicatorColor = NCBrandColor.shared.brandElement
-        } else {
-            pagingViewController.indicatorColor = .clear
-        }
         (pagingViewController.view as? NCSharePagingView)?.setupConstraints()
         pagingViewController.reloadMenu()
     }
 
-    func setupCapabilities() {
-        guard let appDelegate = appDelegate else { return }
-
-        // Verify Comments & Sharing enabled
-        let serverVersionMajor = NCManageDatabase.shared.getCapabilitiesServerInt(account: appDelegate.account, elements: NCElementsJSON.shared.capabilitiesVersionMajor)
-        let comments = NCManageDatabase.shared.getCapabilitiesServerBool(account: appDelegate.account, elements: NCElementsJSON.shared.capabilitiesFilesComments, exists: false)
-        if serverVersionMajor >= NCGlobal.shared.nextcloudVersion20 && comments == false {
-            commentsEnabled = false
-        }
-        sharingEnabled = metadata.isSharable
-        let activity = NCManageDatabase.shared.getCapabilitiesServerArray(account: appDelegate.account, elements: NCElementsJSON.shared.capabilitiesActivity)
-        activityEnabled = activity != nil
-        if indexPage == .sharing && !sharingEnabled {
-            indexPage = .activity
-        }
-        if indexPage == .activity && !activityEnabled && sharingEnabled {
-            indexPage = .sharing
-        }
-    }
-
     override func viewDidAppear(_ animated: Bool) {
         super.viewDidAppear(animated)
         currentVC = pagingViewController.pageViewController.selectedViewController as? NCSharePagingContent
@@ -140,7 +107,7 @@ class NCSharePaging: UIViewController {
         }
 
         pagingViewController.menuItemSize = .fixed(
-            width: self.view.bounds.width / CGFloat(NCBrandOptions.NCInfoPagingIndex.allCases.count),
+            width: self.view.bounds.width / CGFloat(self.pages.count),
             height: 40)
     }
 
@@ -159,7 +126,7 @@ class NCSharePaging: UIViewController {
 
         coordinator.animate(alongsideTransition: nil) { _ in
             self.pagingViewController.menuItemSize = .fixed(
-                width: self.view.bounds.width / CGFloat(NCBrandOptions.NCInfoPagingIndex.allCases.count),
+                width: self.view.bounds.width / CGFloat(self.pages.count),
                 height: 40)
             self.currentVC?.textField?.resignFirstResponder()
         }
@@ -196,17 +163,6 @@ extension NCSharePaging: PagingViewControllerDelegate {
 
     func pagingViewController(_ pagingViewController: PagingViewController, willScrollToItem pagingItem: PagingItem, startingViewController: UIViewController, destinationViewController: UIViewController) {
 
-        guard
-            let item = pagingItem as? PagingIndexItem,
-            let itemIndex = NCBrandOptions.NCInfoPagingIndex(rawValue: item.index)
-        else { return }
-
-        if itemIndex == .activity && !activityEnabled || itemIndex == .sharing && !sharingEnabled {
-            pagingViewController.contentInteraction = .none
-        } else {
-            self.title = item.title
-        }
-
         currentVC?.textField?.resignFirstResponder()
         self.currentVC = destinationViewController as? NCSharePagingContent
     }
@@ -220,8 +176,7 @@ extension NCSharePaging: PagingViewControllerDataSource {
 
         let height = pagingViewController.options.menuHeight + NCSharePagingView.headerHeight + NCSharePagingView.tagHeaderHeight
 
-        switch NCBrandOptions.NCInfoPagingIndex(rawValue: index) {
-        case .activity:
+        if pages[index] == .activity {
             guard let viewController = UIStoryboard(name: "NCActivity", bundle: nil).instantiateInitialViewController() as? NCActivity else {
                 return UIViewController()
             }
@@ -231,38 +186,31 @@ extension NCSharePaging: PagingViewControllerDataSource {
             viewController.metadata = metadata
             viewController.objectType = "files"
             return viewController
-        case .sharing:
+        } else if pages[index] == .sharing {
             guard let viewController = UIStoryboard(name: "NCShare", bundle: nil).instantiateViewController(withIdentifier: "sharing") as? NCShare else {
                 return UIViewController()
             }
-            viewController.sharingEnabled = sharingEnabled
             viewController.metadata = metadata
             viewController.height = height
             return viewController
-        default:
+        } else {
             return applicationHandle.pagingViewController(pagingViewController, viewControllerAt: index, metadata: metadata, topHeight: height)
         }
     }
 
     func pagingViewController(_: PagingViewController, pagingItemAt index: Int) -> PagingItem {
 
-        if NCBrandOptions.NCInfoPagingIndex.allCases.count == 2 && !sharingEnabled {
-            self.title = NSLocalizedString("_activity_", comment: "")
-            return PagingIndexItem(index: index, title: "")
-        }
-
-        switch NCBrandOptions.NCInfoPagingIndex(rawValue: index) {
-        case .activity:
+        if pages[index] == .activity {
             return PagingIndexItem(index: index, title: NSLocalizedString("_activity_", comment: ""))
-        case .sharing:
+        } else if pages[index] == .sharing {
             return PagingIndexItem(index: index, title: NSLocalizedString("_sharing_", comment: ""))
-        default:
+        } else {
             return applicationHandle.pagingViewController(pagingViewController, pagingItemAt: index)
         }
     }
 
     func numberOfViewControllers(in pagingViewController: PagingViewController) -> Int {
-        return NCBrandOptions.NCInfoPagingIndex.allCases.count
+        return self.pages.count
     }
 }
 
@@ -287,9 +235,11 @@ class NCShareHeaderViewController: PagingViewController {
     }
 
     override func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
+        /*
         guard NCBrandOptions.NCInfoPagingIndex(rawValue: indexPath.item) != .activity || activityEnabled,
               NCBrandOptions.NCInfoPagingIndex(rawValue: indexPath.item) != .sharing || sharingEnabled
         else { return }
+        */
         super.collectionView(collectionView, didSelectItemAt: indexPath)
     }
 }

+ 1 - 1
iOSClient/Viewer/NCViewerNextcloudText/NCViewerNextcloudText.swift

@@ -154,7 +154,7 @@ class NCViewerNextcloudText: UIViewController, WKNavigationDelegate, WKScriptMes
             }
 
             if message.body as? String == "share" {
-                NCActionCenter.shared.openShare(viewController: self, metadata: metadata, indexPage: .sharing)
+                NCActionCenter.shared.openShare(viewController: self, metadata: metadata, page: .sharing)
             }
 
             if message.body as? String == "loading" {

+ 1 - 1
iOSClient/Viewer/NCViewerRichdocument/NCViewerRichdocument.swift

@@ -174,7 +174,7 @@ class NCViewerRichdocument: UIViewController, WKNavigationDelegate, WKScriptMess
             }
 
             if message.body as? String == "share" {
-                NCActionCenter.shared.openShare(viewController: self, metadata: metadata, indexPage: .sharing)
+                NCActionCenter.shared.openShare(viewController: self, metadata: metadata, page: .sharing)
             }
 
             if let param = message.body as? [AnyHashable: Any] {