marinofaggiana 3 years ago
parent
commit
ed21f5a81f

+ 31 - 9
iOSClient/Main/Collection Common/NCCollectionViewCommon.swift

@@ -33,7 +33,8 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
     internal let refreshControl = UIRefreshControl()
     internal var searchController: UISearchController?
     internal var emptyDataSet: NCEmptyDataSet?
-    
+    internal var backgroundImageView = UIImageView()
+
     internal var serverUrl: String = ""
     internal var isEncryptedFolder = false
     internal var isEditMode = false
@@ -176,14 +177,7 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
             appDelegate.activeServerUrl = serverUrl
         }
         
-        (layout, sort, ascending, groupBy, directoryOnTop, titleButtonHeader, itemForLine, fillBackgroud, fillBackgroudContentMode) = NCUtility.shared.getLayoutForView(key: layoutKey, serverUrl: serverUrl)
-        gridLayout.itemForLine = CGFloat(itemForLine)
-        
-        if layout == NCGlobal.shared.layoutList {
-            collectionView?.collectionViewLayout = listLayout
-        } else {
-            collectionView?.collectionViewLayout = gridLayout
-        }
+        setLayout()
         
         navigationController?.navigationBar.prefersLargeTitles = true
         navigationController?.setNavigationBarHidden(false, animated: true)
@@ -602,7 +596,35 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
             }
         }
     }
+
+    // MARK: - Layout
+    
+    func setLayout() {
+        
+        (layout, sort, ascending, groupBy, directoryOnTop, titleButtonHeader, itemForLine, fillBackgroud, fillBackgroudContentMode) = NCUtility.shared.getLayoutForView(key: layoutKey, serverUrl: serverUrl)
+        gridLayout.itemForLine = CGFloat(itemForLine)
         
+        if layout == NCGlobal.shared.layoutList {
+            collectionView?.collectionViewLayout = listLayout
+        } else {
+            collectionView?.collectionViewLayout = gridLayout
+        }
+        
+        if fillBackgroud != "" {
+            let imagePath = CCUtility.getDirectoryGroup().appendingPathComponent(NCGlobal.shared.appBackground).path + "/" + fillBackgroud
+            do {
+                let data = try Data.init(contentsOf: URL(fileURLWithPath: imagePath))
+                if let image = UIImage.init(data: data) {
+                    backgroundImageView.image = image
+                    backgroundImageView.contentMode = .scaleToFill
+                    collectionView.backgroundView = backgroundImageView
+                }
+            } catch {
+                print("error")
+            }
+        }
+    }
+
     // MARK: - Empty
     
     func emptyDataSetView(_ view: NCEmptyView) {

+ 9 - 0
iOSClient/Main/NCFunctionCenter.swift

@@ -317,6 +317,15 @@ import NCCommunication
         
         if NCUtilityFileSystem.shared.copyFile(atPath: fileNamePath, toPath: destination) {
             
+            if appDelegate.activeViewController is NCCollectionViewCommon {
+                let viewController: NCCollectionViewCommon = appDelegate.activeViewController as! NCCollectionViewCommon
+                let layout = viewController.layout
+                let serverUrl = viewController.serverUrl
+                if serverUrl == metadata.serverUrl {
+                    NCUtility.shared.setBackgroundForView(key: layout, serverUrl: serverUrl, fillBackgroud: metadata.fileNameView, fillBackgroudContentMode: "")
+                    viewController.setLayout()
+                }
+            }
         }
     }
     

+ 0 - 7
iOSClient/Select/NCSelect.swift

@@ -188,13 +188,6 @@ class NCSelect: UIViewController, UIGestureRecognizerDelegate, UIAdaptivePresent
         (layout, sort, ascending, groupBy, directoryOnTop, titleButtonHeader, itemForLine, fillBackgroud, fillBackgroudContentMode) = NCUtility.shared.getLayoutForView(key: keyLayout,serverUrl: serverUrl)
         gridLayout.itemForLine = CGFloat(itemForLine)
         
-        /*
-        let image = UIColor.red.image(CGSize(width: collectionView.frame.width, height: collectionView.frame.width))
-        backgroundImageView.image = image
-        backgroundImageView.contentMode = .scaleToFill
-        collectionView.backgroundView = backgroundImageView
-        */
-        
         if layout == NCGlobal.shared.layoutList {
             collectionView.collectionViewLayout = listLayout
         } else {

+ 15 - 0
iOSClient/Utility/NCUtility.swift

@@ -78,6 +78,21 @@ class NCUtility: NSObject {
         setLayoutForView(key: key, serverUrl: serverUrl, layout: layout, sort: sort, ascending: ascending, groupBy: groupBy, directoryOnTop: directoryOnTop, titleButtonHeader: titleButtonHeader, itemForLine: itemForLine, fillBackgroud: fillBackgroud, fillBackgroudContentMode: fillBackgroudContentMode)
     }
     
+    func setBackgroundForView(key: String, serverUrl: String, fillBackgroud: String, fillBackgroudContentMode: String) {
+
+        var layout: String
+        var sort: String
+        var ascending: Bool
+        var groupBy: String
+        var directoryOnTop: Bool
+        var titleButtonHeader: String
+        var itemForLine: Int
+        
+        (layout, sort, ascending, groupBy, directoryOnTop, titleButtonHeader, itemForLine, _, _) = NCUtility.shared.getLayoutForView(key: key, serverUrl: serverUrl)
+        
+        setLayoutForView(key: key, serverUrl: serverUrl, layout: layout, sort: sort, ascending: ascending, groupBy: groupBy, directoryOnTop: directoryOnTop, titleButtonHeader: titleButtonHeader, itemForLine: itemForLine, fillBackgroud: fillBackgroud, fillBackgroudContentMode: fillBackgroudContentMode)
+    }
+    
     func getLayoutForView(key: String, serverUrl: String, sort: String = "fileName", ascending: Bool = true, titleButtonHeader: String = "_sorted_by_name_a_z_") -> (layout: String, sort: String, ascending: Bool, groupBy: String, directoryOnTop: Bool, titleButtonHeader: String, itemForLine: Int, fillBackgroud: String, fillBackgroudContentMode: String) {
         
         var keyStore = key