Skip to content

Commit

Permalink
Merge pull request #12 from someoneAnyone/convert-to-framework
Browse files Browse the repository at this point in the history
Convert to framework
  • Loading branch information
someoneAnyone committed Aug 19, 2015
2 parents 9c0fbd4 + d42aef9 commit 9b11207
Show file tree
Hide file tree
Showing 52 changed files with 1,940 additions and 981 deletions.
581 changes: 482 additions & 99 deletions Nightscouter.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEWorkspaceSharedSettings_AutocreateContextsIfNeeded</key>
<true/>
</dict>
</plist>
61 changes: 20 additions & 41 deletions Nightscouter/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//

import UIKit
import NightscouterKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
Expand All @@ -25,10 +26,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
// println(">>> Entering \(__FUNCTION__) <<<")
// Override point for customization after application launch.

application.setMinimumBackgroundFetchInterval(UIApplicationBackgroundFetchIntervalMinimum)
application.applicationIconBadgeNumber = 0
application.cancelAllLocalNotifications()

setupNotificationSettings() // Need to move this to when the user adds a server valid to the array.

AppThemeManager.themeApp
Expand All @@ -41,7 +38,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
// println(">>> Entering \(__FUNCTION__) <<<")
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.

self.timer?.invalidate()
}

Expand Down Expand Up @@ -84,10 +80,8 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
for notification in UIApplication.sharedApplication().scheduledLocalNotifications as! [UILocalNotification] { // loop through notifications...
if (notification.userInfo![Site.PropertyKey.uuidKey] as! String == site.uuid) { // ...and cancel the notification that corresponds to this TodoItem instance (matched by UUID)
UIApplication.sharedApplication().cancelLocalNotification(notification) // there should be a maximum of one match on UUID
break
}
}


nsApi.fetchServerConfiguration { (result) -> Void in
switch (result) {
Expand All @@ -100,20 +94,8 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
nsApi.fetchDataForWatchEntry({ (watchEntry, errorCode) -> Void in
site.configuration = configuration
site.watchEntry = watchEntry

if let defaults = configuration.defaults {
// don't push a notification if the data is stale. Probably needs to be refactored.
let timeFrame = site.watchEntry?.date.timeIntervalSinceNow
let timeLimit = max(Constants.NotableTime.StaleDataTimeFrame, defaults.alarms.alarmTimeAgoWarnMins)

if ( timeFrame < -timeLimit) {
} else {
// TODO: Add some bg threshold checks here.
if site.watchEntry?.bgdelta != 0 {
self.scheduleLocalNotification(site)
}
}
}
AppDataManager.sharedInstance.updateSite(site)
self.scheduleLocalNotification(site)
})
}
}
Expand Down Expand Up @@ -147,32 +129,27 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
if let userInfoDict : [NSObject : AnyObject] = notification.userInfo {
if let uuidString = userInfoDict[Site.PropertyKey.uuidKey] as? String {
let uuid = NSUUID(UUIDString: uuidString) // Get the uuid from the notification.
// let site = sites.filter{ $0.uuid == uuid }.first // Use the uuid value to get the site object from the array.
// let siteIndex = find(sites, site!) // Use the site object to get its index position in the array.

// site?.notifications.removeAtIndex(find(site!.notifications, notification)!)


// println("User tapped on notification for site: \(site) at index \(siteIndex)")

let url = NSURL(string: "nightscouter://link/\(UIStoryboard.StoryboardViewControllerIdentifier.SiteListPageViewController.rawValue)")
let url = NSURL(string: "nightscouter://link/\(Constants.StoryboardViewControllerIdentifier.SiteListPageViewController.rawValue)/\(uuidString)")
if let site = (sites.filter{ $0.uuid == uuid }.first) { // Use the uuid value to get the site object from the array.
if let siteIndex = find(sites, site) { // Use the site object to get its index position in the array.
AppDataManager.sharedInstance.currentSiteIndex = siteIndex
if let notificationIndex = find(site.notifications, notification) {

site.notifications.removeAtIndex(notificationIndex)
AppDataManager.sharedInstance.updateSite(site)
AppDataManager.sharedInstance.currentSiteIndex = siteIndex
// println("User tapped on notification for site: \(site) at index \(siteIndex)")

let url = NSURL(string: "nightscouter://link/\(UIStoryboard.StoryboardViewControllerIdentifier.SiteListPageViewController.rawValue)")
#if DEDBUG
println("User tapped on notification for site: \(site) at index \(siteIndex) with UUID: \(uuid)")
#endif

let url = NSURL(string: "nightscouter://link/\(Constants.StoryboardViewControllerIdentifier.SiteListPageViewController.rawValue)")
deepLinkToURL(url!)
}
}
}
} else {
let url = NSURL(string: "nightscouter://link/\(UIStoryboard.StoryboardViewControllerIdentifier.SiteFormViewController.rawValue)")
let url = NSURL(string: "nightscouter://link/\(Constants.StoryboardViewControllerIdentifier.SiteFormViewController.rawValue)")
deepLinkToURL(url!)
}
}
Expand Down Expand Up @@ -220,8 +197,8 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
var viewControllers = navController.viewControllers as! [UIViewController] // Grab all the current view controllers in the stack.
for storyboardID in pathComponents { // iterate through all the path components. Currently the app only has one level of deep linking.
if let stringID = storyboardID as? String { // Cast the AnyObject into a string.
if let stor = UIStoryboard.StoryboardViewControllerIdentifier(rawValue: stringID) { // Attempt to create a storyboard identifier out of the string.
let linkIsAllowed = contains(UIStoryboard.StoryboardViewControllerIdentifier.deepLinkableStoryboards, stor) // Check to see if this is an allowed viewcontroller.
if let stor = Constants.StoryboardViewControllerIdentifier(rawValue: stringID) { // Attempt to create a storyboard identifier out of the string.
let linkIsAllowed = contains(Constants.StoryboardViewControllerIdentifier.deepLinkableStoryboards, stor) // Check to see if this is an allowed viewcontroller.
if linkIsAllowed {
let newViewController = storyboard!.instantiateViewControllerWithIdentifier(stringID) as! UIViewController

Expand All @@ -248,7 +225,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
let localTimer = NSTimer.scheduledTimerWithTimeInterval(Constants.NotableTime.StandardRefreshTime, target: self, selector: Selector("updateDataNotification:"), userInfo: nil, repeats: true)
return localTimer
}

func updateDataNotification(timer: NSTimer?) -> Void {
// println(">>> Entering \(__FUNCTION__) <<<")
// println("Posting \(Constants.Notification.DataIsStaleUpdateNow) Notification at \(NSDate())")
Expand Down Expand Up @@ -284,12 +261,10 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
localNotification.alertAction = "View Site"

if let config = site.configuration {
if let defaults = config.defaults {
localNotification.alertTitle = "Update for \(defaults.customTitle)"
localNotification.alertTitle = "Update for \(config.displayName)"
if let watch: WatchEntry = site.watchEntry {
localNotification.alertBody = "As of \(dateFor.stringFromDate(watch.date)), \(defaults.customTitle) saw a BG of \(watch.sgv!.sgvString) with a delta of \(watch.bgdelta.formattedForBGDelta) \(watch.sgv!.direction.description). Uploader battery: \(watch.batteryString)"
localNotification.alertBody = "Last reading: \(dateFor.stringFromDate(watch.date)), BG: \(watch.sgv!.sgvString) \(watch.sgv!.direction.emojiForDirection) Delta: \(watch.bgdelta.formattedForBGDelta) \(config.displayUnits) Battery: \(watch.batteryString)"
}
}
}
site.notifications.append(localNotification)
AppDataManager.sharedInstance.updateSite(site)
Expand All @@ -307,6 +282,10 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
UIApplication.sharedApplication().registerUserNotificationSettings(newNotificationSettings)
// TODO: Enabled remote notifications... need to get a server running.
// UIApplication.sharedApplication().registerForRemoteNotifications()

UIApplication.sharedApplication().setMinimumBackgroundFetchInterval(UIApplicationBackgroundFetchIntervalMinimum)
UIApplication.sharedApplication().applicationIconBadgeNumber = 0
UIApplication.sharedApplication().cancelAllLocalNotifications()
}

// MARK: NSCoding
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
//

import UIKit
import NightscouterKit

@IBDesignable
class TableViewBackgroundView: UIView {
class BackgroundView: UIView {

// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
Expand Down
8 changes: 4 additions & 4 deletions Nightscouter/Base.lproj/Labs.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<rect key="frame" x="0.0" y="44" width="600" height="195"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<subviews>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="F6w-bv-rdP" customClass="CompassControl" customModule="Nightscouter" customModuleProvider="target">
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="F6w-bv-rdP" customClass="CompassControl" customModule="NightscouterKit">
<rect key="frame" x="436" y="0.0" width="156" height="195"/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
<constraints>
Expand Down Expand Up @@ -286,7 +286,7 @@
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="Jvo-b2-fEq">
<rect key="frame" x="0.0" y="0.0" width="600" height="300"/>
<subviews>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="7FA-EX-bG2" customClass="CompassControl" customModule="Nightscouter" customModuleProvider="target">
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="7FA-EX-bG2" customClass="CompassControl" customModule="NightscouterKit">
<rect key="frame" x="436" y="105" width="156" height="195"/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
<constraints>
Expand Down Expand Up @@ -377,8 +377,8 @@
</constraints>
<variation key="default">
<mask key="constraints">
<exclude reference="hwp-ZA-ETk"/>
<exclude reference="X5k-cw-lYC"/>
<exclude reference="hwp-ZA-ETk"/>
<exclude reference="IpE-xB-heY"/>
</mask>
</variation>
Expand Down Expand Up @@ -551,7 +551,7 @@
<color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<nil key="highlightedColor"/>
</label>
<view contentMode="scaleToFill" placeholderIntrinsicWidth="150" placeholderIntrinsicHeight="170" translatesAutoresizingMaskIntoConstraints="NO" id="Wvb-D2-1fi" customClass="CompassControl" customModule="Nightscouter" customModuleProvider="target">
<view contentMode="scaleToFill" placeholderIntrinsicWidth="150" placeholderIntrinsicHeight="170" translatesAutoresizingMaskIntoConstraints="NO" id="Wvb-D2-1fi" customClass="CompassControl" customModule="NightscouterKit">
<rect key="frame" x="222" y="203" width="156" height="195"/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
<constraints>
Expand Down
10 changes: 5 additions & 5 deletions Nightscouter/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
<color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<nil key="highlightedColor"/>
</label>
<view clipsSubviews="YES" alpha="0.79999999999999982" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="KWx-hb-Jfz" customClass="ColorBlockView" customModule="Nightscouter" customModuleProvider="target">
<view clipsSubviews="YES" alpha="0.79999999999999982" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="KWx-hb-Jfz" customClass="ColorBlockView" customModule="NightscouterKit">
<rect key="frame" x="0.0" y="0.0" width="15" height="239"/>
<color key="backgroundColor" white="0.66666666666666663" alpha="1" colorSpace="calibratedWhite"/>
<constraints>
Expand All @@ -69,7 +69,7 @@
<color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<nil key="highlightedColor"/>
</label>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="hvW-MN-sK9" customClass="CompassControl" customModule="Nightscouter" customModuleProvider="target">
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="hvW-MN-sK9" customClass="CompassControl" customModule="NightscouterKit">
<rect key="frame" x="436" y="36" width="156" height="195"/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
<constraints>
Expand Down Expand Up @@ -221,7 +221,7 @@
<viewControllerLayoutGuide type="top" id="oc4-tg-nNC"/>
<viewControllerLayoutGuide type="bottom" id="OWm-MG-Dzh"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="WwH-Wz-ZnL" customClass="TableViewBackgroundView" customModule="Nightscouter" customModuleProvider="target">
<view key="view" contentMode="scaleToFill" id="WwH-Wz-ZnL" customClass="BackgroundView" customModule="Nightscouter" customModuleProvider="target">
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
Expand Down Expand Up @@ -255,7 +255,7 @@
<viewControllerLayoutGuide type="top" id="sim-ic-EM0"/>
<viewControllerLayoutGuide type="bottom" id="UbX-Qv-sdH"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="A2Y-lA-0M9" customClass="TableViewBackgroundView" customModule="Nightscouter" customModuleProvider="target">
<view key="view" contentMode="scaleToFill" id="A2Y-lA-0M9" customClass="BackgroundView" customModule="Nightscouter" customModuleProvider="target">
<rect key="frame" x="0.0" y="0.0" width="600" height="536"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<subviews>
Expand Down Expand Up @@ -285,7 +285,7 @@
</mask>
</variation>
</label>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="ebb-7r-y9k" customClass="CompassControl" customModule="Nightscouter" customModuleProvider="target">
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="ebb-7r-y9k" customClass="CompassControl" customModule="NightscouterKit">
<rect key="frame" x="222" y="42" width="156" height="195"/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
<accessibility key="accessibilityConfiguration">
Expand Down
Loading

0 comments on commit 9b11207

Please sign in to comment.