Skip to content

Commit

Permalink
Add flag for section / reduce complexity of sections
Browse files Browse the repository at this point in the history
Signed-off-by: Milen Pivchev <milen.pivchev@gmail.com>
  • Loading branch information
mpivchev committed Jul 25, 2023
1 parent 2afb8bc commit 756367e
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 94 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ extension UINavigationController {
navigationBar.scrollEdgeAppearance = scrollEdgeAppearance
}

func setGroupeAppreance() {
func setGroupAppearance() {

navigationBar.tintColor = .systemBlue

Expand Down
2 changes: 1 addition & 1 deletion iOSClient/More/NCMore.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -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">
Expand Down
154 changes: 63 additions & 91 deletions iOSClient/More/NCMore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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()
Expand All @@ -91,18 +103,13 @@ class NCMore: UIViewController, UITableViewDelegate, UITableViewDataSource {
var quota: String = ""

// Clear
moreAppsMenu.removeAll()
functionMenu.removeAll()
externalSiteMenu.removeAll()
settingsMenu.removeAll()
quotaMenu.removeAll()
labelQuotaExternalSite.text = ""
progressQuota.progressTintColor = NCBrandColor.shared.brandElement

// ITEM : More apps
item = NKExternalSite()
moreAppsMenu.append(item)

// ITEM : Transfer
item = NKExternalSite()
item.name = "_transfers_"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -263,55 +294,37 @@ 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
}
}

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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -400,67 +402,37 @@ 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
browserWebVC.titleBrowser = item.name

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)

Expand Down
3 changes: 2 additions & 1 deletion iOSClient/NCGlobal.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 756367e

Please sign in to comment.