Skip to content

Commit 9766528

Browse files
NMC 1997 - Sharing customisation
unused changes
1 parent 7a4bb44 commit 9766528

43 files changed

Lines changed: 3605 additions & 1179 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 232 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,232 @@
1+
//
2+
// SharingTest.swift
3+
// NextcloudTests
4+
//
5+
// Created by A200020526 on 07/06/23.
6+
// Copyright © 2023 Marino Faggiana. All rights reserved.
7+
//
8+
9+
import XCTest
10+
@testable import Nextcloud
11+
final class SharingTest: XCTestCase {
12+
13+
var button: UIButton?
14+
var ncShare: NCShare?
15+
16+
override func setUpWithError() throws {
17+
// Put setup code here. This method is called before the invocation of each test method in the class.
18+
super.setUp()
19+
button = UIButton()
20+
ncShare = NCShare()
21+
}
22+
23+
override func tearDownWithError() throws {
24+
// Put teardown code here. This method is called after the invocation of each test method in the class.
25+
button = nil
26+
ncShare = nil
27+
super.tearDown()
28+
}
29+
30+
func testPerformanceExample() throws {
31+
// This is an example of a performance test case.
32+
self.measure {
33+
// Put the code you want to measure the time of here.
34+
}
35+
}
36+
37+
38+
//Date exntesion test case
39+
func testTomorrow() {
40+
let tomorrow = Date.tomorrow
41+
let expectedTomorrow = Calendar.current.date(byAdding: .day, value: 1, to: Date())!
42+
XCTAssertEqual(tomorrow.extendedIso8601String, expectedTomorrow.extendedIso8601String, "Tomorrow date should be correct.")
43+
}
44+
func testToday() {
45+
let today = Date.today
46+
let currentDate = Date()
47+
XCTAssertEqual(today.extendedIso8601String, currentDate.extendedIso8601String, "Today date should be correct.")
48+
}
49+
50+
func testDayAfter() {
51+
let date = Date()
52+
let dayAfter = date.dayAfter
53+
let expectedDayAfter = Calendar.current.date(byAdding: .day, value: 1, to: date)!
54+
XCTAssertEqual(dayAfter.extendedIso8601String, expectedDayAfter.extendedIso8601String, "Day after date should be correct.")
55+
}
56+
57+
//Date Formatter extension Test Case
58+
func testShareExpDate() {
59+
let dateFormatter = DateFormatter.shareExpDate
60+
61+
XCTAssertEqual(dateFormatter.formatterBehavior, .behavior10_4, "Formatter behavior should be correct.")
62+
XCTAssertEqual(dateFormatter.dateStyle, .medium, "Date style should be correct.")
63+
XCTAssertEqual(dateFormatter.dateFormat, NCShareAdvancePermission.displayDateFormat, "Date format should be correct.")
64+
}
65+
66+
//Button Extension test case
67+
func testSetBackgroundColor() {
68+
// Arrange
69+
let color = UIColor.red
70+
let state: UIControl.State = .normal
71+
72+
// Act
73+
button?.setBackgroundColor(color, for: state)
74+
75+
// Assert
76+
XCTAssertNotNil(button?.currentBackgroundImage, "Button background image not nil")
77+
}
78+
79+
func testSetBackgroundColorForDifferentStates() {
80+
// Arrange
81+
82+
let selectedColor = UIColor.green
83+
84+
// Act
85+
button?.isSelected = true
86+
button?.setBackgroundColor(selectedColor, for: .selected)
87+
88+
// Assert
89+
XCTAssertNotNil(button?.currentBackgroundImage, "Button background image not nil")
90+
button?.isSelected = false
91+
XCTAssertNil(button?.currentBackgroundImage,"Button background image will be nil")
92+
button?.isHighlighted = true
93+
XCTAssertNil(button?.currentBackgroundImage, "Button background image will be nil")
94+
}
95+
96+
//UIView extension shadow test case
97+
func testAddShadowWithLocation() {
98+
// Create a UIView instance
99+
let view = UIView()
100+
101+
// Set the shadow with bottom location
102+
view.addShadow(location: .bottom, height: 2, color: .red, opacity: 0.4, radius: 2)
103+
104+
// Verify that the shadow offset is set correctly for the bottom location
105+
let bottomShadowOffset = view.layer.shadowOffset
106+
XCTAssertEqual(bottomShadowOffset, CGSize(width: 0, height: 2), "Shadow offset not set correctly for bottom location")
107+
108+
// Verify that the shadow color is set correctly
109+
let shadowColor = view.layer.shadowColor
110+
XCTAssertEqual(shadowColor, UIColor.red.cgColor, "Shadow color not set correctly")
111+
112+
// Verify that the shadow opacity is set correctly
113+
let shadowOpacity = view.layer.shadowOpacity
114+
XCTAssertEqual(shadowOpacity, 0.4, "Shadow opacity not set correctly")
115+
116+
// Verify that the shadow radius is set correctly
117+
let shadowRadius = view.layer.shadowRadius
118+
XCTAssertEqual(shadowRadius, 2.0, "Shadow radius not set correctly")
119+
}
120+
121+
func testAddShadowWithOffset() {
122+
// Create a UIView instance
123+
let view = UIView()
124+
125+
// Set the shadow with a custom offset
126+
view.addShadow(offset: CGSize(width: 0, height: -4), color: .blue, opacity: 0.6, radius: 3)
127+
128+
// Verify that the shadow offset is set correctly
129+
let shadowOffset = view.layer.shadowOffset
130+
XCTAssertEqual(shadowOffset, CGSize(width: 0, height: -4), "Shadow offset not set correctly")
131+
132+
// Verify that the shadow color is set correctly
133+
let shadowColor = view.layer.shadowColor
134+
XCTAssertEqual(shadowColor, UIColor.blue.cgColor, "Shadow color not set correctly")
135+
136+
// Verify that the shadow opacity is set correctly
137+
let shadowOpacity = view.layer.shadowOpacity
138+
XCTAssertEqual(shadowOpacity, 0.6, "Shadow opacity not set correctly")
139+
140+
// Verify that the shadow radius is set correctly
141+
let shadowRadius = view.layer.shadowRadius
142+
XCTAssertEqual(shadowRadius, 3.0, "Shadow radius not set correctly")
143+
}
144+
145+
func testAddShadowForLocation() {
146+
// Create a UIView instance
147+
let view = UIView()
148+
149+
// Add shadow to the bottom
150+
view.addShadow(location: .bottom, color: UIColor.black)
151+
152+
// Verify that the shadow properties are set correctly for the bottom location
153+
XCTAssertEqual(view.layer.shadowOffset, CGSize(width: 0, height: 2), "Shadow offset not set correctly for bottom location")
154+
XCTAssertEqual(view.layer.shadowColor, UIColor.black.cgColor, "Shadow color not set correctly for bottom location")
155+
XCTAssertEqual(view.layer.shadowOpacity, 0.4, "Shadow opacity not set correctly for bottom location")
156+
XCTAssertEqual(view.layer.shadowRadius, 2.0, "Shadow radius not set correctly for bottom location")
157+
158+
// Add shadow to the top
159+
view.addShadow(location: .top)
160+
161+
// Verify that the shadow properties are set correctly for the top location
162+
XCTAssertEqual(view.layer.shadowOffset, CGSize(width: 0, height: -2), "Shadow offset not set correctly for top location")
163+
XCTAssertEqual(view.layer.shadowColor, NCBrandColor.shared.customerDarkGrey.cgColor, "Shadow color not set correctly for top location")
164+
XCTAssertEqual(view.layer.shadowOpacity, 0.4, "Shadow opacity not set correctly for top location")
165+
XCTAssertEqual(view.layer.shadowRadius, 2.0, "Shadow radius not set correctly for top location")
166+
}
167+
168+
func testAddShadowForOffset() {
169+
// Create a UIView instance
170+
let view = UIView()
171+
172+
// Add shadow with custom offset
173+
view.addShadow(offset: CGSize(width: 2, height: 2))
174+
175+
// Verify that the shadow properties are set correctly for the custom offset
176+
XCTAssertEqual(view.layer.shadowOffset, CGSize(width: 2, height: 2), "Shadow offset not set correctly for custom offset")
177+
XCTAssertEqual(view.layer.shadowColor, UIColor.black.cgColor, "Shadow color not set correctly for custom offset")
178+
XCTAssertEqual(view.layer.shadowOpacity, 0.5, "Shadow opacity not set correctly for custom offset")
179+
XCTAssertEqual(view.layer.shadowRadius, 5.0, "Shadow radius not set correctly for custom offset")
180+
}
181+
182+
183+
func testHasUploadPermission() {
184+
// Create an instance of NCShare
185+
let share = NCShare()
186+
187+
// Define the input parameters
188+
let tableShareWithUploadPermission = tableShare()
189+
tableShareWithUploadPermission.permissions = NCGlobal.shared.permissionMaxFileShare
190+
191+
let tableShareWithoutUploadPermission = tableShare()
192+
tableShareWithoutUploadPermission.permissions = NCGlobal.shared.permissionReadShare
193+
194+
// Call the hasUploadPermission function
195+
let hasUploadPermission1 = share.hasUploadPermission(tableShare: tableShareWithUploadPermission)
196+
let hasUploadPermission2 = share.hasUploadPermission(tableShare: tableShareWithoutUploadPermission)
197+
198+
// Verify the results
199+
XCTAssertTrue(hasUploadPermission1, "hasUploadPermission returned false for a tableShare with upload permission")
200+
XCTAssertFalse(hasUploadPermission2, "hasUploadPermission returned true for a tableShare without upload permission")
201+
}
202+
203+
func testGetImageShareType() {
204+
let sut = NCShareCommon() // Replace with the actual class containing the getImageShareType function
205+
206+
// Test case 1: SHARE_TYPE_USER
207+
let shareType1 = sut.SHARE_TYPE_USER
208+
let result1 = sut.getImageShareType(shareType: shareType1)
209+
XCTAssertEqual(result1, UIImage(named: "shareTypeEmail")?.imageColor(NCBrandColor.shared.label))
210+
211+
// Test case 2: SHARE_TYPE_GROUP
212+
let shareType2 = sut.SHARE_TYPE_GROUP
213+
let result2 = sut.getImageShareType(shareType: shareType2)
214+
XCTAssertEqual(result2, UIImage(named: "shareTypeGroup")?.imageColor(NCBrandColor.shared.label))
215+
216+
// Test case 3: SHARE_TYPE_LINK
217+
let shareType3 = sut.SHARE_TYPE_LINK
218+
let result3 = sut.getImageShareType(shareType: shareType3)
219+
XCTAssertEqual(result3, UIImage(named: "shareTypeLink")?.imageColor(NCBrandColor.shared.label))
220+
221+
// Test case 4: SHARE_TYPE_EMAIL (with isDropDown=false)
222+
let shareType4 = sut.SHARE_TYPE_EMAIL
223+
let result4 = sut.getImageShareType(shareType: shareType4)
224+
XCTAssertEqual(result4, UIImage(named: "shareTypeUser")?.imageColor(NCBrandColor.shared.label))
225+
226+
// Test case 5: SHARE_TYPE_EMAIL (with isDropDown=true)
227+
let shareType5 = sut.SHARE_TYPE_EMAIL
228+
let isDropDown5 = true
229+
let result5 = sut.getImageShareType(shareType: shareType5, isDropDown: isDropDown5)
230+
XCTAssertEqual(result5, UIImage(named: "email")?.imageColor(NCBrandColor.shared.label))
231+
}
232+
}

iOSClient/Activity/NCActivity.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class NCActivity: UIViewController, NCSharePagingContent {
3131
@IBOutlet weak var tableView: UITableView!
3232

3333
var commentView: NCActivityCommentView?
34-
var textField: UIView? { commentView?.newCommentField }
34+
var textField: UITextField? { commentView?.newCommentField }
3535
var height: CGFloat = 0
3636
var metadata: tableMetadata?
3737
var showComments: Bool = false

iOSClient/Extensions/DateFormatter+Extension.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,15 @@ extension DateFormatter {
2929
let dateFormatter = DateFormatter()
3030
dateFormatter.formatterBehavior = .behavior10_4
3131
dateFormatter.dateStyle = .medium
32+
dateFormatter.dateFormat = NCShareAdvancePermission.displayDateFormat
3233
return dateFormatter
3334
}()
3435
}
36+
37+
extension Date {
38+
static var tomorrow: Date { return Date().dayAfter }
39+
static var today: Date {return Date()}
40+
var dayAfter: Date {
41+
return Calendar.current.date(byAdding: .day, value: 1, to: Date())!
42+
}
43+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//
2+
// UIButton+Extension.swift
3+
// Nextcloud
4+
//
5+
// Created by A200020526 on 30/05/23.
6+
// Copyright © 2023 Marino Faggiana. All rights reserved.
7+
//
8+
9+
import UIKit
10+
11+
extension UIButton {
12+
13+
func setBackgroundColor(_ color: UIColor, for forState: UIControl.State) {
14+
UIGraphicsBeginImageContext(CGSize(width: 1, height: 1))
15+
UIGraphicsGetCurrentContext()!.setFillColor(color.cgColor)
16+
UIGraphicsGetCurrentContext()!.fill(CGRect(x: 0, y: 0, width: 1, height: 1))
17+
let colorImage = UIGraphicsGetImageFromCurrentImageContext()
18+
UIGraphicsEndImageContext()
19+
self.setBackgroundImage(colorImage, for: forState)
20+
}
21+
}
22+

iOSClient/Extensions/UIToolbar+Extension.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,20 @@ extension UIToolbar {
5858
])
5959
return view
6060
}
61+
62+
static func doneToolbar(completion: @escaping () -> Void) -> UIToolbar {
63+
let doneToolbar: UIToolbar = UIToolbar(frame: CGRect.init(x: 0, y: 0, width: UIScreen.main.bounds.width, height: 50))
64+
doneToolbar.barStyle = .default
65+
66+
let flexSpace = UIBarButtonItem(barButtonSystemItem: .flexibleSpace, target: nil, action: nil)
67+
let done: UIBarButtonItem = UIBarButtonItem(title: NSLocalizedString("_done_", comment: ""), style: .done) {
68+
completion()
69+
}
70+
let items = [flexSpace, done]
71+
doneToolbar.items = items
72+
doneToolbar.sizeToFit()
73+
return doneToolbar
74+
}
6175
}
6276

6377
// https://stackoverflow.com/a/67985180/9506784

iOSClient/Extensions/UIView+Extension.swift

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@
2424
import Foundation
2525
import UIKit
2626

27+
enum VerticalLocation: String {
28+
case bottom
29+
case top
30+
}
31+
2732
extension UIView {
2833

2934
// Source
@@ -69,4 +74,21 @@ extension UIView {
6974
self.layer.cornerRadius = self.frame.size.width / 2
7075
self.layer.masksToBounds = true
7176
}
77+
78+
func addShadow(location: VerticalLocation, height: CGFloat = 2, color: UIColor = NCBrandColor.shared.customerDarkGrey, opacity: Float = 0.4, radius: CGFloat = 2) {
79+
switch location {
80+
case .bottom:
81+
addShadow(offset: CGSize(width: 0, height: height), color: color, opacity: opacity, radius: radius)
82+
case .top:
83+
addShadow(offset: CGSize(width: 0, height: -height), color: color, opacity: opacity, radius: radius)
84+
}
85+
}
86+
87+
func addShadow(offset: CGSize, color: UIColor = .black, opacity: Float = 0.5, radius: CGFloat = 5.0) {
88+
self.layer.masksToBounds = false
89+
self.layer.shadowColor = color.cgColor
90+
self.layer.shadowOffset = offset
91+
self.layer.shadowOpacity = opacity
92+
self.layer.shadowRadius = radius
93+
}
7294
}

iOSClient/Main/NCActionCenter.swift

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -274,36 +274,9 @@ class NCActionCenter: NSObject, UIDocumentInteractionControllerDelegate, NCSelec
274274
NCActivityIndicator.shared.stop()
275275

276276
if let metadata = metadata, error == .success {
277-
278-
var pages: [NCBrandOptions.NCInfoPagingTab] = []
279-
280277
let shareNavigationController = UIStoryboard(name: "NCShare", bundle: nil).instantiateInitialViewController() as? UINavigationController
281-
let shareViewController = shareNavigationController?.topViewController as? NCSharePaging
282-
283-
for value in NCBrandOptions.NCInfoPagingTab.allCases {
284-
pages.append(value)
285-
}
286-
287-
if NCGlobal.shared.capabilityActivity.isEmpty, let idx = pages.firstIndex(of: .activity) {
288-
pages.remove(at: idx)
289-
}
290-
if !metadata.isSharable(), let idx = pages.firstIndex(of: .sharing) {
291-
pages.remove(at: idx)
292-
}
293-
294-
(pages, page) = NCApplicationHandle().filterPages(pages: pages, page: page, metadata: metadata)
295-
296-
shareViewController?.pages = pages
278+
let shareViewController = shareNavigationController?.topViewController as? NCShare
297279
shareViewController?.metadata = metadata
298-
299-
if pages.contains(page) {
300-
shareViewController?.page = page
301-
} else if let page = pages.first {
302-
shareViewController?.page = page
303-
} else {
304-
return
305-
}
306-
307280
shareNavigationController?.modalPresentationStyle = .formSheet
308281
if let shareNavigationController = shareNavigationController {
309282
viewController.present(shareNavigationController, animated: true, completion: nil)

0 commit comments

Comments
 (0)