Merge branch 'main' of github.com:hykilpikonna/ProjectClock into main

This commit is contained in:
Dallon Archibald
2021-01-20 11:34:46 -05:00
6 changed files with 133 additions and 4 deletions
+4
View File
@@ -22,6 +22,7 @@
7C5DAE9C25AF812200E44C52 /* clock.png in Resources */ = {isa = PBXBuildFile; fileRef = 7C5DAE9B25AF812200E44C52 /* clock.png */; };
7C83963625AF375B0027A94C /* NotificationLogic.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C83963525AF375B0027A94C /* NotificationLogic.swift */; };
7C83963925AF68980027A94C /* TestingViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C83963825AF68980027A94C /* TestingViewController.swift */; };
C7E638E825B88F8B00799512 /* MathExpressions.swift in Sources */ = {isa = PBXBuildFile; fileRef = C7E638E725B88F8B00799512 /* MathExpressions.swift */; };
/* End PBXBuildFile section */
/* Begin PBXFileReference section */
@@ -44,6 +45,7 @@
7C83962F25AF34F10027A94C /* HealthKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = HealthKit.framework; path = System/Library/Frameworks/HealthKit.framework; sourceTree = SDKROOT; };
7C83963525AF375B0027A94C /* NotificationLogic.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotificationLogic.swift; sourceTree = "<group>"; };
7C83963825AF68980027A94C /* TestingViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestingViewController.swift; sourceTree = "<group>"; };
C7E638E725B88F8B00799512 /* MathExpressions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MathExpressions.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@@ -94,6 +96,7 @@
7C83963825AF68980027A94C /* TestingViewController.swift */,
4FD642D225B48C380069171E /* AlarmActivator.swift */,
4FD642DA25B4B7F60069171E /* Utils.swift */,
C7E638E725B88F8B00799512 /* MathExpressions.swift */,
);
path = ProjectClock;
sourceTree = "<group>";
@@ -189,6 +192,7 @@
4FD642DB25B4B7F60069171E /* Utils.swift in Sources */,
4FA419AF25AF93EC004CE0FC /* AlarmViewController.swift in Sources */,
4F509BD225AE22D100726227 /* Models.swift in Sources */,
C7E638E825B88F8B00799512 /* MathExpressions.swift in Sources */,
7C83963625AF375B0027A94C /* NotificationLogic.swift in Sources */,
4FD642E025B4D5F30069171E /* AlarmActivationViewController.swift in Sources */,
);
@@ -11,11 +11,24 @@ import AVFoundation
class AlarmActivationViewController: UIViewController
{
var timer: Timer?
var currentAlarm: Alarm?
init?(coder: NSCoder, currentAlarm: Alarm)
{
self.currentAlarm = currentAlarm
//print(currentAlarm.wakeMethod)
super.init(coder: coder)
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override func viewDidLoad()
{
super.viewDidLoad()
timer = Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(AlarmActivationViewController.playSound), userInfo: nil, repeats: true)
setAlarmType()
}
@objc func playSound()
@@ -23,4 +36,23 @@ class AlarmActivationViewController: UIViewController
AudioServicesPlayAlertSound(SystemSoundID(1005))
AudioServicesPlayAlertSound(kSystemSoundID_Vibrate)
}
func setAlarmType()
{
if let alarm = currentAlarm
{
switch alarm.wakeMethod.name {
case "Walk":
walkAction()
case "Jump":
jumpAction()
case "Puzzle":
puzzleAction()
case "Smash":
print("")
default:
print("Invalid alarm type")
}
}
}
}
+9 -3
View File
@@ -20,6 +20,7 @@ class AlarmActivator: UITabBarController
/// Timer for scheduled calls
var timer: Timer?
var alarm: Alarm?
override func viewDidLoad()
{
@@ -49,7 +50,7 @@ class AlarmActivator: UITabBarController
*/
@objc func check()
{
NSLog("Check")
//NSLog("Check")
// Get the alarm to activate
let alarms = Alarms.fromLocal()
@@ -62,9 +63,14 @@ class AlarmActivator: UITabBarController
}
alarms.localSave()
self.alarm = alarm
// Segue
NSLog(JSON.stringify(alarm)!)
//NSLog(JSON.stringify(alarm)!)
performSegue(withIdentifier: "activate-alarm", sender: alarm)
}
@IBSegueAction func sendAlarm(_ coder: NSCoder) -> AlarmActivationViewController? {
return AlarmActivationViewController(coder: coder, currentAlarm: alarm!)
}
}
+1 -1
View File
@@ -672,7 +672,7 @@
<segue destination="Bqt-du-DT2" kind="relationship" relationship="viewControllers" id="ZTh-ke-ZIV"/>
<segue destination="BYZ-38-t0r" kind="relationship" relationship="viewControllers" destinationCreationSelector="Account" id="NN6-JO-Hmi"/>
<segue destination="r8W-6e-Hn2" kind="relationship" relationship="viewControllers" destinationCreationSelector="Testing" id="SLn-vq-UnH"/>
<segue destination="hDW-11-g9U" kind="showDetail" identifier="activate-alarm" id="z9o-Jh-fnM"/>
<segue destination="hDW-11-g9U" kind="showDetail" identifier="activate-alarm" destinationCreationSelector="sendAlarm:" id="z9o-Jh-fnM"/>
</connections>
</tabBarController>
<placeholder placeholderIdentifier="IBFirstResponder" id="S6R-Xr-Nfe" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
+86
View File
@@ -0,0 +1,86 @@
//
// MathExpressions.swift
// ProjectClock
//
// Class that will generate a simple math expression
import Foundation
enum MathElement : CustomStringConvertible {
case Integer(value: Int)
case Percentage(value: Int)
case Expression(expression: MathExpression)
var description: String {
switch self {
case .Integer(let value): return "\(value)"
case .Percentage(let percentage): return "\(percentage)%"
case .Expression(let expr): return expr.description
}
}
var nsExpressionFormatString : String {
switch self {
case .Integer(let value): return "\(value).0"
case .Percentage(let percentage): return "\(Double(percentage) / 100)"
case .Expression(let expr): return "(\(expr.description))"
}
}
}
enum MathOperator : String {
case plus = "+"
case minus = "-"
case multiply = "*"
case divide = "/"
static func random() -> MathOperator {
let allMathOperators: [MathOperator] = [.plus, .minus, .multiply, .divide]
let index = Int(arc4random_uniform(UInt32(allMathOperators.count)))
return allMathOperators[index]
}
}
class MathExpression : CustomStringConvertible {
var lhs: MathElement
var rhs: MathElement
var `operator`: MathOperator
init(lhs: MathElement, rhs: MathElement, operator: MathOperator) {
self.lhs = lhs
self.rhs = rhs
self.operator = `operator`
}
var description: String {
var leftString = ""
var rightString = ""
if case .Expression(_) = lhs {
leftString = "(\(lhs))"
} else {
leftString = lhs.description
}
if case .Expression(_) = rhs {
rightString = "(\(rhs))"
} else {
rightString = rhs.description
}
return "\(leftString) \(self.operator.rawValue) \(rightString)"
}
var result : Any? {
let format = "\(lhs.nsExpressionFormatString) \(`operator`.rawValue) \(rhs.nsExpressionFormatString)"
let expr = NSExpression(format: format)
return expr.expressionValue(with: nil, context: nil)
}
static func random() -> MathExpression {
let lhs = MathElement.Integer(value: Int(arc4random_uniform(10)))
let rhs = MathElement.Integer(value: Int(arc4random_uniform(10)))
return MathExpression(lhs: lhs, rhs: rhs, operator: .random())
}
}
+1
View File
@@ -34,3 +34,4 @@ func puzzleAction() {
func smashAction() {
}