From 832b5cd622982a1e00ff57c85965aca113245adb Mon Sep 17 00:00:00 2001 From: TSI-amrutwaghmare <96108296+TSI-amrutwaghmare@users.noreply.github.com> Date: Wed, 1 Nov 2023 15:13:42 +0530 Subject: [PATCH] NMC 2237 - More option tab customisation changes --- .../File Provider Extension UI.xcscheme | 1 - .../WidgetDashboardIntentHandler.xcscheme | 1 - Tests/NextcloudUnitTests/MoreTests.swift | 37 ++++ iOSClient/More/Cells/BaseNCMoreCell.swift | 14 -- iOSClient/More/Cells/NCMoreUserCell.xib | 76 ++++++++ iOSClient/More/NCMore.storyboard | 171 ++++++++++-------- iOSClient/More/NCMore.swift | 159 +++++++++------- 7 files changed, 305 insertions(+), 154 deletions(-) create mode 100644 Tests/NextcloudUnitTests/MoreTests.swift create mode 100755 iOSClient/More/Cells/NCMoreUserCell.xib diff --git a/Nextcloud.xcodeproj/xcshareddata/xcschemes/File Provider Extension UI.xcscheme b/Nextcloud.xcodeproj/xcshareddata/xcschemes/File Provider Extension UI.xcscheme index c06627e268..e19e0492e1 100644 --- a/Nextcloud.xcodeproj/xcshareddata/xcschemes/File Provider Extension UI.xcscheme +++ b/Nextcloud.xcodeproj/xcshareddata/xcschemes/File Provider Extension UI.xcscheme @@ -73,7 +73,6 @@ savedToolIdentifier = "" useCustomWorkingDirectory = "NO" debugDocumentVersioning = "YES" - askForAppToLaunch = "Yes" launchAutomaticallySubstyle = "2"> diff --git a/Nextcloud.xcodeproj/xcshareddata/xcschemes/WidgetDashboardIntentHandler.xcscheme b/Nextcloud.xcodeproj/xcshareddata/xcschemes/WidgetDashboardIntentHandler.xcscheme index e7fe4caf7c..0b68bbe8b4 100644 --- a/Nextcloud.xcodeproj/xcshareddata/xcschemes/WidgetDashboardIntentHandler.xcscheme +++ b/Nextcloud.xcodeproj/xcshareddata/xcschemes/WidgetDashboardIntentHandler.xcscheme @@ -73,7 +73,6 @@ savedToolIdentifier = "" useCustomWorkingDirectory = "NO" debugDocumentVersioning = "YES" - askForAppToLaunch = "Yes" launchAutomaticallySubstyle = "2"> diff --git a/Tests/NextcloudUnitTests/MoreTests.swift b/Tests/NextcloudUnitTests/MoreTests.swift new file mode 100644 index 0000000000..0a96912994 --- /dev/null +++ b/Tests/NextcloudUnitTests/MoreTests.swift @@ -0,0 +1,37 @@ +// +// MoreTests.swift +// NextcloudTests +// +// Created by A200020526 on 09/06/23. +// Copyright © 2023 Marino Faggiana. All rights reserved. +// + +@testable import Nextcloud +import XCTest + +final class MoreTests: XCTestCase { + + override func setUpWithError() throws { + // Put setup code here. This method is called before the invocation of each test method in the class. + } + + override func tearDownWithError() throws { + // Put teardown code here. This method is called after the invocation of each test method in the class. + } + + func testExample() throws { + // This is an example of a functional test case. + // Use XCTAssert and related functions to verify your tests produce the correct results. + // Any test you write for XCTest can be annotated as throws and async. + // Mark your test throws to produce an unexpected failure when your test encounters an uncaught error. + // Mark your test async to allow awaiting for asynchronous code to complete. Check the results with assertions afterwards. + } + + func testPerformanceExample() throws { + // This is an example of a performance test case. + self.measure { + // Put the code you want to measure the time of here. + } + } + +} diff --git a/iOSClient/More/Cells/BaseNCMoreCell.swift b/iOSClient/More/Cells/BaseNCMoreCell.swift index 79b64b80d5..1868d3b7f0 100644 --- a/iOSClient/More/Cells/BaseNCMoreCell.swift +++ b/iOSClient/More/Cells/BaseNCMoreCell.swift @@ -27,20 +27,6 @@ class BaseNCMoreCell: UITableViewCell { let selectionColor: UIView = UIView() let defaultCornerRadius: CGFloat = 10.0 - override var frame: CGRect { - get { - return super.frame - } - set (newFrame) { - var frame = newFrame - let newWidth = frame.width * 0.90 - let space = (frame.width - newWidth) / 2 - frame.size.width = newWidth - frame.origin.x += space - super.frame = frame - } - } - override func awakeFromNib() { super.awakeFromNib() diff --git a/iOSClient/More/Cells/NCMoreUserCell.xib b/iOSClient/More/Cells/NCMoreUserCell.xib new file mode 100755 index 0000000000..477fe2539e --- /dev/null +++ b/iOSClient/More/Cells/NCMoreUserCell.xib @@ -0,0 +1,76 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/iOSClient/More/NCMore.storyboard b/iOSClient/More/NCMore.storyboard index 57caeedfce..794b3d16a6 100644 --- a/iOSClient/More/NCMore.storyboard +++ b/iOSClient/More/NCMore.storyboard @@ -1,102 +1,114 @@ - + - + - + - - + + - - + + + + + + + - + - - + + - - + + - - + + - - - - - + + + + + - - - - - - - - - - + + - - + + - - + + - - - - - - - - - - - + + + + + + + + + + + + + + + + - + - - - - - - - + + + + + + + - + - - - - - + + + + + + + - + + diff --git a/iOSClient/More/NCMore.swift b/iOSClient/More/NCMore.swift index 688ac0ad7e..0a6b1e76c5 100644 --- a/iOSClient/More/NCMore.swift +++ b/iOSClient/More/NCMore.swift @@ -24,15 +24,16 @@ import UIKit import NextcloudKit import SafariServices -import SwiftUI -import Foundation 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! + @IBOutlet weak var quotaLabel1: UILabel! + @IBOutlet weak var quotalabel2: UILabel! private var functionMenu: [NKExternalSite] = [] private var externalSiteMenu: [NKExternalSite] = [] @@ -41,7 +42,6 @@ class NCMore: UIViewController, UITableViewDelegate, UITableViewDataSource { private let appDelegate = (UIApplication.shared.delegate as? AppDelegate)! private let applicationHandle = NCApplicationHandle() private var tabAccount: tableAccount? - let utilityFileSystem = NCUtilityFileSystem() let utility = NCUtility() @@ -50,10 +50,12 @@ class NCMore: UIViewController, UITableViewDelegate, UITableViewDataSource { var type: SectionType enum SectionType { + case account case moreApps case regular } } + private var sections: [Section] = [] // MARK: - View Life Cycle @@ -68,6 +70,7 @@ class NCMore: UIViewController, UITableViewDelegate, UITableViewDataSource { tableView.delegate = self tableView.dataSource = self tableView.backgroundColor = .systemGroupedBackground + tableView.register(NCMoreUserCell.fromNib(), forCellReuseIdentifier: NCMoreUserCell.reuseIdentifier) tableView.register(NCMoreAppSuggestionsCell.fromNib(), forCellReuseIdentifier: NCMoreAppSuggestionsCell.reuseIdentifier) // create tap gesture recognizer @@ -78,15 +81,27 @@ class NCMore: UIViewController, UITableViewDelegate, UITableViewDataSource { override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) - + appDelegate.activeViewController = self navigationController?.setGroupAppearance() loadItems() + changeTheming() tableView.reloadData() } // MARK: - + + @objc func changeTheming() { + viewQuota.backgroundColor = NCBrandColor.shared.memoryConsuptionBackground + quotaLabel1.textColor = NCBrandColor.shared.label + quotalabel2.textColor = NCBrandColor.shared.label + labelQuota.textColor = NCBrandColor.shared.label + labelQuotaExternalSite.textColor = NCBrandColor.shared.label + progressQuota.progressTintColor = NCBrandColor.shared.brandElement + progressQuota.trackTintColor = NCBrandColor.shared.commonViewInfoText + } func loadItems() { + var item = NKExternalSite() var quota: String = "" @@ -105,39 +120,37 @@ class NCMore: UIViewController, UITableViewDelegate, UITableViewDataSource { item.icon = "arrow.left.arrow.right" item.url = "segueTransfers" item.order = 10 - functionMenu.append(item) +// functionMenu.append(item) // ITEM : Recent item = NKExternalSite() item.name = "_recent_" - item.icon = "clock.arrow.circlepath" + item.icon = "recent" item.url = "segueRecent" item.order = 20 functionMenu.append(item) + + // ITEM : Notification + item = NKExternalSite() + item.name = "_notifications_" + item.icon = "notification" + item.url = "segueNotification" + item.order = 30 + functionMenu.append(item) // ITEM : Activity item = NKExternalSite() item.name = "_activity_" item.icon = "bolt" item.url = "segueActivity" - item.order = 30 - functionMenu.append(item) - - if NCGlobal.shared.capabilityAssistantEnabled, NCBrandOptions.shared.disable_show_more_nextcloud_apps_in_settings { - // ITEM : Assistant - item = NKExternalSite() - item.name = "_assistant_" - item.icon = "sparkles" - item.url = "openAssistant" - item.order = 40 - functionMenu.append(item) - } + item.order = 40 +// functionMenu.append(item) // ITEM : Shares if NCGlobal.shared.capabilityFileSharingApiEnabled { item = NKExternalSite() item.name = "_list_shares_" - item.icon = "person.badge.plus" + item.icon = "shareFill" item.url = "segueShares" item.order = 50 functionMenu.append(item) @@ -146,7 +159,7 @@ class NCMore: UIViewController, UITableViewDelegate, UITableViewDataSource { // ITEM : Offline item = NKExternalSite() item.name = "_manage_file_offline_" - item.icon = "icloud.and.arrow.down" + item.icon = "offlineMenu" item.url = "segueOffline" item.order = 60 functionMenu.append(item) @@ -158,16 +171,15 @@ class NCMore: UIViewController, UITableViewDelegate, UITableViewDataSource { item.icon = "person.2" item.url = "segueGroupfolders" item.order = 61 - functionMenu.append(item) +// functionMenu.append(item) } - // ITEM : Scan item = NKExternalSite() item.name = "_scanned_images_" item.icon = "doc.text.viewfinder" item.url = "openStoryboardNCScan" item.order = 70 - functionMenu.append(item) +// functionMenu.append(item) // ITEM : Trash if NCGlobal.shared.capabilityServerVersionMajor >= NCGlobal.shared.nextcloudVersion15 { @@ -188,8 +200,8 @@ class NCMore: UIViewController, UITableViewDelegate, UITableViewDataSource { // ITEM : Settings item = NKExternalSite() item.name = "_settings_" - item.icon = "gear" - item.url = "openSettings" + item.icon = "settings" + item.url = "segueSettings" settingsMenu.append(item) if !quotaMenu.isEmpty { @@ -198,7 +210,9 @@ class NCMore: UIViewController, UITableViewDelegate, UITableViewDataSource { } // Display Name user & Quota + if let activeAccount = NCManageDatabase.shared.getActiveAccount() { + self.tabAccount = activeAccount if activeAccount.quotaRelative > 0 { @@ -219,8 +233,14 @@ class NCMore: UIViewController, UITableViewDelegate, UITableViewDataSource { } let quotaUsed: String = utilityFileSystem.transformedSize(activeAccount.quotaUsed) + let quota2: String = utilityFileSystem.transformedSize(activeAccount.quotaTotal) + let percentageUsedFormatted = "\(Int(progressQuota.progress * 100))%" + + labelQuota.text = String.localizedStringWithFormat(NSLocalizedString("_quota_using_percentage_", comment: ""), percentageUsedFormatted) + + quotaLabel1.text = String.localizedStringWithFormat(NSLocalizedString("_quota_using_", comment: ""), quotaUsed) + quotalabel2.text = String.localizedStringWithFormat(NSLocalizedString("_quota_using_of_", comment: ""), quota2) - labelQuota.text = String.localizedStringWithFormat(NSLocalizedString("_quota_using_", comment: ""), quotaUsed, quota) } // ITEM : External @@ -245,8 +265,8 @@ class NCMore: UIViewController, UITableViewDelegate, UITableViewDataSource { } private func loadSections() { - if !NCBrandOptions.shared.disable_show_more_nextcloud_apps_in_settings { - sections.append(Section(items: [NKExternalSite()], type: .moreApps)) + if tabAccount != nil { + sections.append(Section(items: [NKExternalSite()], type: .account)) } if !functionMenu.isEmpty { @@ -265,6 +285,7 @@ class NCMore: UIViewController, UITableViewDelegate, UITableViewDataSource { // MARK: - Action @objc func tapLabelQuotaExternalSite() { + if !quotaMenu.isEmpty { let item = quotaMenu[0] if let browserWebVC = UIStoryboard(name: "NCBrowserWeb", bundle: nil).instantiateInitialViewController() as? NCBrowserWeb { @@ -277,10 +298,21 @@ class NCMore: UIViewController, UITableViewDelegate, UITableViewDataSource { } } + @objc func tapImageLogoManageAccount() { + + let controller = CCManageAccount() + + self.navigationController?.pushViewController(controller, animated: true) + } + // MARK: - func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { - return 50 + if sections[indexPath.section].type == .account { + return 100 + } else { + return NCGlobal.shared.heightCellSettings + } } func numberOfSections(in tableView: UITableView) -> Int { @@ -290,7 +322,9 @@ class NCMore: UIViewController, UITableViewDelegate, UITableViewDataSource { func tableView(_ tableView: UITableView, heightForHeaderInSection index: Int) -> CGFloat { let section = sections[index] - if section.type == .moreApps || (index > 0 && sections[index - 1].type == .moreApps) { + if section.type == .account { + return 10 + } else if section.type == .moreApps || sections[index - 1].type == .moreApps { return 1 } else { return 20 @@ -304,40 +338,43 @@ class NCMore: UIViewController, UITableViewDelegate, UITableViewDataSource { func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let section = sections[indexPath.section] - if section.type == .moreApps { + if section.type == .account { + + guard let cell = tableView.dequeueReusableCell(withIdentifier: NCMoreUserCell.reuseIdentifier, for: indexPath) as? NCMoreUserCell else { return UITableViewCell() } + + cell.avatar.image = nil + cell.icon.image = nil + cell.status.text = "" + cell.displayName.text = "" + + if let account = tabAccount { + cell.avatar.image = UIImage.init(named: "user_settings")?.image(color: NCBrandColor.shared.iconColor, size: 25) + + if account.alias.isEmpty { + cell.displayName?.text = account.displayName + } else { + cell.displayName?.text = account.displayName + " (" + account.alias + ")" + } + cell.displayName.textColor = .label + } + cell.removeCornerRadius() + cell.icon.isHidden = true + return cell + + } else if section.type == .moreApps { guard let cell = tableView.dequeueReusableCell(withIdentifier: NCMoreAppSuggestionsCell.reuseIdentifier, for: indexPath) as? NCMoreAppSuggestionsCell else { return UITableViewCell() } + return cell } else { guard let cell = tableView.dequeueReusableCell(withIdentifier: CCCellMore.reuseIdentifier, for: indexPath) as? CCCellMore else { return UITableViewCell() } let item = sections[indexPath.section].items[indexPath.row] - cell.imageIcon?.image = utility.loadImage(named: item.icon, colors: [NCBrandColor.shared.iconImageColor]) + cell.imageIcon?.image = utility.loadImage(named: item.icon).image(color: NCBrandColor.shared.iconColor, size: 25) cell.imageIcon?.contentMode = .scaleAspectFit cell.labelText?.text = NSLocalizedString(item.name, comment: "") - cell.labelText.textColor = NCBrandColor.shared.textColor - - cell.accessoryType = UITableViewCell.AccessoryType.disclosureIndicator - - cell.separator.backgroundColor = .separator - cell.separatorHeigth.constant = 0.4 - + cell.labelText.textColor = .label 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 } @@ -366,8 +403,12 @@ class NCMore: UIViewController, UITableViewDelegate, UITableViewDataSource { } } 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 - self.appDelegate.openLogin(selector: NCGlobal.shared.introLogin, openLoginWeb: false) + 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 @@ -377,14 +418,6 @@ class NCMore: UIViewController, UITableViewDelegate, UITableViewDataSource { alertController.addAction(actionYes) alertController.addAction(actionNo) self.present(alertController, animated: true, completion: nil) - } else if item.url == "openAssistant" { - let assistant = NCAssistant().environmentObject(NCAssistantTask()) - let hostingController = UIHostingController(rootView: assistant) - present(hostingController, animated: true, completion: nil) - } else if item.url == "openSettings" { - let settingsView = NCSettingsView(model: NCSettingsModel(controller: tabBarController as? NCMainTabBarController)) - let settingsController = UIHostingController(rootView: settingsView) - navigationController?.pushViewController(settingsController, animated: true) } else { applicationHandle.didSelectItem(item, viewController: self) }