marinofaggiana 3 years ago
parent
commit
0e15b05ddc

+ 10 - 0
Nextcloud.xcodeproj/project.pbxproj

@@ -264,6 +264,10 @@
 		F798F0EC2588060A000DAFFD /* UIColor+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = F70CEF5523E9C7E50007035B /* UIColor+Extensions.swift */; };
 		F79A65C32191D90F00FF6DCC /* NCSelect.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = F79A65C22191D90F00FF6DCC /* NCSelect.storyboard */; };
 		F79A65C62191D95E00FF6DCC /* NCSelect.swift in Sources */ = {isa = PBXBuildFile; fileRef = F79A65C52191D95E00FF6DCC /* NCSelect.swift */; };
+		F79B646026CA661600838ACA /* UIControl+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = F79B645F26CA661600838ACA /* UIControl+Extensions.swift */; };
+		F79B646126CA661600838ACA /* UIControl+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = F79B645F26CA661600838ACA /* UIControl+Extensions.swift */; };
+		F79B646226CA661600838ACA /* UIControl+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = F79B645F26CA661600838ACA /* UIControl+Extensions.swift */; };
+		F79B646326CA661600838ACA /* UIControl+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = F79B645F26CA661600838ACA /* UIControl+Extensions.swift */; };
 		F79B869B265E19D40085C0E0 /* NSMutableAttributedString+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = F79B869A265E19D40085C0E0 /* NSMutableAttributedString+Extensions.swift */; };
 		F79EC77F26316193004E59D6 /* NCRenameFile.swift in Sources */ = {isa = PBXBuildFile; fileRef = F70D87CE25EE6E58008CBBBD /* NCRenameFile.swift */; };
 		F79EC784263161BA004E59D6 /* NCRenameFile.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = F70D87CD25EE6E58008CBBBD /* NCRenameFile.storyboard */; };
@@ -667,6 +671,7 @@
 		F79918A72199840500C2E308 /* Sheeeeeeeeet.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Sheeeeeeeeet.framework; path = Carthage/Build/iOS/Sheeeeeeeeet.framework; sourceTree = "<group>"; };
 		F79A65C22191D90F00FF6DCC /* NCSelect.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = NCSelect.storyboard; sourceTree = "<group>"; };
 		F79A65C52191D95E00FF6DCC /* NCSelect.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCSelect.swift; sourceTree = "<group>"; };
+		F79B645F26CA661600838ACA /* UIControl+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIControl+Extensions.swift"; sourceTree = "<group>"; };
 		F79B869A265E19D40085C0E0 /* NSMutableAttributedString+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NSMutableAttributedString+Extensions.swift"; sourceTree = "<group>"; };
 		F79EDA9F26B004980007D134 /* NCViewerVideoToolBar.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NCViewerVideoToolBar.swift; sourceTree = "<group>"; };
 		F79EDAA026B004980007D134 /* NCKTVHTTPCache.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NCKTVHTTPCache.swift; sourceTree = "<group>"; };
@@ -1222,6 +1227,7 @@
 				F78071081EDAB65800EAFFF6 /* NSNotificationCenter+MainThread.m */,
 				F7A0D1342591FBC5008F8A13 /* String+Extensions.swift */,
 				F70CEF5523E9C7E50007035B /* UIColor+Extensions.swift */,
+				F79B645F26CA661600838ACA /* UIControl+Extensions.swift */,
 				F713FEFE2472764000214AF6 /* UIImage+animatedGIF.h */,
 				F713FEFF2472764100214AF6 /* UIImage+animatedGIF.m */,
 				F7B7504A2397D38E004E13EC /* UIImage+Extensions.swift */,
@@ -2016,6 +2022,7 @@
 				2C1D5D7623E2DE3300334ABB /* NCManageDatabase.swift in Sources */,
 				2C33C48223E2C475005F963B /* NotificationService.swift in Sources */,
 				F73D5E4A246DE09200DF6467 /* NCElementsJSON.swift in Sources */,
+				F79B646326CA661600838ACA /* UIControl+Extensions.swift in Sources */,
 				F798F0EC2588060A000DAFFD /* UIColor+Extensions.swift in Sources */,
 				2CB7D1CA23E2EDCB00376EF9 /* NCPushNotificationEncryption.m in Sources */,
 				F782FDC424E6933900666099 /* NCUtility.swift in Sources */,
@@ -2034,6 +2041,7 @@
 				F7707687263A853700A1BA94 /* NCContentPresenter.swift in Sources */,
 				F70460532499095400BB98A7 /* NotificationCenter+MainThread.swift in Sources */,
 				F70BFC7520E0FA7D00C67599 /* NCUtility.swift in Sources */,
+				F79B646126CA661600838ACA /* UIControl+Extensions.swift in Sources */,
 				F7E17F4726C40AFA000AB7DD /* NCOperationQueue.swift in Sources */,
 				F7EDE4CC262D7B6F00414FE6 /* NCEmptyDataSet.swift in Sources */,
 				F798F0E225880608000DAFFD /* UIColor+Extensions.swift in Sources */,
@@ -2076,6 +2084,7 @@
 				F798F0E725880609000DAFFD /* UIColor+Extensions.swift in Sources */,
 				F70460542499095400BB98A7 /* NotificationCenter+MainThread.swift in Sources */,
 				F785EEA42461A4A600B3F945 /* NCUtility.swift in Sources */,
+				F79B646226CA661600838ACA /* UIControl+Extensions.swift in Sources */,
 				F771E3F320E239A600AFB62D /* FileProviderData.swift in Sources */,
 				F7B8CD9B261AF401007C1359 /* NCNetworkingChunkedUpload.swift in Sources */,
 				F7A0D1372591FBC5008F8A13 /* String+Extensions.swift in Sources */,
@@ -2171,6 +2180,7 @@
 				F718C24E254D507B00C5C256 /* NCViewerImageDetailView.swift in Sources */,
 				F7381EE1218218C9000B1560 /* NCOffline.swift in Sources */,
 				F78071091EDAB65800EAFFF6 /* NSNotificationCenter+MainThread.m in Sources */,
+				F79B646026CA661600838ACA /* UIControl+Extensions.swift in Sources */,
 				F7CA212D25F1333300826ABB /* NCAccountRequest.swift in Sources */,
 				F765F73125237E3F00391DBE /* NCRecent.swift in Sources */,
 				F76B3CCE1EAE01BD00921AC9 /* NCBrand.swift in Sources */,

+ 50 - 54
Share/NCShareExtension.swift

@@ -225,7 +225,21 @@ class NCShareExtension: UIViewController, NCListCellDelegate, NCEmptyDataSetDele
         backButton.semanticContentAttribute = .forceLeftToRight
         backButton.setTitle(" "+NSLocalizedString("_back_", comment: ""), for: .normal)
         backButton.setTitleColor(.systemBlue, for: .normal)
-        backButton.addTarget(self, action: #selector(backButtonTapped(sender:)), for: .touchUpInside)
+        backButton.action(for: .touchUpInside) { _ in
+            
+            while self.serverUrl.last != "/" {
+                self.serverUrl.removeLast()
+            }
+            self.serverUrl.removeLast()
+
+            self.reloadDatasource(withLoadFolder: true)
+            
+            var navigationTitle = (self.serverUrl as NSString).lastPathComponent
+            if NCUtilityFileSystem.shared.getHomeServer(account: self.activeAccount.account) == self.serverUrl {
+                navigationTitle = NCBrandOptions.shared.brand
+            }
+            self.setNavigationBar(navigationTitle: navigationTitle)
+        }
         
         // PROFILE BUTTON
                 
@@ -256,8 +270,42 @@ class NCShareExtension: UIViewController, NCListCellDelegate, NCEmptyDataSetDele
             
         profileButton.semanticContentAttribute = .forceLeftToRight
         profileButton.sizeToFit()
-        profileButton.addTarget(self, action: #selector(profileButtonTapped(sender:)), for: .touchUpInside)
+        profileButton.action(for: .touchUpInside) { _ in
+            
+            let accounts = NCManageDatabase.shared.getAllAccountOrderAlias()
+            if accounts.count > 1 {
+                
+                if let vcAccountRequest = UIStoryboard(name: "NCAccountRequest", bundle: nil).instantiateInitialViewController() as? NCAccountRequest {
                    
+                    // Only here change the active account
+                    for account in accounts {
+                        if account.account == self.activeAccount.account {
+                            account.active = true
+                        } else {
+                            account.active = false
+                        }
+                    }
+                    
+                    vcAccountRequest.activeAccount = self.activeAccount
+                    vcAccountRequest.accounts = accounts.sorted { (sorg, dest) -> Bool in
+                        return sorg.active && !dest.active
+                    }
+                    vcAccountRequest.enableTimerProgress = false
+                    vcAccountRequest.enableAddAccount = false
+                    vcAccountRequest.delegate = self
+                    vcAccountRequest.dismissDidEnterBackground = true
+
+                    let screenHeighMax = UIScreen.main.bounds.height - (UIScreen.main.bounds.height/5)
+                    let numberCell = accounts.count
+                    let height = min(CGFloat(numberCell * Int(vcAccountRequest.heightCell) + 45), screenHeighMax)
+                    
+                    let popup = NCPopupViewController(contentController: vcAccountRequest, popupWidth: 300, popupHeight: height+20)
+                    
+                    self.present(popup, animated: true)
+                }
+            }
+        }
+                           
         if serverUrl == NCUtilityFileSystem.shared.getHomeServer(account: activeAccount.account) {
 
             navigationItem.setLeftBarButtonItems([UIBarButtonItem(customView: profileButton)], animated: true)
@@ -399,22 +447,6 @@ class NCShareExtension: UIViewController, NCListCellDelegate, NCEmptyDataSetDele
         }
     }
     
-    @objc func backButtonTapped(sender: Any) {
-                
-        while serverUrl.last != "/" {
-            serverUrl.removeLast()
-        }
-        serverUrl.removeLast()
-
-        reloadDatasource(withLoadFolder: true)
-        
-        var navigationTitle = (serverUrl as NSString).lastPathComponent
-        if NCUtilityFileSystem.shared.getHomeServer(account: activeAccount.account) == serverUrl {
-            navigationTitle = NCBrandOptions.shared.brand
-        }
-        setNavigationBar(navigationTitle: navigationTitle)
-    }
-    
     func rename(fileName: String, fileNameNew: String) {
         
         if let row = self.filesName.firstIndex(where: {$0 == fileName}) {
@@ -466,42 +498,6 @@ class NCShareExtension: UIViewController, NCListCellDelegate, NCEmptyDataSetDele
     func accountRequestChangeAccount(account: String) {
         setAccount(account: account)
     }
-    
-    @objc func profileButtonTapped(sender: Any) {
-        
-        let accounts = NCManageDatabase.shared.getAllAccountOrderAlias()
-        if accounts.count > 1 {
-            
-            if let vcAccountRequest = UIStoryboard(name: "NCAccountRequest", bundle: nil).instantiateInitialViewController() as? NCAccountRequest {
-               
-                // Only here change the active account 
-                for account in accounts {
-                    if account.account == self.activeAccount.account {
-                        account.active = true
-                    } else {
-                        account.active = false
-                    }
-                }
-                
-                vcAccountRequest.activeAccount = self.activeAccount
-                vcAccountRequest.accounts = accounts.sorted { (sorg, dest) -> Bool in
-                    return sorg.active && !dest.active
-                }
-                vcAccountRequest.enableTimerProgress = false
-                vcAccountRequest.enableAddAccount = false
-                vcAccountRequest.delegate = self
-                vcAccountRequest.dismissDidEnterBackground = true
-
-                let screenHeighMax = UIScreen.main.bounds.height - (UIScreen.main.bounds.height/5)
-                let numberCell = accounts.count
-                let height = min(CGFloat(numberCell * Int(vcAccountRequest.heightCell) + 45), screenHeighMax)
-                
-                let popup = NCPopupViewController(contentController: vcAccountRequest, popupWidth: 300, popupHeight: height+20)
-                
-                self.present(popup, animated: true)
-            }
-        }
-    }
 }
 
 // MARK: - Collection View

+ 48 - 0
iOSClient/Extensions/UIControl+Extensions.swift

@@ -0,0 +1,48 @@
+//
+//  UIControl+Extensions.swift
+//  Nextcloud
+//
+//  Created by Marino Faggiana on 16/08/21.
+//  Copyright © 2021 Marino Faggiana. All rights reserved.
+//
+//  Author Marino Faggiana <marino.faggiana@nextcloud.com>
+//  Found in Internet
+//
+//  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 Foundation
+
+public class ActionClosure {
+    
+    public let selector : Selector
+    private let closure : (_ sendersender: Any?) -> ()
+    
+    init(_ attachObj: AnyObject, closure: @escaping (_ sender: Any?) -> ()) {
+        self.closure = closure
+        self.selector = #selector(target(_ :))
+        objc_setAssociatedObject(attachObj, UUID().uuidString, self, .OBJC_ASSOCIATION_RETAIN)
+    }
+    
+    @objc func target(_ sender: Any?) {
+        closure(sender)
+    }
+}
+
+public extension UIControl {
+    func action(for event: UIControl.Event, _ closure : @escaping (_ object: Any?) -> Void) {
+        let actionClosure = ActionClosure(self, closure: closure)
+        self.addTarget(actionClosure, action: actionClosure.selector, for: event)
+    }
+}

+ 27 - 32
iOSClient/Main/Collection Common/NCCollectionViewCommon.swift

@@ -113,7 +113,9 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
         
         // Refresh Control
         collectionView.addSubview(refreshControl)
-        refreshControl.addTarget(self, action: #selector(reloadDataSourceNetworkRefreshControl), for: .valueChanged)
+        refreshControl.action(for: .valueChanged) { _ in
+            self.reloadDataSourceNetwork(forced: true)
+        }
         
         // Empty
         emptyDataSet = NCEmptyDataSet.init(view: collectionView, offset: headerHeight, delegate: self)
@@ -652,8 +654,30 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
                 
                 button.semanticContentAttribute = .forceLeftToRight
                 button.sizeToFit()
-                button.addTarget(self, action: #selector(profileButtonTapped(sender:)), for: .touchUpInside)
-                       
+                button.action(for: .touchUpInside) { _ in
+                    
+                    let accounts = NCManageDatabase.shared.getAllAccountOrderAlias()
+                    if accounts.count > 0 {
+                        
+                        if let vcAccountRequest = UIStoryboard(name: "NCAccountRequest", bundle: nil).instantiateInitialViewController() as? NCAccountRequest {
+                           
+                            vcAccountRequest.activeAccount = NCManageDatabase.shared.getActiveAccount()
+                            vcAccountRequest.accounts = accounts
+                            vcAccountRequest.enableTimerProgress = false
+                            vcAccountRequest.enableAddAccount = true
+                            vcAccountRequest.delegate = self
+                            vcAccountRequest.dismissDidEnterBackground = true
+
+                            let screenHeighMax = UIScreen.main.bounds.height - (UIScreen.main.bounds.height/5)
+                            let numberCell = accounts.count + 1
+                            let height = min(CGFloat(numberCell * Int(vcAccountRequest.heightCell) + 45), screenHeighMax)
+                            
+                            let popup = NCPopupViewController(contentController: vcAccountRequest, popupWidth: 300, popupHeight: height)
+                            
+                            UIApplication.shared.keyWindow?.rootViewController?.present(popup, animated: true)
+                        }
+                    }
+                }
                 navigationItem.setLeftBarButton(UIBarButtonItem(customView: button), animated: true)
                 navigationItem.leftItemsSupplementBackButton = true
             }
@@ -769,31 +793,6 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
         appDelegate.openLogin(viewController: self, selector: NCGlobal.shared.introLogin, openLoginWeb: false)
     }
     
-    @objc func profileButtonTapped(sender: Any) {
-        
-        let accounts = NCManageDatabase.shared.getAllAccountOrderAlias()
-        if accounts.count > 0 {
-            
-            if let vcAccountRequest = UIStoryboard(name: "NCAccountRequest", bundle: nil).instantiateInitialViewController() as? NCAccountRequest {
-               
-                vcAccountRequest.activeAccount = NCManageDatabase.shared.getActiveAccount()
-                vcAccountRequest.accounts = accounts
-                vcAccountRequest.enableTimerProgress = false
-                vcAccountRequest.enableAddAccount = true
-                vcAccountRequest.delegate = self
-                vcAccountRequest.dismissDidEnterBackground = true
-
-                let screenHeighMax = UIScreen.main.bounds.height - (UIScreen.main.bounds.height/5)
-                let numberCell = accounts.count + 1
-                let height = min(CGFloat(numberCell * Int(vcAccountRequest.heightCell) + 45), screenHeighMax)
-                
-                let popup = NCPopupViewController(contentController: vcAccountRequest, popupWidth: 300, popupHeight: height)
-                
-                UIApplication.shared.keyWindow?.rootViewController?.present(popup, animated: true)
-            }
-        }
-    }
-    
     func tapSwitchHeader(sender: Any) {
         
         if collectionView.collectionViewLayout == gridLayout {
@@ -1004,10 +1003,6 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
     
     @objc func reloadDataSourceNetwork(forced: Bool = false) { }
     
-    @objc func reloadDataSourceNetworkRefreshControl() {
-        reloadDataSourceNetwork(forced: true)
-    }
-    
     @objc func networkSearch() {
         
         if appDelegate.account == "" { return }

+ 12 - 16
iOSClient/Main/NCMainTabBar.swift

@@ -190,26 +190,22 @@ class NCMainTabBar: UITabBar {
         centerButton.layer.shadowOffset = CGSize(width: 0, height: 0)
         centerButton.layer.shadowRadius = 3.0
         centerButton.layer.shadowOpacity = 0.5
-        
-        centerButton.addTarget(self, action: #selector(self.centerButtonAction), for: .touchUpInside)
-        
-        self.addSubview(centerButton)
-    }
-    
-    // Menu Button Touch Action
-    @objc func centerButtonAction(sender: UIButton) {
-        
-        if let directory = NCManageDatabase.shared.getTableDirectory(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@", appDelegate.account, appDelegate.activeServerUrl)) {
+        centerButton.action(for: .touchUpInside) { _ in
+            
+            if let directory = NCManageDatabase.shared.getTableDirectory(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@", self.appDelegate.account, self.appDelegate.activeServerUrl)) {
+                
+                if !directory.permissions.contains("CK") {
+                    NCContentPresenter.shared.messageNotification("_warning_", description: "_no_permission_add_file_", delay: NCGlobal.shared.dismissAfterSecond, type: NCContentPresenter.messageType.info, errorCode: NCGlobal.shared.errorInternalError)
+                    return
+                }
+            }
             
-            if !directory.permissions.contains("CK") {
-                NCContentPresenter.shared.messageNotification("_warning_", description: "_no_permission_add_file_", delay: NCGlobal.shared.dismissAfterSecond, type: NCContentPresenter.messageType.info, errorCode: NCGlobal.shared.errorInternalError)
-                return
+            if let viewController = self.window?.rootViewController {
+                self.appDelegate.toggleMenu(viewController: viewController)
             }
         }
         
-        if let viewController = self.window?.rootViewController {
-            appDelegate.toggleMenu(viewController: viewController)
-        }
+        self.addSubview(centerButton)
     }
     
     @objc func updateBadgeNumber() {

+ 2 - 12
iOSClient/Select/NCSelect.swift

@@ -83,9 +83,7 @@ class NCSelect: UIViewController, UIGestureRecognizerDelegate, UIAdaptivePresent
     private let footerHeight: CGFloat = 100
     
     private var shares: [tableShare]?
-    
-    private let refreshControl = UIRefreshControl()
-    
+        
     private var backgroundImageView = UIImageView()
     
     private var activeAccount: tableAccount!
@@ -117,12 +115,6 @@ class NCSelect: UIViewController, UIGestureRecognizerDelegate, UIAdaptivePresent
         listLayout = NCListLayout()
         gridLayout = NCGridLayout()
         
-        // Add Refresh Control
-        collectionView.addSubview(refreshControl)
-        refreshControl.tintColor = NCBrandColor.shared.brandText
-        refreshControl.backgroundColor = NCBrandColor.shared.systemBackground
-        refreshControl.addTarget(self, action: #selector(loadDatasource), for: .valueChanged)
-        
         buttonCancel.title = NSLocalizedString("_cancel_", comment: "")
         
         // Empty
@@ -707,9 +699,7 @@ extension NCSelect {
         
         if withLoadFolder {
             loadFolder()
-        } else {
-            self.refreshControl.endRefreshing()
-        }
+        } 
         
         let directory = NCManageDatabase.shared.getTableDirectory(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@", activeAccount.account,serverUrl))
         richWorkspaceText = directory?.richWorkspace