Skip to content
This repository has been archived by the owner on Oct 15, 2018. It is now read-only.

Commit

Permalink
Trim the fat
Browse files Browse the repository at this point in the history
  • Loading branch information
andreamazz committed May 24, 2015
1 parent b9f8bc2 commit 2b5e45f
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 68 deletions.
10 changes: 5 additions & 5 deletions Gulps/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -225,31 +225,31 @@
<constraint firstAttribute="height" constant="300" id="38h-4O-5tL"/>
</constraints>
</view>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" misplaced="YES" text="0%" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Nja-Uo-jJw">
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="0%" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Nja-Uo-jJw">
<rect key="frame" x="16" y="338" width="288" height="35"/>
<fontDescription key="fontDescription" name="KaushanScript-Regular" family="Kaushan Script" pointSize="24"/>
<color key="textColor" red="0.21960784310000001" green="0.49019607840000001" blue="0.81176470590000005" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" misplaced="YES" text="Liters drank in the last" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="4E2-NO-CiF">
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Liters drank in the last" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="4E2-NO-CiF">
<rect key="frame" x="16" y="133" width="288" height="25"/>
<fontDescription key="fontDescription" name="KaushanScript-Regular" family="Kaushan Script" pointSize="17"/>
<color key="textColor" red="0.21960784310000001" green="0.49019607840000001" blue="0.81176470590000005" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" misplaced="YES" text="200" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" minimumScaleFactor="0.5" translatesAutoresizingMaskIntoConstraints="NO" id="lon-Jb-3Cm" customClass="UICountingLabel">
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="200" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" minimumScaleFactor="0.5" translatesAutoresizingMaskIntoConstraints="NO" id="lon-Jb-3Cm" customClass="UICountingLabel">
<rect key="frame" x="16" y="40" width="288" height="93"/>
<fontDescription key="fontDescription" name="KaushanScript-Regular" family="Kaushan Script" pointSize="64"/>
<color key="textColor" red="0.21960784310000001" green="0.49019607840000001" blue="0.81176470590000005" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" misplaced="YES" text="days" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="jpZ-Ht-zcx">
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="days" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="jpZ-Ht-zcx">
<rect key="frame" x="16" y="263" width="288" height="25"/>
<fontDescription key="fontDescription" name="KaushanScript-Regular" family="Kaushan Script" pointSize="17"/>
<color key="textColor" red="0.21960784310000001" green="0.49019607840000001" blue="0.81176470590000005" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" misplaced="YES" text="200" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" minimumScaleFactor="0.5" translatesAutoresizingMaskIntoConstraints="NO" id="R2u-Oc-VLI" customClass="UICountingLabel">
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="200" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" minimumScaleFactor="0.5" translatesAutoresizingMaskIntoConstraints="NO" id="R2u-Oc-VLI" customClass="UICountingLabel">
<rect key="frame" x="16" y="170" width="288" height="93"/>
<fontDescription key="fontDescription" name="KaushanScript-Regular" family="Kaushan Script" pointSize="64"/>
<color key="textColor" red="0.21960784310000001" green="0.49019607840000001" blue="0.81176470590000005" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
Expand Down
73 changes: 33 additions & 40 deletions Gulps/ViewControllers/SettingsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,20 @@ class SettingsViewController: UITableViewController, UIAlertViewDelegate, UIText

let userDefaults = NSUserDefaults.groupUserDefaults()

let numberFormatter: NSNumberFormatter = {
let formatter = NSNumberFormatter()
formatter.numberStyle = .DecimalStyle
return formatter
}()

override func viewDidLoad() {
super.viewDidLoad()
self.title = "Preferences"
for element in [self.smallPortionText, self.largePortionText, self.dailyGoalText] {
for element in [smallPortionText, largePortionText, dailyGoalText] {
element.inputAccessoryView = Globals.numericToolbar(element,
selector: Selector("resignFirstResponder"),
barColor: UIColor.mainColor(),
textColor: UIColor.whiteColor())
barColor: .mainColor(),
textColor: .whiteColor())
}
}

Expand All @@ -35,24 +41,24 @@ class SettingsViewController: UITableViewController, UIAlertViewDelegate, UIText
let numberFormatter = NSNumberFormatter()
numberFormatter.numberStyle = .DecimalStyle
var suffix = ""
if let unit = UnitsOfMeasure(rawValue: self.userDefaults.integerForKey(Settings.General.UnitOfMeasure.key())) {
self.unitOfMesureLabel.text = unit.nameForUnitOfMeasure()
if let unit = UnitsOfMeasure(rawValue: userDefaults.integerForKey(Settings.General.UnitOfMeasure.key())) {
unitOfMesureLabel.text = unit.nameForUnitOfMeasure()
suffix = unit.suffixForUnitOfMeasure()
}

self.uomLabels.map({$0.text = suffix})
self.largePortionText.text = numberFormatter.stringFromNumber(self.userDefaults.doubleForKey(Settings.Gulp.Big.key()))
self.smallPortionText.text = numberFormatter.stringFromNumber(self.userDefaults.doubleForKey(Settings.Gulp.Small.key()))
self.dailyGoalText.text = numberFormatter.stringFromNumber(self.userDefaults.doubleForKey(Settings.Gulp.Goal.key()))
uomLabels.map({$0.text = suffix})
largePortionText.text = numberFormatter.stringFromNumber(userDefaults.doubleForKey(Settings.Gulp.Big.key()))
smallPortionText.text = numberFormatter.stringFromNumber(userDefaults.doubleForKey(Settings.Gulp.Small.key()))
dailyGoalText.text = numberFormatter.stringFromNumber(userDefaults.doubleForKey(Settings.Gulp.Goal.key()))

self.notificationSwitch.on = self.userDefaults.boolForKey(Settings.Notification.On.key())
self.notificationFromLabel.text = "\(self.userDefaults.integerForKey(Settings.Notification.From.key())):00"
self.notificationToLabel.text = "\(self.userDefaults.integerForKey(Settings.Notification.To.key())):00"
self.notificationIntervalLabel.text = "\(self.userDefaults.integerForKey(Settings.Notification.Interval.key())) hours"
notificationSwitch.on = userDefaults.boolForKey(Settings.Notification.On.key())
notificationFromLabel.text = "\(userDefaults.integerForKey(Settings.Notification.From.key())):00"
notificationToLabel.text = "\(userDefaults.integerForKey(Settings.Notification.To.key())):00"
notificationIntervalLabel.text = "\(userDefaults.integerForKey(Settings.Notification.Interval.key())) hours"
}

func updateNotificationPreferences() {
if (self.notificationSwitch.on) {
if (notificationSwitch.on) {
NotificationHelper.unscheduleNotifications()
NotificationHelper.askPermission()
} else {
Expand Down Expand Up @@ -121,8 +127,6 @@ class SettingsViewController: UITableViewController, UIAlertViewDelegate, UIText
}

@IBAction func reminderAction(sender: UISwitch) {
let userDefaults = NSUserDefaults.groupUserDefaults()

userDefaults.setBool(sender.on, forKey: Settings.Notification.On.key())
userDefaults.synchronize()
self.tableView.reloadData()
Expand All @@ -144,7 +148,7 @@ class SettingsViewController: UITableViewController, UIAlertViewDelegate, UIText
} else if (section == 1) {
return 3
} else {
if (NSUserDefaults.groupUserDefaults().boolForKey(Settings.Notification.On.key())) {
if NSUserDefaults.groupUserDefaults().boolForKey(Settings.Notification.On.key()) {
return 4
} else {
return 1
Expand All @@ -153,34 +157,23 @@ class SettingsViewController: UITableViewController, UIAlertViewDelegate, UIText
}

func textFieldDidEndEditing(textField: UITextField) {
let numberFormatter = NSNumberFormatter()
numberFormatter.numberStyle = .DecimalStyle
if (textField == self.smallPortionText) {
var small = 0.0
if let number = numberFormatter.numberFromString(self.smallPortionText.text) {
small = number as Double
}
self.userDefaults.setDouble(small, forKey: Settings.Gulp.Small.key())
self.userDefaults.synchronize()
if (textField == smallPortionText) {
storeText(smallPortionText, toKey: Settings.Gulp.Small.key())
}
if (textField == self.largePortionText) {
var big = 0.0
if let number = numberFormatter.numberFromString(self.largePortionText.text) {
big = number as Double
}
self.userDefaults.setDouble(big, forKey: Settings.Gulp.Big.key())
self.userDefaults.synchronize()
if (textField == largePortionText) {
storeText(largePortionText, toKey: Settings.Gulp.Big.key())
}
if (textField == self.dailyGoalText) {
var goal = 0.0
if let number = numberFormatter.numberFromString(self.dailyGoalText.text) {
goal = number as Double
}
self.userDefaults.setDouble(goal, forKey: Settings.Gulp.Goal.key())
self.userDefaults.synchronize()
if (textField == dailyGoalText) {
storeText(dailyGoalText, toKey: Settings.Gulp.Goal.key())
}
}

func storeText(textField: UITextField, toKey key: String) {
let number = numberFormatter.numberFromString(textField.text) as? Double
userDefaults.setDouble(number ?? 0.0, forKey: key)
userDefaults.synchronize()
}

func textField(textField: UITextField, shouldChangeCharactersInRange range: NSRange, replacementString string: String) -> Bool {
return Globals.numericTextField(textField, shouldChangeCharactersInRange: range, replacementString: string)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@ extension CalendarViewController {
}

animating = true
if let button = self.navigationItem.rightBarButtonItem {
let animatedButton: AnimatedShareButton = button.customView as! AnimatedShareButton
animatedButton.showsMenu = !animatedButton.showsMenu
if let button = self.navigationItem.rightBarButtonItem?.customView as? AnimatedShareButton {
button.showsMenu = !button.showsMenu
}
if (showingStats) {
let slideIn = POPSpringAnimation(propertyNamed: kPOPLayoutConstraintConstant)
Expand Down
40 changes: 20 additions & 20 deletions Gulps/ViewControllers/Support/DrinkViewController+Animations.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import pop
extension DrinkViewController {

func initAnimation() {
self.smallButton.alpha = 0
self.largeButton.alpha = 0
smallButton.alpha = 0
largeButton.alpha = 0
}

func expandAddButton() {
self.addButton.userInteractionEnabled = false
addButton.userInteractionEnabled = false

let rotate = POPSpringAnimation(propertyNamed: kPOPLayerRotation)
rotate.fromValue = 0
Expand Down Expand Up @@ -38,13 +38,13 @@ extension DrinkViewController {
color.springBounciness = 5
color.removedOnCompletion = true

self.addButton.layer.pop_addAnimation(rotate, forKey: "rotate")
self.addButton.pop_addAnimation(scale, forKey: "scale")
self.addButton.pop_addAnimation(color, forKey: "color")
self.minusButton.pop_addAnimation(scaleMinus, forKey: "scaleMinus")
addButton.layer.pop_addAnimation(rotate, forKey: "rotate")
addButton.pop_addAnimation(scale, forKey: "scale")
addButton.pop_addAnimation(color, forKey: "color")
minusButton.pop_addAnimation(scaleMinus, forKey: "scaleMinus")

[self.smallButton, self.largeButton].map({$0.alpha = 1})
for button in [self.smallButton, self.largeButton] {
[smallButton, largeButton].map({$0.alpha = 1})
for button in [smallButton, largeButton] {
let pop = POPSpringAnimation(propertyNamed: kPOPViewScaleXY)
pop.fromValue = NSValue(CGPoint: CGPointMake(0.1, 0.1))
pop.toValue = NSValue(CGPoint: CGPointMake(1, 1))
Expand All @@ -57,18 +57,18 @@ extension DrinkViewController {
left.springBounciness = 5
left.fromValue = 0
left.toValue = -100
self.smallButton.layer.pop_addAnimation(left, forKey: "left")
smallButton.layer.pop_addAnimation(left, forKey: "left")

let right = POPSpringAnimation(propertyNamed: kPOPLayerTranslationX)
right.springBounciness = 5
right.fromValue = 0
right.toValue = 100
self.largeButton.layer.pop_addAnimation(right, forKey: "right")
largeButton.layer.pop_addAnimation(right, forKey: "right")
}

func contractAddButton() {
[self.smallButton, self.largeButton].map({$0.userInteractionEnabled = false})
self.addButton.userInteractionEnabled = false
[smallButton, largeButton].map({$0.userInteractionEnabled = false})
addButton.userInteractionEnabled = false

let rotate = POPSpringAnimation(propertyNamed: kPOPLayerRotation)
rotate.fromValue = -M_PI + M_PI_4
Expand All @@ -95,12 +95,12 @@ extension DrinkViewController {
scaleMinus.toValue = NSValue(CGPoint: CGPointMake(1, 1))
scaleMinus.removedOnCompletion = true

self.addButton.layer.pop_addAnimation(rotate, forKey: "rotate")
self.addButton.pop_addAnimation(scale, forKey: "scale")
self.addButton.pop_addAnimation(color, forKey: "color")
self.minusButton.pop_addAnimation(scaleMinus, forKey: "scaleMinus")
addButton.layer.pop_addAnimation(rotate, forKey: "rotate")
addButton.pop_addAnimation(scale, forKey: "scale")
addButton.pop_addAnimation(color, forKey: "color")
minusButton.pop_addAnimation(scaleMinus, forKey: "scaleMinus")

for button in [self.smallButton, self.largeButton] {
for button in [smallButton, largeButton] {
let pop = POPSpringAnimation(propertyNamed: kPOPViewScaleXY)
pop.fromValue = NSValue(CGPoint: CGPointMake(1, 1))
pop.toValue = NSValue(CGPoint: CGPointMake(0.1, 0.1))
Expand All @@ -113,12 +113,12 @@ extension DrinkViewController {
left.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseOut)
left.fromValue = -100
left.toValue = 0
self.smallButton.layer.pop_addAnimation(left, forKey: "left")
smallButton.layer.pop_addAnimation(left, forKey: "left")

let right = POPBasicAnimation(propertyNamed: kPOPLayerTranslationX)
right.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseOut)
right.fromValue = 100
right.toValue = 0
self.largeButton.layer.pop_addAnimation(right, forKey: "right")
largeButton.layer.pop_addAnimation(right, forKey: "right")
}
}
1 change: 1 addition & 0 deletions Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ def common_pods
pod 'UICountingLabel', '~> 1.2'
pod 'JTCalendar', git: 'https://github.com/andreamazz/JTCalendar', branch: 'develop'
pod 'DPMeterView', git: 'https://github.com/andreamazz/DPMeterView'
# pod 'BEMSimpleLineGraph'
end

target 'Gulps' do
Expand Down

0 comments on commit 2b5e45f

Please sign in to comment.