فهرست منبع

new layoutForView

marinofaggiana 4 سال پیش
والد
کامیت
b942f2a5c1

+ 5 - 13
Share/NCShareExtension.swift

@@ -53,16 +53,8 @@ class NCShareExtension: UIViewController, NCListCellDelegate, NCEmptyDataSetDele
     private var networkInProgress = false
     private var dataSource = NCDataSource()
 
-    private var sort: String = ""
-    private var ascending: Bool = true
-    private var directoryOnTop: Bool = true
-    private var layout = ""
-    private var groupBy = ""
-    private var titleButtonHeader = ""
-    private var itemForLine = 0
-    private var fillBackgroud = ""
-    private var fillBackgroudContentMode = ""
-    
+    private var layoutForView: NCGlobal.layoutForViewType?
+  
     private var heightRowTableView: CGFloat = 50
     private var heightCommandView: CGFloat = 170
     
@@ -194,7 +186,7 @@ class NCShareExtension: UIViewController, NCListCellDelegate, NCEmptyDataSetDele
         
         serverUrl = NCUtilityFileSystem.shared.getHomeServer(urlBase: activeAccount.urlBase, account: activeAccount.account)
         
-        (layout, sort, ascending, groupBy, directoryOnTop, titleButtonHeader, itemForLine, fillBackgroud, fillBackgroudContentMode) = NCUtility.shared.getLayoutForView(key: keyLayout,serverUrl: serverUrl)
+        layoutForView = NCUtility.shared.getLayoutForView(key: keyLayout,serverUrl: serverUrl)
             
         reloadDatasource(withLoadFolder: true)
         setNavigationBar(navigationTitle: NCBrandOptions.shared.brand)
@@ -690,10 +682,10 @@ extension NCShareExtension {
 
     @objc func reloadDatasource(withLoadFolder: Bool) {
                 
-        (layout, sort, ascending, groupBy, directoryOnTop, titleButtonHeader, itemForLine, fillBackgroud, fillBackgroudContentMode) = NCUtility.shared.getLayoutForView(key: keyLayout, serverUrl: serverUrl)
+        layoutForView = NCUtility.shared.getLayoutForView(key: keyLayout, serverUrl: serverUrl)
                 
         let metadatasSource = NCManageDatabase.shared.getMetadatas(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@ AND directory == true", activeAccount.account, serverUrl))
-        self.dataSource = NCDataSource.init(metadatasSource: metadatasSource, sort: sort, ascending: ascending, directoryOnTop: directoryOnTop, favoriteOnTop: true, filterLivePhoto: true)
+        self.dataSource = NCDataSource.init(metadatasSource: metadatasSource, sort: layoutForView?.sort, ascending: layoutForView?.ascending, directoryOnTop: layoutForView?.directoryOnTop, favoriteOnTop: true, filterLivePhoto: true)
         
         if withLoadFolder {
             loadFolder()

+ 6 - 6
iOSClient/Data/NCDataSource.swift

@@ -39,14 +39,14 @@ class NCDataSource: NSObject {
         super.init()
     }
     
-    init(metadatasSource: [tableMetadata], sort: String = "", ascending: Bool = false, directoryOnTop: Bool = false, favoriteOnTop: Bool = false, filterLivePhoto: Bool = false) {
+    init(metadatasSource: [tableMetadata], sort: String? = "none", ascending: Bool? = false, directoryOnTop: Bool? = true, favoriteOnTop: Bool? = true, filterLivePhoto: Bool? = true) {
         super.init()
         
-        self.sort = sort
-        self.ascending = ascending
-        self.directoryOnTop = directoryOnTop
-        self.favoriteOnTop = favoriteOnTop
-        self.filterLivePhoto = filterLivePhoto
+        self.sort = sort ?? "none"
+        self.ascending = ascending ?? false
+        self.directoryOnTop = directoryOnTop ?? true
+        self.favoriteOnTop = favoriteOnTop ?? true
+        self.filterLivePhoto = filterLivePhoto ?? true
         
         createMetadatas(metadatasSource: metadatasSource)
     }

+ 3 - 1
iOSClient/Data/NCManageDatabase.swift

@@ -2899,9 +2899,11 @@ class NCManageDatabase: NSObject {
         }
     }
     
-    @objc func getTrash(filePath: String, sort: String, ascending: Bool, account: String) -> [tableTrash]? {
+    func getTrash(filePath: String, sort: String?, ascending: Bool?, account: String) -> [tableTrash]? {
         
         let realm = try! Realm()
+        let sort = sort ?? "date"
+        let ascending = ascending ?? false
         
         let results = realm.objects(tableTrash.self).filter("account == %@ AND filePath == %@", account, filePath).sorted(byKeyPath: sort, ascending: ascending)
 

+ 1 - 1
iOSClient/Favorites/NCFavorite.swift

@@ -55,7 +55,7 @@ class NCFavorite: NCCollectionViewCommon  {
                 }
             }
             
-            self.dataSource = NCDataSource.init(metadatasSource: self.metadatasSource, sort:self.sort, ascending: self.ascending, directoryOnTop: self.directoryOnTop, favoriteOnTop: true, filterLivePhoto: true)
+            self.dataSource = NCDataSource.init(metadatasSource: self.metadatasSource, sort:self.layoutForView?.sort, ascending: self.layoutForView?.ascending, directoryOnTop: self.layoutForView?.directoryOnTop, favoriteOnTop: true, filterLivePhoto: true)
             
             DispatchQueue.main.async {
                 self.refreshControl.endRefreshing()

+ 4 - 4
iOSClient/FileViewInFolder/NCFileViewInFolder.swift

@@ -53,10 +53,10 @@ class NCFileViewInFolder: NCCollectionViewCommon  {
         
         presentationController?.delegate = self
         
-        (layout, sort, ascending, groupBy, directoryOnTop, titleButtonHeader, itemForLine, fillBackgroud, fillBackgroudContentMode) = NCUtility.shared.getLayoutForView(key: layoutKey, serverUrl: serverUrl)
-        gridLayout.itemForLine = CGFloat(itemForLine)
+        layoutForView = NCUtility.shared.getLayoutForView(key: layoutKey, serverUrl: serverUrl)
+        gridLayout.itemForLine = CGFloat(layoutForView?.itemForLine ?? 3)
         
-        if layout == NCGlobal.shared.layoutList {
+        if layoutForView?.layout == NCGlobal.shared.layoutList {
             collectionView?.collectionViewLayout = listLayout
         } else {
             collectionView?.collectionViewLayout = gridLayout
@@ -88,7 +88,7 @@ class NCFileViewInFolder: NCCollectionViewCommon  {
                 }
             }
             
-            self.dataSource = NCDataSource.init(metadatasSource: self.metadatasSource, sort: self.sort, ascending: self.ascending, directoryOnTop: self.directoryOnTop, favoriteOnTop: true, filterLivePhoto: true)
+            self.dataSource = NCDataSource.init(metadatasSource: self.metadatasSource, sort: self.layoutForView?.sort, ascending: self.layoutForView?.ascending, directoryOnTop: self.layoutForView?.directoryOnTop, favoriteOnTop: true, filterLivePhoto: true)
             
             DispatchQueue.main.async {
             

+ 1 - 1
iOSClient/Files/NCFiles.swift

@@ -77,7 +77,7 @@ class NCFiles: NCCollectionViewCommon  {
                 }
             }
             
-            self.dataSource = NCDataSource.init(metadatasSource: self.metadatasSource, sort: self.sort, ascending: self.ascending, directoryOnTop: self.directoryOnTop, favoriteOnTop: true, filterLivePhoto: true)
+            self.dataSource = NCDataSource.init(metadatasSource: self.metadatasSource, sort: self.layoutForView?.sort, ascending: self.layoutForView?.ascending, directoryOnTop: self.layoutForView?.directoryOnTop, favoriteOnTop: true, filterLivePhoto: true)
             
             DispatchQueue.main.async { [weak self] in
                 self?.refreshControl.endRefreshing()

+ 18 - 26
iOSClient/Main/Collection Common/NCCollectionViewCommon.swift

@@ -45,15 +45,7 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
     internal var dataSource = NCDataSource()
     internal var richWorkspaceText: String?
         
-    internal var layout = ""
-    internal var sort: String = ""
-    internal var ascending: Bool = true
-    internal var directoryOnTop: Bool = true
-    internal var groupBy = ""
-    internal var titleButtonHeader = ""
-    internal var itemForLine = 0
-    internal var fillBackgroud = ""
-    internal var fillBackgroudContentMode = ""
+    internal var layoutForView: NCGlobal.layoutForViewType?
 
     private var autoUploadFileName = ""
     private var autoUploadDirectory = ""
@@ -601,20 +593,17 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
     
     func setLayout() {
         
-        (layout, sort, ascending, groupBy, directoryOnTop, titleButtonHeader, itemForLine, fillBackgroud, fillBackgroudContentMode) = NCUtility.shared.getLayoutForView(key: layoutKey, serverUrl: serverUrl)
-        gridLayout.itemForLine = CGFloat(itemForLine)
+        layoutForView = NCUtility.shared.getLayoutForView(key: layoutKey, serverUrl: serverUrl)
+        gridLayout.itemForLine = CGFloat(layoutForView?.itemForLine ?? 3)
         
-        if layout == NCGlobal.shared.layoutList {
+        if layoutForView?.layout == NCGlobal.shared.layoutList {
             collectionView?.collectionViewLayout = listLayout
         } else {
             collectionView?.collectionViewLayout = gridLayout
         }
         
-        if fillBackgroud == "" {
-            backgroundImageView.image = nil
-            collectionView.backgroundView = nil
-        } else {
-            let imagePath = CCUtility.getDirectoryGroup().appendingPathComponent(NCGlobal.shared.appBackground).path + "/" + fillBackgroud
+        if layoutForView?.imageBackgroud != "" {
+            let imagePath = CCUtility.getDirectoryGroup().appendingPathComponent(NCGlobal.shared.appBackground).path + "/" + layoutForView!.imageBackgroud
             do {
                 let data = try Data.init(contentsOf: URL(fileURLWithPath: imagePath))
                 if let image = UIImage.init(data: data) {
@@ -623,6 +612,9 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
                     collectionView.backgroundView = backgroundImageView
                 }
             } catch { }
+        } else {
+            backgroundImageView.image = nil
+            collectionView.backgroundView = nil
         }
     }
 
@@ -743,8 +735,8 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
                     self.collectionView.reloadData()
                 })
             })
-            layout = NCGlobal.shared.layoutList
-            NCUtility.shared.setLayoutForView(key: layoutKey, serverUrl: serverUrl, layout: layout)
+            layoutForView?.layout = NCGlobal.shared.layoutList
+            NCUtility.shared.setLayoutForView(key: layoutKey, serverUrl: serverUrl, layout: layoutForView?.layout)
         } else {
             // grid layout
             UIView.animate(withDuration: 0.0, animations: {
@@ -753,8 +745,8 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
                     self.collectionView.reloadData()
                 })
             })
-            layout = NCGlobal.shared.layoutGrid
-            NCUtility.shared.setLayoutForView(key: layoutKey, serverUrl: serverUrl, layout: layout)
+            layoutForView?.layout = NCGlobal.shared.layoutGrid
+            NCUtility.shared.setLayoutForView(key: layoutKey, serverUrl: serverUrl, layout: layoutForView?.layout)
         }
     }
     
@@ -930,7 +922,7 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
         autoUploadDirectory = NCManageDatabase.shared.getAccountAutoUploadDirectory(urlBase: appDelegate.urlBase, account: appDelegate.account)
         
         // get layout for view
-        (layout, sort, ascending, groupBy, directoryOnTop, titleButtonHeader, itemForLine, fillBackgroud, fillBackgroudContentMode) = NCUtility.shared.getLayoutForView(key: layoutKey, serverUrl: serverUrl)
+        layoutForView = NCUtility.shared.getLayoutForView(key: layoutKey, serverUrl: serverUrl)
     }
     @objc func reloadDataSourceNetwork(forced: Bool = false) { }
     @objc func reloadDataSourceNetworkRefreshControl() {
@@ -1270,7 +1262,7 @@ extension NCCollectionViewCommon: UICollectionViewDataSource {
             
             header.delegate = self
             header.setStatusButton(count: dataSource.metadatas.count)
-            header.setTitleSorted(datasourceTitleButton: titleButtonHeader)
+            header.setTitleSorted(datasourceTitleButton: layoutForView?.titleButtonHeader ?? "")
             header.viewRichWorkspaceHeightConstraint.constant = headerRichWorkspaceHeight
             header.setRichWorkspaceText(richWorkspaceText: richWorkspaceText)
 
@@ -1300,7 +1292,7 @@ extension NCCollectionViewCommon: UICollectionViewDataSource {
     func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
                 
         guard let metadata = dataSource.cellForItemAt(indexPath: indexPath) else {
-            if layout == NCGlobal.shared.layoutList {
+            if layoutForView?.layout == NCGlobal.shared.layoutList {
                 return collectionView.dequeueReusableCell(withReuseIdentifier: "listCell", for: indexPath) as! NCListCell
             } else {
                 return collectionView.dequeueReusableCell(withReuseIdentifier: "gridCell", for: indexPath) as! NCGridCell
@@ -1323,7 +1315,7 @@ extension NCCollectionViewCommon: UICollectionViewDataSource {
         //
         // LAYOUT LIST
         //
-        if layout == NCGlobal.shared.layoutList {
+        if layoutForView?.layout == NCGlobal.shared.layoutList {
             
             let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "listCell", for: indexPath) as! NCListCell
             cell.delegate = self
@@ -1523,7 +1515,7 @@ extension NCCollectionViewCommon: UICollectionViewDataSource {
         //
         // LAYOUT GRID
         //
-        if layout == NCGlobal.shared.layoutGrid {
+        if layoutForView?.layout == NCGlobal.shared.layoutGrid {
             
             let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "gridCell", for: indexPath) as! NCGridCell
             cell.delegate = self

+ 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, fillBackgroud: metadata.fileNameView, fillBackgroudContentMode: "")
+                    NCUtility.shared.setBackgroundForView(key: layoutKey, serverUrl: serverUrl, imageBackgroud: metadata.fileNameView, imageBackgroudContentMode: "", colorBackground: "")
                     viewController.setLayout()
                 }
             }

+ 32 - 39
iOSClient/Menu/NCSortMenu.swift

@@ -31,15 +31,6 @@ class NCSortMenu: NSObject {
     private var hideDirectoryOnTop: Bool?
     
     private var key = ""
-    private var layout = ""
-    private var sort = ""
-    private var ascending = true
-    private var groupBy = ""
-    private var directoryOnTop = false
-    private var titleButtonHeader = ""
-    private var itemForLine: Int = 0
-    private var fillBackgroud = ""
-    private var fillBackgroudContentMode = ""
 
     func toggleMenu(viewController: UIViewController, key: String, sortButton: UIButton?, serverUrl: String, hideDirectoryOnTop: Bool = false) {
         
@@ -48,7 +39,7 @@ class NCSortMenu: NSObject {
         self.serverUrl = serverUrl
         self.hideDirectoryOnTop = hideDirectoryOnTop
         
-        (layout, sort, ascending, groupBy, directoryOnTop, titleButtonHeader, itemForLine, fillBackgroud, fillBackgroudContentMode) = NCUtility.shared.getLayoutForView(key: key, serverUrl: serverUrl)
+        var layoutForView = NCUtility.shared.getLayoutForView(key: key, serverUrl: serverUrl)
 
         let menuViewController = UIStoryboard.init(name: "NCMenu", bundle: nil).instantiateInitialViewController() as! NCMenu
         var actions = [NCMenuAction]()
@@ -59,15 +50,15 @@ class NCSortMenu: NSObject {
                 icon: UIImage(named: "sortFileNameAZ")!.image(color: NCBrandColor.shared.gray, size: 50),
                 onTitle: NSLocalizedString("_order_by_name_z_a_", comment: ""),
                 onIcon: UIImage(named: "sortFileNameZA")!.image(color: NCBrandColor.shared.gray, size: 50),
-                selected: self.sort == "fileName",
-                on: self.sort == "fileName",
+                selected: layoutForView.sort == "fileName",
+                on: layoutForView.sort == "fileName",
                 action: { menuAction in
-                    if self.sort == "fileName" {
-                        self.ascending = !self.ascending
+                    if layoutForView.sort == "fileName" {
+                        layoutForView.ascending = !layoutForView.ascending
                     } else {
-                        self.sort = "fileName"
+                        layoutForView.sort = "fileName"
                     }
-                    self.actionMenu()
+                    self.actionMenu(layoutForView: layoutForView)
                 }
             )
         )
@@ -78,15 +69,15 @@ class NCSortMenu: NSObject {
                 icon: UIImage(named: "sortDateMoreRecent")!.image(color: NCBrandColor.shared.gray, size: 50),
                 onTitle: NSLocalizedString("_order_by_date_less_recent_", comment: ""),
                 onIcon: UIImage(named: "sortDateLessRecent")!.image(color: NCBrandColor.shared.gray, size: 50),
-                selected: self.sort == "date",
-                on: self.sort == "date",
+                selected: layoutForView.sort == "date",
+                on: layoutForView.sort == "date",
                 action: { menuAction in
-                    if self.sort == "date" {
-                        self.ascending = !self.ascending
+                    if layoutForView.sort == "date" {
+                        layoutForView.ascending = !layoutForView.ascending
                     } else {
-                        self.sort = "date"
+                        layoutForView.sort = "date"
                     }
-                    self.actionMenu()
+                    self.actionMenu(layoutForView: layoutForView)
                 }
             )
         )
@@ -97,15 +88,15 @@ class NCSortMenu: NSObject {
                 icon: UIImage(named: "sortSmallest")!.image(color: NCBrandColor.shared.gray, size: 50),
                 onTitle: NSLocalizedString("_order_by_size_largest_", comment: ""),
                 onIcon: UIImage(named: "sortLargest")!.image(color: NCBrandColor.shared.gray, size: 50),
-                selected: self.sort == "size",
-                on: self.sort == "size",
+                selected: layoutForView.sort == "size",
+                on: layoutForView.sort == "size",
                 action: { menuAction in
-                    if self.sort == "size" {
-                        self.ascending = !self.ascending
+                    if layoutForView.sort == "size" {
+                        layoutForView.ascending = !layoutForView.ascending
                     } else {
-                        self.sort = "size"
+                        layoutForView.sort = "size"
                     }
-                    self.actionMenu()
+                    self.actionMenu(layoutForView: layoutForView)
                 }
             )
         )
@@ -115,11 +106,11 @@ class NCSortMenu: NSObject {
                 NCMenuAction(
                     title: NSLocalizedString("_directory_on_top_no_", comment: ""),
                     icon: UIImage(named: "foldersOnTop")!.image(color: NCBrandColor.shared.gray, size: 50),
-                    selected: self.directoryOnTop,
-                    on: self.directoryOnTop,
+                    selected: layoutForView.directoryOnTop,
+                    on: layoutForView.directoryOnTop,
                     action: { menuAction in
-                        self.directoryOnTop = !self.directoryOnTop
-                        self.actionMenu()
+                        layoutForView.directoryOnTop = !layoutForView.directoryOnTop
+                        self.actionMenu(layoutForView: layoutForView)
                     }
                 )
             )
@@ -136,22 +127,24 @@ class NCSortMenu: NSObject {
         viewController.present(menuPanelController, animated: true, completion: nil)
     }
     
-    func actionMenu() {
+    func actionMenu(layoutForView: NCGlobal.layoutForViewType) {
                 
-        switch sort {
+        var layoutForView = layoutForView
+        
+        switch layoutForView.sort {
         case "fileName":
-            titleButtonHeader = ascending ? "_sorted_by_name_a_z_" : "_sorted_by_name_z_a_"
+            layoutForView.titleButtonHeader = layoutForView.ascending ? "_sorted_by_name_a_z_" : "_sorted_by_name_z_a_"
         case "date":
-            titleButtonHeader = ascending ? "_sorted_by_date_less_recent_" : "_sorted_by_date_more_recent_"
+            layoutForView.titleButtonHeader = layoutForView.ascending ? "_sorted_by_date_less_recent_" : "_sorted_by_date_more_recent_"
         case "size":
-            titleButtonHeader = ascending ? "_sorted_by_size_smallest_" : "_sorted_by_size_largest_"
+            layoutForView.titleButtonHeader = layoutForView.ascending ? "_sorted_by_size_smallest_" : "_sorted_by_size_largest_"
         default:
             break
         }
         
-        self.sortButton?.setTitle(NSLocalizedString(titleButtonHeader, comment: ""), for: .normal)
+        self.sortButton?.setTitle(NSLocalizedString(layoutForView.titleButtonHeader, comment: ""), for: .normal)
         
-        NCUtility.shared.setLayoutForView(key: key, serverUrl: serverUrl, layout: layout, sort: sort, ascending: ascending, groupBy: groupBy, directoryOnTop: directoryOnTop, titleButtonHeader: titleButtonHeader, itemForLine: itemForLine, fillBackgroud: fillBackgroud, fillBackgroudContentMode: fillBackgroudContentMode)
+        NCUtility.shared.setLayoutForView(key: key, serverUrl: serverUrl, layoutForView: layoutForView)
         
         NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterReloadDataSource, userInfo: ["serverUrl":self.serverUrl])
     }

+ 4 - 2
iOSClient/NCGlobal.swift

@@ -40,14 +40,16 @@ class NCGlobal: NSObject {
     // Struct for LayoutForView
     //
     struct layoutForViewType {
+        var layout: String
         var sort: String
         var ascending: Bool
         var groupBy: String
         var directoryOnTop: Bool
         var titleButtonHeader: String
         var itemForLine: Int
-        var fillBackgroud: String
-        var fillBackgroudContentMode: String
+        var imageBackgroud: String
+        var imageBackgroudContentMode: String
+        var colorBackground: String
     }
     
     // Directory on Group

+ 1 - 1
iOSClient/Offline/NCOffline.swift

@@ -71,7 +71,7 @@ class NCOffline: NCCollectionViewCommon  {
                 }
             }
             
-            self.dataSource = NCDataSource.init(metadatasSource: self.metadatasSource, sort: self.sort, ascending: self.ascending, directoryOnTop: self.directoryOnTop, favoriteOnTop: true, filterLivePhoto: true)
+            self.dataSource = NCDataSource.init(metadatasSource: self.metadatasSource, sort: self.layoutForView?.sort, ascending: self.layoutForView?.ascending, directoryOnTop: self.layoutForView?.directoryOnTop, favoriteOnTop: true, filterLivePhoto: true)
             
             DispatchQueue.main.async {
                 self.refreshControl.endRefreshing()

+ 12 - 20
iOSClient/Select/NCSelect.swift

@@ -70,15 +70,7 @@ class NCSelect: UIViewController, UIGestureRecognizerDelegate, UIAdaptivePresent
     private var dataSource = NCDataSource()
     internal var richWorkspaceText: String?
 
-    private var sort: String = ""
-    private var ascending: Bool = true
-    private var directoryOnTop: Bool = true
-    private var layout = ""
-    private var groupBy = ""
-    private var titleButtonHeader = ""
-    private var itemForLine = 0
-    private var fillBackgroud = ""
-    private var fillBackgroudContentMode = ""
+    private var layoutForView: NCGlobal.layoutForViewType?
 
     private var autoUploadFileName = ""
     private var autoUploadDirectory = ""
@@ -185,10 +177,10 @@ class NCSelect: UIViewController, UIGestureRecognizerDelegate, UIAdaptivePresent
         autoUploadFileName = NCManageDatabase.shared.getAccountAutoUploadFileName()
         autoUploadDirectory = NCManageDatabase.shared.getAccountAutoUploadDirectory(urlBase: activeAccount.urlBase, account: activeAccount.account)
         
-        (layout, sort, ascending, groupBy, directoryOnTop, titleButtonHeader, itemForLine, fillBackgroud, fillBackgroudContentMode) = NCUtility.shared.getLayoutForView(key: keyLayout,serverUrl: serverUrl)
-        gridLayout.itemForLine = CGFloat(itemForLine)
+        layoutForView = NCUtility.shared.getLayoutForView(key: keyLayout,serverUrl: serverUrl)
+        gridLayout.itemForLine = CGFloat(layoutForView?.itemForLine ?? 3)
         
-        if layout == NCGlobal.shared.layoutList {
+        if layoutForView?.layout == NCGlobal.shared.layoutList {
             collectionView.collectionViewLayout = listLayout
         } else {
             collectionView.collectionViewLayout = gridLayout
@@ -297,7 +289,7 @@ class NCSelect: UIViewController, UIGestureRecognizerDelegate, UIAdaptivePresent
                     self.collectionView.reloadData()
                 })
             })
-            layout = NCGlobal.shared.layoutList
+            layoutForView?.layout = NCGlobal.shared.layoutList
         } else {
             // grid layout
             UIView.animate(withDuration: 0.0, animations: {
@@ -306,7 +298,7 @@ class NCSelect: UIViewController, UIGestureRecognizerDelegate, UIAdaptivePresent
                     self.collectionView.reloadData()
                 })
             })
-            layout = NCGlobal.shared.layoutGrid
+            layoutForView?.layout = NCGlobal.shared.layoutGrid
         }
     }
     
@@ -381,7 +373,7 @@ extension NCSelect: UICollectionViewDataSource {
             
             header.delegate = self
             header.setStatusButton(count: dataSource.metadatas.count)
-            header.setTitleSorted(datasourceTitleButton: titleButtonHeader)
+            header.setTitleSorted(datasourceTitleButton: layoutForView?.titleButtonHeader ?? "")
             header.viewRichWorkspaceHeightConstraint.constant = headerRichWorkspaceHeight
             header.setRichWorkspaceText(richWorkspaceText: richWorkspaceText)
             
@@ -412,7 +404,7 @@ extension NCSelect: UICollectionViewDataSource {
     func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
         
         guard let metadata = dataSource.cellForItemAt(indexPath: indexPath) else {
-            if layout == NCGlobal.shared.layoutList {
+            if layoutForView?.layout == NCGlobal.shared.layoutList {
                 return collectionView.dequeueReusableCell(withReuseIdentifier: "listCell", for: indexPath) as! NCListCell
             } else {
                 return collectionView.dequeueReusableCell(withReuseIdentifier: "gridCell", for: indexPath) as! NCGridCell
@@ -435,7 +427,7 @@ extension NCSelect: UICollectionViewDataSource {
         
         // LAYOUT LIST
         
-        if layout == NCGlobal.shared.layoutList {
+        if layoutForView?.layout == NCGlobal.shared.layoutList {
             
             let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "listCell", for: indexPath) as! NCListCell
             cell.delegate = self
@@ -564,7 +556,7 @@ extension NCSelect: UICollectionViewDataSource {
         
         // LAYOUT GRID
         
-        if layout == NCGlobal.shared.layoutGrid {
+        if layoutForView?.layout == NCGlobal.shared.layoutGrid {
             
             let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "gridCell", for: indexPath) as! NCGridCell
             cell.delegate = self
@@ -690,7 +682,7 @@ extension NCSelect {
         
         var predicate: NSPredicate?
         
-        (layout, sort, ascending, groupBy, directoryOnTop, titleButtonHeader, itemForLine, fillBackgroud, fillBackgroudContentMode) = NCUtility.shared.getLayoutForView(key: keyLayout, serverUrl: serverUrl)
+        layoutForView = NCUtility.shared.getLayoutForView(key: keyLayout, serverUrl: serverUrl)
         
         if includeDirectoryE2EEncryption {
             
@@ -710,7 +702,7 @@ extension NCSelect {
         }
         
         let metadatasSource = NCManageDatabase.shared.getMetadatas(predicate: predicate!)
-        self.dataSource = NCDataSource.init(metadatasSource: metadatasSource, sort: sort, ascending: ascending, directoryOnTop: directoryOnTop, favoriteOnTop: true, filterLivePhoto: true)
+        self.dataSource = NCDataSource.init(metadatasSource: metadatasSource, sort: layoutForView?.sort, ascending: layoutForView?.ascending, directoryOnTop: layoutForView?.directoryOnTop, favoriteOnTop: true, filterLivePhoto: true)
         
         if withLoadFolder {
             loadFolder()

+ 1 - 1
iOSClient/Shares/NCShares.swift

@@ -53,7 +53,7 @@ class NCShares: NCCollectionViewCommon  {
                 }
             }
             
-            self.dataSource = NCDataSource.init(metadatasSource: self.metadatasSource, sort:self.sort, ascending: self.ascending, directoryOnTop: self.directoryOnTop, favoriteOnTop: true, filterLivePhoto: true)
+            self.dataSource = NCDataSource.init(metadatasSource: self.metadatasSource, sort: self.layoutForView?.sort, ascending: self.layoutForView?.ascending, directoryOnTop: self.layoutForView?.directoryOnTop, favoriteOnTop: true, filterLivePhoto: true)
             
             DispatchQueue.main.async {
                 self.refreshControl.endRefreshing()

+ 11 - 23
iOSClient/Trash/NCTrash.swift

@@ -39,22 +39,10 @@ class NCTrash: UIViewController, UIGestureRecognizerDelegate, NCTrashListCellDel
     internal var selectOcId: [String] = []
     
     private var datasource: [tableTrash] = []
-    
-    private var sort: String = ""
-    private var ascending: Bool = true
-    private var directoryOnTop: Bool = true
-    private var layout = ""
-    private var groupBy = "none"
-    private var titleButtonHeader = ""
-    private var itemForLine = 0
-    private var fillBackgroud = ""
-    private var fillBackgroudContentMode = ""
-
+    private var layoutForView: NCGlobal.layoutForViewType?
     private var listLayout: NCListLayout!
     private var gridLayout: NCGridLayout!
-    
     private let highHeader: CGFloat = 50
-    
     private let refreshControl = UIRefreshControl()
 
     // MARK: - View Life Cycle
@@ -99,10 +87,10 @@ class NCTrash: UIViewController, UIGestureRecognizerDelegate, NCTrashListCellDel
         
         self.navigationItem.title = titleCurrentFolder
 
-        (layout, sort, ascending, groupBy, directoryOnTop, titleButtonHeader, itemForLine, fillBackgroud, fillBackgroudContentMode) = NCUtility.shared.getLayoutForView(key: NCGlobal.shared.layoutViewTrash, serverUrl: "", sort: "date", ascending: false, titleButtonHeader: "_sorted_by_date_more_recent_")
-        gridLayout.itemForLine = CGFloat(itemForLine)
+        layoutForView = NCUtility.shared.getLayoutForView(key: NCGlobal.shared.layoutViewTrash, serverUrl: "", sort: "date", ascending: false, titleButtonHeader: "_sorted_by_date_more_recent_")
+        gridLayout.itemForLine = CGFloat(layoutForView?.itemForLine ?? 3)
         
-        if layout == NCGlobal.shared.layoutList {
+        if layoutForView?.layout == NCGlobal.shared.layoutList {
             collectionView.collectionViewLayout = listLayout
         } else {
             collectionView.collectionViewLayout = gridLayout
@@ -154,8 +142,8 @@ class NCTrash: UIViewController, UIGestureRecognizerDelegate, NCTrashListCellDel
                     self.collectionView.reloadData()
                 })
             })
-            layout = NCGlobal.shared.layoutList
-            NCUtility.shared.setLayoutForView(key: NCGlobal.shared.layoutViewTrash, serverUrl: "", layout: layout)
+            layoutForView?.layout = NCGlobal.shared.layoutList
+            NCUtility.shared.setLayoutForView(key: NCGlobal.shared.layoutViewTrash, serverUrl: "", layout: layoutForView?.layout)
         } else {
             // grid layout
             UIView.animate(withDuration: 0.0, animations: {
@@ -164,8 +152,8 @@ class NCTrash: UIViewController, UIGestureRecognizerDelegate, NCTrashListCellDel
                     self.collectionView.reloadData()
                 })
             })
-            layout = NCGlobal.shared.layoutGrid
-            NCUtility.shared.setLayoutForView(key: NCGlobal.shared.layoutViewTrash, serverUrl: "", layout: layout)
+            layoutForView?.layout = NCGlobal.shared.layoutGrid
+            NCUtility.shared.setLayoutForView(key: NCGlobal.shared.layoutViewTrash, serverUrl: "", layout: layoutForView?.layout)
         }
     }
     
@@ -268,7 +256,7 @@ extension NCTrash: UICollectionViewDataSource {
             trashHeader.backgroundColor = NCBrandColor.shared.systemBackground
             trashHeader.separator.backgroundColor = NCBrandColor.shared.separator
             trashHeader.setStatusButton(datasource: datasource)
-            trashHeader.setTitleSorted(datasourceTitleButton: titleButtonHeader)
+            trashHeader.setTitleSorted(datasourceTitleButton: layoutForView?.titleButtonHeader ?? "")
             
             return trashHeader
             
@@ -392,11 +380,11 @@ extension NCTrash {
 
     @objc func reloadDataSource() {
         
-        (layout, sort, ascending, groupBy, directoryOnTop, titleButtonHeader, itemForLine, fillBackgroud, fillBackgroudContentMode) = NCUtility.shared.getLayoutForView(key: NCGlobal.shared.layoutViewTrash, serverUrl: "")
+        layoutForView = NCUtility.shared.getLayoutForView(key: NCGlobal.shared.layoutViewTrash, serverUrl: "")
         
         datasource.removeAll()
         
-        guard let tashItems = NCManageDatabase.shared.getTrash(filePath: trashPath, sort: sort, ascending: ascending, account: appDelegate.account) else {
+        guard let tashItems = NCManageDatabase.shared.getTrash(filePath: trashPath, sort: layoutForView?.sort, ascending: layoutForView?.ascending, account: appDelegate.account) else {
             return
         }
         

+ 31 - 53
iOSClient/Utility/NCUtility.swift

@@ -34,13 +34,13 @@ class NCUtility: NSObject {
         return instance
     }()
     
-    private var activityIndicator: UIActivityIndicatorView? // = UIActivityIndicatorView(style: .whiteLarge)
+    private var activityIndicator: UIActivityIndicatorView?
     private var viewActivityIndicator: UIView?
     private var viewBackgroundActivityIndicator: UIView?
 
-    func setLayoutForView(key: String, serverUrl: String, layout: String, object: NCGlobal.layoutForViewType) {
+    func setLayoutForView(key: String, serverUrl: String, layoutForView: NCGlobal.layoutForViewType) {
         
-        let string =  layout + "|" + object.sort + "|" + "\(object.ascending)" + "|" + object.groupBy + "|" + "\(object.directoryOnTop)" + "|" + object.titleButtonHeader + "|" + "\(object.itemForLine)" + "|" + object.fillBackgroud + "|" + object.fillBackgroudContentMode
+        let string =  layoutForView.layout + "|" + layoutForView.sort + "|" + "\(layoutForView.ascending)" + "|" + layoutForView.groupBy + "|" + "\(layoutForView.directoryOnTop)" + "|" + layoutForView.titleButtonHeader + "|" + "\(layoutForView.itemForLine)" + "|" + layoutForView.imageBackgroud + "|" + layoutForView.imageBackgroudContentMode + "|" + layoutForView.colorBackground
         var keyStore = key
         
         if serverUrl != "" {
@@ -50,81 +50,59 @@ class NCUtility: NSObject {
         UICKeyChainStore.setString(string, forKey: keyStore, service: NCGlobal.shared.serviceShareKeyChain)
     }
     
-    func setLayoutForView(key: String, serverUrl: String, layout: String, sort: String, ascending: Bool, groupBy: String, directoryOnTop: Bool, titleButtonHeader: String, itemForLine: Int, fillBackgroud: String, fillBackgroudContentMode: String) {
+    func setLayoutForView(key: String, serverUrl: String, layout: String?) {
         
-        let string =  layout + "|" + sort + "|" + "\(ascending)" + "|" + groupBy + "|" + "\(directoryOnTop)" + "|" + titleButtonHeader + "|" + "\(itemForLine)" + "|" + fillBackgroud + "|" + fillBackgroudContentMode
-        var keyStore = key
+        var layoutForView: NCGlobal.layoutForViewType = NCUtility.shared.getLayoutForView(key: key, serverUrl: serverUrl)
         
-        if serverUrl != "" {
-            keyStore = serverUrl
+        if let layout = layout {
+            layoutForView.layout = layout
+            setLayoutForView(key: key, serverUrl: serverUrl, layoutForView: layoutForView)
         }
-        
-        UICKeyChainStore.setString(string, forKey: keyStore, service: NCGlobal.shared.serviceShareKeyChain)
-    }
-    
-    func setLayoutForView(key: String, serverUrl: String, layout: String) {
-        
-        var sort: String
-        var ascending: Bool
-        var groupBy: String
-        var directoryOnTop: Bool
-        var titleButtonHeader: String
-        var itemForLine: Int
-        var fillBackgroud: String
-        var fillBackgroudContentMode: String
-
-        (_, sort, ascending, groupBy, directoryOnTop, titleButtonHeader, itemForLine, fillBackgroud, fillBackgroudContentMode) = 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 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
+    func setBackgroundForView(key: String, serverUrl: String, imageBackgroud: String, imageBackgroudContentMode: String, colorBackground: String) {
+        
+        var layoutForView: NCGlobal.layoutForViewType = NCUtility.shared.getLayoutForView(key: key, serverUrl: serverUrl)
         
-        (layout, sort, ascending, groupBy, directoryOnTop, titleButtonHeader, itemForLine, _, _) = NCUtility.shared.getLayoutForView(key: key, serverUrl: serverUrl)
+        layoutForView.imageBackgroud = imageBackgroud
+        layoutForView.imageBackgroudContentMode = imageBackgroudContentMode
+        layoutForView.colorBackground = colorBackground
         
-        setLayoutForView(key: key, serverUrl: serverUrl, layout: layout, sort: sort, ascending: ascending, groupBy: groupBy, directoryOnTop: directoryOnTop, titleButtonHeader: titleButtonHeader, itemForLine: itemForLine, fillBackgroud: fillBackgroud, fillBackgroudContentMode: fillBackgroudContentMode)
+        setLayoutForView(key: key, serverUrl: serverUrl, layoutForView: layoutForView)
     }
     
-    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) {
+    func getLayoutForView(key: String, serverUrl: String, sort: String = "fileName", ascending: Bool = true, titleButtonHeader: String = "_sorted_by_name_a_z_") -> (NCGlobal.layoutForViewType) {
         
         var keyStore = key
+        var layoutForView: NCGlobal.layoutForViewType = NCGlobal.layoutForViewType(layout: NCGlobal.shared.layoutList, sort: sort, ascending: ascending, groupBy: "none", directoryOnTop: true, titleButtonHeader: titleButtonHeader, itemForLine: 3, imageBackgroud: "", imageBackgroudContentMode: "", colorBackground: "")
         
         if serverUrl != "" {
             keyStore = serverUrl
         }
         
         guard let string = UICKeyChainStore.string(forKey: keyStore, service: NCGlobal.shared.serviceShareKeyChain) else {
-            setLayoutForView(key: key, serverUrl: serverUrl, layout: NCGlobal.shared.layoutList, sort: sort, ascending: ascending, groupBy: "none", directoryOnTop: true, titleButtonHeader: titleButtonHeader, itemForLine: 3, fillBackgroud: "", fillBackgroudContentMode: "")
-            return (NCGlobal.shared.layoutList, sort, ascending, "none", true, titleButtonHeader, 3, "", "")
+            setLayoutForView(key: key, serverUrl: serverUrl, layoutForView: layoutForView)
+            return layoutForView
         }
 
         let array = string.components(separatedBy: "|")
         if array.count >= 7 {
-            let sort = NSString(string: array[2])
-            let directoryOnTop = NSString(string: array[4])
-            let itemForLine = NSString(string: array[6])
-            var fillBackgroud: String = ""
-            var fillBackgroudContentMode: String = ""
-            
+            layoutForView.layout = array[0]
+            layoutForView.sort = array[1]
+            layoutForView.ascending = NSString(string: array[2]).boolValue
+            layoutForView.groupBy = array[3]
+            layoutForView.directoryOnTop = NSString(string: array[4]).boolValue
+            layoutForView.titleButtonHeader = array[5]
+            layoutForView.itemForLine = Int(NSString(string: array[6]).intValue)
+                       
             if array.count > 8 {
-                fillBackgroud = array[7]
-                fillBackgroudContentMode = array[8]
+                layoutForView.imageBackgroud = array[7]
+                layoutForView.imageBackgroudContentMode = array[8]
+                layoutForView.colorBackground = array[9]
             }
-
-            return (array[0], array[1], sort.boolValue, array[3], directoryOnTop.boolValue, array[5], Int(itemForLine.intValue), fillBackgroud, fillBackgroudContentMode)
         }
         
-        setLayoutForView(key: key, serverUrl: serverUrl, layout: NCGlobal.shared.layoutList, sort: sort, ascending: ascending, groupBy: "none", directoryOnTop: true, titleButtonHeader: titleButtonHeader, itemForLine: 3, fillBackgroud: "", fillBackgroudContentMode: "")
-        
-        return (NCGlobal.shared.layoutList, sort, ascending, "none", true, titleButtonHeader, 3, "", "")
+        return layoutForView
     }
         
     func convertSVGtoPNGWriteToUserData(svgUrlString: String, fileName: String?, width: CGFloat?, rewrite: Bool, account: String, closure: @escaping (String?) -> ()) {