Skip to content

Commit ec56c2d

Browse files
authored
Merge pull request #62 from florianpreknya/UserDefaults-and-AlarmSound
New preferences/alarms UI & a lot of other features
2 parents 2925eed + 496c1fd commit ec56c2d

81 files changed

Lines changed: 3993 additions & 1708 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
nightguard.xcodeproj/project.xcworkspace/xcshareddata/
22
nightguard.xcodeproj/project.xcworkspace/xcuserdata/
3-
nightguard.xcodeproj/xcuserdata/
3+
nightguard.xcodeproj/xcuserdata/
4+
nightguard.xcworkspace/xcuserdata/
5+
Pods/

Podfile

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Uncomment the next line to define a global platform for your project
2+
# platform :ios, '9.0'
3+
4+
target 'nightguard' do
5+
# Comment the next line if you're not using Swift and don't want to use dynamic frameworks
6+
use_frameworks!
7+
8+
# Pods for nightguard
9+
pod 'Eureka'
10+
11+
target 'nightguardTests' do
12+
inherit! :search_paths
13+
# Pods for testing
14+
end
15+
16+
target 'nightguardUITests' do
17+
inherit! :search_paths
18+
# Pods for testing
19+
end
20+
21+
end
22+
23+
target 'nightguard WatchKit App' do
24+
# Comment the next line if you're not using Swift and don't want to use dynamic frameworks
25+
use_frameworks!
26+
27+
# Pods for nightguard WatchKit App
28+
29+
end
30+
31+
target 'nightguard WatchKit Extension' do
32+
# Comment the next line if you're not using Swift and don't want to use dynamic frameworks
33+
use_frameworks!
34+
35+
# Pods for nightguard WatchKit Extension
36+
37+
end

Podfile.lock

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
PODS:
2+
- Eureka (4.3.1)
3+
4+
DEPENDENCIES:
5+
- Eureka
6+
7+
SPEC REPOS:
8+
https://github.com/cocoapods/specs.git:
9+
- Eureka
10+
11+
SPEC CHECKSUMS:
12+
Eureka: 28ea296f06710f6745266b71f17862048941a32d
13+
14+
PODFILE CHECKSUM: 60c292a641d78e0019281e2b1e9a48453daab2a5
15+
16+
COCOAPODS: 1.5.3

nightguard WatchKit App/Base.lproj/Interface.storyboard

Lines changed: 49 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,9 @@
132132
</items>
133133
<edgeInsets key="margins" left="0.0" right="0.0" top="4" bottom="0.0"/>
134134
</group>
135+
<group width="8" height="8" alignment="center" verticalAlignment="bottom" radius="4" id="zdV-tY-qn0">
136+
<color key="backgroundColor" name="systemGreenColor" catalog="System" colorSpace="catalog"/>
137+
</group>
135138
</items>
136139
</group>
137140
</items>
@@ -145,6 +148,7 @@
145148
<outlet property="errorGroup" destination="dXq-O8-Nm3" id="oox-bn-71F"/>
146149
<outlet property="errorLabel" destination="Wmf-Dw-L3A" id="JRC-e5-KcA"/>
147150
<outlet property="iobLabel" destination="oxQ-6L-Aqk" id="fNu-BR-2Ss"/>
151+
<outlet property="nightSafeIndicator" destination="zdV-tY-qn0" id="dms-9T-ZjS"/>
148152
<outlet property="noiseLabel" destination="bBa-oK-viF" id="3e1-rU-UFt"/>
149153
<outlet property="rawValuesGroup" destination="1pi-M7-12E" id="DSq-be-TK7"/>
150154
<outlet property="rawbgLabel" destination="zeh-B2-2k7" id="9WF-fI-jiV"/>
@@ -224,14 +228,49 @@
224228
<controller identifier="SnoozeInterfaceController" fullScreen="YES" id="W3J-ff-Ny6" customClass="SnoozeInterfaceController" customModule="nightguard">
225229
<items>
226230
<button width="1" height="38" alignment="left" title="Stop Snoozing" id="vBI-uK-ui8">
227-
<fontDescription key="font" type="system" pointSize="15"/>
231+
<color key="titleColor" cocoaTouchSystemColor="darkTextColor"/>
232+
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
233+
<fontDescription key="font" type="boldSystem" pointSize="15"/>
228234
<connections>
229235
<action selector="doCancelSnoozeAction" destination="W3J-ff-Ny6" id="lvF-Qh-uHJ"/>
230236
</connections>
231237
</button>
232-
<button width="1" alignment="left" title="30min" id="LmY-nN-0PP">
238+
<group width="1" alignment="left" id="hsc-gi-7ol">
239+
<items>
240+
<button width="0.5" alignment="left" title="5min" id="xxc-dE-3Kb">
241+
<connections>
242+
<action selector="doSnooze5Minutes" destination="W3J-ff-Ny6" id="UV5-uZ-Ayv"/>
243+
</connections>
244+
</button>
245+
<button width="0.48999999999999999" alignment="right" title="10min" id="9VS-98-rhP">
246+
<connections>
247+
<action selector="doSnooze10Minutes" destination="W3J-ff-Ny6" id="Lng-sW-6UK"/>
248+
</connections>
249+
</button>
250+
</items>
251+
</group>
252+
<group width="1" alignment="left" id="mrY-dS-Yui">
253+
<items>
254+
<button width="0.5" alignment="left" title="15min" id="wn2-PF-bKP">
255+
<connections>
256+
<action selector="doSnooze15Minutes" destination="W3J-ff-Ny6" id="6Qx-gE-kVe"/>
257+
</connections>
258+
</button>
259+
<button width="0.48999999999999999" alignment="right" title="20min" id="08g-dW-F7X">
260+
<connections>
261+
<action selector="doSnooze20Minutes" destination="W3J-ff-Ny6" id="lWe-nH-bYl"/>
262+
</connections>
263+
</button>
264+
</items>
265+
</group>
266+
<button width="1" alignment="left" title="30min" id="PSv-3m-jyA">
233267
<connections>
234-
<action selector="doSnooze30Minutes" destination="W3J-ff-Ny6" id="ahC-xB-tbj"/>
268+
<action selector="doSnooze30Minutes" destination="W3J-ff-Ny6" id="Mlt-K0-GEp"/>
269+
</connections>
270+
</button>
271+
<button width="1" alignment="left" title="45min" id="1Bd-ZE-voa">
272+
<connections>
273+
<action selector="doSnooze45Minutes" destination="W3J-ff-Ny6" id="Rxl-ML-VwK"/>
235274
</connections>
236275
</button>
237276
<button width="1" alignment="left" title="1h" id="B6w-zl-nKO">
@@ -244,14 +283,14 @@
244283
<action selector="doSnooze2Hours" destination="W3J-ff-Ny6" id="rVZ-fg-vmz"/>
245284
</connections>
246285
</button>
247-
<button width="1" alignment="left" title="3h" id="4ee-cb-NHg" userLabel="3h">
286+
<button width="1" alignment="left" title="3h" id="Vbc-n1-Q5B">
248287
<connections>
249-
<action selector="doSnooze3Hours" destination="W3J-ff-Ny6" id="Q6K-rp-kha"/>
288+
<action selector="doSnooze3Hours" destination="W3J-ff-Ny6" id="xDQ-dG-JPg"/>
250289
</connections>
251290
</button>
252-
<button width="1" alignment="left" title="6h" id="QlQ-f0-7ep">
291+
<button width="1" alignment="left" title="6h" id="SKd-7S-4Ns">
253292
<connections>
254-
<action selector="doSnooze6Hours" destination="W3J-ff-Ny6" id="sgy-sc-nEO"/>
293+
<action selector="doSnooze6Hours" destination="W3J-ff-Ny6" id="mOd-TY-gpt"/>
255294
</connections>
256295
</button>
257296
<button width="1" alignment="left" title="1d" id="E2D-TG-Tr3">
@@ -260,6 +299,9 @@
260299
</connections>
261300
</button>
262301
</items>
302+
<connections>
303+
<outlet property="stopSnoozingButton" destination="vBI-uK-ui8" id="pcc-Ya-weq"/>
304+
</connections>
263305
</controller>
264306
</objects>
265307
<point key="canvasLocation" x="409" y="-44"/>

nightguard WatchKit Extension/AppMessageService.swift

Lines changed: 3 additions & 119 deletions
Original file line numberDiff line numberDiff line change
@@ -11,128 +11,12 @@ import WatchKit
1111
import WatchConnectivity
1212

1313
// This class handles values that are passed from the ios app.
14-
class AppMessageService : NSObject, WCSessionDelegate {
14+
class AppMessageService {
1515

1616
static let singleton = AppMessageService()
17-
18-
// request the baseUri from the iosApp and stores the result in the UserDefaultsRepository
19-
func requestBaseUri() {
2017

21-
if WCSession.isSupported() {
22-
23-
let session = WCSession.default
24-
25-
if session.isReachable {
26-
session.sendMessage(["requestBaseUri": ""], replyHandler: { (response) -> Void in
27-
28-
if let baseUri = response.first?.1 {
29-
UserDefaultsRepository.saveBaseUri(String(describing: baseUri))
30-
}
31-
}, errorHandler: { (error) -> Void in
32-
print(error)
33-
})
34-
}
35-
}
36-
}
37-
18+
// send a dummy message to keep the phone app awake (start the app if is not started)
3819
func keepAwakePhoneApp() {
39-
40-
// send a dummy message to keep the phone app awake (start the app if is not started)
41-
if WCSession.isSupported() {
42-
43-
let session = WCSession.default
44-
if session.isReachable {
45-
session.sendMessage(["keepAwake": ""], replyHandler: nil) { error in
46-
print(error)
47-
BackgroundRefreshLogger.info("Error received while trying to awake phone app: \(error)")
48-
}
49-
}
50-
}
51-
}
52-
53-
func updateValuesFromApplicationContext(_ applicationContext: [String : AnyObject]) {
54-
if let units = applicationContext["units"] as? String {
55-
UserDefaultsRepository.saveUnits(Units(rawValue: units)!)
56-
}
57-
58-
if let hostUri = applicationContext["hostUri"] as? String {
59-
UserDefaultsRepository.saveBaseUri(hostUri)
60-
}
61-
62-
if let showRawBG = applicationContext["showRawBG"] as? Bool {
63-
UserDefaultsRepository.saveShowRawBG(showRawBG)
64-
}
65-
66-
var shouldRepaintCharts = false
67-
if let alertIfAboveValue = applicationContext["alertIfAboveValue"] as? Float {
68-
let defaults = UserDefaults(suiteName: AppConstants.APP_GROUP_ID)
69-
defaults!.setValue(alertIfAboveValue, forKey: "alertIfAboveValue")
70-
AlarmRule.alertIfAboveValue = alertIfAboveValue
71-
72-
shouldRepaintCharts = true
73-
}
74-
75-
if let alertIfBelowValue = applicationContext["alertIfBelowValue"] as? Float {
76-
let defaults = UserDefaults(suiteName: AppConstants.APP_GROUP_ID)
77-
defaults!.setValue(alertIfBelowValue, forKey: "alertIfBelowValue")
78-
AlarmRule.alertIfBelowValue = alertIfBelowValue
79-
80-
shouldRepaintCharts = true
81-
}
82-
83-
if shouldRepaintCharts {
84-
if #available(watchOSApplicationExtension 3.0, *) {
85-
if let interfaceController = WKExtension.shared().rootInterfaceController as? InterfaceController {
86-
if WKExtension.shared().applicationState == .active {
87-
DispatchQueue.main.async {
88-
interfaceController.loadAndPaintChartData(forceRepaint: true)
89-
}
90-
} else {
91-
interfaceController.shouldRepaintChartsOnActivation = true
92-
}
93-
}
94-
}
95-
}
96-
97-
if let _ = applicationContext["nightscoutData"] {
98-
if #available(watchOSApplicationExtension 3.0, *) {
99-
if let extensionDelegate = WKExtension.shared().delegate as? ExtensionDelegate {
100-
DispatchQueue.main.async {
101-
extensionDelegate.handleNightscoutDataMessage(applicationContext)
102-
}
103-
}
104-
}
105-
}
106-
}
107-
108-
@available(watchOSApplicationExtension 2.2, *)
109-
func session(_ session: WCSession, activationDidCompleteWith activationState: WCSessionActivationState, error: Error?) {
110-
111-
DispatchQueue.main.async { () -> Void in
112-
113-
self.updateValuesFromApplicationContext(session.receivedApplicationContext as [String : AnyObject])
114-
}
115-
}
116-
117-
/** Called on the delegate of the receiver. Will be called on startup if an applicationContext is available. */
118-
@available(watchOS 2.0, *)
119-
func session(_ session: WCSession, didReceiveApplicationContext applicationContext: [String : Any]) {
120-
updateValuesFromApplicationContext(applicationContext as [String : AnyObject])
121-
}
122-
123-
/** Called on the delegate of the receiver. Will be called on startup if the user info finished transferring when the receiver was not running. */
124-
@available(watchOS 2.0, *)
125-
func session(_ session: WCSession, didReceiveUserInfo userInfo: [String : Any]) {
126-
updateValuesFromApplicationContext(userInfo as [String : AnyObject])
127-
}
128-
129-
@available(watchOS 2.0, *)
130-
func session(_ session: WCSession, didReceiveMessage message: [String : Any]) {
131-
updateValuesFromApplicationContext(message as [String : AnyObject])
132-
}
133-
134-
@available(watchOS 2.0, *)
135-
func session(_ session: WCSession, didReceiveMessage message: [String : Any], replyHandler: @escaping ([String : Any]) -> Swift.Void) {
136-
updateValuesFromApplicationContext(message as [String : AnyObject])
20+
KeepAwakeMessage().send()
13721
}
13822
}

0 commit comments

Comments
 (0)