Skip to content

[stable-6.6.0] NMC/2157 - move copy #328

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: stable-6.6.0
Choose a base branch
from
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
8 changes: 8 additions & 0 deletions Nextcloud.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@
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 */; };
B52FAED32DA8F22F001AB1BD /* MoveAndCopyTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B52FAED22DA8F22F001AB1BD /* MoveAndCopyTests.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 */; };
Expand Down Expand Up @@ -1330,6 +1333,8 @@
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>"; };
B52FAED22DA8F22F001AB1BD /* MoveAndCopyTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MoveAndCopyTests.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 @@ -2118,6 +2123,8 @@
isa = PBXGroup;
children = (
AA52EB452D42AC5A0089C348 /* Placeholder.swift */,
B52FAED22DA8F22F001AB1BD /* MoveAndCopyTests.swift */,
AF8ED1FB2757821000B8DBC4 /* NextcloudUnitTests.swift */,
);
path = NextcloudUnitTests;
sourceTree = "<group>";
Expand Down Expand Up @@ -4145,6 +4152,7 @@
F372087D2BAB4C0F006B5430 /* TestConstants.swift in Sources */,
F78E2D6C29AF02DB0024D4F3 /* Database.swift in Sources */,
F7817CFE29801A3500FFBC65 /* Data+Extension.swift in Sources */,
B52FAED32DA8F22F001AB1BD /* MoveAndCopyTests.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
106 changes: 106 additions & 0 deletions Tests/NextcloudUnitTests/MoveAndCopyTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
//
// MoveAndCopyTests.swift
// NextcloudTests
//
// Created by A200073704 on 05/06/23.
// Copyright © 2023 Marino Faggiana. All rights reserved.
//

@testable import Nextcloud
import XCTest
import NextcloudKit


class MoveAndCopyTests: XCTestCase {

var view : NCSelectCommandView?
var viewController : NCSelect?

override func setUpWithError() throws {
// Put setup code here. This method is called before the invocation of each test method in the class.

let storyboard = UIStoryboard(name: "NCSelect", bundle: nil)
if let navigationController = storyboard.instantiateInitialViewController() as? UINavigationController {
let viewController = navigationController.topViewController as? NCSelect

let _ = viewController?.view
viewController?.loadViewIfNeeded()
}
view = NCSelectCommandView()

}

override func setUp() {
super.setUp()
let nib = Bundle.main.loadNibNamed("NCSelectCommandViewCopyMove", owner: nil, options: nil)
view = nib?.first as? NCSelectCommandView
}

override func tearDownWithError() throws {
// Put teardown code here. This method is called after the invocation of each test method in the class.

viewController = nil
view = nil

}

func testCreateFolderButton() {

let image: Void? = view?.createFolderButton?.setImage(UIImage(named: "addFolder")?.withTintColor(UIColor.label), for: .normal)

XCTAssertNotNil(image)
}

func testOverwriteSwitch() {

let mySwitch = view?.overwriteSwitch

XCTAssertNotNil(mySwitch)

}

func testCopyButton() {

let copy = view?.copyButton

XCTAssertNotNil(copy)
}


func testOverwriteSwitchAlwaysOn() {

XCTAssertTrue(view?.overwriteSwitch?.isOn ?? false, "Overwrite Switch should always be on")
}

func testCopyButtonandMoveButtonCondition() {

// Disable copy and move
view?.copyButton?.isEnabled = false
view?.moveButton?.isEnabled = false

// Creating a test item
let item = tableMetadata()
item.serverUrl = "serverUrl" // Set the serverUrl property of the item

let items: [tableMetadata] = [item]

// Update the items in the view controller
viewController?.items = items

// Verify that the copy and move buttons are still disabled
XCTAssertFalse(view?.copyButton?.isEnabled ?? true, "Copy Button should remain disabled when items.first matches the condition")
XCTAssertFalse(view?.moveButton?.isEnabled ?? true, "Move Button should remain disabled when items.first matches the condition")

// Enable copy and move
view?.copyButton?.isEnabled = true
view?.moveButton?.isEnabled = true

// Update the items in the view controller
viewController?.items = [] // Empty items

// Verify that the copyButton is still enabled
XCTAssertTrue(view?.copyButton?.isEnabled ?? false, "Copy Button should remain enabled when items.first doesn't match the condition")
XCTAssertTrue(view?.moveButton?.isEnabled ?? false, "Move Button should remain enabled when items.first doesn't match the condition")
}

}
105 changes: 76 additions & 29 deletions iOSClient/Main/Collection Common/Cell/NCListCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class NCListCell: UICollectionViewCell, UIGestureRecognizerDelegate, NCCellProto
@IBOutlet weak var separator: UIView!
@IBOutlet weak var tag0: UILabel!
@IBOutlet weak var tag1: UILabel!
@IBOutlet weak var progressView: UIProgressView!

@IBOutlet weak var imageItemLeftConstraint: NSLayoutConstraint!
@IBOutlet weak var separatorHeightConstraint: NSLayoutConstraint!
Expand All @@ -51,6 +52,7 @@ class NCListCell: UICollectionViewCell, UIGestureRecognizerDelegate, NCCellProto
var user = ""

weak var listCellDelegate: NCListCellDelegate?
var namedButtonMore = ""

var fileAvatarImageView: UIImageView? {
return imageShared
Expand Down Expand Up @@ -132,33 +134,55 @@ class NCListCell: UICollectionViewCell, UIGestureRecognizerDelegate, NCCellProto
}

func initCell() {

imageItem.layer.cornerRadius = 6
imageItem.layer.masksToBounds = true

accessibilityHint = nil
accessibilityLabel = nil
accessibilityValue = nil
isAccessibilityElement = true

imageItem.image = nil
imageItem.layer.cornerRadius = 6
imageItem.layer.masksToBounds = true
imageStatus.image = nil
imageFavorite.image = nil
imageFavoriteBackground.isHidden = true
imageLocal.image = nil
labelTitle.text = ""
labelInfo.text = ""
labelSubinfo.text = ""
imageShared.image = nil
imageMore.image = nil
progressView.tintColor = NCBrandColor.shared.brand
progressView.transform = CGAffineTransform(scaleX: 1.0, y: 0.5)
progressView.trackTintColor = .clear
imageSelect.isHidden = true

// imageItem.image = nil
// imageItem.layer.cornerRadius = 6
// imageItem.layer.masksToBounds = true
// imageStatus.image = nil
// imageFavorite.image = nil
// imageFavoriteBackground.isHidden = true
// imageLocal.image = nil
// labelTitle.text = ""
// labelInfo.text = ""
// labelSubinfo.text = ""
// imageShared.image = nil
// imageMore.image = nil
separatorHeightConstraint.constant = 0.5
tag0.text = ""
tag1.text = ""
// tag0.text = ""
// tag1.text = ""
titleInfoTrailingDefault()

let longPressedGesture = UILongPressGestureRecognizer(target: self, action: #selector(longPress(gestureRecognizer:)))
longPressedGesture.minimumPressDuration = 0.5
longPressedGesture.delegate = self
longPressedGesture.delaysTouchesBegan = true
self.addGestureRecognizer(longPressedGesture)

separator.backgroundColor = .separator
separatorHeightConstraint.constant = 0.5

labelTitle.text = ""
labelInfo.text = ""
labelSubinfo.text = ""
labelTitle.textColor = .label
labelInfo.textColor = .systemGray
labelSubinfo.textColor = .systemGray
setButtonMore(named: NCGlobal.shared.buttonMoreMore, image: NCImageCache.images.buttonMore)
imageMore.isHidden = false
buttonMore.isHidden = false
}

override func snapshotView(afterScreenUpdates afterUpdates: Bool) -> UIView? {
Expand All @@ -170,11 +194,15 @@ class NCListCell: UICollectionViewCell, UIGestureRecognizerDelegate, NCCellProto
}

@IBAction func touchUpInsideMore(_ sender: Any) {
listCellDelegate?.tapMoreListItem(with: ocId, ocIdTransfer: ocIdTransfer, image: imageItem.image, sender: sender)
listCellDelegate?.tapMoreListItem(with: ocId, ocIdTransfer: ocIdTransfer, namedButtonMore: namedButtonMore, image: imageItem.image, sender: sender)
}

@objc func longPress(gestureRecognizer: UILongPressGestureRecognizer) {
listCellDelegate?.longPressListItem(with: ocId, ocIdTransfer: ocIdTransfer, gestureRecognizer: gestureRecognizer)
listCellDelegate?.longPressListItem(with: ocId, ocIdTransfer: ocIdTransfer, namedButtonMore: namedButtonMore, gestureRecognizer: gestureRecognizer)
}

@objc func longPressInsideMore(gestureRecognizer: UILongPressGestureRecognizer) {
listCellDelegate?.longPressMoreListItem(with: ocId, namedButtonMore: namedButtonMore, gestureRecognizer: gestureRecognizer)
}

fileprivate func setA11yActions() {
Expand Down Expand Up @@ -213,45 +241,63 @@ class NCListCell: UICollectionViewCell, UIGestureRecognizerDelegate, NCCellProto
buttonShared.isHidden = status
}

func selected(_ status: Bool, isEditMode: Bool) {
if isEditMode {
func selectMode(_ status: Bool) {
if status {
imageItemLeftConstraint.constant = 45
imageSelect.isHidden = false
imageShared.isHidden = true
imageMore.isHidden = true
buttonShared.isHidden = true
buttonMore.isHidden = true
accessibilityCustomActions = nil
} else {
imageItemLeftConstraint.constant = 10
imageSelect.isHidden = true
imageShared.isHidden = false
imageMore.isHidden = false
buttonShared.isHidden = false
buttonMore.isHidden = false
backgroundView = nil
setA11yActions()
}
}

func selected(_ status: Bool, isEditMode: Bool) {
// NMC-1190 - iOS - Files - Deleting files while files are still uploading won't delete properly : to fix this issue remove check for !metadata.isInTransfer in below line
guard let metadata = NCManageDatabase.shared.getMetadataFromOcId(ocId), !metadata.isInTransfer, !metadata.e2eEncrypted else {
// guard let metadata = NCManageDatabase.shared.getMetadataFromOcId(ocId), !metadata.e2eEncrypted else {
backgroundView = nil
separator.isHidden = false
imageSelect.isHidden = true

return
}

if status {
var blurEffect: UIVisualEffect?
var blurEffectView: UIView?
blurEffectView = UIVisualEffectView(effect: UIBlurEffect(style: .systemMaterial))
blurEffectView?.backgroundColor = .lightGray
if traitCollection.userInterfaceStyle == .dark {
blurEffect = UIBlurEffect(style: .dark)
blurEffectView = UIVisualEffectView(effect: blurEffect)
blurEffectView?.backgroundColor = .black
} else {
blurEffect = UIBlurEffect(style: .extraLight)
blurEffectView = UIVisualEffectView(effect: blurEffect)
blurEffectView?.backgroundColor = .lightGray
}
blurEffectView?.frame = self.bounds
blurEffectView?.autoresizingMask = [.flexibleWidth, .flexibleHeight]
imageSelect.image = NCImageCache.shared.getImageCheckedYes()
backgroundView = blurEffectView
imageSelect.image = NCImageCache.images.checkedYes
separator.isHidden = true
} else {
imageSelect.image = NCImageCache.shared.getImageCheckedNo()
imageSelect.image = NCImageCache.images.checkedNo
backgroundView = nil
separator.isHidden = false
}

}

func writeInfoDateSize(date: NSDate, size: Int64) {
labelInfo.text = NCUtility().getRelativeDateTitle(date as Date)
labelSubinfo.text = NCUtilityFileSystem().transformedSize(size)
labelInfo.text = NCUtility().dateDiff(date as Date) + " · " + NCUtilityFileSystem().transformedSize(size)
labelSubinfo.text = ""
}

func setAccessibility(label: String, value: String) {
Expand Down Expand Up @@ -300,8 +346,9 @@ class NCListCell: UICollectionViewCell, UIGestureRecognizerDelegate, NCCellProto

protocol NCListCellDelegate: AnyObject {
func tapShareListItem(with ocId: String, ocIdTransfer: String, sender: Any)
func tapMoreListItem(with ocId: String, ocIdTransfer: String, image: UIImage?, sender: Any)
func longPressListItem(with ocId: String, ocIdTransfer: String, gestureRecognizer: UILongPressGestureRecognizer)
func tapMoreListItem(with ocId: String, ocIdTransfer: String, namedButtonMore: String, image: UIImage?, sender: Any)
func longPressMoreListItem(with ocId: String, namedButtonMore: String, gestureRecognizer: UILongPressGestureRecognizer)
func longPressListItem(with ocId: String, ocIdTransfer: String, namedButtonMore: String, gestureRecognizer: UILongPressGestureRecognizer)
}

// MARK: - List Layout
Expand Down
Loading