adds lights UI
This commit is contained in:
@@ -12,10 +12,12 @@ class MainViewController: UIViewController, SwitchesViewControllerDelegate, Serv
|
||||
{
|
||||
fileprivate var _serverMultiplex: ServerMultiplex = ServerMultiplex()
|
||||
fileprivate var _visualizationController: VisualizationViewController = VisualizationViewController()
|
||||
fileprivate var _switchesController: SwitchesViewController = SwitchesViewController()
|
||||
fileprivate var _headerView: HeaderView = HeaderView()
|
||||
fileprivate var _updateDevices: Bool = false
|
||||
|
||||
fileprivate var _switchesController: SwitchesViewController = SwitchesViewController()
|
||||
fileprivate var _lightsController: SwitchesViewController = SwitchesViewController()
|
||||
|
||||
override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?)
|
||||
{
|
||||
super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
|
||||
@@ -46,6 +48,13 @@ class MainViewController: UIViewController, SwitchesViewControllerDelegate, Serv
|
||||
self.addChild(_switchesController)
|
||||
self.view.addSubview(_switchesController.view)
|
||||
|
||||
_lightsController.delegate = self
|
||||
_lightsController.cellHeightScale = 0.7
|
||||
_lightsController.actionCellLayout = .horizontal
|
||||
_lightsController.labelText = "lights"
|
||||
self.addChild(_lightsController)
|
||||
self.view.addSubview(_lightsController.view)
|
||||
|
||||
self.view.addSubview(_headerView)
|
||||
|
||||
_updateConnectivityStatus(.disconnected)
|
||||
@@ -75,10 +84,18 @@ class MainViewController: UIViewController, SwitchesViewControllerDelegate, Serv
|
||||
x: bodyBounds.origin.x,
|
||||
y: bodyBounds.origin.y,
|
||||
width: rint(0.5 * bodyBounds.size.width),
|
||||
height: bodyBounds.size.height
|
||||
height: bodyBounds.size.height / 1.5
|
||||
)
|
||||
_visualizationController.view.frame = visualizationFrame
|
||||
|
||||
let lightsControllerFrame = CGRect(
|
||||
x: bodyBounds.origin.x,
|
||||
y: visualizationFrame.maxY,
|
||||
width: visualizationFrame.width,
|
||||
height: bodyBounds.height - visualizationFrame.height
|
||||
)
|
||||
_lightsController.view.frame = lightsControllerFrame.insetBy(dx: 18.0, dy: 0.0)
|
||||
|
||||
var switchesOriginX: CGFloat = 0.0
|
||||
var switchesWidth: CGFloat = 0.0
|
||||
if (_visualizationShouldBeVisible()) {
|
||||
@@ -205,13 +222,16 @@ class MainViewController: UIViewController, SwitchesViewControllerDelegate, Serv
|
||||
|
||||
func serverMultiplex(_ multiplex: ServerMultiplex, didAddDevices devices: [AnyDevice])
|
||||
{
|
||||
_switchesController.devices = Array(multiplex.devices)
|
||||
_switchesController.devices = multiplex.switchDevices
|
||||
_lightsController.devices = multiplex.lightDevices
|
||||
|
||||
_updateVisualization(false)
|
||||
}
|
||||
|
||||
func serverMultiplex(_ multiplex: ServerMultiplex, devicesStateChanged devices: [AnyDevice])
|
||||
{
|
||||
_switchesController.devicesStateChanged(devices)
|
||||
_switchesController.devicesStateChanged(devices.switches)
|
||||
_lightsController.devicesStateChanged(devices.lights)
|
||||
}
|
||||
|
||||
func serverMultiplex(_ multiplex: ServerMultiplex, didReceiveAcknowledgementFromServer server: Server)
|
||||
@@ -229,3 +249,15 @@ class MainViewController: UIViewController, SwitchesViewControllerDelegate, Serv
|
||||
print(error.localizedDescription, to: &stderr)
|
||||
}
|
||||
}
|
||||
|
||||
extension Array where Element == AnyDevice
|
||||
{
|
||||
var lights: [AnyDevice] { filter { $0.type == .light } }
|
||||
var switches: [AnyDevice] { filter { $0.type == .switch } }
|
||||
}
|
||||
|
||||
extension ServerMultiplex
|
||||
{
|
||||
var lightDevices: [AnyDevice] { devices.filter { $0.type == .light } }
|
||||
var switchDevices: [AnyDevice] { devices.filter { $0.type == .switch } }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user