From 30699eddb735b449358514b6b5621858f68c2629 Mon Sep 17 00:00:00 2001 From: Robbie Trencheny Date: Fri, 6 Jan 2017 22:39:39 -0800 Subject: [PATCH] Swiftlint format --- HomeAssistant/AppDelegate.swift | 48 +-- HomeAssistant/Classes/Entity.swift | 6 +- .../Classes/HA API Responses/Bootstrap.swift | 6 +- .../Classes/HA API Responses/History.swift | 14 +- HomeAssistant/HAAPI.swift | 320 ++++++++--------- HomeAssistant/Views/AboutViewController.swift | 176 ++++----- .../Views/DevicesMapViewController.swift | 20 +- .../EntityAttributesViewController.swift | 98 ++--- HomeAssistant/Views/EurekaLocationRow.swift | 2 +- HomeAssistant/Views/GroupViewController.swift | 84 ++--- .../Views/RootTabBarViewController.swift | 56 +-- .../Views/SettingsDetailViewController.swift | 70 ++-- .../Views/SettingsViewController.swift | 340 +++++++++--------- .../NotificationViewController.swift | 12 +- 14 files changed, 626 insertions(+), 626 deletions(-) diff --git a/HomeAssistant/AppDelegate.swift b/HomeAssistant/AppDelegate.swift index 84fce8a28..363f5fcc4 100644 --- a/HomeAssistant/AppDelegate.swift +++ b/HomeAssistant/AppDelegate.swift @@ -61,22 +61,22 @@ class AppDelegate: UIResponder, UIApplicationDelegate { } firstly { HomeAssistantAPI.sharedInstance.Setup(baseAPIUrl: baseURL, APIPassword: apiPass) - }.then {_ in - HomeAssistantAPI.sharedInstance.Connect() - }.then { _ -> Void in - if HomeAssistantAPI.sharedInstance.notificationsEnabled { - UIApplication.shared.registerForRemoteNotifications() - } - print("Connected!") - return - }.catch {err -> Void in - print("ERROR", err) -// let settingsView = SettingsViewController() -// settingsView.title = "Settings" -// settingsView.showErrorConnectingMessage = true -// let navController = UINavigationController(rootViewController: settingsView) -// self.window?.makeKeyAndVisible() -// self.window?.rootViewController!.present(navController, animated: true, completion: nil) + }.then {_ in + HomeAssistantAPI.sharedInstance.Connect() + }.then { _ -> Void in + if HomeAssistantAPI.sharedInstance.notificationsEnabled { + UIApplication.shared.registerForRemoteNotifications() + } + print("Connected!") + return + }.catch {err -> Void in + print("ERROR", err) + // let settingsView = SettingsViewController() + // settingsView.title = "Settings" + // settingsView.showErrorConnectingMessage = true + // let navController = UINavigationController(rootViewController: settingsView) + // self.window?.makeKeyAndVisible() + // self.window?.rootViewController!.present(navController, animated: true, completion: nil) } } } @@ -138,10 +138,10 @@ class AppDelegate: UIResponder, UIApplicationDelegate { HomeAssistantAPI.sharedInstance.sendOneshotLocation().then { success -> Void in print("Did successfully send location when requested via APNS?", success) completionHandler(UIBackgroundFetchResult.noData) - }.catch {error in - print("Error when attempting to submit location update") - Crashlytics.sharedInstance().recordError((error as Any) as! NSError) - completionHandler(UIBackgroundFetchResult.failed) + }.catch {error in + print("Error when attempting to submit location update") + Crashlytics.sharedInstance().recordError((error as Any) as! NSError) + completionHandler(UIBackgroundFetchResult.failed) } default: print("Received unknown command via APNS!", userInfo) @@ -188,10 +188,10 @@ extension AppDelegate: UNUserNotificationCenterDelegate { } HomeAssistantAPI.sharedInstance.handlePushAction(identifier: response.actionIdentifier, userInfo: response.notification.request.content.userInfo, userInput: userText).then { _ in completionHandler() - }.catch { err -> Void in - print("Error: \(err)") - Crashlytics.sharedInstance().recordError(err) - completionHandler() + }.catch { err -> Void in + print("Error: \(err)") + Crashlytics.sharedInstance().recordError(err) + completionHandler() } } diff --git a/HomeAssistant/Classes/Entity.swift b/HomeAssistant/Classes/Entity.swift index 1d173e76f..6f1cf6d7c 100644 --- a/HomeAssistant/Classes/Entity.swift +++ b/HomeAssistant/Classes/Entity.swift @@ -48,7 +48,7 @@ class Entity: Object, StaticMappable { var UnitOfMeasurement: String? dynamic var LastChanged: Date? = nil dynamic var LastUpdated: Date? = nil -// let Groups = LinkingObjects(fromType: Group.self, property: "Entities") + // let Groups = LinkingObjects(fromType: Group.self, property: "Entities") // Z-Wave properties dynamic var Location: String? = nil @@ -130,8 +130,8 @@ class Entity: Object, StaticMappable { if let pic = self.Picture { HomeAssistantAPI.sharedInstance.getImage(imageUrl: pic).then { image -> Void in self.DownloadedPicture = image - }.catch { err -> Void in - print("Error when attempting to download image", err) + }.catch { err -> Void in + print("Error when attempting to download image", err) } } } diff --git a/HomeAssistant/Classes/HA API Responses/Bootstrap.swift b/HomeAssistant/Classes/HA API Responses/Bootstrap.swift index d0ced3962..8811a6f65 100644 --- a/HomeAssistant/Classes/HA API Responses/Bootstrap.swift +++ b/HomeAssistant/Classes/HA API Responses/Bootstrap.swift @@ -10,11 +10,11 @@ import Foundation //class BootstrapResponse: Mappable { // var Message: String? // var IsOK: Bool? -// +// // required init?(_ map: Map){ -// +// // } -// +// // func mapping(map: Map) { // Message <- map["message"] // IsOK <- (map["message"] == "API running.") diff --git a/HomeAssistant/Classes/HA API Responses/History.swift b/HomeAssistant/Classes/HA API Responses/History.swift index f23391bf3..e0aca9305 100644 --- a/HomeAssistant/Classes/HA API Responses/History.swift +++ b/HomeAssistant/Classes/HA API Responses/History.swift @@ -11,8 +11,8 @@ import ObjectMapper class HistoryResponse: Mappable { -// var EntityId: String? -// var Domain: String? + // var EntityId: String? + // var Domain: String? var Entities: [HistoryGroup]? required init?(map: Map) { @@ -22,9 +22,9 @@ class HistoryResponse: Mappable { func mapping(map: Map) { print("map", map) Entities <- map -// EntityId <- map["message"] -// Domain <- (map["message"] == "API running.") -// Events <- map[ + // EntityId <- map["message"] + // Domain <- (map["message"] == "API running.") + // Events <- map[ } } @@ -33,11 +33,11 @@ class HistoryGroup: Mappable { var Events: [Entity]? required init?(map: Map) { - print("MAP", map) + print("MAP", map) } func mapping(map: Map) { - print("map", map) + print("map", map) Events <- map // EntityId <- map["message"] // Domain <- (map["message"] == "API running.") diff --git a/HomeAssistant/HAAPI.swift b/HomeAssistant/HAAPI.swift index f05de0298..f74bb682a 100644 --- a/HomeAssistant/HAAPI.swift +++ b/HomeAssistant/HAAPI.swift @@ -121,13 +121,13 @@ public class HomeAssistantAPI { _ = self.identifyDevice() } -// self.GetHistory() + // self.GetHistory() self.startStream() fulfill(config) - }.catch {error in - print("Error at launch!", error) - Crashlytics.sharedInstance().recordError((error as Any) as! NSError) - reject(error) + }.catch {error in + print("Error at launch!", error) + Crashlytics.sharedInstance().recordError((error as Any) as! NSError) + reject(error) } } @@ -196,8 +196,8 @@ public class HomeAssistantAPI { self.CallService(domain: "device_tracker", service: "see", serviceData: locationUpdate as [String : Any]).then {_ in print("Device seen!") - }.catch {err in - Crashlytics.sharedInstance().recordError(err as NSError) + }.catch {err in + Crashlytics.sharedInstance().recordError(err as NSError) } UIDevice.current.isBatteryMonitoringEnabled = false @@ -208,20 +208,20 @@ public class HomeAssistantAPI { var shouldNotify = false switch updateType { - case .RegionEnter: - notificationBody = "\(zone!.Name) entered" - notificationIdentifer = "\(zone!.Name)_entered" - shouldNotify = zone!.enterNotification - case .RegionExit: - notificationBody = "\(zone!.Name) exited" - notificationIdentifer = "\(zone!.Name)_exited" - shouldNotify = zone!.exitNotification - case .SignificantLocationUpdate: - notificationBody = "Significant location change detected, notifying Home Assistant" - notificationIdentifer = "sig_change" - shouldNotify = true - default: - notificationBody = "" + case .RegionEnter: + notificationBody = "\(zone!.Name) entered" + notificationIdentifer = "\(zone!.Name)_entered" + shouldNotify = zone!.enterNotification + case .RegionExit: + notificationBody = "\(zone!.Name) exited" + notificationIdentifer = "\(zone!.Name)_exited" + shouldNotify = zone!.exitNotification + case .SignificantLocationUpdate: + notificationBody = "Significant location change detected, notifying Home Assistant" + notificationIdentifer = "sig_change" + shouldNotify = true + default: + notificationBody = "" } if shouldNotify { @@ -277,23 +277,23 @@ public class HomeAssistantAPI { } } -// let location = Location() - -// self.getBeacons().then { beacons -> Void in -// for beacon in beacons { -// print("Got beacon from HA", beacon.UUID, beacon.Major, beacon.Minor) -// try Beacons.monitorForBeacon(proximityUUID: beacon.UUID!, major: UInt16(beacon.Major!), minor: UInt16(beacon.Minor!), onFound: { beaconsFound in -// // beaconsFound is an array of found beacons ([CLBeacon]) but in this case it contains only one beacon -// print("beaconsFound", beaconsFound) -// }) { error in -// // something bad happened -// print("Error happened on beacons", error) -// } -// } -// }.catch {error in -// print("Error when getting beacons!", error) -// Crashlytics.sharedInstance().recordError((error as Any) as! NSError) -// } + // let location = Location() + + // self.getBeacons().then { beacons -> Void in + // for beacon in beacons { + // print("Got beacon from HA", beacon.UUID, beacon.Major, beacon.Minor) + // try Beacons.monitorForBeacon(proximityUUID: beacon.UUID!, major: UInt16(beacon.Major!), minor: UInt16(beacon.Minor!), onFound: { beaconsFound in + // // beaconsFound is an array of found beacons ([CLBeacon]) but in this case it contains only one beacon + // print("beaconsFound", beaconsFound) + // }) { error in + // // something bad happened + // print("Error happened on beacons", error) + // } + // } + // }.catch {error in + // print("Error when getting beacons!", error) + // Crashlytics.sharedInstance().recordError((error as Any) as! NSError) + // } } @@ -358,77 +358,77 @@ public class HomeAssistantAPI { } } -// func GetHistory() -> Promise { -// let queryUrl = baseAPIURL+"history/period?filter_entity_id=sensor.uberpool_time" -// return Promise { fulfill, reject in -// let _ = self.manager!.request(queryUrl, method: .get).validate().responseJSON { response in -// switch response.result { -// case .success: -// print("GOT HISTORY", queryUrl) -// let mapped = Mapper().map(response.result.value!) -// print("MAPPED", mapped) -// fulfill(mapped!) -// case .failure(let error): -// CLSLogv("Error on GetHistory() request: %@", getVaList([error.localizedDescription])) -// Crashlytics.sharedInstance().recordError(error) -// reject(error) -// } -// } -// } -// } + // func GetHistory() -> Promise { + // let queryUrl = baseAPIURL+"history/period?filter_entity_id=sensor.uberpool_time" + // return Promise { fulfill, reject in + // let _ = self.manager!.request(queryUrl, method: .get).validate().responseJSON { response in + // switch response.result { + // case .success: + // print("GOT HISTORY", queryUrl) + // let mapped = Mapper().map(response.result.value!) + // print("MAPPED", mapped) + // fulfill(mapped!) + // case .failure(let error): + // CLSLogv("Error on GetHistory() request: %@", getVaList([error.localizedDescription])) + // Crashlytics.sharedInstance().recordError(error) + // reject(error) + // } + // } + // } + // } func storeEntities(entities: [Entity]) { for entity in entities { try! realm.write { switch entity { - case is Automation: - realm.create(Automation.self, value: entity, update: true) - case is BinarySensor: - realm.create(BinarySensor.self, value: entity, update: true) - case is Climate: - realm.create(Climate.self, value: entity, update: true) - case is DeviceTracker: - realm.create(DeviceTracker.self, value: entity, update: true) - case is GarageDoor: - realm.create(GarageDoor.self, value: entity, update: true) - case is Group: - if let currentObject = realm.object(ofType: Group.self, forPrimaryKey: entity.ID as AnyObject) { - let group = entity as! Group - group.Order = currentObject.Order - realm.create(Group.self, value: entity, update: true) - } else { - realm.create(Group.self, value: entity, update: true) + case is Automation: + realm.create(Automation.self, value: entity, update: true) + case is BinarySensor: + realm.create(BinarySensor.self, value: entity, update: true) + case is Climate: + realm.create(Climate.self, value: entity, update: true) + case is DeviceTracker: + realm.create(DeviceTracker.self, value: entity, update: true) + case is GarageDoor: + realm.create(GarageDoor.self, value: entity, update: true) + case is Group: + if let currentObject = realm.object(ofType: Group.self, forPrimaryKey: entity.ID as AnyObject) { + let group = entity as! Group + group.Order = currentObject.Order + realm.create(Group.self, value: entity, update: true) + } else { + realm.create(Group.self, value: entity, update: true) } - case is Fan: - realm.create(Fan.self, value: entity, update: true) - case is InputBoolean: - realm.create(InputBoolean.self, value: entity, update: true) - case is InputSelect: - realm.create(InputSelect.self, value: entity, update: true) - case is Light: - realm.create(Light.self, value: entity, update: true) - case is Lock: - realm.create(Lock.self, value: entity, update: true) - case is MediaPlayer: - realm.create(MediaPlayer.self, value: entity, update: true) - case is Scene: - realm.create(Scene.self, value: entity, update: true) - case is Script: - realm.create(Script.self, value: entity, update: true) - case is Sensor: - realm.create(Sensor.self, value: entity, update: true) - case is Sun: - realm.create(Sun.self, value: entity, update: true) - case is Switch: - realm.create(Switch.self, value: entity, update: true) - case is Thermostat: - realm.create(Thermostat.self, value: entity, update: true) - case is Weblink: - realm.create(Weblink.self, value: entity, update: true) - case is Zone: - realm.create(Zone.self, value: entity, update: true) - default: - print("Unable to save \(entity.Domain)!") + case is Fan: + realm.create(Fan.self, value: entity, update: true) + case is InputBoolean: + realm.create(InputBoolean.self, value: entity, update: true) + case is InputSelect: + realm.create(InputSelect.self, value: entity, update: true) + case is Light: + realm.create(Light.self, value: entity, update: true) + case is Lock: + realm.create(Lock.self, value: entity, update: true) + case is MediaPlayer: + realm.create(MediaPlayer.self, value: entity, update: true) + case is Scene: + realm.create(Scene.self, value: entity, update: true) + case is Script: + realm.create(Script.self, value: entity, update: true) + case is Sensor: + realm.create(Sensor.self, value: entity, update: true) + case is Sun: + realm.create(Sun.self, value: entity, update: true) + case is Switch: + realm.create(Switch.self, value: entity, update: true) + case is Thermostat: + realm.create(Thermostat.self, value: entity, update: true) + case is Weblink: + realm.create(Weblink.self, value: entity, update: true) + case is Zone: + realm.create(Zone.self, value: entity, update: true) + default: + print("Unable to save \(entity.Domain)!") } realm.create(Entity.self, value: entity, update: true) } @@ -523,7 +523,7 @@ public class HomeAssistantAPI { } func CallService(domain: String, service: String, serviceData: [String:Any]) -> Promise<[ServicesResponse]> { -// self.showMurmur(title: domain+"/"+service+" called") + // self.showMurmur(title: domain+"/"+service+" called") let queryUrl = baseAPIURL+"services/"+domain+"/"+service return Promise { fulfill, reject in let _ = self.manager!.request(queryUrl, method: .post, parameters: serviceData, encoding: JSONEncoding.default).validate().responseArray { (response: DataResponse<[ServicesResponse]>) in @@ -806,18 +806,18 @@ public class HomeAssistantAPI { if #available(iOS 10, *) { self.setupUserNotificationPushActions().then { categories -> Void in UNUserNotificationCenter.current().setNotificationCategories(categories) - }.catch {error -> Void in - print("Error when attempting to setup push actions", error) - Crashlytics.sharedInstance().recordError((error as Any) as! NSError) + }.catch {error -> Void in + print("Error when attempting to setup push actions", error) + Crashlytics.sharedInstance().recordError((error as Any) as! NSError) } } else { self.setupPushActions().then { categories -> Void in let types: UIUserNotificationType = ([.alert, .badge, .sound]) let settings = UIUserNotificationSettings(types: types, categories: categories) UIApplication.shared.registerUserNotificationSettings(settings) - }.catch {error -> Void in - print("Error when attempting to setup push actions", error) - Crashlytics.sharedInstance().recordError((error as Any) as! NSError) + }.catch {error -> Void in + print("Error when attempting to setup push actions", error) + Crashlytics.sharedInstance().recordError((error as Any) as! NSError) } } } @@ -834,9 +834,9 @@ public class HomeAssistantAPI { } HomeAssistantAPI.sharedInstance.CreateEvent(eventType: "ios.notification_action_fired", eventData: eventData).then { _ in fulfill(true) - }.catch {error in - Crashlytics.sharedInstance().recordError((error as Any) as! NSError) - reject(error) + }.catch {error in + Crashlytics.sharedInstance().recordError((error as Any) as! NSError) + reject(error) } } } @@ -881,15 +881,15 @@ public class HomeAssistantAPI { } var locationEnabled: Bool { -// return PermissionScope().statusLocationAlways() == .authorized && self.loadedComponents.contains("device_tracker") + // return PermissionScope().statusLocationAlways() == .authorized && self.loadedComponents.contains("device_tracker") return PermissionScope().statusLocationAlways() == .authorized } var notificationsEnabled: Bool { -// return PermissionScope().statusNotifications() == .authorized && prefs.string(forKey: "pushID") != nil + // return PermissionScope().statusNotifications() == .authorized && prefs.string(forKey: "pushID") != nil return prefs.string(forKey: "pushID") != nil -// print("PermissionScope().statusNotifications()", PermissionScope().statusNotifications()) -// return PermissionScope().statusNotifications() == .authorized + // print("PermissionScope().statusNotifications()", PermissionScope().statusNotifications()) + // return PermissionScope().statusNotifications() == .authorized } var iosComponentLoaded: Bool { @@ -985,24 +985,24 @@ class BonjourDelegate: NSObject, NetServiceBrowserDelegate, NetServiceDelegate { resolvingDict.removeValue(forKey: netService.name) } -// func netServiceBrowser(netServiceBrowser: NetServiceBrowser, didFindDomain domainName: String, moreComing moreDomainsComing: Bool) { -// NSLog("BonjourDelegate.Browser.netServiceBrowser.didFindDomain") -// } -// func netServiceBrowser(netServiceBrowser: NetServiceBrowser, didRemoveDomain domainName: String, moreComing moreDomainsComing: Bool) { -// NSLog("BonjourDelegate.Browser.netServiceBrowser.didRemoveDomain") -// } -// func netServiceBrowserWillSearch(netServiceBrowser: NetServiceBrowser){ -// NSLog("BonjourDelegate.Browser.netServiceBrowserWillSearch") -// } -// func netServiceBrowser(netServiceBrowser: NetServiceBrowser, didNotSearch errorInfo: [String : NSNumber]) { -// NSLog("BonjourDelegate.Browser.netServiceBrowser.didNotSearch") -// } -// func netServiceBrowserDidStopSearch(netServiceBrowser: NetServiceBrowser) { -// NSLog("BonjourDelegate.Browser.netServiceBrowserDidStopSearch") -// } -// func netServiceWillPublish(sender: NetService) { -// NSLog("BonjourDelegate.Browser.netServiceWillPublish:\(sender)"); -// } + // func netServiceBrowser(netServiceBrowser: NetServiceBrowser, didFindDomain domainName: String, moreComing moreDomainsComing: Bool) { + // NSLog("BonjourDelegate.Browser.netServiceBrowser.didFindDomain") + // } + // func netServiceBrowser(netServiceBrowser: NetServiceBrowser, didRemoveDomain domainName: String, moreComing moreDomainsComing: Bool) { + // NSLog("BonjourDelegate.Browser.netServiceBrowser.didRemoveDomain") + // } + // func netServiceBrowserWillSearch(netServiceBrowser: NetServiceBrowser){ + // NSLog("BonjourDelegate.Browser.netServiceBrowserWillSearch") + // } + // func netServiceBrowser(netServiceBrowser: NetServiceBrowser, didNotSearch errorInfo: [String : NSNumber]) { + // NSLog("BonjourDelegate.Browser.netServiceBrowser.didNotSearch") + // } + // func netServiceBrowserDidStopSearch(netServiceBrowser: NetServiceBrowser) { + // NSLog("BonjourDelegate.Browser.netServiceBrowserDidStopSearch") + // } + // func netServiceWillPublish(sender: NetService) { + // NSLog("BonjourDelegate.Browser.netServiceWillPublish:\(sender)"); + // } private func DiscoveryInfoFromDict(locationName: String, netServiceDictionary: [String : Data]) -> DiscoveryInfoResponse { var outputDict: [String:Any] = [:] @@ -1016,29 +1016,29 @@ class BonjourDelegate: NSObject, NetServiceBrowserDelegate, NetServiceDelegate { return DiscoveryInfoResponse(JSON: outputDict)! } -// Publisher methods - -// func netService(sender: NetService, didNotPublish errorDict: [String : NSNumber]) { -// NSLog("BonjourDelegate.Publisher.didNotPublish:\(sender)"); -// } -// func netServiceDidPublish(sender: NetService) { -// NSLog("BonjourDelegate.Publisher.netServiceDidPublish:\(sender)"); -// } -// func netServiceWillResolve(sender: NetService) { -// NSLog("BonjourDelegate.Publisher.netServiceWillResolve:\(sender)"); -// } -// func netService(sender: NetService, didNotResolve errorDict: [String : NSNumber]) { -// NSLog("BonjourDelegate.Publisher.netServiceDidNotResolve:\(sender)"); -// } -// func netService(sender: NetService, didUpdateTXTRecordData data: NSData) { -// NSLog("BonjourDelegate.Publisher.netServiceDidUpdateTXTRecordData:\(sender)"); -// } -// func netServiceDidStop(sender: NetService) { -// NSLog("BonjourDelegate.Publisher.netServiceDidStopService:\(sender)"); -// } -// func netService(sender: NetService, didAcceptConnectionWithInputStream inputStream: NSInputStream, outputStream stream: NSOutputStream) { -// NSLog("BonjourDelegate.Publisher.netServiceDidAcceptConnection:\(sender)"); -// } + // Publisher methods + + // func netService(sender: NetService, didNotPublish errorDict: [String : NSNumber]) { + // NSLog("BonjourDelegate.Publisher.didNotPublish:\(sender)"); + // } + // func netServiceDidPublish(sender: NetService) { + // NSLog("BonjourDelegate.Publisher.netServiceDidPublish:\(sender)"); + // } + // func netServiceWillResolve(sender: NetService) { + // NSLog("BonjourDelegate.Publisher.netServiceWillResolve:\(sender)"); + // } + // func netService(sender: NetService, didNotResolve errorDict: [String : NSNumber]) { + // NSLog("BonjourDelegate.Publisher.netServiceDidNotResolve:\(sender)"); + // } + // func netService(sender: NetService, didUpdateTXTRecordData data: NSData) { + // NSLog("BonjourDelegate.Publisher.netServiceDidUpdateTXTRecordData:\(sender)"); + // } + // func netServiceDidStop(sender: NetService) { + // NSLog("BonjourDelegate.Publisher.netServiceDidStopService:\(sender)"); + // } + // func netService(sender: NetService, didAcceptConnectionWithInputStream inputStream: NSInputStream, outputStream stream: NSOutputStream) { + // NSLog("BonjourDelegate.Publisher.netServiceDidAcceptConnection:\(sender)"); + // } } @@ -1073,8 +1073,8 @@ class Bonjour { } func startPublish() { -// self.nsdel = BonjourDelegate() -// nsp.delegate = nsdel + // self.nsdel = BonjourDelegate() + // nsp.delegate = nsdel nsp.setTXTRecord(NetService.data(fromTXTRecord: buildPublishDict())) nsp.publish() } diff --git a/HomeAssistant/Views/AboutViewController.swift b/HomeAssistant/Views/AboutViewController.swift index 1a83d493e..7e5cf0798 100644 --- a/HomeAssistant/Views/AboutViewController.swift +++ b/HomeAssistant/Views/AboutViewController.swift @@ -33,91 +33,91 @@ class AboutViewController: FormViewController { +++ Section() <<< ButtonRow() { $0.title = "Website" - }.cellUpdate { cell, _ in - cell.textLabel?.textAlignment = .left - cell.accessoryType = .disclosureIndicator - cell.editingAccessoryType = cell.accessoryType - cell.textLabel?.textColor = nil - }.onCellSelection({ _ in - openURLInBrowser(url: "https://home-assistant.io/") - }) + }.cellUpdate { cell, _ in + cell.textLabel?.textAlignment = .left + cell.accessoryType = .disclosureIndicator + cell.editingAccessoryType = cell.accessoryType + cell.textLabel?.textColor = nil + }.onCellSelection({ _ in + openURLInBrowser(url: "https://home-assistant.io/") + }) <<< ButtonRow() { $0.title = "Forums" - }.cellUpdate { cell, _ in - cell.textLabel?.textAlignment = .left - cell.accessoryType = .disclosureIndicator - cell.editingAccessoryType = cell.accessoryType - cell.textLabel?.textColor = nil - }.onCellSelection({ _ in - openURLInBrowser(url: "https://community.home-assistant.io/") - }) + }.cellUpdate { cell, _ in + cell.textLabel?.textAlignment = .left + cell.accessoryType = .disclosureIndicator + cell.editingAccessoryType = cell.accessoryType + cell.textLabel?.textColor = nil + }.onCellSelection({ _ in + openURLInBrowser(url: "https://community.home-assistant.io/") + }) <<< ButtonRow() { $0.title = "Chat" - }.cellUpdate { cell, _ in - cell.textLabel?.textAlignment = .left - cell.accessoryType = .disclosureIndicator - cell.editingAccessoryType = cell.accessoryType - cell.textLabel?.textColor = nil - }.onCellSelection({ _ in - openURLInBrowser(url: "https://gitter.im/home-assistant/home-assistant") - }) + }.cellUpdate { cell, _ in + cell.textLabel?.textAlignment = .left + cell.accessoryType = .disclosureIndicator + cell.editingAccessoryType = cell.accessoryType + cell.textLabel?.textColor = nil + }.onCellSelection({ _ in + openURLInBrowser(url: "https://gitter.im/home-assistant/home-assistant") + }) <<< ButtonRow() { $0.title = "Documentation" - }.cellUpdate { cell, _ in - cell.textLabel?.textAlignment = .left - cell.accessoryType = .disclosureIndicator - cell.editingAccessoryType = cell.accessoryType - cell.textLabel?.textColor = nil - }.onCellSelection({ _ in - openURLInBrowser(url: "https://home-assistant.io/ecosystem/ios/") - }) + }.cellUpdate { cell, _ in + cell.textLabel?.textAlignment = .left + cell.accessoryType = .disclosureIndicator + cell.editingAccessoryType = cell.accessoryType + cell.textLabel?.textColor = nil + }.onCellSelection({ _ in + openURLInBrowser(url: "https://home-assistant.io/ecosystem/ios/") + }) <<< ButtonRow() { $0.title = "Home Assistant on Twitter" - }.cellUpdate { cell, _ in - cell.textLabel?.textAlignment = .left - cell.accessoryType = .disclosureIndicator - cell.editingAccessoryType = cell.accessoryType - cell.textLabel?.textColor = nil - }.onCellSelection({ _ in - self.openInTwitterApp(username: "home_assistant") - }) + }.cellUpdate { cell, _ in + cell.textLabel?.textAlignment = .left + cell.accessoryType = .disclosureIndicator + cell.editingAccessoryType = cell.accessoryType + cell.textLabel?.textColor = nil + }.onCellSelection({ _ in + self.openInTwitterApp(username: "home_assistant") + }) <<< ButtonRow() { $0.title = "Home Assistant on Facebook" - }.cellUpdate { cell, _ in - cell.textLabel?.textAlignment = .left - cell.accessoryType = .disclosureIndicator - cell.editingAccessoryType = cell.accessoryType - cell.textLabel?.textColor = nil - }.onCellSelection({ _ in - self.openInFacebook(pageId: "292963007723872") - }) + }.cellUpdate { cell, _ in + cell.textLabel?.textAlignment = .left + cell.accessoryType = .disclosureIndicator + cell.editingAccessoryType = cell.accessoryType + cell.textLabel?.textColor = nil + }.onCellSelection({ _ in + self.openInFacebook(pageId: "292963007723872") + }) <<< ButtonRow() { $0.title = "GitHub" - }.cellUpdate { cell, _ in - cell.textLabel?.textAlignment = .left - cell.accessoryType = .disclosureIndicator - cell.editingAccessoryType = cell.accessoryType - cell.textLabel?.textColor = nil - }.onCellSelection({ _ in - openURLInBrowser(url: "https://github.com/home-assistant/home-assistant-iOS") - }) + }.cellUpdate { cell, _ in + cell.textLabel?.textAlignment = .left + cell.accessoryType = .disclosureIndicator + cell.editingAccessoryType = cell.accessoryType + cell.textLabel?.textColor = nil + }.onCellSelection({ _ in + openURLInBrowser(url: "https://github.com/home-assistant/home-assistant-iOS") + }) <<< ButtonRow() { $0.title = "GitHub Issue Tracker" - }.cellUpdate { cell, _ in - cell.textLabel?.textAlignment = .left - cell.accessoryType = .disclosureIndicator - cell.editingAccessoryType = cell.accessoryType - cell.textLabel?.textColor = nil - }.onCellSelection({ _ in - openURLInBrowser(url: "https://github.com/home-assistant/home-assistant-iOS/issues") - }) + }.cellUpdate { cell, _ in + cell.textLabel?.textAlignment = .left + cell.accessoryType = .disclosureIndicator + cell.editingAccessoryType = cell.accessoryType + cell.textLabel?.textColor = nil + }.onCellSelection({ _ in + openURLInBrowser(url: "https://github.com/home-assistant/home-assistant-iOS/issues") + }) } @@ -128,7 +128,7 @@ class AboutViewController: FormViewController { /* // MARK: - Navigation - + // In a storyboard-based application, you will often want to do a little preparation before navigation override func prepare(for segue: UIStoryboardSegue, sender: Any?) { // Get the new view controller using segue.destinationViewController. @@ -137,11 +137,11 @@ class AboutViewController: FormViewController { */ func generateAcknowledgements() -> CPDAcknowledgementsViewController { -// let robbie = CPDContribution.init(name: "Robbie Trencheny", websiteAddress: "https://twitter.com/robbie", role: "Primary iOS developer") -// robbie.avatarAddress = "https://s.gravatar.com/avatar/04178c46aa6f009adba24b3e7ac64f14" -// let paulus = CPDContribution.init(name: "Paulus Schousten", websiteAddress: "https://twitter.com/balloob", role: "Home Assistant creator & BDFL") -// paulus.avatarAddress = "https://s.gravatar.com/avatar/dee932f2cb7ad0af8c5791217a085d35" -// let contributors = [robbie, paulus] + // let robbie = CPDContribution.init(name: "Robbie Trencheny", websiteAddress: "https://twitter.com/robbie", role: "Primary iOS developer") + // robbie.avatarAddress = "https://s.gravatar.com/avatar/04178c46aa6f009adba24b3e7ac64f14" + // let paulus = CPDContribution.init(name: "Paulus Schousten", websiteAddress: "https://twitter.com/balloob", role: "Home Assistant creator & BDFL") + // paulus.avatarAddress = "https://s.gravatar.com/avatar/dee932f2cb7ad0af8c5791217a085d35" + // let contributors = [robbie, paulus] return CPDAcknowledgementsViewController.init(style: nil, acknowledgements: nil, contributions: nil) } @@ -207,22 +207,22 @@ class HomeAssistantLogoView: UIView { super.init(coder: aDecoder) } -// override init(frame: CGRect) { -// super.init(frame: frame) -// let imageView = UIImageView(image: UIImage(named: "Logo")) -// imageView.frame = CGRect(x: 0, y: 0, width: 320, height: 130) -// imageView.autoresizingMask = .flexibleWidth -// self.frame = CGRect(x: 0, y: 0, width: 320, height: 130) -// imageView.contentMode = .scaleAspectFit -// self.addSubview(imageView) -// -// let descriptionLabel = UILabel(frame: CGRect(x: 0, y: 0, width: 250, height: 50)) -// descriptionLabel.textAlignment = .center -// descriptionLabel.text = "Awaken your home" -// self.addSubview(descriptionLabel) -// } -// -// required init?(coder aDecoder: NSCoder) { -// fatalError("init(coder:) has not been implemented") -// } + // override init(frame: CGRect) { + // super.init(frame: frame) + // let imageView = UIImageView(image: UIImage(named: "Logo")) + // imageView.frame = CGRect(x: 0, y: 0, width: 320, height: 130) + // imageView.autoresizingMask = .flexibleWidth + // self.frame = CGRect(x: 0, y: 0, width: 320, height: 130) + // imageView.contentMode = .scaleAspectFit + // self.addSubview(imageView) + // + // let descriptionLabel = UILabel(frame: CGRect(x: 0, y: 0, width: 250, height: 50)) + // descriptionLabel.textAlignment = .center + // descriptionLabel.text = "Awaken your home" + // self.addSubview(descriptionLabel) + // } + // + // required init?(coder aDecoder: NSCoder) { + // fatalError("init(coder:) has not been implemented") + // } } diff --git a/HomeAssistant/Views/DevicesMapViewController.swift b/HomeAssistant/Views/DevicesMapViewController.swift index 286ac2bb9..bffc1e207 100644 --- a/HomeAssistant/Views/DevicesMapViewController.swift +++ b/HomeAssistant/Views/DevicesMapViewController.swift @@ -59,7 +59,7 @@ class DevicesMapViewController: UIViewController, MKMapViewDelegate { let locateMeButton = MKUserTrackingBarButtonItem(mapView: mapView) let flexibleSpace = UIBarButtonItem(barButtonSystemItem: .flexibleSpace, target: self, action: nil) let segmentedControlButtonItem = UIBarButtonItem(customView: typeController) -// let bookmarksButton = UIBarButtonItem(barButtonSystemItem: .Bookmarks, target: self, action: nil) + // let bookmarksButton = UIBarButtonItem(barButtonSystemItem: .Bookmarks, target: self, action: nil) self.setToolbarItems([locateMeButton, flexibleSpace, segmentedControlButtonItem, flexibleSpace], animated: true) @@ -77,9 +77,9 @@ class DevicesMapViewController: UIViewController, MKMapViewDelegate { dropPin.coordinate = device.locationCoordinates() dropPin.title = device.Name var subtitlePieces: [String] = [] -// if let changedTime = device.LastChanged { -// subtitlePieces.append("Last seen: "+changedTime.toRelativeString(abbreviated: true, maxUnits: 1)!+" ago") -// } + // if let changedTime = device.LastChanged { + // subtitlePieces.append("Last seen: "+changedTime.toRelativeString(abbreviated: true, maxUnits: 1)!+" ago") + // } if let battery = device.Battery.value { subtitlePieces.append("Battery: "+String(battery)+"%") } @@ -139,7 +139,7 @@ class DevicesMapViewController: UIViewController, MKMapViewDelegate { } else { annotationView.leftCalloutAccessoryView = UIImageView(image: annotation.device!.EntityIcon) } -// annotationView.rightCalloutAccessoryView = UIButton(type: .DetailDisclosure) + // annotationView.rightCalloutAccessoryView = UIButton(type: .DetailDisclosure) return annotationView } else { return nil @@ -174,11 +174,11 @@ class DevicesMapViewController: UIViewController, MKMapViewDelegate { let alert = UIAlertController(title: "Location updated", message: "Successfully sent a one shot location to the server", preferredStyle: UIAlertControllerStyle.alert) alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler: nil)) self.present(alert, animated: true, completion: nil) - }.catch {error in - let nserror = error as NSError - let alert = UIAlertController(title: "Location failed to update", message: "Failed to send current location to server. The error was \(nserror.localizedDescription)", preferredStyle: UIAlertControllerStyle.alert) - alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler: nil)) - self.present(alert, animated: true, completion: nil) + }.catch {error in + let nserror = error as NSError + let alert = UIAlertController(title: "Location failed to update", message: "Failed to send current location to server. The error was \(nserror.localizedDescription)", preferredStyle: UIAlertControllerStyle.alert) + alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler: nil)) + self.present(alert, animated: true, completion: nil) } } } diff --git a/HomeAssistant/Views/EntityAttributesViewController.swift b/HomeAssistant/Views/EntityAttributesViewController.swift index 3ede9eaa3..e858125d4 100644 --- a/HomeAssistant/Views/EntityAttributesViewController.swift +++ b/HomeAssistant/Views/EntityAttributesViewController.swift @@ -29,27 +29,27 @@ class EntityAttributesViewController: FormViewController { $0.cell.textView.isScrollEnabled = false $0.cell.textView.backgroundColor = UIColor.clear $0.cell.backgroundColor = UIColor.clear - }.cellUpdate { cell, _ in - let _ = HomeAssistantAPI.sharedInstance.getImage(imageUrl: picture).then { image -> Void in - let attachment = NSTextAttachment() - attachment.image = image - attachment.bounds = CGRect(x: 0, y: 0, width: image.size.width, height: image.size.height) - let attString = NSAttributedString(attachment: attachment) - let result = NSMutableAttributedString(attributedString: attString) - - let paragraphStyle = NSMutableParagraphStyle() - paragraphStyle.alignment = .center - - let attrs: [String:AnyObject] = [NSParagraphStyleAttributeName: paragraphStyle] - let range = NSMakeRange(0, result.length) - result.addAttributes(attrs, range: range) - - cell.textView.textStorage.setAttributedString(result) - cell.height = { attachment.bounds.height + 20 } - self.tableView?.beginUpdates() - self.tableView?.endUpdates() - } - } + }.cellUpdate { cell, _ in + let _ = HomeAssistantAPI.sharedInstance.getImage(imageUrl: picture).then { image -> Void in + let attachment = NSTextAttachment() + attachment.image = image + attachment.bounds = CGRect(x: 0, y: 0, width: image.size.width, height: image.size.height) + let attString = NSAttributedString(attachment: attachment) + let result = NSMutableAttributedString(attributedString: attString) + + let paragraphStyle = NSMutableParagraphStyle() + paragraphStyle.alignment = .center + + let attrs: [String:AnyObject] = [NSParagraphStyleAttributeName: paragraphStyle] + let range = NSMakeRange(0, result.length) + result.addAttributes(attrs, range: range) + + cell.textView.textStorage.setAttributedString(result) + cell.height = { attachment.bounds.height + 20 } + self.tableView?.beginUpdates() + self.tableView?.endUpdates() + } + } } form +++ Section(header: "Attributes", footer: "") @@ -65,12 +65,12 @@ class EntityAttributesViewController: FormViewController { form.last! <<< SwitchRow(attribute.0) { $0.title = prettyLabel $0.value = thermostat.Fan - }.onChange { row -> Void in - if (row.value == true) { - thermostat.turnFanOn() - } else { - thermostat.turnFanOff() - } + }.onChange { row -> Void in + if (row.value == true) { + thermostat.turnFanOn() + } else { + thermostat.turnFanOff() + } } } break @@ -79,12 +79,12 @@ class EntityAttributesViewController: FormViewController { form.last! <<< SwitchRow(attribute.0) { $0.title = prettyLabel $0.value = thermostat.AwayMode - }.onChange { row -> Void in - if (row.value == true) { - thermostat.setAwayModeOn() - } else { - thermostat.setAwayModeOff() - } + }.onChange { row -> Void in + if (row.value == true) { + thermostat.setAwayModeOn() + } else { + thermostat.setAwayModeOff() + } } } break @@ -95,8 +95,8 @@ class EntityAttributesViewController: FormViewController { $0.value = Float(thermostat.Temperature!) $0.maximumValue = 120.0 $0.steps = 120 - }.onChange { row -> Void in - thermostat.setTemperature(row.value!) + }.onChange { row -> Void in + thermostat.setTemperature(row.value!) } } break @@ -114,12 +114,12 @@ class EntityAttributesViewController: FormViewController { form.last! <<< SwitchRow(attribute.0) { $0.title = "Mute" $0.value = mediaPlayer.IsVolumeMuted.value - }.onChange { row -> Void in - if (row.value == true) { - mediaPlayer.muteOn() - } else { - mediaPlayer.muteOff() - } + }.onChange { row -> Void in + if (row.value == true) { + mediaPlayer.muteOn() + } else { + mediaPlayer.muteOff() + } } } break @@ -131,8 +131,8 @@ class EntityAttributesViewController: FormViewController { $0.value = volume $0.maximumValue = 100 $0.steps = 100 - }.onChange { row -> Void in - mediaPlayer.setVolume(row.value!) + }.onChange { row -> Void in + mediaPlayer.setVolume(row.value!) } } break @@ -144,12 +144,12 @@ class EntityAttributesViewController: FormViewController { form.last! <<< SwitchRow(attribute.0) { $0.title = entity?.Name $0.value = (entity?.State == "on") ? true : false - }.onChange { row -> Void in - if (row.value == true) { - let _ = HomeAssistantAPI.sharedInstance.turnOn(entityId: entity!.ID) - } else { - let _ = HomeAssistantAPI.sharedInstance.turnOff(entityId: entity!.ID) - } + }.onChange { row -> Void in + if (row.value == true) { + let _ = HomeAssistantAPI.sharedInstance.turnOn(entityId: entity!.ID) + } else { + let _ = HomeAssistantAPI.sharedInstance.turnOff(entityId: entity!.ID) + } } } else { fallthrough diff --git a/HomeAssistant/Views/EurekaLocationRow.swift b/HomeAssistant/Views/EurekaLocationRow.swift index 34044dabe..7be587701 100644 --- a/HomeAssistant/Views/EurekaLocationRow.swift +++ b/HomeAssistant/Views/EurekaLocationRow.swift @@ -40,7 +40,7 @@ public class MapViewController: UIViewController, TypedRowControllerType, MKMapV let v = MKMapView(frame: self.view.bounds) v.autoresizingMask = UIViewAutoresizing.flexibleWidth.union(UIViewAutoresizing.flexibleHeight) return v - }() + }() required public init?(coder aDecoder: NSCoder) { super.init(coder: aDecoder) diff --git a/HomeAssistant/Views/GroupViewController.swift b/HomeAssistant/Views/GroupViewController.swift index ec64710c0..f31f26d2e 100644 --- a/HomeAssistant/Views/GroupViewController.swift +++ b/HomeAssistant/Views/GroupViewController.swift @@ -91,15 +91,15 @@ class GroupViewController: FormViewController { }, onDismiss: { vc in let _ = vc.navigationController?.popViewController(animated: true) }) - }.cellUpdate { cell, _ in - cell.detailTextLabel?.text = entity.State.capitalized - if let uom = entity.UnitOfMeasurement { - cell.detailTextLabel?.text = (entity.State.capitalized + " " + uom) - } - cell.imageView?.image = entity.EntityIcon - if let picture = entity.DownloadedPicture { - cell.imageView?.image = picture.scaledToSize(CGSize(width: 30, height: 30)) - } + }.cellUpdate { cell, _ in + cell.detailTextLabel?.text = entity.State.capitalized + if let uom = entity.UnitOfMeasurement { + cell.detailTextLabel?.text = (entity.State.capitalized + " " + uom) + } + cell.imageView?.image = entity.EntityIcon + if let picture = entity.DownloadedPicture { + cell.imageView?.image = picture.scaledToSize(CGSize(width: 30, height: 30)) + } } case "device_tracker": if let dtracker = realm.object(ofType: DeviceTracker.self, forPrimaryKey: entity.ID) { @@ -107,12 +107,12 @@ class GroupViewController: FormViewController { self.form.last! <<< LocationRow(entity.ID) { $0.title = entity.Name $0.value = dtracker.location() - }.cellUpdate { cell, _ in - cell.detailTextLabel?.text = entity.CleanedState - cell.imageView?.image = entity.EntityIcon - if let picture = entity.DownloadedPicture { - cell.imageView?.image = picture.scaledToSize(CGSize(width: 30, height: 30)) - } + }.cellUpdate { cell, _ in + cell.detailTextLabel?.text = entity.CleanedState + cell.imageView?.image = entity.EntityIcon + if let picture = entity.DownloadedPicture { + cell.imageView?.image = picture.scaledToSize(CGSize(width: 30, height: 30)) + } } } else { self.form.last! <<< ButtonRow(entity.ID) { @@ -154,19 +154,19 @@ class GroupViewController: FormViewController { } } } -// case "input_select": -// self.form.last! <<< PickerInlineRow(entity.ID) { -// $0.title = entity.Name -// $0.value = entity.State -// $0.options = entity.Attributes["options"] as! [String] -// }.onChange { row -> Void in -// let _ = HomeAssistantAPI.sharedInstance.CallService(domain: "input_select", service: "select_option", serviceData: ["entity_id": entity.ID as AnyObject, "option": row.value! as AnyObject]) -// }.cellUpdate { cell, row in -// cell.imageView?.image = entity.EntityIcon -// if let picture = entity.DownloadedPicture { -// cell.imageView?.image = picture.scaledToSize(CGSize(width: 30, height: 30)) -// } -// } + // case "input_select": + // self.form.last! <<< PickerInlineRow(entity.ID) { + // $0.title = entity.Name + // $0.value = entity.State + // $0.options = entity.Attributes["options"] as! [String] + // }.onChange { row -> Void in + // let _ = HomeAssistantAPI.sharedInstance.CallService(domain: "input_select", service: "select_option", serviceData: ["entity_id": entity.ID as AnyObject, "option": row.value! as AnyObject]) + // }.cellUpdate { cell, row in + // cell.imageView?.image = entity.EntityIcon + // if let picture = entity.DownloadedPicture { + // cell.imageView?.image = picture.scaledToSize(CGSize(width: 30, height: 30)) + // } + // } case "lock": self.form.last! <<< SwitchRow(entity.ID) { $0.title = entity.Name @@ -207,21 +207,21 @@ class GroupViewController: FormViewController { } } - }.onChange { row -> Void in - if let slider = entity as? InputSlider { - slider.SelectValue(row.value!) - } - }.cellUpdate { _, row in -// if let uom = entity.UnitOfMeasurement { -// cell.detailTextLabel?.text = (entity.State.capitalized + " " + uom) -// } - row.displayValueFor = { (_) in - if let uom = entity.UnitOfMeasurement { - return (entity.State.capitalized + " " + uom) - } else { - return entity.State.capitalized + }.onChange { row -> Void in + if let slider = entity as? InputSlider { + slider.SelectValue(row.value!) + } + }.cellUpdate { _, row in + // if let uom = entity.UnitOfMeasurement { + // cell.detailTextLabel?.text = (entity.State.capitalized + " " + uom) + // } + row.displayValueFor = { (_) in + if let uom = entity.UnitOfMeasurement { + return (entity.State.capitalized + " " + uom) + } else { + return entity.State.capitalized + } } - } } default: print("There is no row type defined for \(entity.Domain) so we are skipping it") diff --git a/HomeAssistant/Views/RootTabBarViewController.swift b/HomeAssistant/Views/RootTabBarViewController.swift index 04d710b04..44d7f0360 100644 --- a/HomeAssistant/Views/RootTabBarViewController.swift +++ b/HomeAssistant/Views/RootTabBarViewController.swift @@ -49,13 +49,13 @@ class RootTabBarViewController: UITabBarController, UITabBarControllerDelegate { let allGroups = realm.objects(Group.self).filter { var shouldReturn = true -// if prefs.bool(forKey: "allowAllGroups") == false { -// shouldReturn = (!$0.Auto && !$0.Hidden && $0.View) -// print("$0.Auto: \($0.Auto) !$0.Auto: \(!$0.Auto)") -// print("$0.Hidden: \($0.Hidden) !$0.Hidden: \(!$0.Hidden)") -// print("$0.View: \($0.View) !$0.View: \(!$0.View)") -// print("ShouldReturn is now", shouldReturn) -// } + // if prefs.bool(forKey: "allowAllGroups") == false { + // shouldReturn = (!$0.Auto && !$0.Hidden && $0.View) + // print("$0.Auto: \($0.Auto) !$0.Auto: \(!$0.Auto)") + // print("$0.Hidden: \($0.Hidden) !$0.Hidden: \(!$0.Hidden)") + // print("$0.View: \($0.View) !$0.View: \(!$0.View)") + // print("ShouldReturn is now", shouldReturn) + // } // If all entities are a group, return false var groupCheck = [String]() for entity in $0.Entities { @@ -66,16 +66,16 @@ class RootTabBarViewController: UITabBarController, UITabBarControllerDelegate { shouldReturn = false } return shouldReturn - }.sorted { - if $0.IsAllGroup == true { - return false - } else { - if $0.Order.value != nil && $1.Order.value != nil { - return $0.Order.value! < $1.Order.value! + }.sorted { + if $0.IsAllGroup == true { + return false } else { - return $0.FriendlyName! < $1.FriendlyName! + if $0.Order.value != nil && $1.Order.value != nil { + return $0.Order.value! < $1.Order.value! + } else { + return $0.FriendlyName! < $1.FriendlyName! + } } - } } for (index, group) in allGroups.enumerated() { if group.Entities.count < 1 { continue } @@ -188,22 +188,22 @@ class RootTabBarViewController: UITabBarController, UITabBarControllerDelegate { let alert = UIAlertController(title: "Location updated", message: "Successfully sent a one shot location to the server", preferredStyle: UIAlertControllerStyle.alert) alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler: nil)) self.present(alert, animated: true, completion: nil) - }.catch {error in - let nserror = error as NSError - let alert = UIAlertController(title: "Location failed to update", message: "Failed to send current location to server. The error was \(nserror.localizedDescription)", preferredStyle: UIAlertControllerStyle.alert) - alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler: nil)) - self.present(alert, animated: true, completion: nil) + }.catch {error in + let nserror = error as NSError + let alert = UIAlertController(title: "Location failed to update", message: "Failed to send current location to server. The error was \(nserror.localizedDescription)", preferredStyle: UIAlertControllerStyle.alert) + alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler: nil)) + self.present(alert, animated: true, completion: nil) } } /* - // MARK: - Navigation - - // In a storyboard-based application, you will often want to do a little preparation before navigation - override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { - // Get the new view controller using segue.destinationViewController. - // Pass the selected object to the new view controller. - } - */ + // MARK: - Navigation + + // In a storyboard-based application, you will often want to do a little preparation before navigation + override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { + // Get the new view controller using segue.destinationViewController. + // Pass the selected object to the new view controller. + } + */ } diff --git a/HomeAssistant/Views/SettingsDetailViewController.swift b/HomeAssistant/Views/SettingsDetailViewController.swift index 4f7584d56..69b5dd9b0 100644 --- a/HomeAssistant/Views/SettingsDetailViewController.swift +++ b/HomeAssistant/Views/SettingsDetailViewController.swift @@ -30,10 +30,10 @@ class SettingsDetailViewController: FormViewController { <<< SwitchRow("allowAllGroups") { $0.title = "Show all groups" $0.value = prefs.bool(forKey: "allowAllGroups") - }.onChange { row in - self.prefs.setValue(row.value, forKey: "allowAllGroups") - self.prefs.synchronize() - } + }.onChange { row in + self.prefs.setValue(row.value, forKey: "allowAllGroups") + self.prefs.synchronize() + } case "location": self.title = "Location Settings" for zone in realm.objects(Zone.self) { @@ -44,8 +44,8 @@ class SettingsDetailViewController: FormViewController { <<< SwitchRow() { $0.title = "Updates Enabled" $0.value = zone.trackingEnabled - }.onChange { row in - try! realm.write { zone.trackingEnabled = row.value! } + }.onChange { row in + try! realm.write { zone.trackingEnabled = row.value! } } <<< LocationRow() { $0.title = "Location" @@ -58,15 +58,15 @@ class SettingsDetailViewController: FormViewController { <<< SwitchRow() { $0.title = "Enter Notification" $0.value = zone.enterNotification - }.onChange { row in - try! realm.write { zone.enterNotification = row.value! } + }.onChange { row in + try! realm.write { zone.enterNotification = row.value! } } <<< SwitchRow() { $0.title = "Exit Notification" $0.value = zone.exitNotification - }.onChange { row in - try! realm.write { zone.exitNotification = row.value! } - } + }.onChange { row in + try! realm.write { zone.exitNotification = row.value! } + } } case "notifications": self.title = "Notification Settings" @@ -81,41 +81,41 @@ class SettingsDetailViewController: FormViewController { } $0.disabled = true $0.textAreaHeight = TextAreaHeight.dynamic(initialTextViewHeight: 40) - }.onCellSelection { _, row in - let activityViewController = UIActivityViewController(activityItems: [row.value! as String], applicationActivities: nil) - self.present(activityViewController, animated: true, completion: {}) + }.onCellSelection { _, row in + let activityViewController = UIActivityViewController(activityItems: [row.value! as String], applicationActivities: nil) + self.present(activityViewController, animated: true, completion: {}) } +++ Section(header: "", footer: "Updating push settings will request the latest push actions and categories from Home Assistant.") <<< ButtonRow() { $0.title = "Update push settings" - }.onCellSelection {_, _ in - HomeAssistantAPI.sharedInstance.setupPush() - let alert = UIAlertController(title: "Settings Import", message: "Push settings imported from Home Assistant.", preferredStyle: UIAlertControllerStyle.alert) - alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler: nil)) - self.present(alert, animated: true, completion: nil) + }.onCellSelection {_, _ in + HomeAssistantAPI.sharedInstance.setupPush() + let alert = UIAlertController(title: "Settings Import", message: "Push settings imported from Home Assistant.", preferredStyle: UIAlertControllerStyle.alert) + alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler: nil)) + self.present(alert, animated: true, completion: nil) } +++ Section(header: "", footer: "Custom push notification sounds can be added via iTunes.") <<< ButtonRow() { $0.title = "Import sounds from iTunes" - }.onCellSelection {_, _ in - let moved = movePushNotificationSounds() - let message = (moved > 0) ? "\(moved) sounds were imported. Please restart your phone to complete the import." : "0 sounds were imported." - let alert = UIAlertController(title: "Sounds Import", message: message, preferredStyle: UIAlertControllerStyle.alert) - alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler: nil)) - self.present(alert, animated: true, completion: nil) - } + }.onCellSelection {_, _ in + let moved = movePushNotificationSounds() + let message = (moved > 0) ? "\(moved) sounds were imported. Please restart your phone to complete the import." : "0 sounds were imported." + let alert = UIAlertController(title: "Sounds Import", message: message, preferredStyle: UIAlertControllerStyle.alert) + alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler: nil)) + self.present(alert, animated: true, completion: nil) + } -// <<< ButtonRow() { -// $0.title = "Import system sounds" -// }.onCellSelection {_,_ in -// let list = getSoundList() -// print("system sounds list", list) -// for sound in list { -// copyFileToDirectory(sound) -// } -// } + // <<< ButtonRow() { + // $0.title = "Import system sounds" + // }.onCellSelection {_,_ in + // let list = getSoundList() + // print("system sounds list", list) + // for sound in list { + // copyFileToDirectory(sound) + // } + // } default: print("Something went wrong, no settings detail group named \(detailGroup)") } diff --git a/HomeAssistant/Views/SettingsViewController.swift b/HomeAssistant/Views/SettingsViewController.swift index 76a064aee..ec96ed054 100644 --- a/HomeAssistant/Views/SettingsViewController.swift +++ b/HomeAssistant/Views/SettingsViewController.swift @@ -93,29 +93,29 @@ class SettingsViewController: FormViewController { $0.value = self.baseURL $0.placeholder = "https://homeassistant.myhouse.com" $0.disabled = Condition(booleanLiteral: (self.configured && showErrorConnectingMessage == false)) - }.onChange { row in - if row.value == URL(string: "https://") { return } - let apiPasswordRow: PasswordRow = self.form.rowBy(tag: "apiPassword")! - apiPasswordRow.value = "" - if let url = row.value { - let cleanUrl = HomeAssistantAPI.sharedInstance.CleanBaseURL(baseUrl: url) - if !cleanUrl.hasValidScheme { - let alert = UIAlertController(title: "Invalid URL", message: "The URL must begin with either http:// or https://.", preferredStyle: UIAlertControllerStyle.alert) - alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler: nil)) - self.present(alert, animated: true, completion: nil) - } else { - self.baseURL = cleanUrl.cleanedURL + }.onChange { row in + if row.value == URL(string: "https://") { return } + let apiPasswordRow: PasswordRow = self.form.rowBy(tag: "apiPassword")! + apiPasswordRow.value = "" + if let url = row.value { + let cleanUrl = HomeAssistantAPI.sharedInstance.CleanBaseURL(baseUrl: url) + if !cleanUrl.hasValidScheme { + let alert = UIAlertController(title: "Invalid URL", message: "The URL must begin with either http:// or https://.", preferredStyle: UIAlertControllerStyle.alert) + alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler: nil)) + self.present(alert, animated: true, completion: nil) + } else { + self.baseURL = cleanUrl.cleanedURL + } } - } - }.cellUpdate { cell, row in - if row.isHighlighted { - row.value = URL(string: "https://") - } else { - if row.value == URL(string: "https://") { - row.value = nil - cell.update() + }.cellUpdate { cell, row in + if row.isHighlighted { + row.value = URL(string: "https://") + } else { + if row.value == URL(string: "https://") { + row.value = nil + cell.update() + } } - } } <<< PasswordRow("apiPassword") { @@ -124,85 +124,85 @@ class SettingsViewController: FormViewController { $0.disabled = Condition(booleanLiteral: self.configured && showErrorConnectingMessage == false) $0.hidden = Condition(booleanLiteral: self.connectStep == 1) $0.placeholder = "password" - }.onChange { row in - self.password = row.value + }.onChange { row in + self.password = row.value } <<< ButtonRow("connect") { $0.title = "Connect" $0.hidden = Condition(booleanLiteral: self.configured) - }.onCellSelection { _, row in - if self.connectStep == 1 { - if let url = self.baseURL { - HomeAssistantAPI.sharedInstance.GetDiscoveryInfo(baseUrl: url).then { discoveryInfo -> Void in - let urlRow: URLRow = self.form.rowBy(tag: "baseURL")! - urlRow.disabled = true - urlRow.evaluateDisabled() - let apiPasswordRow: PasswordRow = self.form.rowBy(tag: "apiPassword")! - apiPasswordRow.value = "" - apiPasswordRow.hidden = Condition(booleanLiteral: !discoveryInfo.RequiresPassword) - apiPasswordRow.evaluateHidden() - let discoverySection: Section = self.form.sectionBy(tag: "discoveredInstances")! - discoverySection.hidden = true - discoverySection.evaluateHidden() - self.connectStep = 2 - }.catch { error in - print("Hit error when attempting to get discovery information", error) - let alert = UIAlertController(title: "Error during connection attempt", message: "\(error.localizedDescription)\r\n\r\nPlease try again.", preferredStyle: UIAlertControllerStyle.alert) - alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler: nil)) - self.present(alert, animated: true, completion: nil) - } - } - } else if self.connectStep == 2 { - firstly { - HomeAssistantAPI.sharedInstance.Setup(baseAPIUrl: self.baseURL!.absoluteString, APIPassword: self.password!) - }.then {_ in - HomeAssistantAPI.sharedInstance.Connect() - }.then { config -> Void in - print("Connected!") - let apiPasswordRow: PasswordRow = self.form.rowBy(tag: "apiPassword")! - apiPasswordRow.disabled = true - apiPasswordRow.evaluateDisabled() - self.connectStep = 1 - row.hidden = true - row.evaluateHidden() + }.onCellSelection { _, row in + if self.connectStep == 1 { if let url = self.baseURL { - self.prefs.setValue(url.absoluteString, forKey: "baseURL") - } - if let password = self.password { - self.prefs.setValue(password, forKey: "apiPassword") - } - self.prefs.synchronize() - self.form.setValues(["locationName": config.LocationName, "version": config.Version]) - let locationNameRow: LabelRow = self.form.rowBy(tag: "locationName")! - locationNameRow.updateCell() - let versionRow: LabelRow = self.form.rowBy(tag: "version")! - versionRow.updateCell() - let statusSection: Section = self.form.sectionBy(tag: "status")! - statusSection.hidden = false - statusSection.evaluateHidden() - let detailsSection: Section = self.form.sectionBy(tag: "details")! - detailsSection.hidden = false - detailsSection.evaluateHidden() - let resetSection: Section = self.form.sectionBy(tag: "reset")! - resetSection.hidden = false - resetSection.evaluateHidden() - let alert = UIAlertController(title: "Connected", message: "Please force quit and re-open the app to continue.", preferredStyle: UIAlertControllerStyle.alert) - alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler: nil)) - self.present(alert, animated: true, completion: nil) - }.catch { error in - print("Connection error!", error) - var errorMessage = error.localizedDescription - if let error = error as? AFError { - if error.responseCode == 401 { - errorMessage = "The password was incorrect." + HomeAssistantAPI.sharedInstance.GetDiscoveryInfo(baseUrl: url).then { discoveryInfo -> Void in + let urlRow: URLRow = self.form.rowBy(tag: "baseURL")! + urlRow.disabled = true + urlRow.evaluateDisabled() + let apiPasswordRow: PasswordRow = self.form.rowBy(tag: "apiPassword")! + apiPasswordRow.value = "" + apiPasswordRow.hidden = Condition(booleanLiteral: !discoveryInfo.RequiresPassword) + apiPasswordRow.evaluateHidden() + let discoverySection: Section = self.form.sectionBy(tag: "discoveredInstances")! + discoverySection.hidden = true + discoverySection.evaluateHidden() + self.connectStep = 2 + }.catch { error in + print("Hit error when attempting to get discovery information", error) + let alert = UIAlertController(title: "Error during connection attempt", message: "\(error.localizedDescription)\r\n\r\nPlease try again.", preferredStyle: UIAlertControllerStyle.alert) + alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler: nil)) + self.present(alert, animated: true, completion: nil) } } - let alert = UIAlertController(title: "Error during connection with authentication attempt", message: "\(errorMessage)\r\n\r\nPlease try again.", preferredStyle: UIAlertControllerStyle.alert) - alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler: nil)) - self.present(alert, animated: true, completion: nil) + } else if self.connectStep == 2 { + firstly { + HomeAssistantAPI.sharedInstance.Setup(baseAPIUrl: self.baseURL!.absoluteString, APIPassword: self.password!) + }.then {_ in + HomeAssistantAPI.sharedInstance.Connect() + }.then { config -> Void in + print("Connected!") + let apiPasswordRow: PasswordRow = self.form.rowBy(tag: "apiPassword")! + apiPasswordRow.disabled = true + apiPasswordRow.evaluateDisabled() + self.connectStep = 1 + row.hidden = true + row.evaluateHidden() + if let url = self.baseURL { + self.prefs.setValue(url.absoluteString, forKey: "baseURL") + } + if let password = self.password { + self.prefs.setValue(password, forKey: "apiPassword") + } + self.prefs.synchronize() + self.form.setValues(["locationName": config.LocationName, "version": config.Version]) + let locationNameRow: LabelRow = self.form.rowBy(tag: "locationName")! + locationNameRow.updateCell() + let versionRow: LabelRow = self.form.rowBy(tag: "version")! + versionRow.updateCell() + let statusSection: Section = self.form.sectionBy(tag: "status")! + statusSection.hidden = false + statusSection.evaluateHidden() + let detailsSection: Section = self.form.sectionBy(tag: "details")! + detailsSection.hidden = false + detailsSection.evaluateHidden() + let resetSection: Section = self.form.sectionBy(tag: "reset")! + resetSection.hidden = false + resetSection.evaluateHidden() + let alert = UIAlertController(title: "Connected", message: "Please force quit and re-open the app to continue.", preferredStyle: UIAlertControllerStyle.alert) + alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler: nil)) + self.present(alert, animated: true, completion: nil) + }.catch { error in + print("Connection error!", error) + var errorMessage = error.localizedDescription + if let error = error as? AFError { + if error.responseCode == 401 { + errorMessage = "The password was incorrect." + } + } + let alert = UIAlertController(title: "Error during connection with authentication attempt", message: "\(errorMessage)\r\n\r\nPlease try again.", preferredStyle: UIAlertControllerStyle.alert) + alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler: nil)) + self.present(alert, animated: true, completion: nil) + } } - } } +++ Section(header: "Status", footer: "") { @@ -251,53 +251,53 @@ class SettingsViewController: FormViewController { $0.value = removeSpecialCharsFromString(text: UIDevice.current.name).replacingOccurrences(of: " ", with: "_").lowercased() } $0.cell.textField.autocapitalizationType = .none - }.cellUpdate { _, row in - if row.isHighlighted == false { - self.prefs.setValue(row.value, forKey: "deviceId") - self.prefs.synchronize() - } + }.cellUpdate { _, row in + if row.isHighlighted == false { + self.prefs.setValue(row.value, forKey: "deviceId") + self.prefs.synchronize() + } } +++ Section() { $0.tag = "details" $0.hidden = Condition(booleanLiteral: !self.configured) } -// <<< ButtonRow("displaySettings") { -// $0.title = "Display Settings" -// $0.presentationMode = .show(controllerProvider: ControllerProvider.callback { -// let view = SettingsDetailViewController() -// view.detailGroup = "display" -// return view -// }, onDismiss: { vc in -// let _ = vc.navigationController?.popViewController(animated: true) -// }) -// } + // <<< ButtonRow("displaySettings") { + // $0.title = "Display Settings" + // $0.presentationMode = .show(controllerProvider: ControllerProvider.callback { + // let view = SettingsDetailViewController() + // view.detailGroup = "display" + // return view + // }, onDismiss: { vc in + // let _ = vc.navigationController?.popViewController(animated: true) + // }) + // } <<< ButtonRow("enableLocation") { $0.title = "Enable location tracking" $0.hidden = Condition(booleanLiteral: HomeAssistantAPI.sharedInstance.locationEnabled) - }.onCellSelection { _, row in - let pscope = PermissionScope() - - pscope.addPermission(LocationAlwaysPermission(), - message: "We use this to inform\r\nHome Assistant of your device location and state.") - pscope.show({finished, results in - if finished { - print("Location Permissions finished!", finished, results) - if results[0].status == .authorized { - HomeAssistantAPI.sharedInstance.trackLocation() + }.onCellSelection { _, row in + let pscope = PermissionScope() + + pscope.addPermission(LocationAlwaysPermission(), + message: "We use this to inform\r\nHome Assistant of your device location and state.") + pscope.show({finished, results in + if finished { + print("Location Permissions finished!", finished, results) + if results[0].status == .authorized { + HomeAssistantAPI.sharedInstance.trackLocation() + } + row.hidden = true + row.evaluateHidden() + let locationSettingsRow: ButtonRow = self.form.rowBy(tag: "locationSettings")! + locationSettingsRow.hidden = false + locationSettingsRow.evaluateHidden() + let deviceTrackerComponentLoadedRow: LabelRow = self.form.rowBy(tag: "deviceTrackerComponentLoaded")! + deviceTrackerComponentLoadedRow.hidden = false + deviceTrackerComponentLoadedRow.evaluateHidden() } - row.hidden = true - row.evaluateHidden() - let locationSettingsRow: ButtonRow = self.form.rowBy(tag: "locationSettings")! - locationSettingsRow.hidden = false - locationSettingsRow.evaluateHidden() - let deviceTrackerComponentLoadedRow: LabelRow = self.form.rowBy(tag: "deviceTrackerComponentLoaded")! - deviceTrackerComponentLoadedRow.hidden = false - deviceTrackerComponentLoadedRow.evaluateHidden() - } - }, cancelled: { (results) -> Void in - print("Permissions finished, resetting API!") - }) + }, cancelled: { (results) -> Void in + print("Permissions finished, resetting API!") + }) } <<< ButtonRow("locationSettings") { @@ -307,37 +307,37 @@ class SettingsViewController: FormViewController { let view = SettingsDetailViewController() view.detailGroup = "location" return view - }, onDismiss: { vc in - let _ = vc.navigationController?.popViewController(animated: true) + }, onDismiss: { vc in + let _ = vc.navigationController?.popViewController(animated: true) }) } <<< ButtonRow("enableNotifications") { $0.title = "Enable notifications" $0.hidden = Condition(booleanLiteral: HomeAssistantAPI.sharedInstance.notificationsEnabled) - }.onCellSelection { _, row in - let pscope = PermissionScope() - - pscope.addPermission(NotificationsPermission(), - message: "We use this to let you\r\nsend notifications to your device.") - pscope.show({finished, results in - if finished { - print("Notifications Permissions finished!", finished, results) - if results[0].status == .authorized { - HomeAssistantAPI.sharedInstance.setupPush() - row.hidden = true - row.evaluateHidden() - let notificationSettingsRow: ButtonRow = self.form.rowBy(tag: "notificationSettings")! - notificationSettingsRow.hidden = false - notificationSettingsRow.evaluateHidden() - let notifyPlatformLoadedRow: LabelRow = self.form.rowBy(tag: "notifyPlatformLoaded")! - notifyPlatformLoadedRow.hidden = false - notifyPlatformLoadedRow.evaluateHidden() + }.onCellSelection { _, row in + let pscope = PermissionScope() + + pscope.addPermission(NotificationsPermission(), + message: "We use this to let you\r\nsend notifications to your device.") + pscope.show({finished, results in + if finished { + print("Notifications Permissions finished!", finished, results) + if results[0].status == .authorized { + HomeAssistantAPI.sharedInstance.setupPush() + row.hidden = true + row.evaluateHidden() + let notificationSettingsRow: ButtonRow = self.form.rowBy(tag: "notificationSettings")! + notificationSettingsRow.hidden = false + notificationSettingsRow.evaluateHidden() + let notifyPlatformLoadedRow: LabelRow = self.form.rowBy(tag: "notifyPlatformLoaded")! + notifyPlatformLoadedRow.hidden = false + notifyPlatformLoadedRow.evaluateHidden() + } } - } - }, cancelled: { (results) -> Void in - print("Permissions finished, resetting API!") - }) + }, cancelled: { (results) -> Void in + print("Permissions finished, resetting API!") + }) } <<< ButtonRow("notificationSettings") { @@ -348,8 +348,8 @@ class SettingsViewController: FormViewController { let view = SettingsDetailViewController() view.detailGroup = "notifications" return view - }, onDismiss: { vc in - let _ = vc.navigationController?.popViewController(animated: true) + }, onDismiss: { vc in + let _ = vc.navigationController?.popViewController(animated: true) }) } @@ -359,22 +359,22 @@ class SettingsViewController: FormViewController { } <<< ButtonRow("resetApp") { $0.title = "Reset" - }.cellUpdate { cell, _ in - cell.textLabel?.textColor = .red - }.onCellSelection { _, _ in - let alert = UIAlertController(title: "Reset", message: "Your settings will be reset and this device will be unregistered from push notifications as well as removed from your Home Assistant configuration.", preferredStyle: UIAlertControllerStyle.alert) + }.cellUpdate { cell, _ in + cell.textLabel?.textColor = .red + }.onCellSelection { _, _ in + let alert = UIAlertController(title: "Reset", message: "Your settings will be reset and this device will be unregistered from push notifications as well as removed from your Home Assistant configuration.", preferredStyle: UIAlertControllerStyle.alert) - alert.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: { (_) in - print("Handle Cancel Logic here") - })) + alert.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: { (_) in + print("Handle Cancel Logic here") + })) - alert.addAction(UIAlertAction(title: "Reset", style: .destructive, handler: { (_) in - print("Handle Ok logic here") - self.ResetApp() - })) + alert.addAction(UIAlertAction(title: "Reset", style: .destructive, handler: { (_) in + print("Handle Ok logic here") + self.ResetApp() + })) - self.present(alert, animated: true, completion: nil) - } + self.present(alert, animated: true, completion: nil) + } } override func didReceiveMemoryWarning() { @@ -393,8 +393,8 @@ class SettingsViewController: FormViewController { if self.form.rowBy(tag: discoveryInfo.LocationName) == nil { discoverySection <<< ButtonRow(discoveryInfo.LocationName) { - $0.title = discoveryInfo.LocationName - $0.cellStyle = UITableViewCellStyle.subtitle + $0.title = discoveryInfo.LocationName + $0.cellStyle = UITableViewCellStyle.subtitle }.cellUpdate { cell, _ in cell.textLabel?.textColor = .black cell.detailTextLabel?.text = detailTextLabel @@ -547,6 +547,6 @@ class SettingsViewController: FormViewController { let navController = UINavigationController(rootViewController: aboutView) self.show(navController, sender: nil) -// self.present(navController, animated: true, completion: nil) + // self.present(navController, animated: true, completion: nil) } } diff --git a/NotificationContentExtension/NotificationViewController.swift b/NotificationContentExtension/NotificationViewController.swift index 7d52d6650..7a5238315 100644 --- a/NotificationContentExtension/NotificationViewController.swift +++ b/NotificationContentExtension/NotificationViewController.swift @@ -40,12 +40,12 @@ class NotificationViewController: UIViewController, UNNotificationContentExtensi hud.offset = CGPoint(x: 0, y: -MBProgressMaxOffset+50) self.hud = hud switch (notification.request.content.categoryIdentifier) { - case "map": - mapHandler(notification) - case "camera": - cameraHandler(notification) - default: - return + case "map": + mapHandler(notification) + case "camera": + cameraHandler(notification) + default: + return } }