Skip to content

Commit 79b554e

Browse files
author
SpiralArm Consulting Ltd
committed
updated to make watch app functional
1 parent 948a5c9 commit 79b554e

File tree

7 files changed

+592
-4
lines changed

7 files changed

+592
-4
lines changed

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ My plan is to:
1414

1515
## Versions
1616

17+
18+
### 1.2
19+
Updated Watch app and added functioning WatchTips. Watch app can now be used to calculate Bill split and tips.
20+
1721
### 1.1
1822
After using XCode to define a simulator with an attached Watch Emulator the standard Vanilla app (from 1.0) was updated as follows
1923

ios/Runner.xcodeproj/project.pbxproj

+12
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
/* Begin PBXBuildFile section */
1010
1498D2341E8E89220040F4C2 /* GeneratedPluginRegistrant.m in Sources */ = {isa = PBXBuildFile; fileRef = 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */; };
11+
2D020CB721FEF3D200DC71C2 /* SplitController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2D020CB621FEF3D200DC71C2 /* SplitController.swift */; };
12+
2D020CB921FEF5A100DC71C2 /* BillController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2D020CB821FEF5A100DC71C2 /* BillController.swift */; };
1113
2D5378261FAA1A9400D5DBA9 /* flutter_assets in Resources */ = {isa = PBXBuildFile; fileRef = 2D5378251FAA1A9400D5DBA9 /* flutter_assets */; };
1214
2D69490521FDFD9600B94252 /* Interface.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 2D69490321FDFD9600B94252 /* Interface.storyboard */; };
1315
2D69490721FDFD9700B94252 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 2D69490621FDFD9700B94252 /* Assets.xcassets */; };
@@ -16,6 +18,7 @@
1618
2D69491521FDFD9700B94252 /* ExtensionDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2D69491421FDFD9700B94252 /* ExtensionDelegate.swift */; };
1719
2D69491721FDFD9700B94252 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 2D69491621FDFD9700B94252 /* Assets.xcassets */; };
1820
2D69491B21FDFD9700B94252 /* WatchTips.app in Embed Watch Content */ = {isa = PBXBuildFile; fileRef = 2D69490121FDFD9600B94252 /* WatchTips.app */; };
21+
2D69492921FE165500B94252 /* TipController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2D69492821FE165500B94252 /* TipController.swift */; };
1922
3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */ = {isa = PBXBuildFile; fileRef = 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */; };
2023
3B80C3941E831B6300D905FE /* App.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3B80C3931E831B6300D905FE /* App.framework */; };
2124
3B80C3951E831B6300D905FE /* App.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 3B80C3931E831B6300D905FE /* App.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
@@ -86,6 +89,8 @@
8689
/* Begin PBXFileReference section */
8790
1498D2321E8E86230040F4C2 /* GeneratedPluginRegistrant.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GeneratedPluginRegistrant.h; sourceTree = "<group>"; };
8891
1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GeneratedPluginRegistrant.m; sourceTree = "<group>"; };
92+
2D020CB621FEF3D200DC71C2 /* SplitController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SplitController.swift; sourceTree = "<group>"; };
93+
2D020CB821FEF5A100DC71C2 /* BillController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BillController.swift; sourceTree = "<group>"; };
8994
2D5378251FAA1A9400D5DBA9 /* flutter_assets */ = {isa = PBXFileReference; lastKnownFileType = folder; name = flutter_assets; path = Flutter/flutter_assets; sourceTree = SOURCE_ROOT; };
9095
2D69490121FDFD9600B94252 /* WatchTips.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = WatchTips.app; sourceTree = BUILT_PRODUCTS_DIR; };
9196
2D69490421FDFD9600B94252 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Interface.storyboard; sourceTree = "<group>"; };
@@ -96,6 +101,7 @@
96101
2D69491421FDFD9700B94252 /* ExtensionDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ExtensionDelegate.swift; sourceTree = "<group>"; };
97102
2D69491621FDFD9700B94252 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
98103
2D69491821FDFD9700B94252 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
104+
2D69492821FE165500B94252 /* TipController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TipController.swift; sourceTree = "<group>"; };
99105
3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = AppFrameworkInfo.plist; path = Flutter/AppFrameworkInfo.plist; sourceTree = "<group>"; };
100106
3B80C3931E831B6300D905FE /* App.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = App.framework; path = Flutter/App.framework; sourceTree = "<group>"; };
101107
7AFA3C8E1D35360C0083082E /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = Release.xcconfig; path = Flutter/Release.xcconfig; sourceTree = "<group>"; };
@@ -147,8 +153,11 @@
147153
children = (
148154
2D69491221FDFD9700B94252 /* InterfaceController.swift */,
149155
2D69491421FDFD9700B94252 /* ExtensionDelegate.swift */,
156+
2D69492821FE165500B94252 /* TipController.swift */,
150157
2D69491621FDFD9700B94252 /* Assets.xcassets */,
151158
2D69491821FDFD9700B94252 /* Info.plist */,
159+
2D020CB621FEF3D200DC71C2 /* SplitController.swift */,
160+
2D020CB821FEF5A100DC71C2 /* BillController.swift */,
152161
);
153162
path = "WatchTips Extension";
154163
sourceTree = "<group>";
@@ -385,8 +394,11 @@
385394
isa = PBXSourcesBuildPhase;
386395
buildActionMask = 2147483647;
387396
files = (
397+
2D020CB721FEF3D200DC71C2 /* SplitController.swift in Sources */,
398+
2D020CB921FEF5A100DC71C2 /* BillController.swift in Sources */,
388399
2D69491521FDFD9700B94252 /* ExtensionDelegate.swift in Sources */,
389400
2D69491321FDFD9700B94252 /* InterfaceController.swift in Sources */,
401+
2D69492921FE165500B94252 /* TipController.swift in Sources */,
390402
);
391403
runOnlyForDeploymentPostprocessing = 0;
392404
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
//
2+
// BillController.swift
3+
// WatchTips Extension
4+
//
5+
// Created by Stephen Rogers on 28/01/2019.
6+
// Copyright © 2019 The Chromium Authors. All rights reserved.
7+
//
8+
9+
import WatchKit
10+
import Foundation
11+
12+
13+
class BillController: WKInterfaceController {
14+
15+
16+
var billValue = "0"
17+
var decimalAdded = false
18+
var sourceController: InterfaceController!
19+
@IBOutlet weak var totalAmount: WKInterfaceLabel!
20+
21+
22+
23+
override func awake(withContext context: Any?) {
24+
super.awake(withContext: context)
25+
26+
// Configure interface objects here.
27+
sourceController = context as? InterfaceController
28+
if sourceController.billTotal != 0.0 {
29+
billValue = "\(sourceController.billTotal)"
30+
} else {
31+
billValue = "0"
32+
}
33+
displayBillValue()
34+
35+
}
36+
37+
override func willActivate() {
38+
// This method is called when watch view controller is about to be visible to user
39+
super.willActivate()
40+
}
41+
42+
override func didDeactivate() {
43+
// This method is called when watch view controller is no longer visible
44+
super.didDeactivate()
45+
}
46+
47+
48+
// Clear
49+
@IBAction func clearBtn() {
50+
billValue.remove(at: billValue.index(before: billValue.endIndex))
51+
if billValue.count == 0 {
52+
billValue = "0"
53+
}
54+
displayBillValue()
55+
}
56+
57+
58+
@IBAction func decimalBtn() {
59+
appendDecimal()
60+
}
61+
62+
63+
@IBAction func zeroBtn() {
64+
appendValue(value: 0)
65+
}
66+
67+
68+
@IBAction func oneBtn() {
69+
appendValue(value: 1)
70+
}
71+
72+
73+
@IBAction func twoBtn() {
74+
appendValue(value: 2)
75+
}
76+
77+
@IBAction func threeBtn() {
78+
appendValue(value: 3)
79+
}
80+
81+
82+
@IBAction func fourBtn() {
83+
appendValue(value: 4)
84+
}
85+
86+
87+
@IBAction func fiveBtn() {
88+
appendValue(value: 5)
89+
}
90+
91+
92+
@IBAction func sixBtn() {
93+
appendValue(value: 6)
94+
}
95+
96+
97+
@IBAction func sevenBtn() {
98+
appendValue(value: 7)
99+
}
100+
101+
102+
@IBAction func eightBtn() {
103+
appendValue(value: 8)
104+
}
105+
106+
@IBAction func nineBtn() {
107+
appendValue(value: 9)
108+
}
109+
110+
// display the bill value and update amount in source controller
111+
func displayBillValue(){
112+
if let _ = billValue.index(of: (".")) {
113+
decimalAdded = true
114+
} else {
115+
decimalAdded = false
116+
}
117+
totalAmount.setText(billValue)
118+
sourceController.billTotal = Double(billValue)!
119+
}
120+
121+
// Append an amount to the displayed bill
122+
func appendValue(value: Int){
123+
124+
let stringValue = "\(value)"
125+
if(billValue == "0"){
126+
billValue = stringValue
127+
} else {
128+
billValue = billValue + stringValue
129+
}
130+
displayBillValue()
131+
}
132+
133+
// only add decimal if not already added
134+
func appendDecimal(){
135+
136+
// did we have a decimal?
137+
if !decimalAdded {
138+
billValue = billValue + "."
139+
}
140+
141+
// display total
142+
displayBillValue()
143+
144+
145+
}
146+
147+
}

ios/WatchTips Extension/InterfaceController.swift

+77-1
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,98 @@ import WatchKit
1010
import Foundation
1111

1212

13-
class InterfaceController: WKInterfaceController {
13+
class InterfaceController: WKInterfaceController, WKCrownDelegate {
14+
15+
16+
var tipAmount: Int = 10
17+
var splitBetween: Int = 1
18+
var billTotal = Double(0)
19+
var focusButton: Int = 0
20+
var accumulatedCrownDelta = 0.0
1421

22+
@IBOutlet weak var currentSplit: WKInterfaceButton!
23+
@IBOutlet weak var currentTip: WKInterfaceButton!
24+
@IBOutlet weak var billButton: WKInterfaceButton!
25+
@IBOutlet weak var currentTotal: WKInterfaceLabel!
26+
@IBOutlet weak var costEach: WKInterfaceLabel!
27+
@IBOutlet weak var withTip: WKInterfaceLabel!
28+
29+
30+
func crownDidBecomeIdle(_ crownSequencer: WKCrownSequencer?) {
31+
accumulatedCrownDelta = 0.0
32+
}
33+
34+
func crownDidRotate(_ crownSequencer: WKCrownSequencer?, rotationalDelta: Double) {
35+
accumulatedCrownDelta += rotationalDelta
36+
//let threshoold = 0.5
37+
38+
39+
}
40+
41+
1542
override func awake(withContext context: Any?) {
1643
super.awake(withContext: context)
1744

1845
// Configure interface objects here.
46+
crownSequencer.delegate = self
47+
updateCalc()
1948
}
2049

2150
override func willActivate() {
2251
// This method is called when watch view controller is about to be visible to user
2352
super.willActivate()
53+
54+
crownSequencer.focus()
55+
updateCalc()
2456
}
2557

2658
override func didDeactivate() {
2759
// This method is called when watch view controller is no longer visible
2860
super.didDeactivate()
2961
}
62+
63+
64+
// chnage how many the bill is split between
65+
@IBAction func showSplitController() {
66+
presentController(withName: "SplitController", context: self)
67+
}
68+
69+
70+
@IBAction func showTipController() {
71+
presentController(withName: "TipController", context: self)
72+
}
73+
74+
75+
@IBAction func showBillController() {
76+
presentController(withName: "BillController", context: self)
77+
}
78+
79+
// Update the actual calculations
80+
func updateCalc(){
81+
82+
// do bill calculations
83+
let tip = (billTotal/100) * Double(tipAmount)
84+
let billWithTip = billTotal + tip
85+
let perPerson = billWithTip / Double(splitBetween)
86+
87+
// update display
88+
currentTip.setTitle("\(tipAmount)%")
89+
currentSplit.setTitle("\(splitBetween)")
90+
currentTotal.setText(String(format: "%.2f", billTotal))
91+
withTip.setText(String(format: "%.2f", billWithTip))
92+
costEach.setText(String(format: "%.2f", perPerson))
93+
94+
// now see if we can sent the calc data back to the app
95+
//if WCSession.isSupported() {
96+
// let session = WCSession.default()
97+
// let calcInfo = [
98+
// "tip":"\(tipAmount)",
99+
// "split": "\(splitBetween)",
100+
// "bill": "\(billTotal)"
101+
// ] as [String : Any];
102+
// session.transferUserInfo(calcInfo)
103+
//}
104+
}
105+
30106

31107
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
//
2+
// SplitController.swift
3+
// WatchTips Extension
4+
//
5+
// Created by Stephen Rogers on 28/01/2019.
6+
// Copyright © 2019 The Chromium Authors. All rights reserved.
7+
//
8+
9+
import WatchKit
10+
import Foundation
11+
12+
13+
class SplitController: WKInterfaceController {
14+
15+
16+
@IBOutlet weak var splitBetween: WKInterfaceLabel!
17+
var split: Int = 1
18+
var sourceController: InterfaceController!
19+
20+
21+
override func awake(withContext context: Any?) {
22+
super.awake(withContext: context)
23+
24+
// Configure interface objects here.
25+
sourceController = context as? InterfaceController
26+
split = sourceController.splitBetween
27+
updateSplit()
28+
}
29+
30+
override func willActivate() {
31+
// This method is called when watch view controller is about to be visible to user
32+
super.willActivate()
33+
}
34+
35+
override func didDeactivate() {
36+
// This method is called when watch view controller is no longer visible
37+
super.didDeactivate()
38+
}
39+
40+
// update the slit display and the bill split
41+
func updateSplit(){
42+
sourceController.splitBetween = split
43+
splitBetween.setText("\(split)")
44+
}
45+
46+
@IBAction func increaseSplit() {
47+
if split < 50 {
48+
split += 1
49+
updateSplit()
50+
}
51+
}
52+
53+
54+
@IBAction func decreaseSplit() {
55+
if split > 1 {
56+
split -= 1
57+
updateSplit()
58+
}
59+
}
60+
61+
62+
}

0 commit comments

Comments
 (0)