-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMoreViewController.swift
More file actions
193 lines (151 loc) · 6.63 KB
/
MoreViewController.swift
File metadata and controls
193 lines (151 loc) · 6.63 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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
//
// MoreViewController.swift
// MickleDeals
//
// Created by Chan, Nicky on 8/16/15.
// Copyright © 2015 Chan, Nicky. All rights reserved.
//
import UIKit
class MoreViewController: UITableViewController, UIAlertViewDelegate, MDLoginCallback {
@IBOutlet weak var emailLabel: UILabel!
var alertView: UIAlertView!
let hideLoginSections = [1, 3]
let hideLogoutSections = [0]
override func viewDidLoad() {
super.viewDidLoad()
self.clearsSelectionOnViewWillAppear = true
MDLoginManager.loginCallbackList.append(self)
showEmail()
// tableView.reloadData()
}
override func tableView(tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
if section == tableView.numberOfSections - 1 {
let footerView = UILabel()
footerView.text = "All Rights Reserved © MickleDeals LLC\n\nVersion 1.0"
footerView.textAlignment = NSTextAlignment.Center
footerView.textColor = UIColor.lightGrayColor()
footerView.font = footerView.font.fontWithSize(13)
footerView.numberOfLines = 0
return footerView
}
return nil
}
override func tableView(tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
if section == tableView.numberOfSections - 1 {
return 100
} else {
if hideLoginSections.contains(section) {
if !MDLoginManager.isLogin() {
return 0.1
}
} else if hideLogoutSections.contains(section) {
if MDLoginManager.isLogin() {
return 0.1
}
}
return 20
}
}
override func tableView(tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
if hideLoginSections.contains(section) {
if !MDLoginManager.isLogin() {
return 0.1
}
}
// else if hideLogoutSections.contains(section) {
// if MDLoginManager.isLogin() {
// return 0.1
// }
// }
return super.tableView(tableView, heightForHeaderInSection: section)
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if hideLoginSections.contains(section) {
if !MDLoginManager.isLogin() {
return 0
}
} else if hideLogoutSections.contains(section) {
if MDLoginManager.isLogin() {
return 0
}
}
return super.tableView(tableView, numberOfRowsInSection:section)
}
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
let tag = tableView.cellForRowAtIndexPath(indexPath)!.tag
//tag 5 is log in/signup, tag 6 is rate & comment on appstore
//if tag >= 1 &&
if tag == 1 {
//show get more credits alert
let title = "How to earn more Mickle Credits"
let message = "1. If you log in for 7 consecutive days, you will get $2 Mickle Credits. \n\n 2. Add a valid payment method to get $5 Mickle Credits"
showAlert(title, dismissTitle: "OK", actionTitle: nil, message: message, tag: tag, handler: nil)
tableView.deselectRowAtIndexPath(indexPath, animated: true)
} else if tag == 2 {
let title = "Are you sure you want to log out of \(MDLoginManager.userName == nil ? MDLoginManager.userEmail! : MDLoginManager.userName!) ?"
showAlert(title, dismissTitle: "Cancel", actionTitle: "Yes", message: nil, tag: tag, handler: logoutAlertAction)
} else if tag == 3 {
//show clear history alert
showAlert("Are you sure you want to clear search history?", dismissTitle: "Cancel", actionTitle: "Yes", message: nil, tag: tag, handler: clearHistoryAlertAction)
} else if tag == 4 {
//show remove used/expired alert
showAlert("Are you sure you want to clear used/expired coupons in My Coupons section?", dismissTitle: "Cancel", actionTitle: "Yes", message: nil, tag: tag, handler: removedUsedCouponsAlertAction)
}
}
func showAlert(title: String, dismissTitle: String, actionTitle: String?, message: String?, tag: Int, handler: ((AnyObject) -> Void)?) {
if #available(iOS 8.0, *) {
let alertController = UIAlertController(title: title, message: message, preferredStyle: UIAlertControllerStyle.Alert)
let cancelAction = UIAlertAction(title: dismissTitle, style: UIAlertActionStyle.Default, handler: nil)
alertController.addAction(cancelAction)
if actionTitle != nil {
let mainAction = UIAlertAction(title: actionTitle, style: UIAlertActionStyle.Default, handler: handler)
alertController.addAction(mainAction)
}
presentViewController(alertController, animated: true, completion: nil)
} else {
alertView = UIAlertView()
alertView.tag = tag
alertView.delegate = self
alertView.title = title
alertView.message = message
alertView.addButtonWithTitle(dismissTitle)
if actionTitle != nil {
alertView.addButtonWithTitle(actionTitle)
}
alertView.show()
}
}
func alertView(alertView: UIAlertView, clickedButtonAtIndex buttonIndex: Int) {
if buttonIndex == 1 {
if alertView.tag == 2 {
logoutAlertAction(nil)
} else if alertView.tag == 3 {
clearHistoryAlertAction(nil)
} else if alertView.tag == 4 {
removedUsedCouponsAlertAction(nil)
}
}
}
//@available(iOS 8.0, *)
func logoutAlertAction(alert: AnyObject?) -> Void {
MDLoginManager.logOut()
}
func clearHistoryAlertAction(alert: AnyObject?) -> Void {
}
func removedUsedCouponsAlertAction(alert: AnyObject?) -> Void {
}
func onLoginSuccess() {
tableView.reloadData()
showEmail()
}
func onLogOut() {
tableView.reloadData()
}
func showEmail() {
guard let emailText = MDLoginManager.userEmail else {
emailLabel.text = ""
return;
}
emailLabel.text = emailText
}
}