-
Notifications
You must be signed in to change notification settings - Fork 62
Enable or disable the “Add Sensors” button #60
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -429,6 +429,12 @@ extension ActionArea { | |
(stackView.arrangedSubviews.count ..< 4).forEach { _ in | ||
stackView.addArrangedSubview(UIView()) | ||
} | ||
|
||
items.forEach { (item) in | ||
item.enabler?.observe({ (enabled) in | ||
self.setButtonFor(item: item, enabled: enabled) | ||
}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
} | ||
} | ||
} | ||
|
||
|
@@ -448,8 +454,12 @@ extension ActionArea { | |
fatalError("init(coder:) has not been implemented") | ||
} | ||
|
||
func setButtonFor(item: BarButtonItem, enabled: Bool, animated: Bool = true) { | ||
if let index = items.index(of: item) { | ||
buttons[index].setEnabled(enabled, animated: animated) | ||
} | ||
} | ||
} | ||
|
||
} | ||
|
||
// MARK: - ActionArea.BarButton | ||
|
@@ -527,8 +537,20 @@ extension ActionArea { | |
button.backgroundColor = customTint.secondary | ||
} | ||
|
||
func setEnabled(_ enabled: Bool, animated: Bool = true) { | ||
button.isEnabled = enabled | ||
let updatedAlpha: CGFloat = enabled ? 1.0 : BarViewController.Metrics.Bar.disabledAlpha | ||
if animated { | ||
UIView.animate(withDuration: 0.5) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
self.button.alpha = updatedAlpha | ||
self.label.alpha = updatedAlpha | ||
} | ||
} else { | ||
self.button.alpha = updatedAlpha | ||
self.label.alpha = updatedAlpha | ||
} | ||
} | ||
} | ||
|
||
} | ||
|
||
// MARK: - Debugging | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -176,6 +176,8 @@ open class ObserveViewController: ScienceJournalCollectionViewController, ChartC | |
return self.observeDataSource.availableSensorIDs | ||
} | ||
|
||
@objc dynamic private(set) var unusedSensors: Bool = false | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
// MARK: - Public | ||
|
||
/// Designated initializer. | ||
|
@@ -197,6 +199,7 @@ open class ObserveViewController: ScienceJournalCollectionViewController, ChartC | |
|
||
let flowLayout = MDCCollectionViewFlowLayout() | ||
flowLayout.minimumLineSpacing = SensorCardCell.cardInsets.bottom | ||
|
||
super.init(collectionViewLayout: flowLayout, analyticsReporter: analyticsReporter) | ||
|
||
observeDataSource.delegate = self | ||
|
@@ -757,6 +760,10 @@ open class ObserveViewController: ScienceJournalCollectionViewController, ChartC | |
sensorCard.toneGenerator.stop() | ||
} | ||
|
||
private func updateUnusedSensors() { | ||
unusedSensors = observeDataSource.items.count < sensorController.availableSensors.count | ||
} | ||
|
||
private func removeSensorCardCell(_ cell: SensorCardCell) { | ||
guard let indexPath = collectionView?.indexPath(for: cell) else { | ||
return | ||
|
@@ -780,7 +787,7 @@ open class ObserveViewController: ScienceJournalCollectionViewController, ChartC | |
} | ||
}, completion: { (_) in | ||
self.updateSensorPickersIfNeeded() | ||
// TODO: Show/Enable the "Add Sensor" button if needed | ||
self.updateUnusedSensors() | ||
}) | ||
} | ||
|
||
|
@@ -809,7 +816,7 @@ open class ObserveViewController: ScienceJournalCollectionViewController, ChartC | |
self.collectionView?.deleteSections(IndexSet(integer: previousFooterIndexPath.section)) | ||
} | ||
}, completion: { (_) in | ||
// TODO: Hide/Disable the "Add Sensor" button. | ||
self.updateUnusedSensors() | ||
}) | ||
collectionView?.scrollToItem(at: IndexPath(item: newItemIndexPath.item, section: 0), | ||
at: .top, | ||
|
@@ -1028,6 +1035,7 @@ open class ObserveViewController: ScienceJournalCollectionViewController, ChartC | |
addInitialSensorCardIfNeeded(andAddListener: andAddListeners) | ||
|
||
collectionView?.reloadData() | ||
updateUnusedSensors() | ||
} | ||
|
||
/// Sets the available sensors for the current experiment. | ||
|
There was a problem hiding this comment.
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
andenabled
)