Skip to content

Commit

Permalink
Merge pull request #19 from someoneAnyone/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
someoneAnyone committed Sep 9, 2015
2 parents 6e1888a + 0182a56 commit 1ff0a30
Show file tree
Hide file tree
Showing 15 changed files with 305 additions and 127 deletions.
4 changes: 0 additions & 4 deletions Nightscouter.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
1771B0691B7524AA006C1F5E /* NightscoutAPIClient.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1771B0651B7524AA006C1F5E /* NightscoutAPIClient.swift */; };
1771B0751B7524D5006C1F5E /* CompassControl+Convience.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1771B06B1B7524D5006C1F5E /* CompassControl+Convience.swift */; };
1771B0761B7524D5006C1F5E /* Double+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1771B06C1B7524D5006C1F5E /* Double+Extension.swift */; };
1771B0771B7524D5006C1F5E /* Int+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1771B06D1B7524D5006C1F5E /* Int+Extensions.swift */; };
1771B0781B7524D5006C1F5E /* NSAssetKit.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1771B06E1B7524D5006C1F5E /* NSAssetKit.swift */; };
1771B0791B7524D5006C1F5E /* NSAssetKit+Helpers.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1771B06F1B7524D5006C1F5E /* NSAssetKit+Helpers.swift */; };
1771B07A1B7524D5006C1F5E /* NSCalendar+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1771B0701B7524D5006C1F5E /* NSCalendar+Extension.swift */; };
Expand Down Expand Up @@ -126,7 +125,6 @@
1771B0651B7524AA006C1F5E /* NightscoutAPIClient.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = NightscoutAPIClient.swift; path = API/NightscoutAPIClient.swift; sourceTree = "<group>"; };
1771B06B1B7524D5006C1F5E /* CompassControl+Convience.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = "CompassControl+Convience.swift"; path = "Extensions/CompassControl+Convience.swift"; sourceTree = "<group>"; };
1771B06C1B7524D5006C1F5E /* Double+Extension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = "Double+Extension.swift"; path = "Extensions/Double+Extension.swift"; sourceTree = "<group>"; };
1771B06D1B7524D5006C1F5E /* Int+Extensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = "Int+Extensions.swift"; path = "Extensions/Int+Extensions.swift"; sourceTree = "<group>"; };
1771B06E1B7524D5006C1F5E /* NSAssetKit.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = NSAssetKit.swift; path = Extensions/NSAssetKit.swift; sourceTree = "<group>"; };
1771B06F1B7524D5006C1F5E /* NSAssetKit+Helpers.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = "NSAssetKit+Helpers.swift"; path = "Extensions/NSAssetKit+Helpers.swift"; sourceTree = "<group>"; };
1771B0701B7524D5006C1F5E /* NSCalendar+Extension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = "NSCalendar+Extension.swift"; path = "Extensions/NSCalendar+Extension.swift"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -370,7 +368,6 @@
isa = PBXGroup;
children = (
1771B06C1B7524D5006C1F5E /* Double+Extension.swift */,
1771B06D1B7524D5006C1F5E /* Int+Extensions.swift */,
1771B0701B7524D5006C1F5E /* NSCalendar+Extension.swift */,
1771B0711B7524D5006C1F5E /* NSURL-Extensions.swift */,
1771B0721B7524D5006C1F5E /* String+Extensions.swift */,
Expand Down Expand Up @@ -614,7 +611,6 @@
1771B0761B7524D5006C1F5E /* Double+Extension.swift in Sources */,
1771B0751B7524D5006C1F5E /* CompassControl+Convience.swift in Sources */,
1771B0781B7524D5006C1F5E /* NSAssetKit.swift in Sources */,
1771B0771B7524D5006C1F5E /* Int+Extensions.swift in Sources */,
1771B0671B7524AA006C1F5E /* AppTheme.swift in Sources */,
1771B0871B7524FD006C1F5E /* WatchEntry.swift in Sources */,
1771B0681B7524AA006C1F5E /* Constants.swift in Sources */,
Expand Down
2 changes: 1 addition & 1 deletion Nightscouter/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
</dict>
</array>
<key>CFBundleVersion</key>
<string>130</string>
<string>132</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>NSUserActivityTypes</key>
Expand Down
4 changes: 3 additions & 1 deletion Nightscouter/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,6 @@
"uiAlertScreenOverrideTitle" = "Prevent Screen from Locking?";
"uiAlertScreenOverrideMessage" = "Selecting Yes will prevent the application from going to sleep and locking while viewing this site.";

"sgvLowString" = "Low";
"sgvLowString" = "Low";

"nightscoutTitleString" = "Nightscouter";
15 changes: 11 additions & 4 deletions Nightscouter/SiteDetailViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ extension SiteDetailViewController {
let updateData = "updateData(\(self.data))"

if let configuration = site?.configuration {
let updateUnits = "updateUnits(\(configuration.displayUnits.rawValue))"

let updateUnits = "updateUnits(\(configuration.displayUnits.hashValue))"
webView.stringByEvaluatingJavaScriptFromString(updateUnits)
}
webView.stringByEvaluatingJavaScriptFromString(updateData)
Expand Down Expand Up @@ -167,9 +168,15 @@ extension SiteDetailViewController {

// Raw label
if let rawValue = watchEntry.raw {
let color = colorForDesiredColorState(configuration.boundedColorForGlucoseValue(Int(rawValue)))
let color = colorForDesiredColorState(configuration.boundedColorForGlucoseValue(rawValue))

var raw = "\(rawValue.formattedForMgdl)"
if configuration.displayUnits == .Mmol {
raw = rawValue.formattedForMmol
}

self.siteRawLabel?.textColor = color
self.siteRawLabel?.text = "\(NSNumberFormatter.localizedStringFromNumber(rawValue, numberStyle: NSNumberFormatterStyle.DecimalStyle)) : \(sgv.noise)"
self.siteRawLabel?.text = "\(raw) : \(sgv.noise)"
}

let timeAgo = watchEntry.date.timeIntervalSinceNow
Expand All @@ -195,7 +202,7 @@ extension SiteDetailViewController {
if let entries = entries {
for entry in entries {
if let sgv = entry.sgv {
if (sgv.sgv > Constants.EntryCount.LowerLimitForValidSGV) {
if (sgv.sgv > Double(Constants.EntryCount.LowerLimitForValidSGV)) {
self.data.append(entry.jsonForChart)
}
}
Expand Down
19 changes: 15 additions & 4 deletions Nightscouter/SiteTableViewCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,27 @@ class SiteTableViewCell: UITableViewCell {

if let sgvValue = watchEntry.sgv {

let color = colorForDesiredColorState(site.configuration!.boundedColorForGlucoseValue(sgvValue.sgv))
var boundedColor = configuration.boundedColorForGlucoseValue(sgvValue.sgv)
if configuration.displayUnits == .Mmol {
boundedColor = configuration.boundedColorForGlucoseValue(sgvValue.sgv.toMgdl)
}
let color = colorForDesiredColorState(boundedColor)

siteColorBlockView.backgroundColor = color

if let enabledOptions = configuration.enabledOptions {
let rawEnabled = contains(enabledOptions, EnabledOptions.rawbg)
if rawEnabled {
if let rawValue = watchEntry.raw {
let color = colorForDesiredColorState(configuration.boundedColorForGlucoseValue(Int(rawValue)))
let color = colorForDesiredColorState(configuration.boundedColorForGlucoseValue(rawValue))

var raw = "\(rawValue.formattedForMgdl)"
if configuration.displayUnits == .Mmol {
raw = rawValue.formattedForMmol
}

siteRawLabel?.textColor = color
siteRawLabel.text = "\(NSNumberFormatter.localizedStringFromNumber(rawValue, numberStyle: .DecimalStyle)) : \(sgvValue.noise)"
siteRawLabel.text = "\(raw) : \(sgvValue.noise)"
}
} else {
siteRawHeader.hidden = true
Expand Down Expand Up @@ -132,7 +143,7 @@ class SiteTableViewCell: UITableViewCell {
siteColorBlockView.backgroundColor = siteCompassControl.color
siteLastReadingLabel.text = Constants.LocalizedString.tableViewCellLoading.localized
siteLastReadingLabel.textColor = Theme.Color.labelTextColor

siteRawHeader.hidden = false
siteRawLabel.hidden = false
siteRawLabel.textColor = Theme.Color.labelTextColor
Expand Down
2 changes: 1 addition & 1 deletion Nightscouter/TestHarnessForCompassViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ extension TestHarnessForCompassViewController {

func updateDelta(){
print("newValue: \(newValue); oldValue: \(oldValue); delta: \(newValue - oldValue)")
let deltaValue = newValue - oldValue
let deltaValue = Double(newValue - oldValue)
compassControlView.delta = "\(deltaValue.formattedForBGDelta) " + bgUnits
}

Expand Down
11 changes: 8 additions & 3 deletions NightscouterKit/Extensions/CompassControl+Convience.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import UIKit

public extension CompassControl {

func configure(sgvText: String, color: UIColor, direction: Direction, bgdelta: Int, units: String) -> Void {
func configure(sgvText: String, color: UIColor, direction: Direction, bgdelta: Double, units: String) -> Void {
self.sgvText = sgvText
self.color = color
self.direction = direction
Expand All @@ -20,11 +20,16 @@ public extension CompassControl {
public func configureWith(site: Site){
if let configuration: ServerConfiguration = site.configuration, watch: WatchEntry = site.watchEntry, sgv: SensorGlucoseValue = watch.sgv {

let color = colorForDesiredColorState(configuration.boundedColorForGlucoseValue(sgv.sgv))
var boundedColor = configuration.boundedColorForGlucoseValue(sgv.sgv)

var units: Units = configuration.displayUnits
if units == .Mmol {
boundedColor = configuration.boundedColorForGlucoseValue(sgv.sgv.toMgdl)
}

configure(sgv.sgvString, color: color, direction: sgv.direction, bgdelta: watch.bgdelta, units: units.rawValue)
let color = colorForDesiredColorState(boundedColor)

configure(sgv.sgvString, color: color, direction: sgv.direction, bgdelta: watch.bgdelta, units: units.description)
}
}

Expand Down
60 changes: 60 additions & 0 deletions NightscouterKit/Extensions/Double+Extension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,65 @@ public extension Double {
let date = NSDate(timeIntervalSince1970:millisecondsToSecondsTimeInterval())
return date
}

}

public extension Double {
public var toMmol: Double {
get{
return (self / 18)
}
}

public var toMgdl: Double {
get{
return self * 18
}
}

internal var mgdlFormatter: NSNumberFormatter {
let numberFormat = NSNumberFormatter()
numberFormat.numberStyle = .NoStyle

return numberFormat
}

public var formattedForMgdl: String {
return self.mgdlFormatter.stringFromNumber(self)!
}

internal var mmolFormatter: NSNumberFormatter {
let numberFormat = NSNumberFormatter()
numberFormat.numberStyle = .DecimalStyle
numberFormat.minimumFractionDigits = 1
numberFormat.maximumFractionDigits = 1
numberFormat.secondaryGroupingSize = 1

return numberFormat
}

public var formattedForMmol: String {
return self.mmolFormatter.stringFromNumber(self.toMmol)!
}
}

public extension Double {
internal var bgDeltaFormatter: NSNumberFormatter {
let numberFormat = NSNumberFormatter()
numberFormat.numberStyle = .DecimalStyle
numberFormat.positivePrefix = numberFormat.plusSign
numberFormat.negativePrefix = numberFormat.minusSign

return numberFormat
}

public var formattedForBGDelta: String {
return self.bgDeltaFormatter.stringFromNumber(self)!
}
}

public extension Double {
var isInteger: Bool {
return rint(self) == self
}
}
24 changes: 0 additions & 24 deletions NightscouterKit/Extensions/Int+Extensions.swift

This file was deleted.

16 changes: 13 additions & 3 deletions NightscouterKit/Extensions/String+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,19 @@

import Foundation

extension String {
public extension String {
public var localized: String {
return NSLocalizedString(self, tableName: nil, bundle: NSBundle.mainBundle(), value: "", comment: "")
}
public func localizedWithComment(comment:String) -> String {
return NSLocalizedString(self, tableName: nil, bundle: NSBundle.mainBundle(), value: "", comment: comment)
}

}

public extension String {
public var versions: [String] {
return self.componentsSeparatedByString(".")
}

public var majorVersion: Int {
return versions.first!.toInt()!
}
Expand All @@ -29,4 +30,13 @@ extension String {
public var buildVersion: Int {
return versions.last!.toInt()!
}
}

public extension String {
public var floatValue: Float? {
return NSNumberFormatter().numberFromString(self)?.floatValue //(self as NSString).floatValue
}
public var toDouble: Double? {
return NSNumberFormatter().numberFromString(self)?.doubleValue
}
}
Loading

0 comments on commit 1ff0a30

Please sign in to comment.