Skip to content

Commit

Permalink
NMC 1997 - Sharing customisation
Browse files Browse the repository at this point in the history
  • Loading branch information
TSI-amrutwaghmare committed Dec 26, 2023
1 parent f72360b commit 5334dee
Show file tree
Hide file tree
Showing 45 changed files with 3,865 additions and 1,158 deletions.
68 changes: 68 additions & 0 deletions Nextcloud.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

232 changes: 232 additions & 0 deletions Tests/NextcloudUnitTests/SharingTest.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,232 @@
//
// SharingTest.swift
// NextcloudTests
//
// Created by A200020526 on 07/06/23.
// Copyright © 2023 Marino Faggiana. All rights reserved.
//

import XCTest
@testable import Nextcloud
final class SharingTest: XCTestCase {

var button: UIButton?
var ncShare: NCShare?

override func setUpWithError() throws {
// Put setup code here. This method is called before the invocation of each test method in the class.
super.setUp()
button = UIButton()
ncShare = NCShare()
}

override func tearDownWithError() throws {
// Put teardown code here. This method is called after the invocation of each test method in the class.
button = nil
ncShare = nil
super.tearDown()
}

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.
}
}


//Date exntesion test case
func testTomorrow() {
let tomorrow = Date.tomorrow
let expectedTomorrow = Calendar.current.date(byAdding: .day, value: 1, to: Date())!
XCTAssertEqual(tomorrow.extendedIso8601String, expectedTomorrow.extendedIso8601String, "Tomorrow date should be correct.")
}
func testToday() {
let today = Date.today
let currentDate = Date()
XCTAssertEqual(today.extendedIso8601String, currentDate.extendedIso8601String, "Today date should be correct.")
}

func testDayAfter() {
let date = Date()
let dayAfter = date.dayAfter
let expectedDayAfter = Calendar.current.date(byAdding: .day, value: 1, to: date)!
XCTAssertEqual(dayAfter.extendedIso8601String, expectedDayAfter.extendedIso8601String, "Day after date should be correct.")
}

//Date Formatter extension Test Case
func testShareExpDate() {
let dateFormatter = DateFormatter.shareExpDate

XCTAssertEqual(dateFormatter.formatterBehavior, .behavior10_4, "Formatter behavior should be correct.")
XCTAssertEqual(dateFormatter.dateStyle, .medium, "Date style should be correct.")
XCTAssertEqual(dateFormatter.dateFormat, NCShareAdvancePermission.displayDateFormat, "Date format should be correct.")
}

//Button Extension test case
func testSetBackgroundColor() {
// Arrange
let color = UIColor.red
let state: UIControl.State = .normal

// Act
button?.setBackgroundColor(color, for: state)

// Assert
XCTAssertNotNil(button?.currentBackgroundImage, "Button background image not nil")
}

func testSetBackgroundColorForDifferentStates() {
// Arrange

let selectedColor = UIColor.green

// Act
button?.isSelected = true
button?.setBackgroundColor(selectedColor, for: .selected)

// Assert
XCTAssertNotNil(button?.currentBackgroundImage, "Button background image not nil")
button?.isSelected = false
XCTAssertNil(button?.currentBackgroundImage,"Button background image will be nil")
button?.isHighlighted = true
XCTAssertNil(button?.currentBackgroundImage, "Button background image will be nil")
}

//UIView extension shadow test case
func testAddShadowWithLocation() {
// Create a UIView instance
let view = UIView()

// Set the shadow with bottom location
view.addShadow(location: .bottom, height: 2, color: .red, opacity: 0.4, radius: 2)

// Verify that the shadow offset is set correctly for the bottom location
let bottomShadowOffset = view.layer.shadowOffset
XCTAssertEqual(bottomShadowOffset, CGSize(width: 0, height: 2), "Shadow offset not set correctly for bottom location")

// Verify that the shadow color is set correctly
let shadowColor = view.layer.shadowColor
XCTAssertEqual(shadowColor, UIColor.red.cgColor, "Shadow color not set correctly")

// Verify that the shadow opacity is set correctly
let shadowOpacity = view.layer.shadowOpacity
XCTAssertEqual(shadowOpacity, 0.4, "Shadow opacity not set correctly")

// Verify that the shadow radius is set correctly
let shadowRadius = view.layer.shadowRadius
XCTAssertEqual(shadowRadius, 2.0, "Shadow radius not set correctly")
}

func testAddShadowWithOffset() {
// Create a UIView instance
let view = UIView()

// Set the shadow with a custom offset
view.addShadow(offset: CGSize(width: 0, height: -4), color: .blue, opacity: 0.6, radius: 3)

// Verify that the shadow offset is set correctly
let shadowOffset = view.layer.shadowOffset
XCTAssertEqual(shadowOffset, CGSize(width: 0, height: -4), "Shadow offset not set correctly")

// Verify that the shadow color is set correctly
let shadowColor = view.layer.shadowColor
XCTAssertEqual(shadowColor, UIColor.blue.cgColor, "Shadow color not set correctly")

// Verify that the shadow opacity is set correctly
let shadowOpacity = view.layer.shadowOpacity
XCTAssertEqual(shadowOpacity, 0.6, "Shadow opacity not set correctly")

// Verify that the shadow radius is set correctly
let shadowRadius = view.layer.shadowRadius
XCTAssertEqual(shadowRadius, 3.0, "Shadow radius not set correctly")
}

func testAddShadowForLocation() {
// Create a UIView instance
let view = UIView()

// Add shadow to the bottom
view.addShadow(location: .bottom, color: UIColor.black)

// Verify that the shadow properties are set correctly for the bottom location
XCTAssertEqual(view.layer.shadowOffset, CGSize(width: 0, height: 2), "Shadow offset not set correctly for bottom location")
XCTAssertEqual(view.layer.shadowColor, UIColor.black.cgColor, "Shadow color not set correctly for bottom location")
XCTAssertEqual(view.layer.shadowOpacity, 0.4, "Shadow opacity not set correctly for bottom location")
XCTAssertEqual(view.layer.shadowRadius, 2.0, "Shadow radius not set correctly for bottom location")

// Add shadow to the top
view.addShadow(location: .top)

// Verify that the shadow properties are set correctly for the top location
XCTAssertEqual(view.layer.shadowOffset, CGSize(width: 0, height: -2), "Shadow offset not set correctly for top location")
XCTAssertEqual(view.layer.shadowColor, NCBrandColor.shared.customerDarkGrey.cgColor, "Shadow color not set correctly for top location")
XCTAssertEqual(view.layer.shadowOpacity, 0.4, "Shadow opacity not set correctly for top location")
XCTAssertEqual(view.layer.shadowRadius, 2.0, "Shadow radius not set correctly for top location")
}

func testAddShadowForOffset() {
// Create a UIView instance
let view = UIView()

// Add shadow with custom offset
view.addShadow(offset: CGSize(width: 2, height: 2))

// Verify that the shadow properties are set correctly for the custom offset
XCTAssertEqual(view.layer.shadowOffset, CGSize(width: 2, height: 2), "Shadow offset not set correctly for custom offset")
XCTAssertEqual(view.layer.shadowColor, UIColor.black.cgColor, "Shadow color not set correctly for custom offset")
XCTAssertEqual(view.layer.shadowOpacity, 0.5, "Shadow opacity not set correctly for custom offset")
XCTAssertEqual(view.layer.shadowRadius, 5.0, "Shadow radius not set correctly for custom offset")
}


func testHasUploadPermission() {
// Create an instance of NCShare
let share = NCShare()

// Define the input parameters
let tableShareWithUploadPermission = tableShare()
tableShareWithUploadPermission.permissions = NCGlobal.shared.permissionMaxFileShare

let tableShareWithoutUploadPermission = tableShare()
tableShareWithoutUploadPermission.permissions = NCGlobal.shared.permissionReadShare

// Call the hasUploadPermission function
let hasUploadPermission1 = share.hasUploadPermission(tableShare: tableShareWithUploadPermission)
let hasUploadPermission2 = share.hasUploadPermission(tableShare: tableShareWithoutUploadPermission)

// Verify the results
XCTAssertTrue(hasUploadPermission1, "hasUploadPermission returned false for a tableShare with upload permission")
XCTAssertFalse(hasUploadPermission2, "hasUploadPermission returned true for a tableShare without upload permission")
}

func testGetImageShareType() {
let sut = NCShareCommon() // Replace with the actual class containing the getImageShareType function

// Test case 1: SHARE_TYPE_USER
let shareType1 = sut.SHARE_TYPE_USER
let result1 = sut.getImageShareType(shareType: shareType1)
XCTAssertEqual(result1, UIImage(named: "shareTypeEmail")?.imageColor(NCBrandColor.shared.label))

// Test case 2: SHARE_TYPE_GROUP
let shareType2 = sut.SHARE_TYPE_GROUP
let result2 = sut.getImageShareType(shareType: shareType2)
XCTAssertEqual(result2, UIImage(named: "shareTypeGroup")?.imageColor(NCBrandColor.shared.label))

// Test case 3: SHARE_TYPE_LINK
let shareType3 = sut.SHARE_TYPE_LINK
let result3 = sut.getImageShareType(shareType: shareType3)
XCTAssertEqual(result3, UIImage(named: "shareTypeLink")?.imageColor(NCBrandColor.shared.label))

// Test case 4: SHARE_TYPE_EMAIL (with isDropDown=false)
let shareType4 = sut.SHARE_TYPE_EMAIL
let result4 = sut.getImageShareType(shareType: shareType4)
XCTAssertEqual(result4, UIImage(named: "shareTypeUser")?.imageColor(NCBrandColor.shared.label))

// Test case 5: SHARE_TYPE_EMAIL (with isDropDown=true)
let shareType5 = sut.SHARE_TYPE_EMAIL
let isDropDown5 = true
let result5 = sut.getImageShareType(shareType: shareType5, isDropDown: isDropDown5)
XCTAssertEqual(result5, UIImage(named: "email")?.imageColor(NCBrandColor.shared.label))
}
}
9 changes: 9 additions & 0 deletions iOSClient/Extensions/DateFormatter+Extension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@ extension DateFormatter {
let dateFormatter = DateFormatter()
dateFormatter.formatterBehavior = .behavior10_4
dateFormatter.dateStyle = .medium
dateFormatter.dateFormat = NCShareAdvancePermission.displayDateFormat
return dateFormatter
}()
}

extension Date {
static var tomorrow: Date { return Date().dayAfter }
static var today: Date {return Date()}
var dayAfter: Date {
return Calendar.current.date(byAdding: .day, value: 1, to: Date())!
}
}
22 changes: 22 additions & 0 deletions iOSClient/Extensions/UIButton+Extension.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//
// UIButton+Extension.swift
// Nextcloud
//
// Created by A200020526 on 30/05/23.
// Copyright © 2023 Marino Faggiana. All rights reserved.
//

import UIKit

extension UIButton {

func setBackgroundColor(_ color: UIColor, for forState: UIControl.State) {
UIGraphicsBeginImageContext(CGSize(width: 1, height: 1))
UIGraphicsGetCurrentContext()!.setFillColor(color.cgColor)
UIGraphicsGetCurrentContext()!.fill(CGRect(x: 0, y: 0, width: 1, height: 1))
let colorImage = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
self.setBackgroundImage(colorImage, for: forState)
}
}

14 changes: 14 additions & 0 deletions iOSClient/Extensions/UIToolbar+Extension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,20 @@ extension UIToolbar {
])
return view
}

static func doneToolbar(completion: @escaping () -> Void) -> UIToolbar {
let doneToolbar: UIToolbar = UIToolbar(frame: CGRect.init(x: 0, y: 0, width: UIScreen.main.bounds.width, height: 50))
doneToolbar.barStyle = .default

let flexSpace = UIBarButtonItem(barButtonSystemItem: .flexibleSpace, target: nil, action: nil)
let done: UIBarButtonItem = UIBarButtonItem(title: NSLocalizedString("_done_", comment: ""), style: .done) {
completion()
}
let items = [flexSpace, done]
doneToolbar.items = items
doneToolbar.sizeToFit()
return doneToolbar
}
}

// https://stackoverflow.com/a/67985180/9506784
Expand Down
22 changes: 22 additions & 0 deletions iOSClient/Extensions/UIView+Extension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@
import Foundation
import UIKit

enum VerticalLocation: String {
case bottom
case top
}

extension UIView {

// Source
Expand All @@ -45,4 +50,21 @@ extension UIView {
hiddenView.fillSuperview()
hiddenView.addSubview(view)
}

func addShadow(location: VerticalLocation, height: CGFloat = 2, color: UIColor = NCBrandColor.shared.customerDarkGrey, opacity: Float = 0.4, radius: CGFloat = 2) {
switch location {
case .bottom:
addShadow(offset: CGSize(width: 0, height: height), color: color, opacity: opacity, radius: radius)
case .top:
addShadow(offset: CGSize(width: 0, height: -height), color: color, opacity: opacity, radius: radius)
}
}

func addShadow(offset: CGSize, color: UIColor = .black, opacity: Float = 0.5, radius: CGFloat = 5.0) {
self.layer.masksToBounds = false
self.layer.shadowColor = color.cgColor
self.layer.shadowOffset = offset
self.layer.shadowOpacity = opacity
self.layer.shadowRadius = radius
}
}
29 changes: 1 addition & 28 deletions iOSClient/Main/NCActionCenter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -252,36 +252,9 @@ class NCActionCenter: NSObject, UIDocumentInteractionControllerDelegate, NCSelec
NCActivityIndicator.shared.stop()

if let metadata = metadata, error == .success {

var pages: [NCBrandOptions.NCInfoPagingTab] = []

let shareNavigationController = UIStoryboard(name: "NCShare", bundle: nil).instantiateInitialViewController() as? UINavigationController
let shareViewController = shareNavigationController?.topViewController as? NCSharePaging

for value in NCBrandOptions.NCInfoPagingTab.allCases {
pages.append(value)
}

if NCGlobal.shared.capabilityActivity.isEmpty, let idx = pages.firstIndex(of: .activity) {
pages.remove(at: idx)
}
if !metadata.isSharable(), let idx = pages.firstIndex(of: .sharing) {
pages.remove(at: idx)
}

(pages, page) = NCApplicationHandle().filterPages(pages: pages, page: page, metadata: metadata)

shareViewController?.pages = pages
let shareViewController = shareNavigationController?.topViewController as? NCShare
shareViewController?.metadata = metadata

if pages.contains(page) {
shareViewController?.page = page
} else if let page = pages.first {
shareViewController?.page = page
} else {
return
}

shareNavigationController?.modalPresentationStyle = .formSheet
if let shareNavigationController = shareNavigationController {
viewController.present(shareNavigationController, animated: true, completion: nil)
Expand Down
Loading

0 comments on commit 5334dee

Please sign in to comment.