Browse Source

Improvements class code

Marino Faggiana 6 years ago
parent
commit
9eb533cc54

+ 4 - 0
Nextcloud.xcodeproj/project.pbxproj

@@ -429,6 +429,7 @@
 		F7659A391DC0B737004860C4 /* iRate.m in Sources */ = {isa = PBXBuildFile; fileRef = F7659A331DC0B737004860C4 /* iRate.m */; };
 		F76B3CCE1EAE01BD00921AC9 /* NCBrand.swift in Sources */ = {isa = PBXBuildFile; fileRef = F76B3CCD1EAE01BD00921AC9 /* NCBrand.swift */; };
 		F76B3CCF1EAE01BD00921AC9 /* NCBrand.swift in Sources */ = {isa = PBXBuildFile; fileRef = F76B3CCD1EAE01BD00921AC9 /* NCBrand.swift */; };
+		F76C6F8E21943C8C0063591B /* NCActionSheetHeader.swift in Sources */ = {isa = PBXBuildFile; fileRef = F76C6F8D21943C8C0063591B /* NCActionSheetHeader.swift */; };
 		F76F23341ED4603700C40023 /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = F76F23331ED4603700C40023 /* LaunchScreen.xib */; };
 		F771E3D320E2392D00AFB62D /* FileProviderExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = F771E3D220E2392D00AFB62D /* FileProviderExtension.swift */; };
 		F771E3D520E2392D00AFB62D /* FileProviderItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = F771E3D420E2392D00AFB62D /* FileProviderItem.swift */; };
@@ -1349,6 +1350,7 @@
 		F76C3B841C6388BC00DC4301 /* CCGraphics.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CCGraphics.m; sourceTree = "<group>"; };
 		F76C3B871C638A4C00DC4301 /* CCError.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CCError.h; sourceTree = "<group>"; };
 		F76C3B881C638A4C00DC4301 /* CCError.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CCError.m; sourceTree = "<group>"; };
+		F76C6F8D21943C8C0063591B /* NCActionSheetHeader.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCActionSheetHeader.swift; sourceTree = "<group>"; };
 		F76F23321ED4600700C40023 /* Share-Bridging-Header.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "Share-Bridging-Header.h"; sourceTree = "<group>"; };
 		F76F23331ED4603700C40023 /* LaunchScreen.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = LaunchScreen.xib; sourceTree = "<group>"; };
 		F771E3D020E2392D00AFB62D /* File Provider Extension.appex */ = {isa = PBXFileReference; explicitFileType = "wrapper.app-extension"; includeInIndex = 0; path = "File Provider Extension.appex"; sourceTree = BUILT_PRODUCTS_DIR; };
@@ -2980,6 +2982,7 @@
 			isa = PBXGroup;
 			children = (
 				F729B92C217A2F1B00FE2150 /* NCActionSheetHeaderView.swift */,
+				F76C6F8D21943C8C0063591B /* NCActionSheetHeader.swift */,
 				F729B92A217A2E4E00FE2150 /* NCActionSheetHeaderView.xib */,
 			);
 			path = ActionSheetHeaderView;
@@ -4280,6 +4283,7 @@
 				F762CB0C1EACB66200B38484 /* XLFormSectionDescriptor.m in Sources */,
 				F77B0E131D118A16002130FE /* AppDelegate.m in Sources */,
 				F762CB861EACB81000B38484 /* RECommonFunctions.m in Sources */,
+				F76C6F8E21943C8C0063591B /* NCActionSheetHeader.swift in Sources */,
 				F7622FC62175FCC0000383FF /* UIViewController+RootViewController.swift in Sources */,
 				F758B443212C516300515F55 /* ScannerViewController.swift in Sources */,
 				F750374F1DBFA91A008FB480 /* NSArray+PureLayout.m in Sources */,

+ 59 - 0
iOSClient/Main/ActionSheetHeaderView/NCActionSheetHeader.swift

@@ -0,0 +1,59 @@
+//
+//  NCActionSheetHeader.swift
+//  Nextcloud
+//
+//  Created by Marino Faggiana on 08/11/2018.
+//  Copyright © 2018 Marino Faggiana. All rights reserved.
+//
+//  Author Marino Faggiana <m.faggiana@twsweb.it>
+//
+//  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
+
+class NCActionSheetHeader: NSObject {
+    
+    @objc static let sharedInstance: NCActionSheetHeader = {
+        let instance = NCActionSheetHeader()
+        return instance
+    }()
+    
+    let appDelegate = UIApplication.shared.delegate as! AppDelegate
+
+    func actionSheetHeader(isDirectory: Bool, iconName: String, fileID: String, fileNameView: String, text: String) -> UIView? {
+        
+        var image: UIImage?
+        
+        // Header
+        if isDirectory {
+            image = CCGraphics.changeThemingColorImage(UIImage.init(named: "folder"), multiplier: 3, color: NCBrandColor.sharedInstance.brandElement)
+        } else if iconName.count > 0 {
+            image = UIImage.init(named: iconName)
+        } else {
+            image = UIImage.init(named: "file")
+        }
+        if FileManager().fileExists(atPath: CCUtility.getDirectoryProviderStorageIconFileID(fileID, fileNameView: fileNameView)) {
+            image = UIImage.init(contentsOfFile: CCUtility.getDirectoryProviderStorageIconFileID(fileID, fileNameView: fileNameView))
+        }
+        
+        let headerView = UINib(nibName: "NCActionSheetHeaderView", bundle: nil).instantiate(withOwner: self, options: nil).first as! NCActionSheetHeaderView
+        
+        headerView.imageItem.image = image
+        headerView.label.text = text
+        headerView.label.textColor = NCBrandColor.sharedInstance.icon
+        
+        return headerView
+    }
+}

+ 2 - 41
iOSClient/Offline/NCOffline.swift

@@ -285,7 +285,7 @@ class NCOffline: UIViewController ,UICollectionViewDataSource, UICollectionViewD
                 if item is ActionSheetCancelButton { print("Cancel buttons has the value `true`") }
             }
             
-            let headerView = actionSheetHeader(with: metadata)
+            let headerView = NCActionSheetHeader.sharedInstance.actionSheetHeader(isDirectory: metadata.directory, iconName: metadata.iconName, fileID: metadata.fileID, fileNameView: metadata.fileNameView, text: metadata.fileNameView)
             actionSheet?.headerView = headerView
             actionSheet?.headerView?.frame.size.height = 50
             
@@ -391,7 +391,7 @@ class NCOffline: UIViewController ,UICollectionViewDataSource, UICollectionViewD
             if item is ActionSheetCancelButton { print("Cancel buttons has the value `true`") }
         }
         
-        let headerView = actionSheetHeader(with: metadata)
+        let headerView = NCActionSheetHeader.sharedInstance.actionSheetHeader(isDirectory: metadata.directory, iconName: metadata.iconName, fileID: metadata.fileID, fileNameView: metadata.fileNameView, text: metadata.fileNameView)
         actionSheet?.headerView = headerView
         actionSheet?.headerView?.frame.size.height = 50
         
@@ -607,43 +607,4 @@ class NCOffline: UIViewController ,UICollectionViewDataSource, UICollectionViewD
             }
         }
     }
-    
-    // MARK: UTILITY
-    
-    private func cellBlurEffect(with frame: CGRect) -> UIView {
-        
-        let blurEffect = UIBlurEffect(style: .extraLight)
-        let blurEffectView = UIVisualEffectView(effect: blurEffect)
-        
-        blurEffectView.frame = frame
-        blurEffectView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
-        blurEffectView.backgroundColor = NCBrandColor.sharedInstance.brand.withAlphaComponent(0.2)
-        
-        return blurEffectView
-    }
-    
-    private func actionSheetHeader(with metadata: tableMetadata) -> UIView? {
-        
-        var image: UIImage?
-
-        // Header
-        if metadata.directory {
-            image = CCGraphics.changeThemingColorImage(UIImage.init(named: "folder"), multiplier: 3, color: NCBrandColor.sharedInstance.brandElement)
-        } else if metadata.iconName.count > 0 {
-            image = UIImage.init(named: metadata.iconName)
-        } else {
-            image = UIImage.init(named: "file")
-        }
-        if FileManager().fileExists(atPath: CCUtility.getDirectoryProviderStorageIconFileID(metadata.fileID, fileNameView: metadata.fileNameView)) {
-            image = UIImage.init(contentsOfFile: CCUtility.getDirectoryProviderStorageIconFileID(metadata.fileID, fileNameView: metadata.fileNameView))
-        }
-        
-        let headerView = UINib(nibName: "NCActionSheetHeaderView", bundle: nil).instantiate(withOwner: self, options: nil).first as! NCActionSheetHeaderView
-        
-        headerView.imageItem.image = image
-        headerView.label.text = metadata.fileNameView
-        headerView.label.textColor = NCBrandColor.sharedInstance.icon
-        
-        return headerView
-    }
 }

+ 0 - 39
iOSClient/Select/NCSelect.swift

@@ -747,43 +747,4 @@ class NCSelect: UIViewController ,UICollectionViewDataSource, UICollectionViewDe
         self.navigationController?.pushViewController(visualController, animated: true)
         
     }
-    
-    // MARK: UTILITY
-    
-    private func cellBlurEffect(with frame: CGRect) -> UIView {
-        
-        let blurEffect = UIBlurEffect(style: .extraLight)
-        let blurEffectView = UIVisualEffectView(effect: blurEffect)
-        
-        blurEffectView.frame = frame
-        blurEffectView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
-        blurEffectView.backgroundColor = NCBrandColor.sharedInstance.brand.withAlphaComponent(0.2)
-        
-        return blurEffectView
-    }
-    
-    private func actionSheetHeader(with metadata: tableMetadata) -> UIView? {
-        
-        var image: UIImage?
-        
-        // Header
-        if metadata.directory {
-            image = CCGraphics.changeThemingColorImage(UIImage.init(named: "folder"), multiplier: 3, color: NCBrandColor.sharedInstance.brandElement)
-        } else if metadata.iconName.count > 0 {
-            image = UIImage.init(named: metadata.iconName)
-        } else {
-            image = UIImage.init(named: "file")
-        }
-        if FileManager().fileExists(atPath: CCUtility.getDirectoryProviderStorageIconFileID(metadata.fileID, fileNameView: metadata.fileNameView)) {
-            image = UIImage.init(contentsOfFile: CCUtility.getDirectoryProviderStorageIconFileID(metadata.fileID, fileNameView: metadata.fileNameView))
-        }
-        
-        let headerView = UINib(nibName: "NCActionSheetHeaderView", bundle: nil).instantiate(withOwner: self, options: nil).first as! NCActionSheetHeaderView
-        
-        headerView.imageItem.image = image
-        headerView.label.text = metadata.fileNameView
-        headerView.label.textColor = NCBrandColor.sharedInstance.icon
-        
-        return headerView
-    }
 }

+ 12 - 47
iOSClient/Trash/NCTrash.swift

@@ -273,7 +273,11 @@ class NCTrash: UIViewController ,UICollectionViewDataSource, UICollectionViewDel
                 if item is ActionSheetCancelButton { print("Cancel buttons has the value `true`") }
             }
             
-            let headerView = actionSheetHeader(with: fileID)
+            guard let tableTrash = NCManageDatabase.sharedInstance.getTrashItem(fileID: fileID) else {
+                return
+            }
+            
+            let headerView = NCActionSheetHeader.sharedInstance.actionSheetHeader(isDirectory: tableTrash.directory, iconName: tableTrash.iconName, fileID: tableTrash.fileID, fileNameView: tableTrash.fileName, text: tableTrash.trashbinFileName)            
             actionSheet?.headerView = headerView
             actionSheet?.headerView?.frame.size.height = 50
             
@@ -304,7 +308,11 @@ class NCTrash: UIViewController ,UICollectionViewDataSource, UICollectionViewDel
                 if item is ActionSheetCancelButton { print("Cancel buttons has the value `true`") }
             }
             
-            let headerView = actionSheetHeader(with: fileID)
+            guard let tableTrash = NCManageDatabase.sharedInstance.getTrashItem(fileID: fileID) else {
+                return
+            }
+            
+            let headerView = NCActionSheetHeader.sharedInstance.actionSheetHeader(isDirectory: tableTrash.directory, iconName: tableTrash.iconName, fileID: tableTrash.fileID, fileNameView: tableTrash.fileName, text: tableTrash.trashbinFileName)
             actionSheet?.headerView = headerView
             actionSheet?.headerView?.frame.size.height = 50
             
@@ -635,7 +643,7 @@ class NCTrash: UIViewController ,UICollectionViewDataSource, UICollectionViewDel
                 
                 if selectFileID.contains(tableTrash.fileID) {
                     cell.imageSelect.image = CCGraphics.changeThemingColorImage(UIImage.init(named: "checkedYes"), multiplier: 2, color: NCBrandColor.sharedInstance.brand)
-                    cell.backgroundView = cellBlurEffect(with: cell.bounds)
+                    cell.backgroundView = NCUtility.sharedInstance.cellBlurEffect(with: cell.bounds)
                 } else {
                     cell.imageSelect.image = CCGraphics.changeThemingColorImage(UIImage.init(named: "checkedNo"), multiplier: 2, color: NCBrandColor.sharedInstance.optionItem)
                     cell.backgroundView = nil
@@ -668,7 +676,7 @@ class NCTrash: UIViewController ,UICollectionViewDataSource, UICollectionViewDel
                 cell.imageSelect.isHidden = false
                 if selectFileID.contains(tableTrash.fileID) {
                     cell.imageSelect.image = CCGraphics.changeThemingColorImage(UIImage.init(named: "checkedYes"), multiplier: 2, color: UIColor.white)
-                    cell.backgroundView = cellBlurEffect(with: cell.bounds)
+                    cell.backgroundView = NCUtility.sharedInstance.cellBlurEffect(with: cell.bounds)
                 } else {
                     cell.imageSelect.isHidden = true
                     cell.backgroundView = nil
@@ -705,48 +713,5 @@ class NCTrash: UIViewController ,UICollectionViewDataSource, UICollectionViewDel
             self.navigationController?.pushViewController(ncTrash, animated: true)
         }
     }
-    
-    // MARK: UTILITY
-    
-    private func cellBlurEffect(with frame: CGRect) -> UIView {
-        
-        let blurEffect = UIBlurEffect(style: .extraLight)
-        let blurEffectView = UIVisualEffectView(effect: blurEffect)
-        
-        blurEffectView.frame = frame
-        blurEffectView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
-        blurEffectView.backgroundColor = NCBrandColor.sharedInstance.brand.withAlphaComponent(0.2)
-        
-        return blurEffectView
-    }
-    
-    private func actionSheetHeader(with fileID: String) -> UIView? {
-        
-        var image: UIImage?
-
-        guard let tableTrash = NCManageDatabase.sharedInstance.getTrashItem(fileID: fileID) else {
-            return nil
-        }
-        
-        // Header
-        if tableTrash.directory {
-            image = CCGraphics.changeThemingColorImage(UIImage.init(named: "folder"), multiplier: 3, color: NCBrandColor.sharedInstance.brandElement)
-        } else if tableTrash.iconName.count > 0 {
-            image = UIImage.init(named: tableTrash.iconName)
-        } else {
-            image = UIImage.init(named: "file")
-        }
-        if FileManager().fileExists(atPath: CCUtility.getDirectoryProviderStorageIconFileID(tableTrash.fileID, fileNameView: tableTrash.fileName)) {
-            image = UIImage.init(contentsOfFile: CCUtility.getDirectoryProviderStorageIconFileID(tableTrash.fileID, fileNameView: tableTrash.fileName))
-        }
-        
-        let headerView = UINib(nibName: "NCActionSheetHeaderView", bundle: nil).instantiate(withOwner: self, options: nil).first as! NCActionSheetHeaderView
-        
-        headerView.imageItem.image = image
-        headerView.label.text = tableTrash.trashbinFileName
-        headerView.label.textColor = NCBrandColor.sharedInstance.icon
-        
-        return headerView
-    }
 }