Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions Nextcloud.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@
AFCE353527E4ED5900FEA6C2 /* DateFormatter+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = AFCE353427E4ED5900FEA6C2 /* DateFormatter+Extension.swift */; };
AFCE353727E4ED7B00FEA6C2 /* NCShareCells.swift in Sources */ = {isa = PBXBuildFile; fileRef = AFCE353627E4ED7B00FEA6C2 /* NCShareCells.swift */; };
AFCE353927E5DE0500FEA6C2 /* Shareable.swift in Sources */ = {isa = PBXBuildFile; fileRef = AFCE353827E5DE0400FEA6C2 /* Shareable.swift */; };
AFCE353927E5DE0500FEA6C2 /* NCShare+Helper.swift in Sources */ = {isa = PBXBuildFile; fileRef = AFCE353827E5DE0400FEA6C2 /* NCShare+Helper.swift */; };
B5D45E6D2DA510E000773929 /* NCRenameFile.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = B5D45E6A2DA510E000773929 /* NCRenameFile.storyboard */; };
B5D45E6E2DA510E000773929 /* NCRenameFile.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5D45E6B2DA510E000773929 /* NCRenameFile.swift */; };
B5D45E702DA5119A00773929 /* RenameFileTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5D45E6F2DA5119A00773929 /* RenameFileTests.swift */; };
C04E2F232A17BB4D001BAD85 /* FilesIntegrationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C04E2F222A17BB4D001BAD85 /* FilesIntegrationTests.swift */; };
D575039F27146F93008DC9DC /* String+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7A0D1342591FBC5008F8A13 /* String+Extension.swift */; };
D5B6AA7827200C7200D49C24 /* NCActivityTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5B6AA7727200C7200D49C24 /* NCActivityTableViewCell.swift */; };
F310B1EF2BA862F1001C42F5 /* NCViewerMedia+VisionKit.swift in Sources */ = {isa = PBXBuildFile; fileRef = F310B1EE2BA862F1001C42F5 /* NCViewerMedia+VisionKit.swift */; };
F317C82E2E844C5300761AEA /* ClientIntegrationUIViewer.swift in Sources */ = {isa = PBXBuildFile; fileRef = F317C82D2E844C5300761AEA /* ClientIntegrationUIViewer.swift */; };
Expand Down Expand Up @@ -1235,6 +1241,10 @@
AFCE353427E4ED5900FEA6C2 /* DateFormatter+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "DateFormatter+Extension.swift"; sourceTree = "<group>"; };
AFCE353627E4ED7B00FEA6C2 /* NCShareCells.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCShareCells.swift; sourceTree = "<group>"; };
AFCE353827E5DE0400FEA6C2 /* Shareable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Shareable.swift; sourceTree = "<group>"; };
AFCE353827E5DE0400FEA6C2 /* NCShare+Helper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NCShare+Helper.swift"; sourceTree = "<group>"; };
B5D45E6A2DA510E000773929 /* NCRenameFile.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = NCRenameFile.storyboard; sourceTree = "<group>"; };
B5D45E6B2DA510E000773929 /* NCRenameFile.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCRenameFile.swift; sourceTree = "<group>"; };
B5D45E6F2DA5119A00773929 /* RenameFileTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RenameFileTests.swift; sourceTree = "<group>"; };
C0046CDA2A17B98400D87C9D /* NextcloudUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = NextcloudUITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
C04E2F202A17BB4D001BAD85 /* NextcloudIntegrationTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = NextcloudIntegrationTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
D5B6AA7727200C7200D49C24 /* NCActivityTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCActivityTableViewCell.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -2042,6 +2052,8 @@
isa = PBXGroup;
children = (
AA52EB452D42AC5A0089C348 /* Placeholder.swift */,
B5D45E6F2DA5119A00773929 /* RenameFileTests.swift */,
AF8ED1FB2757821000B8DBC4 /* NextcloudUnitTests.swift */,
);
path = NextcloudUnitTests;
sourceTree = "<group>";
Expand Down Expand Up @@ -2080,6 +2092,15 @@
path = Advanced;
sourceTree = "<group>";
};
B5D45E6C2DA510E000773929 /* Rename file */ = {
isa = PBXGroup;
children = (
B5D45E6A2DA510E000773929 /* NCRenameFile.storyboard */,
B5D45E6B2DA510E000773929 /* NCRenameFile.swift */,
);
path = "Rename file";
sourceTree = "<group>";
};
C0046CDB2A17B98400D87C9D /* NextcloudUITests */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -3292,6 +3313,7 @@
F7381ED9218218A4000B1560 /* Offline */,
F713418B2597513800768D21 /* PushNotification */,
F765F72E25237E3F00391DBE /* Recent */,
B5D45E6C2DA510E000773929 /* Rename file */,
F7CADB3D23CCDDA1000EEC78 /* RichWorkspace */,
F76882042C0DD1E7001CF441 /* Settings */,
F758B41E212C516300515F55 /* Scan document */,
Expand Down Expand Up @@ -3981,6 +4003,8 @@
F7381EE5218218C9000B1560 /* NCOffline.storyboard in Resources */,
F768822D2C0DD1E7001CF441 /* Acknowledgements.rtf in Resources */,
F76D3CF32428B94E005DFA87 /* NCViewerPDFSearchCell.xib in Resources */,
F7CA212E25F1333300826ABB /* NCAccountRequest.storyboard in Resources */,
B5D45E6D2DA510E000773929 /* NCRenameFile.storyboard in Resources */,
F717402D24F699A5000C87D5 /* NCFavorite.storyboard in Resources */,
F723B3DD22FC6D1D00301EFE /* NCShareCommentsCell.xib in Resources */,
F78ACD4B21903F850088454D /* NCTrashListCell.xib in Resources */,
Expand Down Expand Up @@ -4116,6 +4140,7 @@
files = (
AA52EB472D42AC9E0089C348 /* Placeholder.swift in Sources */,
F372087D2BAB4C0F006B5430 /* TestConstants.swift in Sources */,
B5D45E702DA5119A00773929 /* RenameFileTests.swift in Sources */,
F78E2D6C29AF02DB0024D4F3 /* Database.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -4745,6 +4770,7 @@
F763D29D2A249C4500A3C901 /* NCManageDatabase+Capabilities.swift in Sources */,
F76882252C0DD1E7001CF441 /* NCSettingsAdvancedModel.swift in Sources */,
F7C7B489245EBA4100D93E60 /* NCViewerQuickLook.swift in Sources */,
B5D45E6E2DA510E000773929 /* NCRenameFile.swift in Sources */,
F758B45E212C569D00515F55 /* NCScanCell.swift in Sources */,
F78B87E72B62527100C65ADC /* NCMediaDataSource.swift in Sources */,
F76882272C0DD1E7001CF441 /* NCManageE2EEView.swift in Sources */,
Expand Down
108 changes: 108 additions & 0 deletions Tests/NextcloudUnitTests/RenameFileTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
//
// RenameFileTests.swift
// NextcloudTests
//
// Created by A200073704 on 14/06/23.
// Copyright © 2023 Marino Faggiana. All rights reserved.
//

@testable import Nextcloud
import XCTest
import NextcloudKit

class RenameFileTests: 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 testStoryboardPresence() {

let storyboard = UIStoryboard(name: "NCRenameFile", bundle: nil)
XCTAssertNotNil(storyboard, "Storyboard 'NCRenameFile' should be present")

}

func testRenameButtonPresence() {
let storyboard = UIStoryboard(name: "NCRenameFile", bundle: nil)
guard let viewController = storyboard.instantiateInitialViewController() as? NCRenameFile else {
XCTFail("Failed to instantiate view controller from storyboard")
return
}

_ = viewController.view // Load the view

let renameButton = viewController.renameButton
XCTAssertNotNil(renameButton, "Rename button should be present")
}

func testRenameButtonBackgroundColor() {

let storyboard = UIStoryboard(name: "NCRenameFile", bundle: nil)
guard let viewController = storyboard.instantiateInitialViewController() as? NCRenameFile else {
XCTFail("Failed to instantiate view controller from storyboard")
return
}

_ = viewController.view // Load the view

let color = NCBrandColor.shared.brand.cgColor
let renameButton = viewController.renameButton.layer.backgroundColor

XCTAssertEqual(renameButton,color, "Rename Button Bcakground Color should be brand")
}

func testCancelButtonPresence() {
let storyboard = UIStoryboard(name: "NCRenameFile", bundle: nil)
guard let viewController = storyboard.instantiateInitialViewController() as? NCRenameFile else {
XCTFail("Failed to instantiate view controller from storyboard")
return
}

_ = viewController.view // Load the view

let cancelButton = viewController.cancelButton
XCTAssertNotNil(cancelButton, "Cancel button should be present")
}

func testImageViewPresence() {

let storyboard = UIStoryboard(name: "NCRenameFile", bundle: nil)
guard let viewController = storyboard.instantiateInitialViewController() as? NCRenameFile else {
XCTFail("Failed to instantiate view controller from storyboard")
return
}

_ = viewController.view // Load the view

let imageView = viewController.previewFile
XCTAssertNotNil(imageView, "UIImageView should be present on the storyboard")
}

func testTextFiledPresence() {

let storyboard = UIStoryboard(name: "NCRenameFile", bundle: nil)
guard let viewController = storyboard.instantiateInitialViewController() as? NCRenameFile else {
XCTFail("Failed to instantiate view controller from storyboard")
return
}

_ = viewController.view // Load the view

let textField = viewController.fileNameNoExtension
let textFieldExt = viewController.ext

XCTAssertNotNil(textField, "FileNameNoExtention TextFiled should be present on the storyboard")
XCTAssertNotNil(textFieldExt, "Extension TextFiled should be present on the storyboard")

}



}
94 changes: 94 additions & 0 deletions iOSClient/Main/Collection Common/NCCollectionViewCommon.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@

import UIKit
import SwiftUI
import Realm
import RealmSwift
import NextcloudKit
import EasyTipView
import LucidBanner
import MoEngageInApps

class NCCollectionViewCommon: UIViewController, NCAccountSettingsModelDelegate, UIGestureRecognizerDelegate, UISearchResultsUpdating, UISearchControllerDelegate, UISearchBarDelegate, UIAdaptivePresentationControllerDelegate, UIContextMenuInteractionDelegate {

Expand Down Expand Up @@ -52,6 +54,13 @@ class NCCollectionViewCommon: UIViewController, NCAccountSettingsModelDelegate,
var attributesZoomOut: UIMenuElement.Attributes = []
var tipViewAccounts: EasyTipView?
var syncMetadatasTask: Task<Void, Never>?
var tipViewAutoUpload: EasyTipView?
var headerMenu: NCSectionHeaderMenu?
var headerMenuTransferView = false
var headerMenuButtonsView: Bool = true
var headerRichWorkspaceDisable: Bool = false

var selectableDataSource: [RealmSwiftObject] { dataSource.getMetadataSourceForAllSections() }

// DECLARE
var layoutKey = ""
Expand Down Expand Up @@ -230,6 +239,14 @@ class NCCollectionViewCommon: UIViewController, NCAccountSettingsModelDelegate,
let dropInteraction = UIDropInteraction(delegate: self)
self.navigationController?.navigationItem.leftBarButtonItems?.first?.customView?.addInteraction(dropInteraction)

if(!UserDefaults.standard.bool(forKey: "isInitialPrivacySettingsShowed") || isApplicationUpdated()){
redirectToPrivacyViewController()

//set current app version
let appVersion = Bundle.main.infoDictionary?["CFBundleInfoDictionaryVersion"] as? String
UserDefaults.standard.set(appVersion, forKey: "CurrentAppVersion")
}

registerForTraitChanges([UITraitUserInterfaceStyle.self]) { [weak self] (view: NCCollectionViewCommon, _) in
guard let self else { return }

Expand All @@ -250,6 +267,8 @@ class NCCollectionViewCommon: UIViewController, NCAccountSettingsModelDelegate,
await self.debouncerReloadData.resume()
}
}

NotificationCenter.default.addObserver(self, selector: #selector(updateIcons), name: NSNotification.Name(rawValue: global.notificationCenterUpdateIcons), object: nil)

DispatchQueue.main.async {
self.collectionView?.collectionViewLayout.invalidateLayout()
Expand Down Expand Up @@ -351,6 +370,23 @@ class NCCollectionViewCommon: UIViewController, NCAccountSettingsModelDelegate,
override var canBecomeFirstResponder: Bool {
return true
}

@objc func updateIcons() {
collectionView.reloadData()
}

func isApplicationUpdated() -> Bool {
let appVersion = Bundle.main.infoDictionary?["CFBundleInfoDictionaryVersion"] as? String ?? ""
let currentVersion = UserDefaults.standard.string(forKey: "CurrentAppVersion")
return currentVersion != appVersion
}

func redirectToPrivacyViewController() {
let storyBoard: UIStoryboard = UIStoryboard(name: "NCSettings", bundle: nil)
let newViewController = storyBoard.instantiateViewController(withIdentifier: "privacySettingsNavigation") as? UINavigationController
newViewController?.modalPresentationStyle = .fullScreen
self.present(newViewController!, animated: true, completion: nil)
}

// MARK: - NotificationCenter

Expand Down Expand Up @@ -514,6 +550,64 @@ class NCCollectionViewCommon: UIViewController, NCAccountSettingsModelDelegate,

// MARK: - TAP EVENT

func tapMoreListItem(with ocId: String, ocIdTransfer: String, image: UIImage?, sender: Any) {
tapMoreGridItem(with: ocId, ocIdTransfer: ocIdTransfer, image: image, sender: sender)
}

func tapMorePhotoItem(with ocId: String, ocIdTransfer: String, image: UIImage?, sender: Any) {
tapMoreGridItem(with: ocId, ocIdTransfer: ocIdTransfer, image: image, sender: sender)
}

func tapShareListItem(with ocId: String, ocIdTransfer: String, sender: Any) {
guard let metadata = self.database.getMetadataFromOcId(ocId) else { return }

NCCreate().createShare(viewController: self, metadata: metadata, page: .sharing)
// NCDownloadAction.shared.openShare(viewController: self, metadata: metadata, page: .sharing)
TealiumHelper.shared.trackEvent(title: "magentacloud-app.filebrowser.sharing", data: ["": ""])
appDelegate.adjust.trackEvent(TriggerEvent(Sharing.rawValue))

}

func tapMoreGridItem(with ocId: String, ocIdTransfer: String, image: UIImage?, sender: Any) {
guard let metadata = self.database.getMetadataFromOcId(ocId) else { return }
toggleMenu(metadata: metadata, image: image, sender: sender)
}

func tapRichWorkspace(_ sender: Any) {
if let navigationController = UIStoryboard(name: "NCViewerRichWorkspace", bundle: nil).instantiateInitialViewController() as? UINavigationController {
if let viewerRichWorkspace = navigationController.topViewController as? NCViewerRichWorkspace {
viewerRichWorkspace.richWorkspaceText = richWorkspaceText ?? ""
viewerRichWorkspace.serverUrl = serverUrl
viewerRichWorkspace.delegate = self

navigationController.modalPresentationStyle = .fullScreen
self.present(navigationController, animated: true, completion: nil)
}
}
}

func tapRecommendationsButtonMenu(with metadata: tableMetadata, image: UIImage?, sender: Any?) {
toggleMenu(metadata: metadata, image: image, sender: sender)
}

func tapButtonSection(_ sender: Any, metadataForSection: NCMetadataForSection?) {
unifiedSearchMore(metadataForSection: metadataForSection)
}

func tapRecommendations(with metadata: tableMetadata) {
didSelectMetadata(metadata, withOcIds: false)
}

func longPressListItem(with ocId: String, ocIdTransfer: String, gestureRecognizer: UILongPressGestureRecognizer) { }

func longPressGridItem(with ocId: String, ocIdTransfer: String, gestureRecognizer: UILongPressGestureRecognizer) { }

func longPressMoreListItem(with ocId: String, ocIdTransfer: String, gestureRecognizer: UILongPressGestureRecognizer) { }

func longPressPhotoItem(with ocId: String, ocIdTransfer: String, gestureRecognizer: UILongPressGestureRecognizer) { }

func longPressMoreGridItem(with ocId: String, ocIdTransfer: String, gestureRecognizer: UILongPressGestureRecognizer) { }

@objc func longPressCollecationView(_ gestureRecognizer: UILongPressGestureRecognizer) {
openMenuItems(with: nil, gestureRecognizer: gestureRecognizer)
}
Expand Down
Loading