Browse Source

Add flag for section / reduce complexity of sections

Signed-off-by: Milen Pivchev <milen.pivchev@gmail.com>
Milen Pivchev 1 year ago
parent
commit
50f06b37a8

+ 3 - 3
Nextcloud.xcodeproj/project.pbxproj

@@ -818,8 +818,8 @@
 		F33AAF992A60394C006ECCBD /* NCMoreUserCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = NCMoreUserCell.xib; sourceTree = "<group>"; };
 		F343A4B22A1E01FF00DDA874 /* PHAsset+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "PHAsset+Extension.swift"; sourceTree = "<group>"; };
 		F343A4BA2A1E734600DDA874 /* Optional+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Optional+Extension.swift"; sourceTree = "<group>"; };
-		F3953BD62A6E87E000EE03F9 /* BaseIntegrationXCTestCase.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BaseIntegrationXCTestCase.swift; sourceTree = "<group>"; };
 		F39298962A3B12CB00509762 /* BaseNCMoreCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BaseNCMoreCell.swift; sourceTree = "<group>"; };
+		F3953BD62A6E87E000EE03F9 /* BaseIntegrationXCTestCase.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BaseIntegrationXCTestCase.swift; sourceTree = "<group>"; };
 		F3A7AFC52A41AA82001FC89C /* BaseUIXCTestCase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BaseUIXCTestCase.swift; sourceTree = "<group>"; };
 		F3BB464C2A39ADCC00461F6E /* NCMoreAppSuggestionsCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = NCMoreAppSuggestionsCell.xib; sourceTree = "<group>"; };
 		F3BB464E2A39EBE500461F6E /* NCMoreUserCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCMoreUserCell.swift; sourceTree = "<group>"; };
@@ -4979,8 +4979,8 @@
 			isa = XCRemoteSwiftPackageReference;
 			repositoryURL = "https://github.com/nextcloud/NextcloudKit";
 			requirement = {
-				branch = "2521-external-share-with-email-2-mails-sent-instead-of-1";
-				kind = branch;
+				kind = exactVersion;
+				version = 2.7.0;
 			};
 		};
 		F788ECC5263AAAF900ADC67F /* XCRemoteSwiftPackageReference "MarkdownKit" */ = {

+ 1 - 1
iOSClient/Extensions/UINavigationController+Extension.swift

@@ -51,7 +51,7 @@ extension UINavigationController {
         navigationBar.scrollEdgeAppearance = scrollEdgeAppearance
     }
 
-    func setGroupeAppreance() {
+    func setGroupAppearance() {
 
         navigationBar.tintColor = .systemBlue
 

+ 1 - 1
iOSClient/More/NCMore.storyboard

@@ -22,7 +22,7 @@
                                 <color key="backgroundColor" systemColor="systemBackgroundColor"/>
                                 <inset key="separatorInset" minX="56" minY="0.0" maxX="0.0" maxY="0.0"/>
                                 <prototypes>
-                                    <tableViewCell contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" reuseIdentifier="Cell" rowHeight="50" id="qwS-lS-XzK" customClass="CCCellMore" customModule="Nextcloud" customModuleProvider="target">
+                                    <tableViewCell contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" reuseIdentifier="CCCellMore" rowHeight="50" id="qwS-lS-XzK" customClass="CCCellMore" customModule="Nextcloud" customModuleProvider="target">
                                         <rect key="frame" x="0.0" y="55.5" width="414" height="50"/>
                                         <autoresizingMask key="autoresizingMask"/>
                                         <tableViewCellContentView key="contentView" multipleTouchEnabled="YES" contentMode="center" tableViewCell="qwS-lS-XzK" id="1FG-Yi-cbC">

+ 63 - 91
iOSClient/More/NCMore.swift

@@ -32,16 +32,28 @@ class NCMore: UIViewController, UITableViewDelegate, UITableViewDataSource {
     @IBOutlet weak var progressQuota: UIProgressView!
     @IBOutlet weak var viewQuota: UIView!
 
-    var moreAppsMenu: [NKExternalSite] = []
-    var functionMenu: [NKExternalSite] = []
-    var externalSiteMenu: [NKExternalSite] = []
-    var settingsMenu: [NKExternalSite] = []
-    var quotaMenu: [NKExternalSite] = []
-
-    let appDelegate = UIApplication.shared.delegate as! AppDelegate
-    let applicationHandle = NCApplicationHandle()
-    
-    var tabAccount: tableAccount?
+    private var functionMenu: [NKExternalSite] = []
+    private var externalSiteMenu: [NKExternalSite] = []
+    private var settingsMenu: [NKExternalSite] = []
+    private var quotaMenu: [NKExternalSite] = []
+
+    private let appDelegate = UIApplication.shared.delegate as! AppDelegate
+    private let applicationHandle = NCApplicationHandle()
+
+    private var tabAccount: tableAccount?
+
+    private struct Section {
+        var items: [NKExternalSite]
+        var type: SectionType
+
+        enum SectionType {
+            case account
+            case moreApps
+            case regular
+        }
+    }
+
+    private var sections: [Section] = []
 
     // MARK: - View Life Cycle
 
@@ -70,7 +82,7 @@ class NCMore: UIViewController, UITableViewDelegate, UITableViewDataSource {
     override func viewWillAppear(_ animated: Bool) {
         super.viewWillAppear(animated)
 
-        navigationController?.setGroupeAppreance()
+        navigationController?.setGroupAppearance()
         
         appDelegate.activeViewController = self
         loadItems()
@@ -91,7 +103,6 @@ class NCMore: UIViewController, UITableViewDelegate, UITableViewDataSource {
         var quota: String = ""
 
         // Clear
-        moreAppsMenu.removeAll()
         functionMenu.removeAll()
         externalSiteMenu.removeAll()
         settingsMenu.removeAll()
@@ -99,10 +110,6 @@ class NCMore: UIViewController, UITableViewDelegate, UITableViewDataSource {
         labelQuotaExternalSite.text = ""
         progressQuota.progressTintColor = NCBrandColor.shared.brandElement
 
-        // ITEM : More apps
-        item = NKExternalSite()
-        moreAppsMenu.append(item)
-
         // ITEM : Transfer
         item = NKExternalSite()
         item.name = "_transfers_"
@@ -235,6 +242,30 @@ class NCMore: UIViewController, UITableViewDelegate, UITableViewDataSource {
                 }
             }
         }
+
+        loadSections()
+    }
+
+    private func loadSections() {
+        if tabAccount != nil {
+            sections.append(Section(items: [NKExternalSite()], type: .account))
+        }
+
+        if NCGlobal.shared.showMoreAppsSection {
+            sections.append(Section(items: [NKExternalSite()], type: .moreApps))
+        }
+
+        if !functionMenu.isEmpty {
+            sections.append(Section(items: functionMenu, type: .regular))
+        }
+
+        if !externalSiteMenu.isEmpty {
+            sections.append(Section(items: externalSiteMenu, type: .regular))
+        }
+
+        if !settingsMenu.isEmpty {
+            sections.append(Section(items: settingsMenu, type: .regular))
+        }
     }
 
     // MARK: - Action
@@ -263,7 +294,7 @@ class NCMore: UIViewController, UITableViewDelegate, UITableViewDataSource {
     // MARK: -
 
     func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
-        if indexPath.section == 0 {
+        if sections[indexPath.section].type == .account {
             return 75
         } else {
             return NCGlobal.shared.heightCellSettings
@@ -271,47 +302,29 @@ class NCMore: UIViewController, UITableViewDelegate, UITableViewDataSource {
     }
 
     func numberOfSections(in tableView: UITableView) -> Int {
-        if externalSiteMenu.isEmpty {
-            return 4
-        } else {
-            return 5
-        }
+        return sections.count
     }
     
-    func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
-        if section == 0 {
+    func tableView(_ tableView: UITableView, heightForHeaderInSection index: Int) -> CGFloat {
+        let section = sections[index]
+
+        if section.type == .account {
             return 10
-        } else if section == 1 || section == 2 {
+        } else if section.type == .moreApps || sections[index - 1].type == .moreApps {
             return 1
         } else {
             return 20
         }
     }
 
-    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
-        var cont = 0
-        
-        if section == 0 {
-            cont = tabAccount == nil ? 0 : 1
-        } else if section == 1 {
-            // Menu Normal
-            cont = moreAppsMenu.count
-        } else if section == 2 {
-            cont = functionMenu.count
-        } else if section == 3 {
-            cont = numberOfSections(in: tableView) == 4 ? settingsMenu.count : externalSiteMenu.count
-        } else if section == 4 {
-            cont = settingsMenu.count
-        }
-
-        return cont
+    func tableView(_ tableView: UITableView, numberOfRowsInSection index: Int) -> Int {
+        return sections[index].items.count
     }
 
     func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
+        let section = sections[indexPath.section]
 
-        var item = NKExternalSite()
-
-        if indexPath.section == 0 {
+        if section.type == .account {
 
             let cell = tableView.dequeueReusableCell(withIdentifier: NCMoreUserCell.reuseIdentifier, for: indexPath) as! NCMoreUserCell
 
@@ -349,25 +362,14 @@ class NCMore: UIViewController, UITableViewDelegate, UITableViewDataSource {
 
             return cell
 
-        } else if indexPath.section == 1 {
+        } else if section.type == .moreApps {
             let cell = tableView.dequeueReusableCell(withIdentifier: NCMoreAppSuggestionsCell.reuseIdentifier, for: indexPath) as! NCMoreAppSuggestionsCell
 
             return cell
         } else {
-            let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as! CCCellMore
+            let cell = tableView.dequeueReusableCell(withIdentifier: CCCellMore.reuseIdentifier, for: indexPath) as! CCCellMore
 
-            // Menu Normal
-            if indexPath.section == 2 {
-                item = functionMenu[indexPath.row]
-            }
-            // Menu External Site
-            if numberOfSections(in: tableView) == 5 && indexPath.section == 3 {
-                item = externalSiteMenu[indexPath.row]
-            }
-            // Menu Settings
-            if (numberOfSections(in: tableView) == 4 && indexPath.section == 3) || (numberOfSections(in: tableView) == 5 && indexPath.section == 4) {
-                item = settingsMenu[indexPath.row]
-            }
+            let item = sections[indexPath.section].items[indexPath.row]
 
             cell.imageIcon?.image = NCUtility.shared.loadImage(named: item.icon)
             cell.imageIcon?.contentMode = .scaleAspectFit
@@ -400,53 +402,26 @@ class NCMore: UIViewController, UITableViewDelegate, UITableViewDataSource {
         }
     }
 
-    // method to run when table view cell is tapped
     func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
-
-        var item = NKExternalSite()
+        let item = sections[indexPath.section].items[indexPath.row]
 
         // Menu Function
-        if indexPath.section == 0 {
+        if sections[indexPath.section].type == .account {
             tapImageLogoManageAccount()
             return
         }
 
-        // Menu More Apps
-        if indexPath.section == 1 {
-            item = moreAppsMenu[indexPath.row]
-        }
-
-        // Menu Function
-        if indexPath.section == 2 {
-            item = functionMenu[indexPath.row]
-        }
-
-        // Menu External Site
-        if numberOfSections(in: tableView) == 5 && indexPath.section == 3 {
-            item = externalSiteMenu[indexPath.row]
-        }
-
-        // Menu Settings
-        if (numberOfSections(in: tableView) == 4 && indexPath.section == 3) || (numberOfSections(in: tableView) == 5 && indexPath.section == 4) {
-            item = settingsMenu[indexPath.row]
-        }
-
         // Action
         if item.url.contains("segue") && !item.url.contains("//") {
-
             self.navigationController?.performSegue(withIdentifier: item.url, sender: self)
-
         } else if item.url.contains("openStoryboard") && !item.url.contains("//") {
-
             let nameStoryboard = item.url.replacingOccurrences(of: "openStoryboard", with: "")
             let storyboard = UIStoryboard(name: nameStoryboard, bundle: nil)
             if let controller = storyboard.instantiateInitialViewController() {
                 controller.modalPresentationStyle = UIModalPresentationStyle.pageSheet
                 present(controller, animated: true, completion: nil)
             }
-
         } else if item.url.contains("//") {
-
             let browserWebVC = UIStoryboard(name: "NCBrowserWeb", bundle: nil).instantiateInitialViewController() as! NCBrowserWeb
             browserWebVC.urlBase = item.url
             browserWebVC.isHiddenButtonExit = true
@@ -454,13 +429,10 @@ class NCMore: UIViewController, UITableViewDelegate, UITableViewDataSource {
 
             self.navigationController?.pushViewController(browserWebVC, animated: true)
             self.navigationController?.navigationBar.isHidden = false
-
         } else if item.url == "logout" {
-
             let alertController = UIAlertController(title: "", message: NSLocalizedString("_want_delete_", comment: ""), preferredStyle: .alert)
 
             let actionYes = UIAlertAction(title: NSLocalizedString("_yes_delete_", comment: ""), style: .default) { (_: UIAlertAction) in
-
                 let manageAccount = CCManageAccount()
                 manageAccount.delete(self.appDelegate.account)
 

+ 2 - 1
iOSClient/NCGlobal.swift

@@ -448,12 +448,13 @@ class NCGlobal: NSObject {
     var capabilityExternalSites: Bool                           = false
     var capabilityGroupfoldersEnabled: Bool                     = false // NC27
 
-    // MORE APPS
+    // MORE NEXTCLOUD APPS
     let talkSchemeUrl                                           = "nextcloudtalk://"
     let notesSchemeUrl                                          = "nextcloudnotes://"
     let talkAppStoreUrl                                         = "https://apps.apple.com/de/app/nextcloud-talk/id1296825574"
     let notesAppStoreUrl                                        = "https://apps.apple.com/de/app/nextcloud-notes/id813973264"
     let moreAppsUrl                                             = "https://www.apple.com/us/search/nextcloud?src=globalnav"
+    var showMoreAppsSection                                     = false
 
     // SNAPSHOT PREVIEW
     let defaultSnapshotConfiguration                            = "DefaultPreviewConfiguration"