diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..01b9c63 Binary files /dev/null and b/.DS_Store differ diff --git a/Tipsy.xcodeproj/project.pbxproj b/Tipsy.xcodeproj/project.pbxproj index 794ee36..0304797 100644 --- a/Tipsy.xcodeproj/project.pbxproj +++ b/Tipsy.xcodeproj/project.pbxproj @@ -7,19 +7,21 @@ objects = { /* Begin PBXBuildFile section */ + 3EBB13D02421EBB0004D0768 /* ResultsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3EBB13CF2421EBB0004D0768 /* ResultsViewController.swift */; }; ADB689532326708D006D4E2B /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = ADB689522326708D006D4E2B /* AppDelegate.swift */; }; ADB689552326708D006D4E2B /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = ADB689542326708D006D4E2B /* SceneDelegate.swift */; }; - ADB689572326708D006D4E2B /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = ADB689562326708D006D4E2B /* ViewController.swift */; }; + ADB689572326708D006D4E2B /* CalculatorViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = ADB689562326708D006D4E2B /* CalculatorViewController.swift */; }; ADB6895A2326708D006D4E2B /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = ADB689582326708D006D4E2B /* Main.storyboard */; }; ADB6895C2326708E006D4E2B /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = ADB6895B2326708E006D4E2B /* Assets.xcassets */; }; ADB6895F2326708E006D4E2B /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = ADB6895D2326708E006D4E2B /* LaunchScreen.storyboard */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ + 3EBB13CF2421EBB0004D0768 /* ResultsViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ResultsViewController.swift; sourceTree = ""; }; ADB6894F2326708D006D4E2B /* Tipsy.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Tipsy.app; sourceTree = BUILT_PRODUCTS_DIR; }; ADB689522326708D006D4E2B /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; ADB689542326708D006D4E2B /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = ""; }; - ADB689562326708D006D4E2B /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; + ADB689562326708D006D4E2B /* CalculatorViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = CalculatorViewController.swift; path = ../CalculatorViewController.swift; sourceTree = ""; }; ADB689592326708D006D4E2B /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; ADB6895B2326708E006D4E2B /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; ADB6895E2326708E006D4E2B /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; @@ -37,6 +39,15 @@ /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ + 3EBB13D12421EBC4004D0768 /* Controllers */ = { + isa = PBXGroup; + children = ( + ADB689562326708D006D4E2B /* CalculatorViewController.swift */, + 3EBB13CF2421EBB0004D0768 /* ResultsViewController.swift */, + ); + path = Controllers; + sourceTree = ""; + }; ADB689462326708D006D4E2B = { isa = PBXGroup; children = ( @@ -58,7 +69,7 @@ children = ( ADB689522326708D006D4E2B /* AppDelegate.swift */, ADB689542326708D006D4E2B /* SceneDelegate.swift */, - ADB689562326708D006D4E2B /* ViewController.swift */, + 3EBB13D12421EBC4004D0768 /* Controllers */, ADB689582326708D006D4E2B /* Main.storyboard */, ADB6895B2326708E006D4E2B /* Assets.xcassets */, ADB6895D2326708E006D4E2B /* LaunchScreen.storyboard */, @@ -138,9 +149,10 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - ADB689572326708D006D4E2B /* ViewController.swift in Sources */, + ADB689572326708D006D4E2B /* CalculatorViewController.swift in Sources */, ADB689532326708D006D4E2B /* AppDelegate.swift in Sources */, ADB689552326708D006D4E2B /* SceneDelegate.swift in Sources */, + 3EBB13D02421EBB0004D0768 /* ResultsViewController.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/Tipsy.xcodeproj/project.xcworkspace/xcuserdata/tphan.xcuserdatad/UserInterfaceState.xcuserstate b/Tipsy.xcodeproj/project.xcworkspace/xcuserdata/tphan.xcuserdatad/UserInterfaceState.xcuserstate new file mode 100644 index 0000000..72fad11 Binary files /dev/null and b/Tipsy.xcodeproj/project.xcworkspace/xcuserdata/tphan.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/Tipsy.xcodeproj/xcuserdata/tphan.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/Tipsy.xcodeproj/xcuserdata/tphan.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist new file mode 100644 index 0000000..486cc74 --- /dev/null +++ b/Tipsy.xcodeproj/xcuserdata/tphan.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist @@ -0,0 +1,56 @@ + + + + + + + + + + + + + + + + + diff --git a/Tipsy.xcodeproj/xcuserdata/tphan.xcuserdatad/xcschemes/xcschememanagement.plist b/Tipsy.xcodeproj/xcuserdata/tphan.xcuserdatad/xcschemes/xcschememanagement.plist new file mode 100644 index 0000000..eec1f1d --- /dev/null +++ b/Tipsy.xcodeproj/xcuserdata/tphan.xcuserdatad/xcschemes/xcschememanagement.plist @@ -0,0 +1,14 @@ + + + + + SchemeUserState + + Tipsy.xcscheme_^#shared#^_ + + orderHint + 0 + + + + diff --git a/Tipsy/Base.lproj/Main.storyboard b/Tipsy/Base.lproj/Main.storyboard index 938fe27..c4bc75a 100644 --- a/Tipsy/Base.lproj/Main.storyboard +++ b/Tipsy/Base.lproj/Main.storyboard @@ -1,27 +1,28 @@ - + + - + - + - + - + - + - + - + @@ -72,7 +82,7 @@ - + @@ -122,10 +135,10 @@ - + - + @@ -152,7 +165,7 @@ @@ -181,24 +197,33 @@ + + + + + + + + + - + - + - + - + - + + + + + + - + + + + + + + + + + + + + + + + + + + diff --git a/Tipsy/CalculatorViewController.swift b/Tipsy/CalculatorViewController.swift new file mode 100644 index 0000000..25fe7be --- /dev/null +++ b/Tipsy/CalculatorViewController.swift @@ -0,0 +1,101 @@ +// +// ViewController.swift +// Tipsy +// +// Created by Angela Yu on 09/09/2019. +// Copyright © 2019 The App Brewery. All rights reserved. +// + +import UIKit + +class CalculatorViewController: UIViewController { + + @IBOutlet weak var billTextField: UITextField! + @IBOutlet weak var zeroPctButton: UIButton! + @IBOutlet weak var tenPctButton: UIButton! + @IBOutlet weak var twentyPctButton: UIButton! + @IBOutlet weak var splitNumberLabel: UILabel! + + var tip = 0.10 + var numberOfPeople: Int = 2 + var numberOfPeopleAsString: String = "" + var billTotal = 0.0 + var resultTo2DecimalPlace: String = "" + var buttonTitle: String = "" + + override func touchesBegan(_ touches: Set, with event: UIEvent?) { + view.endEditing(true) + } + + + @IBAction func tipChanged(_ sender: UIButton) { + zeroPctButton.isSelected = false + tenPctButton.isSelected = false + twentyPctButton.isSelected = false + + // Highlight selected button. + sender.isSelected = true + + // Grab button title. + buttonTitle = sender.currentTitle! + + // Remove % sign from the end of button title that was grabbed. + let buttonTitleMinusPercentSign = String(buttonTitle.dropLast()) + + // Change String into Double. + let buttonTitleAsANumber = Double(buttonTitleMinusPercentSign)! + + // Turn tip into decimal. + tip = buttonTitleAsANumber / 100 + + } + + @IBAction func stepperValueChanged(_ sender: UIStepper) { + + // Update var splitValue to label. + numberOfPeopleAsString = String(sender.value) + numberOfPeople = Int(sender.value) + + // Update bill split number label. + splitNumberLabel.text = String(numberOfPeople) + + } + + @IBAction func calculatePressed(_ sender: UIButton) { + + // Storing user inputted string from billTextField into a new constant. + let bill = billTextField.text! + + // If the text is not an empty string. + if bill != "" { + + // Convert string to double. + billTotal = Double(bill)! + + // Calculate amount including tip, split between number of people. + let result = billTotal * (1 + tip) / Double(numberOfPeople) + + // Convert double to string and format to 2 decimal places + resultTo2DecimalPlace = String(format: "%.2f", result) + + } + + //JUSTIN + performSegue(withIdentifier: "resultsSegue", sender: nil) + } + + //JUSTIN + override func prepare(for segue: UIStoryboardSegue, sender: Any?) { + if segue.identifier == "resultsSegue" { + + // Pass the values to ResultsViewController via Segue + let destinationVC = segue.destination as! ResultsViewController + print(self.resultTo2DecimalPlace) + destinationVC.billTotalIncludingTip = self.resultTo2DecimalPlace + destinationVC.numberOfPeopleResult = numberOfPeopleAsString + destinationVC.percentTipResult = buttonTitle + } + } + +} + diff --git a/Tipsy/Controllers/ResultsViewController.swift b/Tipsy/Controllers/ResultsViewController.swift new file mode 100644 index 0000000..766a214 --- /dev/null +++ b/Tipsy/Controllers/ResultsViewController.swift @@ -0,0 +1,32 @@ +// +// ResultsViewController.swift +// Tipsy +// +// Created by Tam Phan on 3/17/20. +// Copyright © 2020 The App Brewery. All rights reserved. +// + +import UIKit + +class ResultsViewController: UIViewController { + + @IBOutlet weak var totalLabel: UILabel! + @IBOutlet weak var settingsLabel: UILabel! + + var billTotalIncludingTip: String? + var numberOfPeopleResult: String? + var percentTipResult: String? + + override func viewDidLoad() { + super.viewDidLoad() + + // Test -- If nil, print PooP + totalLabel.text = billTotalIncludingTip ?? "PooP" + settingsLabel.text = "Split between \(numberOfPeopleResult!) people, with \(percentTipResult!) tip." + } + + @IBAction func recalculatePressed(_ sender: Any) { + + dismiss(animated: true, completion: nil) + } +} diff --git a/Tipsy/ViewController.swift b/Tipsy/ViewController.swift index c716da4..395635d 100644 --- a/Tipsy/ViewController.swift +++ b/Tipsy/ViewController.swift @@ -8,13 +8,21 @@ import UIKit -class ViewController: UIViewController { - - override func viewDidLoad() { - super.viewDidLoad() - // Do any additional setup after loading the view. - } +class CalculatorViewController: UIViewController { + @IBOutlet weak var billTextField: UITextField! + @IBOutlet weak var zeroPctButton: UIButton! + @IBOutlet weak var tenPctButton: UIButton! + @IBOutlet weak var twentyPctButton: UIButton! + @IBOutlet weak var splitNumberLabel: UILabel! + @IBAction func tipChanged(_ sender: Any) { + } + + @IBAction func stepperValueChanged(_ sender: Any) { + } + + @IBAction func calculatorPressed(_ sender: Any) { + } }