|
@@ -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)
|
|
|
|