-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAESettingsViewController.swift
102 lines (77 loc) · 3.93 KB
/
AESettingsViewController.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
//
// AESettingsViewController.swift
// Æffect
//
// Created by Joshua O'Steen on 4/21/15.
// Copyright (c) 2015 Josh O'Steen. All rights reserved.
//
import UIKit
class AESettingsViewController: UITableViewController {
struct AEData {
var emoji: String
var bgColor: UIColor
}
let emojiArray = ["😄", "😳", "😢", "😒", "😖", "😠"]
let emotionArray = ["happy", "surprise", "sadness", "worried", "fear", "anger"]
let aedictionary: [String: AEData] = [
"happy": AEData(emoji: "😄", bgColor: UIColor(red: 0.925, green: 0.776, blue: 0.184, alpha: 0.8)),
"surprise": AEData(emoji: "😳", bgColor: UIColor(red: 0.467, green: 0.749, blue: 0.173, alpha: 0.8)),
"sadness": AEData(emoji: "😢", bgColor: UIColor(red: 0.039, green: 0.510, blue: 0.663, alpha: 0.8)),
"worried": AEData(emoji: "😒", bgColor: UIColor(red: 0.494, green: 0.298, blue: 0.631, alpha: 0.8)),
"fear": AEData(emoji: "😖", bgColor: UIColor(red: 0.871, green: 0.000, blue: 0.286, alpha: 0.8)),
"anger": AEData(emoji: "😠", bgColor: UIColor(red: 0.914, green: 0.439, blue: 0.118, alpha: 0.8)),
]
@IBOutlet weak var defaultEmotionButton: UIButton!
@IBOutlet weak var nightMode: UISwitch!
override func viewDidLoad() {
super.viewDidLoad()
nightMode.on = NSUserDefaults.standardUserDefaults().boolForKey("nightMode")
// set popover content size
let bounds = UIScreen.mainScreen().bounds
var width : CGFloat = 0
var height : CGFloat = 0
if bounds.size.width < 375.0 { // 5s or older
width = bounds.size.width * 0.8
height = bounds.size.height * 0.55
} else {
width = bounds.size.width * 0.75
height = bounds.size.height * 0.4
}
self.preferredContentSize = CGSizeMake(width, height)
}
@IBAction func changeNightMode(sender: AnyObject) {
nightMode.on = (sender as! UISwitch).on
//println("check in settings" + "\(nightMode.on)")
NSUserDefaults.standardUserDefaults().setBool(nightMode.on, forKey: "nightMode")
NSUserDefaults.standardUserDefaults().synchronize()
NSNotificationCenter.defaultCenter().postNotificationName("load", object: nil)
}
override func viewWillAppear(animated: Bool) {
let defaults = NSUserDefaults.standardUserDefaults()
if let emotion = defaults.stringForKey("emotion"){
let idx = find(emotionArray, emotion)!
defaultEmotionButton.setTitle(emotionArray[idx].capitalizedString + " " + emojiArray[idx], forState: UIControlState.Normal)
defaultEmotionButton.setTitleColor(aedictionary[emotionArray[idx]]!.bgColor, forState: UIControlState.Normal)
}
}
@IBAction func switchDefaultEmotion(sender: UIButton!) {
let defaults = NSUserDefaults.standardUserDefaults()
let tempArray: [String] = sender.titleLabel!.text!.componentsSeparatedByString(" ")
let idx = (find(emojiArray, tempArray[1])! + 1) % emojiArray.count
defaults.setObject(emotionArray[idx], forKey: "emotion")
let newString = emotionArray[idx].capitalizedString + " " + emojiArray[idx]
sender.setTitle(newString, forState: UIControlState.Normal)
sender.setTitleColor(aedictionary[emotionArray[idx]]!.bgColor, forState: UIControlState.Normal)
}
// MARK: - Table view data source
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
// #warning Potentially incomplete method implementation.
// Return the number of sections.
return 2
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// #warning Incomplete method implementation.
// Return the number of rows in the section.
return 1
}
}