Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1 | pmbaty | 1 | // |
2 | // SettingsViewController.swift |
||
3 | // GyroMouse |
||
4 | // |
||
5 | // Created by Matteo Riva on 08/09/15. |
||
6 | // Copyright © 2015 Matteo Riva. All rights reserved. |
||
7 | // |
||
8 | |||
9 | import UIKit |
||
10 | |||
11 | protocol SettingsViewControllerDelegate: class { |
||
12 | func settingsDidChangeMoveVelocity(_ moveVelocity: Double); |
||
13 | func settingsDidChangeScrollVelocity(_ scrollVelocity: Double); |
||
14 | func settingsDidChangeShakeToReset(_ shakeActive: Bool); |
||
15 | } |
||
16 | |||
17 | class SettingsViewController: UIViewController { |
||
18 | |||
19 | |||
20 | @IBOutlet weak var moveSlider: UISlider! |
||
21 | @IBOutlet weak var scrollSlider: UISlider! |
||
22 | @IBOutlet weak var shakeSwitch: UISwitch! |
||
23 | @IBOutlet weak var screenSwitch: UISwitch! |
||
24 | @IBOutlet weak var versionLabel: UILabel! |
||
25 | |||
26 | weak var delegate: SettingsViewControllerDelegate? |
||
27 | |||
28 | override func viewDidLoad() { |
||
29 | super.viewDidLoad() |
||
30 | |||
31 | let moveVelocity = UserDefaults.standard.double(forKey: "moveVelocity") |
||
32 | let scrollVelocity = UserDefaults.standard.double(forKey: "scrollVelocity") |
||
33 | let shakeGest = UserDefaults.standard.bool(forKey: "shakeToReset") |
||
34 | let keepActive = UserDefaults.standard.bool(forKey: "keepScreenActive") |
||
35 | |||
36 | moveSlider.value = Float(moveVelocity) |
||
37 | scrollSlider.value = Float(scrollVelocity) |
||
38 | shakeSwitch.isOn = shakeGest |
||
39 | screenSwitch.isOn = keepActive |
||
40 | |||
41 | let infoDictionary = Bundle.main.infoDictionary! |
||
42 | let build: String = infoDictionary[String(kCFBundleVersionKey)] as! String |
||
43 | let version: String = infoDictionary["CFBundleShortVersionString"] as! String |
||
44 | versionLabel.text = "version".localized + " \(version) (\(build))" |
||
45 | } |
||
46 | |||
47 | @IBAction func moveSliderDidChange() { |
||
48 | let value = Double(moveSlider.value) |
||
49 | UserDefaults.standard.set(value, forKey: "moveVelocity") |
||
50 | delegate?.settingsDidChangeMoveVelocity(value) |
||
51 | } |
||
52 | |||
53 | @IBAction func scrollSliderDidChange() { |
||
54 | let value = Double(scrollSlider.value) |
||
55 | UserDefaults.standard.set(value, forKey: "scrollVelocity") |
||
56 | delegate?.settingsDidChangeScrollVelocity(value) |
||
57 | } |
||
58 | |||
59 | @IBAction func shakeSwitchDidChange() { |
||
60 | UserDefaults.standard.set(shakeSwitch.isOn, forKey: "shakeToReset") |
||
61 | delegate?.settingsDidChangeShakeToReset(shakeSwitch.isOn) |
||
62 | } |
||
63 | |||
64 | @IBAction func screenSwitchDidChange() { |
||
65 | UserDefaults.standard.set(screenSwitch.isOn, forKey: "keepScreenActive") |
||
66 | UIApplication.shared.isIdleTimerDisabled = screenSwitch.isOn |
||
67 | } |
||
68 | |||
69 | @IBAction func dismissAction() { |
||
70 | dismiss(animated: true, completion: nil) |
||
71 | } |
||
72 | |||
73 | } |