marinofaggiana 4 anni fa
parent
commit
0f285912f7

+ 25 - 18
iOSClient/BackgroundImageColor/NCBackgroundImageColor.swift

@@ -24,6 +24,19 @@
 import UIKit
 import ChromaColorPicker
 
+public protocol NCBackgroundImageColorDelegate {
+    func colorPickerCancel()
+    func colorPickerWillChange(color: UIColor)
+    func colorPickerDidChange(lightColor: String, darkColor: String, useForAll: Bool)
+}
+
+// optional func
+public extension NCBackgroundImageColorDelegate {
+    func colorPickerCancel() {}
+    func colorPickerWillChange(color: UIColor) { }
+    func colorPickerDidChange(lightColor: String, darkColor: String, useForAll: Bool) { }
+}
+
 class NCBackgroundImageColor: UIViewController {
 
     @IBOutlet weak var titleLabel: UILabel!
@@ -54,7 +67,9 @@ class NCBackgroundImageColor: UIViewController {
     private var darkColor = ""
     private var lightColor = ""
     
-    public var collectionViewCommon: NCCollectionViewCommon?
+    var delegate: NCBackgroundImageColorDelegate?
+    var setupColor: UIColor?
+    var layoutForView: NCGlobal.layoutForViewType?
 
     let width: CGFloat = 300
     let height: CGFloat = 485
@@ -124,12 +139,11 @@ class NCBackgroundImageColor: UIViewController {
         useForAllSwitch.isOn = false
         
         // Color for this view
-        if let collectionViewCommon = collectionViewCommon {
-            let layoutForView = NCUtility.shared.getLayoutForView(key: collectionViewCommon.layoutKey, serverUrl: collectionViewCommon.serverUrl)
+        if let layoutForView = layoutForView {
             darkColor = layoutForView.darkColorBackground
             lightColor = layoutForView.lightColorBackground
         }
-                
+        
         // Color for all folders
         if let activeAccount = NCManageDatabase.shared.getActiveAccount() {
             if darkColor == "" {
@@ -237,7 +251,8 @@ class NCBackgroundImageColor: UIViewController {
     }
     
     @IBAction func cancelAction(_ sender: Any) {
-        collectionViewCommon?.setLayout()
+
+        self.delegate?.colorPickerCancel()
         dismiss(animated: true)
     }
     
@@ -248,17 +263,9 @@ class NCBackgroundImageColor: UIViewController {
         
         if lightColor == "#FFFFFF" { lightColor = "" }
         if darkColor == "#000000" { darkColor = "" }
-
-        if let collectionViewCommon = collectionViewCommon {
-            if useForAllSwitch.isOn {
-                NCManageDatabase.shared.setAccountColorFiles(lightColorBackground: lightColor, darkColorBackground: darkColor)
-                NCUtility.shared.setBackgroundColorForView(key: collectionViewCommon.layoutKey, serverUrl: collectionViewCommon.serverUrl, lightColorBackground: "", darkColorBackground: "")
-            } else {
-                NCUtility.shared.setBackgroundColorForView(key: collectionViewCommon.layoutKey, serverUrl: collectionViewCommon.serverUrl, lightColorBackground: lightColor, darkColorBackground: darkColor)
-            }
-        }
         
-        collectionViewCommon?.setLayout()
+        self.delegate?.colorPickerDidChange(lightColor: lightColor, darkColor: darkColor, useForAll: useForAllSwitch.isOn)
+        
         dismiss(animated: true)
     }
     
@@ -297,7 +304,7 @@ class NCBackgroundImageColor: UIViewController {
     }
     
     private func setupColorPickerHandles() {
-        colorHandle = colorPicker.addHandle(at: collectionViewCommon?.collectionView.backgroundColor)
+        colorHandle = colorPicker.addHandle(at: setupColor)
     }
     
     private func changeColor(_ color: UIColor) {
@@ -312,7 +319,7 @@ class NCBackgroundImageColor: UIViewController {
             lightColor = color.hexString
         }
         
-        collectionViewCommon?.collectionView.backgroundColor = color
+        self.delegate?.colorPickerWillChange(color: color)
     }
 }
 
@@ -325,6 +332,6 @@ extension NCBackgroundImageColor: ChromaColorPickerDelegate {
             lightColor = color.hexString
         }
         
-        collectionViewCommon?.collectionView.backgroundColor = color
+        self.delegate?.colorPickerWillChange(color: color)
     }
 }

+ 2 - 2
iOSClient/Brand/NCBrand.swift

@@ -89,8 +89,8 @@ import UIKit
     @objc public var disable_crash_service:             Bool = false
     @objc public var disable_request_account:           Bool = false
     
-    @objc public var disable_background_color:          Bool = true
-    @objc public var disable_background_image:          Bool = true
+    @objc public var disable_background_color:          Bool = false
+    @objc public var disable_background_image:          Bool = false
 
     override init() {
         

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

@@ -24,7 +24,7 @@
 import Foundation
 import NCCommunication
 
-class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UISearchResultsUpdating, UISearchControllerDelegate, UISearchBarDelegate, NCListCellDelegate, NCGridCellDelegate, NCSectionHeaderMenuDelegate, UIAdaptivePresentationControllerDelegate, NCEmptyDataSetDelegate, UIContextMenuInteractionDelegate, NCAccountRequestDelegate  {
+class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UISearchResultsUpdating, UISearchControllerDelegate, UISearchBarDelegate, NCListCellDelegate, NCGridCellDelegate, NCSectionHeaderMenuDelegate, UIAdaptivePresentationControllerDelegate, NCEmptyDataSetDelegate, UIContextMenuInteractionDelegate, NCAccountRequestDelegate, NCBackgroundImageColorDelegate  {
     
     @IBOutlet weak var collectionView: UICollectionView!
 
@@ -648,6 +648,29 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
         collectionView.reloadData()
     }
 
+    // MARK: - BackgroundImageColor Delegate
+    
+    func colorPickerCancel() {
+        setLayout()
+    }
+    
+    func colorPickerWillChange(color: UIColor) {
+        collectionView.backgroundColor = color
+    }
+    
+    func colorPickerDidChange(lightColor: String, darkColor: String, useForAll: Bool) {
+        
+        if useForAll {
+            NCManageDatabase.shared.setAccountColorFiles(lightColorBackground: lightColor, darkColorBackground: darkColor)
+            NCUtility.shared.setBackgroundColorForView(key: layoutKey, serverUrl: serverUrl, lightColorBackground: "", darkColorBackground: "")
+        } else {
+            NCUtility.shared.setBackgroundColorForView(key: layoutKey, serverUrl: serverUrl, lightColorBackground: lightColor, darkColorBackground: darkColor)
+        }
+        
+        setLayout()
+    }
+        
+    
     // MARK: - Empty
     
     func emptyDataSetView(_ view: NCEmptyView) {
@@ -929,7 +952,9 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
        
         if let vcBackgroundImageColor = UIStoryboard(name: "NCBackgroundImageColor", bundle: nil).instantiateInitialViewController() as? NCBackgroundImageColor {
             
-            vcBackgroundImageColor.collectionViewCommon = self
+            vcBackgroundImageColor.delegate = self
+            vcBackgroundImageColor.setupColor = collectionView.backgroundColor
+            vcBackgroundImageColor.layoutForView = layoutForView
             
             let popup = NCPopupViewController(contentController: vcBackgroundImageColor, popupWidth: vcBackgroundImageColor.width, popupHeight: vcBackgroundImageColor.height)
             popup.backgroundAlpha = 0

+ 4 - 0
iOSClient/Main/NCMainNavigationController.swift

@@ -57,4 +57,8 @@ class NCMainNavigationController: UINavigationController {
         navigationBar.tintColor = .systemBlue
         navigationBar.setNeedsLayout()
     }
+    
+    override func viewDidLayoutSubviews() {
+        super.viewDidLayoutSubviews()
+    }
 }