123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453 |
- import UIKit
- import NextcloudKit
- class NCMore: UIViewController, UITableViewDelegate, UITableViewDataSource {
- @IBOutlet weak var tableView: UITableView!
- @IBOutlet weak var labelQuota: UILabel!
- @IBOutlet weak var labelQuotaExternalSite: UILabel!
- @IBOutlet weak var progressQuota: UIProgressView!
- @IBOutlet weak var viewQuota: UIView!
- 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] = []
-
- override func viewDidLoad() {
- super.viewDidLoad()
- self.navigationItem.title = NSLocalizedString("_more_", comment: "")
- view.backgroundColor = .systemGroupedBackground
- tableView.insetsContentViewsToSafeArea = false
- tableView.delegate = self
- tableView.dataSource = self
- tableView.backgroundColor = .systemGroupedBackground
- tableView.register(NCMoreUserCell.fromNib(), forCellReuseIdentifier: NCMoreUserCell.reuseIdentifier)
- tableView.register(NCMoreAppSuggestionsCell.fromNib(), forCellReuseIdentifier: NCMoreAppSuggestionsCell.reuseIdentifier)
-
- let tapQuota = UITapGestureRecognizer(target: self, action: #selector(tapLabelQuotaExternalSite))
- labelQuotaExternalSite.isUserInteractionEnabled = true
- labelQuotaExternalSite.addGestureRecognizer(tapQuota)
-
- NotificationCenter.default.addObserver(self, selector: #selector(initialize), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterInitialize), object: nil)
- }
- override func viewWillAppear(_ animated: Bool) {
- super.viewWillAppear(animated)
- navigationController?.setGroupAppearance()
-
- appDelegate.activeViewController = self
- loadItems()
- tableView.reloadData()
- }
-
- @objc func initialize() {
- loadItems()
- }
-
- func loadItems() {
- var item = NKExternalSite()
- var quota: String = ""
-
- functionMenu.removeAll()
- externalSiteMenu.removeAll()
- settingsMenu.removeAll()
- quotaMenu.removeAll()
- labelQuotaExternalSite.text = ""
- progressQuota.progressTintColor = NCBrandColor.shared.brandElement
-
- item = NKExternalSite()
- item.name = "_transfers_"
- item.icon = "arrow.left.arrow.right"
- item.url = "segueTransfers"
- item.order = 10
- functionMenu.append(item)
-
- item = NKExternalSite()
- item.name = "_recent_"
- item.icon = "clock.arrow.circlepath"
- item.url = "segueRecent"
- item.order = 20
- functionMenu.append(item)
-
- item = NKExternalSite()
- item.name = "_activity_"
- item.icon = "bolt"
- item.url = "segueActivity"
- item.order = 40
- functionMenu.append(item)
-
- if NCGlobal.shared.capabilityFileSharingApiEnabled {
- item = NKExternalSite()
- item.name = "_list_shares_"
- item.icon = "share"
- item.url = "segueShares"
- item.order = 50
- functionMenu.append(item)
- }
-
- item = NKExternalSite()
- item.name = "_manage_file_offline_"
- item.icon = "tray.and.arrow.down"
- item.url = "segueOffline"
- item.order = 60
- functionMenu.append(item)
-
- if NCGlobal.shared.capabilityGroupfoldersEnabled {
- item = NKExternalSite()
- item.name = "_group_folders_"
- item.icon = "person.2"
- item.url = "segueGroupfolders"
- item.order = 61
- functionMenu.append(item)
- }
-
- item = NKExternalSite()
- item.name = "_scanned_images_"
- item.icon = "doc.text.viewfinder"
- item.url = "openStoryboardNCScan"
- item.order = 70
- functionMenu.append(item)
-
- if NCGlobal.shared.capabilityServerVersionMajor >= NCGlobal.shared.nextcloudVersion15 {
- item = NKExternalSite()
- item.name = "_trash_view_"
- item.icon = "trash"
- item.url = "segueTrash"
- item.order = 80
- functionMenu.append(item)
- }
-
- applicationHandle.loadItems(functionMenu: &functionMenu)
-
- functionMenu = functionMenu.sorted(by: { $0.order < $1.order })
-
- item = NKExternalSite()
- item.name = "_settings_"
- item.icon = "gear"
- item.url = "segueSettings"
- settingsMenu.append(item)
- if quotaMenu.count > 0 {
- let item = quotaMenu[0]
- labelQuotaExternalSite.text = item.name
- }
-
- if let activeAccount = NCManageDatabase.shared.getActiveAccount() {
- self.tabAccount = activeAccount
- if activeAccount.quotaRelative > 0 {
- progressQuota.progress = Float(activeAccount.quotaRelative) / 100
- } else {
- progressQuota.progress = 0
- }
- switch activeAccount.quotaTotal {
- case -1:
- quota = "0"
- case -2:
- quota = NSLocalizedString("_quota_space_unknown_", comment: "")
- case -3:
- quota = NSLocalizedString("_quota_space_unlimited_", comment: "")
- default:
- quota = CCUtility.transformedSize(activeAccount.quotaTotal)
- }
- let quotaUsed: String = CCUtility.transformedSize(activeAccount.quotaUsed)
- labelQuota.text = String.localizedStringWithFormat(NSLocalizedString("_quota_using_", comment: ""), quotaUsed, quota)
- }
-
- if NCBrandOptions.shared.disable_more_external_site == false {
- if let externalSites = NCManageDatabase.shared.getAllExternalSites(account: appDelegate.account) {
- for externalSite in externalSites {
- if (externalSite.name != "" && externalSite.url != ""), let urlEncoded = externalSite.url.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed) {
- item = NKExternalSite()
- item.name = externalSite.name
- item.url = urlEncoded
- item.icon = "network"
- if externalSite.type == "settings" {
- item.icon = "gear"
- }
- externalSiteMenu.append(item)
- }
- }
- }
- }
- loadSections()
- }
- private func loadSections() {
- if tabAccount != nil {
- sections.append(Section(items: [NKExternalSite()], type: .account))
- }
- if !NCBrandOptions.shared.disable_show_more_nextcloud_apps_in_settings {
- 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))
- }
- }
-
- @objc func tapLabelQuotaExternalSite() {
- if quotaMenu.count > 0 {
- let item = quotaMenu[0]
- let browserWebVC = UIStoryboard(name: "NCBrowserWeb", bundle: nil).instantiateInitialViewController() as! NCBrowserWeb
- browserWebVC.urlBase = item.url
- browserWebVC.isHiddenButtonExit = true
- self.navigationController?.pushViewController(browserWebVC, animated: true)
- self.navigationController?.navigationBar.isHidden = false
- }
- }
- @objc func tapImageLogoManageAccount() {
- let controller = CCManageAccount()
- self.navigationController?.pushViewController(controller, animated: true)
- }
-
- func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
- if sections[indexPath.section].type == .account {
- return 75
- } else {
- return NCGlobal.shared.heightCellSettings
- }
- }
- func numberOfSections(in tableView: UITableView) -> Int {
- return sections.count
- }
-
- func tableView(_ tableView: UITableView, heightForHeaderInSection index: Int) -> CGFloat {
- let section = sections[index]
- if section.type == .account {
- return 10
- } else if section.type == .moreApps || sections[index - 1].type == .moreApps {
- return 1
- } else {
- return 20
- }
- }
- 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]
- if section.type == .account {
- let cell = tableView.dequeueReusableCell(withIdentifier: NCMoreUserCell.reuseIdentifier, for: indexPath) as! NCMoreUserCell
- cell.avatar.image = nil
- cell.icon.image = nil
- cell.status.text = ""
- cell.displayName.text = ""
- if let account = tabAccount {
- cell.avatar.image = NCUtility.shared.loadUserImage(for: account.user, displayName: account.displayName, userBaseUrl: appDelegate)
- if account.alias == "" {
- cell.displayName?.text = account.displayName
- } else {
- cell.displayName?.text = account.displayName + " (" + account.alias + ")"
- }
- cell.displayName.textColor = .label
- }
- cell.accessoryType = UITableViewCell.AccessoryType.disclosureIndicator
- if NCGlobal.shared.capabilityUserStatusEnabled, let account = NCManageDatabase.shared.getAccount(predicate: NSPredicate(format: "account == %@", appDelegate.account)) {
- let status = NCUtility.shared.getUserStatus(userIcon: account.userStatusIcon, userStatus: account.userStatusStatus, userMessage: account.userStatusMessage)
- cell.icon.image = status.onlineStatus
- cell.status.text = status.statusMessage
- cell.status.textColor = .label
- cell.status.trailingBuffer = cell.status.frame.width
- if cell.status.labelShouldScroll() {
- cell.status.tapToScroll = true
- } else {
- cell.status.tapToScroll = false
- }
- }
-
- cell.layer.maskedCorners = [.layerMaxXMinYCorner, .layerMinXMinYCorner, .layerMaxXMaxYCorner, .layerMinXMaxYCorner]
- return cell
- } else if section.type == .moreApps {
- let cell = tableView.dequeueReusableCell(withIdentifier: NCMoreAppSuggestionsCell.reuseIdentifier, for: indexPath) as! NCMoreAppSuggestionsCell
- return cell
- } else {
- let cell = tableView.dequeueReusableCell(withIdentifier: CCCellMore.reuseIdentifier, for: indexPath) as! CCCellMore
- let item = sections[indexPath.section].items[indexPath.row]
- cell.imageIcon?.image = NCUtility.shared.loadImage(named: item.icon)
- cell.imageIcon?.contentMode = .scaleAspectFit
- cell.labelText?.text = NSLocalizedString(item.name, comment: "")
- cell.labelText.textColor = .label
- cell.accessoryType = UITableViewCell.AccessoryType.disclosureIndicator
- cell.separator.backgroundColor = .separator
- cell.separatorHeigth.constant = 0.4
- cell.removeCornerRadius()
- let rows = tableView.numberOfRows(inSection: indexPath.section)
-
- if indexPath.row == 0 {
- cell.applyCornerRadius()
- if indexPath.row == rows - 1 {
- cell.separator.backgroundColor = .clear
- cell.layer.maskedCorners = [.layerMaxXMinYCorner, .layerMinXMinYCorner, .layerMaxXMaxYCorner, .layerMinXMaxYCorner]
- } else {
- cell.layer.maskedCorners = [.layerMaxXMinYCorner, .layerMinXMinYCorner]
- }
- } else if indexPath.row == rows - 1 {
- cell.applyCornerRadius()
- cell.layer.maskedCorners = [.layerMaxXMaxYCorner, .layerMinXMaxYCorner]
- cell.separator.backgroundColor = .clear
- }
- return cell
- }
- }
- func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
- let item = sections[indexPath.section].items[indexPath.row]
-
- if sections[indexPath.section].type == .account {
- tapImageLogoManageAccount()
- return
- }
-
- 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)
- self.appDelegate.openLogin(viewController: self, selector: NCGlobal.shared.introLogin, openLoginWeb: false)
- }
- let actionNo = UIAlertAction(title: NSLocalizedString("_no_delete_", comment: ""), style: .default) { (_: UIAlertAction) in
- print("You've pressed No button")
- }
- alertController.addAction(actionYes)
- alertController.addAction(actionNo)
- self.present(alertController, animated: true, completion: nil)
- } else {
- applicationHandle.didSelectItem(item, viewController: self)
- }
- }
- }
|