-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSettingsViewController.swift
More file actions
167 lines (121 loc) · 4.99 KB
/
SettingsViewController.swift
File metadata and controls
167 lines (121 loc) · 4.99 KB
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
//
// AccountViewController.swift
// Belashi-iOS
//
// Created by Noah on 8/1/16.
// Copyright © 2016 AppDelegates. All rights reserved.
//
import UIKit
import PKHUD
// TODO: This is a bit messy with all the initters
struct SettingsOption {
let label: String
var image: String? = nil
var segue: String? = nil
var action: Selector? = nil
init(label: String) {
self.label = label
}
init(label: String, image: String) {
self.label = label
self.image = image
}
init(label: String, segue: String) {
self.label = label
self.segue = segue
}
init(label: String, action: Selector ) {
self.label = label
self.action = action
}
}
class SettingsViewController : AccountBaseViewController, UITableViewDelegate, UITableViewDataSource, UITextFieldDelegate {
@IBAction func unwindToSettings(segue: UIStoryboardSegue) { }
var tableView: UITableView!
//TODO this is gross, but I am in a hurry
let options = Settings.sharedInstance.userIsDeveloper ?
[
SettingsOption(label: "My Venues", segue: "fromSettingsToVenues"),
SettingsOption(label: "Setup OG Device", segue: "fromSettingsToSetup"),
//SettingsOption(label: "Invite Friends", segue: "fromSettingsToInvite"),
SettingsOption(label: "Edit Account", segue: "fromSettingsToEdit"),
SettingsOption(label: "Developer", segue: "fromSettingsToDev"),
SettingsOption(label: "Log Out", action: #selector(logout)),
SettingsOption(label: "", action: #selector(secret)),
] :
[
SettingsOption(label: "My Venues", segue: "fromSettingsToVenues"),
SettingsOption(label: "Setup OG Device", segue: "fromSettingsToSetup"),
//SettingsOption(label: "Invite Friends", segue: "fromSettingsToInvite"),
SettingsOption(label: "Edit Account", segue: "fromSettingsToEdit"),
SettingsOption(label: "Log Out", action: #selector(logout)),
SettingsOption(label: "", action: #selector(secret)),
]
override func viewDidLoad() {
super.viewDidLoad()
self.tableView = self.view as! UITableView
self.tableView.delegate = self
self.tableView.dataSource = self
}
func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return options.count
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
tableView.deselectRow(at: indexPath, animated: true)
let op = options[indexPath.row]
if let segue = op.segue {
self.performSegue(withIdentifier: segue , sender: self)
}
if op.action != nil {
self.perform(op.action)
}
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "settingsCell", for: indexPath) as! SettingsCell
cell.isUserInteractionEnabled = true
let op = options[indexPath.row]
cell.label.text = op.label
if op.segue == nil {
cell.accessoryType = .none
} else {
cell.accessoryType = .disclosureIndicator
}
return cell
}
func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return 15.0
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 40.0
}
func logout() -> Void {
let alertController = UIAlertController(title: "Log out", message: "Are you sure you want to log out?", preferredStyle: .alert)
let cancelAction = UIAlertAction(title: "No", style: .cancel) { (action) in }
alertController.addAction(cancelAction)
let okAction = UIAlertAction(title: "Yes", style: .default) { (action) in
OGCloud.sharedInstance.logout()
.always{
HUD.flash(.labeledSuccess(title: "Logged out!", subtitle: ""), delay: 0.5, completion: { (_) in
self.performSegue(withIdentifier: "fromSettingsToRegistration", sender: nil)
})
}
}
alertController.addAction(okAction)
self.present(alertController, animated: true, completion: nil)
}
func secret(){
log.debug("secret!");
//ASNotification.error403.issue()
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if let op = sender as? SettingsOption {
segue.destination.title = op.label
}
}
}