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

This commit is contained in:
Aaron
2021-01-21 09:33:05 -05:00
4 changed files with 129 additions and 19 deletions
+34 -13
View File
@@ -17,29 +17,50 @@ class AddAlarmViewController: UIViewController
scrollView.addSubview(scrollViewInner)
scrollView.contentSize = scrollViewInner.frame.size
}
@IBOutlet weak var repeatWeekdaysSwitch: UISwitch!
@IBOutlet weak var repeatWeekendsSwitch: UISwitch!
// Pickers
@IBOutlet weak var timePicker: UIDatePicker!
@IBOutlet weak var wvmPicker: UIPickerView!
@IBAction func defaultRingtonesButton(_ sender: Any) {
}
@IBAction func soundLibraryButton(_ sender: Any) {
}
// UI Elements
@IBOutlet weak var repeatWeekdaysSwitch: UISwitch!
@IBOutlet weak var repeatWeekendsSwitch: UISwitch!
@IBOutlet weak var alarmNameTextField: UITextField!
override func viewDidLoad()
@IBAction func defaultRingtonesButton(_ sender: Any)
{
super.viewDidLoad()
}
@IBAction func soundLibraryButton(_ sender: Any)
{
}
/**
Called when the user clicks Add Alarm
*/
@IBAction func addAlarmButton(_ sender: Any) {
let (h, m, _) = timePicker.date.getHMS()
// Create the alarm
let alarm = Alarm(hour: h, minute: m,
text: alarmNameTextField.text ?? "Alarm",
wakeMethod: wvms[wvmPicker.selectedRow(inComponent: 0)],
lastActivate: Date())
// TODO: Set alarm.repeats to correspond with what the user selects
// Add the alarm to the list and save the list
Alarms.fromLocal().apply { $0.list.append(alarm) }.localSave();
// Dismiss this view
self.dismiss(animated: true, completion: nil)
}
}
class WVMDataSource: UIPickerView, UIPickerViewDelegate, UIPickerViewDataSource
{
required init?(coder: NSCoder)
+22 -2
View File
@@ -410,6 +410,9 @@
</constraints>
<fontDescription key="fontDescription" type="system" pointSize="30"/>
<state key="normal" image="checkmark" catalog="system"/>
<connections>
<action selector="addAlarmButton:" destination="Mki-dC-5Kc" eventType="touchUpInside" id="AiG-Cc-DlR"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="6d8-Gi-Ipa">
<rect key="frame" x="20" y="20" width="30" height="30"/>
@@ -490,7 +493,7 @@
<nil key="highlightedColor"/>
</label>
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" spacing="10" translatesAutoresizingMaskIntoConstraints="NO" id="e8v-cM-bxf">
<rect key="frame" x="20" y="553.5" width="334" height="72"/>
<rect key="frame" x="20" y="553.5" width="334" height="116"/>
<subviews>
<stackView opaque="NO" contentMode="scaleToFill" spacing="20" translatesAutoresizingMaskIntoConstraints="NO" id="iAX-G9-qxh">
<rect key="frame" x="0.0" y="0.0" width="334" height="31"/>
@@ -520,6 +523,22 @@
</switch>
</subviews>
</stackView>
<stackView opaque="NO" contentMode="scaleToFill" spacing="20" translatesAutoresizingMaskIntoConstraints="NO" id="gdH-Ok-RIH">
<rect key="frame" x="0.0" y="82" width="334" height="34"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Alarm Name:" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="5LP-Zk-4Sh">
<rect key="frame" x="0.0" y="0.0" width="98.5" height="34"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<textField opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" textAlignment="natural" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="bJg-zp-Aan">
<rect key="frame" x="118.5" y="0.0" width="215.5" height="34"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<textInputTraits key="textInputTraits"/>
</textField>
</subviews>
</stackView>
</subviews>
</stackView>
</subviews>
@@ -581,6 +600,7 @@
</view>
<navigationItem key="navigationItem" id="Ydw-dw-vLC"/>
<connections>
<outlet property="alarmNameTextField" destination="bJg-zp-Aan" id="Itt-3v-GJB"/>
<outlet property="repeatWeekdaysSwitch" destination="5oN-BL-Xtu" id="gqb-l3-1jZ"/>
<outlet property="repeatWeekendsSwitch" destination="WPM-Fh-sRB" id="LB7-zW-jpC"/>
<outlet property="scrollView" destination="ybc-8d-6pJ" id="m1B-ff-zeC"/>
@@ -591,7 +611,7 @@
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="0OD-e8-Pfh" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="-494" y="1576"/>
<point key="canvasLocation" x="-494.20289855072468" y="1575.6696428571429"/>
</scene>
<!--Alarm Activation View Controller-->
<scene sceneID="21H-AI-pzd">
+72 -3
View File
@@ -33,9 +33,10 @@ enum MathOperator : String {
case minus = "-"
case multiply = "*"
case divide = "/"
case power = "**"
static func random() -> MathOperator {
let allMathOperators: [MathOperator] = [.plus, .minus, .multiply, .divide]
let allMathOperators: [MathOperator] = [.plus, .minus, .multiply, .divide, .power]
let index = Int(arc4random_uniform(UInt32(allMathOperators.count)))
return allMathOperators[index]
@@ -71,10 +72,10 @@ class MathExpression : CustomStringConvertible {
return "\(leftString) \(self.operator.rawValue) \(rightString)"
}
var result : Any? {
var result : Int? {
let format = "\(lhs.nsExpressionFormatString) \(`operator`.rawValue) \(rhs.nsExpressionFormatString)"
let expr = NSExpression(format: format)
return expr.expressionValue(with: nil, context: nil)
return expr.expressionValue(with: nil, context: nil) as? Int
}
static func random() -> MathExpression {
@@ -84,3 +85,71 @@ class MathExpression : CustomStringConvertible {
return MathExpression(lhs: lhs, rhs: rhs, operator: .random())
}
}
//WARNING: This code is ugly, and probably out of place...but it works!
// Simple Problem - 2 expressions
class AlgProb2 : MathExpression{
let a = MathExpression.random()
let b = MathExpression.random()
func getProblem() -> String {
let problem = ("\(a) + \(b)")
return problem
}
func getAnswer() -> String {
let answer = "\(a.result! + b.result!)"
return answer
}
}
// Simple Problem - 3 expressions
class AlgProb3 : MathExpression{
let a = MathExpression.random()
let b = MathExpression.random()
let c = MathExpression.random()
func getProblem() -> String {
let problem = ("\(a) + \(b) + \(c)")
return problem
}
func getAnswer() -> String {
let answer = "\(a.result! + b.result! + c.result!)"
return answer
}
}
class quadraticProb{
let a = Int.random(in: 1...10)//ax^2
let b = Int.random(in: 1...10)//bx
let c = Int.random(in: 1...10)//c
var roots = [Int]()
func getProblem() -> String{
return "\(a)x^2 + \(b)x + \(c)"
}
//finds the roots of the quadratic **NOTE**: the return type is [Int], not a String
func getAnswer() -> [Int]{
let d = Int(pow(Double(b), 2) - 4 * Double(a) * Double(c)) // discriminant
// if d>0 , equation has two distinct real roots exist.
if d > 0 {
let x1 = Int((-Double(b) + sqrt(Double(d)))/(2*Double(a)))
let x2 = Int((-Double(b) - sqrt(Double(d)))/(2*Double(a)))
roots = [x1, x2]
}
//if d=0, equation has two repeated real roots.
else if d == 0 {
let x = Int(-Double(b)/(2*Double(a)))
roots = [x]
}
// if d<0 equation has two complex roots, but idk how to calculate that by hand, so we'll return nothing
else if d < 0 {
roots = []
}
return roots
}
}
+1 -1
View File
@@ -89,7 +89,7 @@ class Alarm: Codable
guard (repeats.contains { $0 }) else { return nil }
// If the day is not one of the "repeat" days, keep adding 1 until it is
while !repeats[date.get(.weekday)] { date = date.added(.day, 1) }
while !repeats[date.get(.weekday) - 1] { date = date.added(.day, 1) }
return date
}