marinofaggiana 3 years ago
parent
commit
751b71a03a

+ 14 - 3
iOSClient/BackgroundImageColor/NCBackgroundImageColor.swift

@@ -44,7 +44,8 @@ class NCBackgroundImageColor: UIViewController {
     private var colorHexString = ""
     
     public var collectionViewCommon: NCCollectionViewCommon?
-    
+    public var defaultColor: UIColor = NCBrandColor.shared.systemBackground
+
     let width: CGFloat = 300
     let height: CGFloat = 500
     
@@ -74,9 +75,10 @@ class NCBackgroundImageColor: UIViewController {
     
     @IBAction func defaultAction(_ sender: Any) {
         
-        colorHandle?.color = NCBrandColor.shared.systemBackground
+        colorHandle?.color = defaultColor
         colorPicker.setNeedsLayout()
-        brightnessSlider.trackColor = NCBrandColor.shared.systemBackground
+        brightnessSlider.trackColor = defaultColor
+        collectionViewCommon?.collectionView.backgroundColor = defaultColor
     }
     
     @IBAction func cancelAction(_ sender: Any) {
@@ -86,6 +88,15 @@ class NCBackgroundImageColor: UIViewController {
     
     @IBAction func okAction(_ sender: Any) {
         
+        if let collectionViewCommon = collectionViewCommon {
+            if colorHandle?.color == defaultColor {
+                NCUtility.shared.setBackgroundColorForView(key: collectionViewCommon.layoutKey, serverUrl: collectionViewCommon.serverUrl, colorBackground: "")
+            } else {
+                NCUtility.shared.setBackgroundColorForView(key: collectionViewCommon.layoutKey, serverUrl: collectionViewCommon.serverUrl, colorBackground: colorHexString)
+            }
+        }
+        collectionViewCommon?.setLayout()
+        dismiss(animated: true)
     }
     
     // MARK: - ChromaColorPicker

+ 5 - 4
iOSClient/Main/Collection Common/NCCollectionViewCommon.swift

@@ -34,7 +34,7 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
     internal var searchController: UISearchController?
     internal var emptyDataSet: NCEmptyDataSet?
     internal var backgroundImageView = UIImageView()
-
+    internal let defaultBackgroundColor = NCBrandColor.shared.systemBackground
     internal var serverUrl: String = ""
     internal var isEncryptedFolder = false
     internal var isEditMode = false
@@ -84,9 +84,9 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
         super.viewDidLoad()
         
         self.navigationController?.presentationController?.delegate = self
-        view.backgroundColor = NCBrandColor.shared.systemBackground
+        view.backgroundColor = defaultBackgroundColor
         
-        collectionView.backgroundColor = NCBrandColor.shared.systemBackground
+        collectionView.backgroundColor = defaultBackgroundColor
         collectionView.alwaysBounceVertical = true
 
         if enableSearchBar {
@@ -619,7 +619,7 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
         if layoutForView?.colorBackground != "" {
             collectionView.backgroundColor = UIColor.init(hex: layoutForView?.colorBackground ?? "")
         } else {
-            collectionView.backgroundColor = NCBrandColor.shared.systemBackground
+            collectionView.backgroundColor = defaultBackgroundColor
         }
     }
 
@@ -902,6 +902,7 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
         if let vcBackgroundImageColor = UIStoryboard(name: "NCBackgroundImageColor", bundle: nil).instantiateInitialViewController() as? NCBackgroundImageColor {
             
             vcBackgroundImageColor.collectionViewCommon = self
+            vcBackgroundImageColor.defaultColor = defaultBackgroundColor
             
             let popup = NCPopupViewController(contentController: vcBackgroundImageColor, popupWidth: vcBackgroundImageColor.width, popupHeight: vcBackgroundImageColor.height)
                                         

+ 1 - 1
iOSClient/Main/NCFunctionCenter.swift

@@ -322,7 +322,7 @@ import NCCommunication
                 let layoutKey = viewController.layoutKey
                 let serverUrl = viewController.serverUrl
                 if serverUrl == metadata.serverUrl {
-                    NCUtility.shared.setBackgroundForView(key: layoutKey, serverUrl: serverUrl, imageBackgroud: metadata.fileNameView, imageBackgroudContentMode: "", colorBackground: "")
+                    NCUtility.shared.setBackgroundImageForView(key: layoutKey, serverUrl: serverUrl, imageBackgroud: metadata.fileNameView, imageBackgroudContentMode: "")
                     viewController.setLayout()
                 }
             }

+ 10 - 2
iOSClient/Utility/NCUtility.swift

@@ -60,13 +60,21 @@ class NCUtility: NSObject {
         }
     }
     
-    func setBackgroundForView(key: String, serverUrl: String, imageBackgroud: String, imageBackgroudContentMode: String, colorBackground: String) {
+    func setBackgroundColorForView(key: String, serverUrl: String, colorBackground: String) {
+        
+        var layoutForView: NCGlobal.layoutForViewType = NCUtility.shared.getLayoutForView(key: key, serverUrl: serverUrl)
+        
+        layoutForView.colorBackground = colorBackground
+        
+        setLayoutForView(key: key, serverUrl: serverUrl, layoutForView: layoutForView)
+    }
+    
+    func setBackgroundImageForView(key: String, serverUrl: String, imageBackgroud: String, imageBackgroudContentMode: String) {
         
         var layoutForView: NCGlobal.layoutForViewType = NCUtility.shared.getLayoutForView(key: key, serverUrl: serverUrl)
         
         layoutForView.imageBackgroud = imageBackgroud
         layoutForView.imageBackgroudContentMode = imageBackgroudContentMode
-        layoutForView.colorBackground = colorBackground
         
         setLayoutForView(key: key, serverUrl: serverUrl, layoutForView: layoutForView)
     }