Skip to content

Commit

Permalink
- added design resource
Browse files Browse the repository at this point in the history
- updated SDK
- various fixes to make progress observation in ProgressView and ProgressSummarizer thread-safe
  • Loading branch information
felix-schwarz committed Jan 29, 2019
1 parent 1a7f260 commit 966eddf
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 28 deletions.
Binary file modified design/cloud-symbols-thick.idraw
Binary file not shown.
4 changes: 3 additions & 1 deletion ownCloud/UI Elements/Progress/ProgressSummarizer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ class ProgressSummarizer: NSObject {

deinit {
OCSynchronized(self) {
for progress in trackedProgress {
let existingTrackedProgress = trackedProgress

for progress in existingTrackedProgress {
self.stopTracking(progress: progress, remove: false)
}
}
Expand Down
71 changes: 46 additions & 25 deletions ownCloud/UI Elements/ProgressView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,42 +26,63 @@ class ProgressView: UIView, Themeable {
private let dimensions : CGSize = CGSize(width: 30, height: 30)
private let circleLineWidth : CGFloat = 3

// private var progressObservationFractionCompleted : NSKeyValueObservation?
// private var progressObservationIsIndeterminate : NSKeyValueObservation?
// private var progressObservationCancelled : NSKeyValueObservation?
// private var progressObservationFinished : NSKeyValueObservation?

private var _observerRegistered : Bool = false
private var _progress : Progress?
var progress : Progress? {
willSet {
if newValue !== progress, progress != nil {
progress?.removeObserver(self, forKeyPath: "fractionCompleted")
progress?.removeObserver(self, forKeyPath: "indeterminate")
progress?.removeObserver(self, forKeyPath: "cancelled")
progress?.removeObserver(self, forKeyPath: "finished")
set {
OCSynchronized(self) {
if _observerRegistered, let progress = _progress {
progress.removeObserver(self, forKeyPath: "fractionCompleted")
progress.removeObserver(self, forKeyPath: "indeterminate")
progress.removeObserver(self, forKeyPath: "cancelled")
progress.removeObserver(self, forKeyPath: "finished")

_observerRegistered = false
}

_progress = newValue

if !_observerRegistered, let progress = newValue {
progress.addObserver(self, forKeyPath: "fractionCompleted", options: [], context: nil)
progress.addObserver(self, forKeyPath: "indeterminate", options: [], context: nil)
progress.addObserver(self, forKeyPath: "cancelled", options: [], context: nil)
progress.addObserver(self, forKeyPath: "finished", options: [], context: nil)

_observerRegistered = true
}

if Thread.isMainThread {
CATransaction.begin()
CATransaction.setDisableActions(true)
CATransaction.setAnimationDuration(0)
} else {
Log.log("Progress not set on main thread")
}

self.update()

if Thread.isMainThread {
CATransaction.commit()
}
}
}

didSet {
CATransaction.begin()
CATransaction.setDisableActions(true)
CATransaction.setAnimationDuration(0)
get {
var progress : Progress?

if let newProgress = progress {
newProgress.addObserver(self, forKeyPath: "fractionCompleted", options: [], context: nil)
newProgress.addObserver(self, forKeyPath: "indeterminate", options: [], context: nil)
newProgress.addObserver(self, forKeyPath: "cancelled", options: [], context: nil)
newProgress.addObserver(self, forKeyPath: "finished", options: [], context: nil)
OCSynchronized(self) {
progress = _progress
}

self.update()

CATransaction.commit()
return progress
}
}

override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
if (object as? Progress) === progress {
self.update()
OnMainThread {
self.update()
}
} else {
super.observeValue(forKeyPath: keyPath, of: object, change: change, context: context)
}
Expand Down Expand Up @@ -139,7 +160,7 @@ class ProgressView: UIView, Themeable {
return
}

if let progress = progress {
if let progress = self.progress {

self.spinning = progress.isIndeterminate || progress.isCancelled

Expand Down
14 changes: 13 additions & 1 deletion ownCloudTests/Security/PasscodeTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,16 @@ class PasscodeTests: XCTestCase {

// Show the passcode
AppLockManager.shared.showLockscreenIfNeeded()
EarlGrey.waitForElement(accessibilityID: "number1Button")

// Tap the number buttons
EarlGrey.select(elementWithMatcher: grey_accessibilityID("number1Button")).perform(grey_tap())
EarlGrey.select(elementWithMatcher: grey_accessibilityID("number1Button")).perform(grey_tap())
EarlGrey.select(elementWithMatcher: grey_accessibilityID("number1Button")).perform(grey_tap())
EarlGrey.select(elementWithMatcher: grey_accessibilityID("number1Button")).perform(grey_tap())

EarlGrey.waitForElement(accessibilityID: "addServer")

// Asserts
EarlGrey.select(elementWithMatcher: grey_accessibilityID("addServer")).assert(grey_sufficientlyVisible())
}
Expand All @@ -61,6 +64,7 @@ class PasscodeTests: XCTestCase {

// Show the passcode
AppLockManager.shared.showLockscreenIfNeeded()
EarlGrey.waitForElement(accessibilityID: "number1Button")

// Tap the number buttons
EarlGrey.select(elementWithMatcher: grey_accessibilityID("number1Button")).perform(grey_tap())
Expand All @@ -87,10 +91,12 @@ class PasscodeTests: XCTestCase {
EarlGrey.select(elementWithMatcher: grey_accessibilityID("number1Button")).perform(grey_tap())
EarlGrey.select(elementWithMatcher: grey_text("Cancel".localized)).perform(grey_tap())

EarlGrey.waitForElementMissing(accessibilityID: "number1Button")

// Asserts
EarlGrey.select(elementWithMatcher: grey_accessibilityID("passcodeSwitchIdentifier")).assert(grey_switchWithOnState(false))

//Reset status
// Reset status
EarlGrey.select(elementWithMatcher: grey_text("ownCloud")).perform(grey_tap())
}

Expand All @@ -115,6 +121,8 @@ class PasscodeTests: XCTestCase {
EarlGrey.select(elementWithMatcher: grey_accessibilityID("number1Button")).perform(grey_tap())
EarlGrey.select(elementWithMatcher: grey_text("Cancel".localized)).perform(grey_tap())

EarlGrey.waitForElementMissing(accessibilityID: "number1Button")

// Asserts
EarlGrey.select(elementWithMatcher: grey_accessibilityID("passcodeSwitchIdentifier")).assert(grey_switchWithOnState(false))

Expand Down Expand Up @@ -171,6 +179,8 @@ class PasscodeTests: XCTestCase {
EarlGrey.select(elementWithMatcher: grey_accessibilityID("number1Button")).perform(grey_tap())
EarlGrey.select(elementWithMatcher: grey_accessibilityID("number1Button")).perform(grey_tap())

EarlGrey.waitForElementMissing(accessibilityID: "number1Button")

// Asserts
EarlGrey.select(elementWithMatcher: grey_accessibilityID("passcodeSwitchIdentifier")).assert(grey_switchWithOnState(false))
EarlGrey.select(elementWithMatcher: grey_accessibilityID("lockFrequency")).assert(grey_notVisible())
Expand All @@ -196,6 +206,8 @@ class PasscodeTests: XCTestCase {
EarlGrey.select(elementWithMatcher: grey_accessibilityID("number1Button")).perform(grey_tap())
EarlGrey.select(elementWithMatcher: grey_text("Cancel".localized)).perform(grey_tap())

EarlGrey.waitForElementMissing(accessibilityID: "number1Button")

// Asserts
EarlGrey.select(elementWithMatcher: grey_accessibilityID("passcodeSwitchIdentifier")).assert(grey_switchWithOnState(true))
EarlGrey.select(elementWithMatcher: grey_accessibilityID("lockFrequency")).assert(grey_sufficientlyVisible())
Expand Down

0 comments on commit 966eddf

Please sign in to comment.