Skip to content
This repository has been archived by the owner on Dec 15, 2020. It is now read-only.

Enable or disable the “Add Sensors” button #60

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

mattblair
Copy link
Contributor

Checklist

Motivation and Context

The "Add Sensor" button in the action area remains enabled, even when there are no additional sensors to add. This could be confusing for users. The visual characteristics and interactivity of the "Add Sensor" button should change based on whether there are unused sensors available for the device.

Description

  • Added an unusedSensors Bool to ObserveViewController to store the current state of sensors that are available but not currently in use.
  • Added an enabler property to BarButtonItem to handle KVO observations of Bool properties.
  • Specified enabler for the "Add Sensor" bar button item, to observe changes to ObserveViewController's unusedSensors property.
  • Added a setButtonFor(item:enabled:animated:) method to the ActionArea.Bar to toggle enabled for buttons based on observations received by a BarButtonItem.
  • Added a setEnabled(_:animated:) method on the BarButton to change the interactivity and alpha of its subviews.

Tested in the simulator and on devices running iOS 12 and 13.

Based on whether there are unused sensors available for the device.
@@ -429,6 +429,12 @@ extension ActionArea {
(stackView.arrangedSubviews.count ..< 4).forEach { _ in
stackView.addArrangedSubview(UIView())
}

items.forEach { (item) in
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no parens around block args (item and enabled)

items.forEach { (item) in
item.enabler?.observe({ (enabled) in
self.setButtonFor(item: item, enabled: enabled)
})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do all the items need to be re-enabled here? It seems like if one were previously disabled, it may not get turned back on after a button change.

button.isEnabled = enabled
let updatedAlpha: CGFloat = enabled ? 1.0 : BarViewController.Metrics.Bar.disabledAlpha
if animated {
UIView.animate(withDuration: 0.5) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd move the animation block up to the VC. It currently controls timings for animations, so it'll be easier to reason about with those in the same place. There's also some logic up there related to enabling/disabling the entire bar/detail era, and the alpha values there and here are likely related.

@@ -176,6 +176,8 @@ open class ObserveViewController: ScienceJournalCollectionViewController, ChartC
return self.observeDataSource.availableSensorIDs
}

@objc dynamic private(set) var unusedSensors: Bool = false
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hasUnusedSensors would be more consistent with the property naming guidelines for boolean values.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants