iPhone Support

This commit is contained in:
Charles Magahern
2016-07-24 00:14:04 -07:00
parent 2f5c807dc6
commit 56de300889
17 changed files with 143 additions and 59 deletions

View File

@@ -8,7 +8,8 @@
import UIKit
class MainViewController: UIViewController, SwitchesViewControllerDelegate {
class MainViewController: UIViewController, SwitchesViewControllerDelegate
{
private var _server: WemoServer
private var _visualizationController: VisualizationViewController = VisualizationViewController()
private var _switchesController: SwitchesViewController = SwitchesViewController()
@@ -53,11 +54,13 @@ class MainViewController: UIViewController, SwitchesViewControllerDelegate {
super.viewDidLayoutSubviews()
let bounds = self.view.bounds
let horizontalSizeClass = self.traitCollection.horizontalSizeClass
let headerBounds = CGRect(
x: 0.0,
y: 0.0,
width: bounds.size.width,
height: rint(bounds.size.height / 10.0)
height: rint(bounds.size.height / 8.0)
)
let bodyBounds = CGRect(
x: 0.0,
@@ -76,10 +79,20 @@ class MainViewController: UIViewController, SwitchesViewControllerDelegate {
)
_visualizationController.view.frame = visualizationFrame
var switchesOriginX: CGFloat = 0.0
var switchesWidth: CGFloat = 0.0
if (horizontalSizeClass == .Regular) {
switchesOriginX = CGRectGetMaxX(visualizationFrame)
switchesWidth = bodyBounds.size.width - visualizationFrame.size.width
} else {
switchesOriginX = 0.0
switchesWidth = bodyBounds.size.width
}
let switchesControllerFrame = CGRect(
x: CGRectGetMaxX(visualizationFrame),
x: switchesOriginX,
y: bodyBounds.origin.y,
width: bodyBounds.size.width - visualizationFrame.size.width,
width: switchesWidth,
height: bodyBounds.size.height
)
_switchesController.view.frame = switchesControllerFrame
@@ -104,6 +117,12 @@ class MainViewController: UIViewController, SwitchesViewControllerDelegate {
}
}
override func viewWillTransitionToSize(size: CGSize, withTransitionCoordinator coordinator: UIViewControllerTransitionCoordinator)
{
super.viewWillTransitionToSize(size, withTransitionCoordinator: coordinator)
_updateSizeClassPresentation()
}
override func prefersStatusBarHidden() -> Bool
{
return true
@@ -133,6 +152,16 @@ class MainViewController: UIViewController, SwitchesViewControllerDelegate {
// MARK: Internal
internal func _updateSizeClassPresentation()
{
let horizontalSizeClass = self.traitCollection.horizontalSizeClass
if (horizontalSizeClass == .Regular) {
_visualizationController.view.hidden = false
} else {
_visualizationController.view.hidden = true
}
}
internal func _updateVisualization(animated: Bool)
{
var activatedDevicesCount = 0
@@ -152,6 +181,7 @@ class MainViewController: UIViewController, SwitchesViewControllerDelegate {
{
dispatch_async(dispatch_get_main_queue()) { () -> Void in
self._headerView.connectionStatusView.connectivityStatus = status
self._headerView.setNeedsLayout()
self._visualizationController.connectionStatus = status
}
}

View File

@@ -10,11 +10,13 @@ import Darwin
import Foundation
import UIKit
protocol SwitchesViewControllerDelegate: class {
protocol SwitchesViewControllerDelegate: class
{
func switchesViewControllerDidToggleDevices(controller: SwitchesViewController, devices: [WemoDevice])
}
extension SwitchesViewControllerDelegate {
extension SwitchesViewControllerDelegate
{
func switchesViewControllerDidToggleDevices(controller: SwitchesViewController, devices: [WemoDevice]) {}
}
@@ -30,9 +32,9 @@ class SwitchesViewController: UIViewController,
static private let collectionViewDeviceSwitchCellReuseIdentifier = "DeviceSwitchReuseID"
static private let collectionViewActionCellReuseIdentifier = "ActionCellReuseID"
static private let collectionViewCellsSpacing: CGFloat = 5.0
static private let collectionViewCellsPerRow = 3
private enum ActionCell: Int {
private enum ActionCell: Int
{
case AllOn
case AllOff
@@ -181,9 +183,20 @@ class SwitchesViewController: UIViewController,
sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize
{
let spacing = SwitchesViewController.collectionViewCellsSpacing
let cellsPerRow = CGFloat(SwitchesViewController.collectionViewCellsPerRow)
let dimensions = floor((collectionView.bounds.size.width / cellsPerRow) - ((spacing * (cellsPerRow - 1.0)) / cellsPerRow))
let bounds = collectionView.bounds
var cellsPerRow: CGFloat = 0.0
switch (self.traitCollection.horizontalSizeClass) {
case .Regular, .Compact where (bounds.size.width >= 400.0):
cellsPerRow = 3.0
break
case .Compact:
cellsPerRow = 2.0
default:
cellsPerRow = 2.0
}
let dimensions = floor((collectionView.bounds.size.width / cellsPerRow) - ((spacing * (cellsPerRow - 1.0)) / cellsPerRow))
if (indexPath.item < ActionCell.count) {
return CGSize(width: collectionView.bounds.size.width, height: rint(dimensions / 2.0))
} else {

View File

@@ -14,7 +14,8 @@ import UIKit
let π = CGFloat(M_PI)
class VisualizationViewController: UIViewController {
class VisualizationViewController: UIViewController
{
private var _scene: SCNScene = SCNScene()
private var _sceneView: SCNView?
private var _cameraNode: SCNNode = SCNNode()

View File

@@ -8,14 +8,16 @@
import Foundation
enum ConnectionStatus {
enum ConnectionStatus
{
case Disconnected
case Connecting
case Connected
case Error
}
class WemoServer {
class WemoServer
{
private(set) var baseURL: NSURL
private(set) var connected: Bool = false
@@ -108,7 +110,8 @@ class WemoServer {
}
}
internal class WemoOperation : NSOperation {
internal class WemoOperation : NSOperation
{
var baseURL: NSURL
var session: NSURLSession
@@ -121,7 +124,8 @@ internal class WemoOperation : NSOperation {
}
}
internal class ConnectOperation : WemoOperation {
internal class ConnectOperation : WemoOperation
{
override func main()
{
let semaphore = Semaphore(value: 0)
@@ -140,7 +144,8 @@ internal class ConnectOperation : WemoOperation {
}
}
internal class FetchDevicesOperation : WemoOperation {
internal class FetchDevicesOperation : WemoOperation
{
internal(set) var devices: [WemoDevice] = []
override func main()
@@ -176,7 +181,8 @@ internal class FetchDevicesOperation : WemoOperation {
}
}
internal class ToggleDeviceOperation : WemoOperation {
internal class ToggleDeviceOperation : WemoOperation
{
var device: WemoDevice
var state: WemoDevice.State