/
MoreTableViewController.swift
218 lines (186 loc) · 7.06 KB
/
MoreTableViewController.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
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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
//
// MoreTableViewController.swift
// trySwift
//
// Created by Natasha Murashev on 2/12/16.
// Copyright © 2016 NatashaTheRobot. All rights reserved.
//
import UIKit
import AcknowList
import TrySwiftData
class MoreTableViewController: UITableViewController {
fileprivate let cellIdentifier = "BasicCell"
fileprivate let moreDetailSegue = "moreDetailSegue"
fileprivate var didShowDetail = false
fileprivate enum MoreSection: Int {
case eventDetails, acknowledgements, feedback, slack
}
fileprivate enum EventDetailsRow: Int {
case about, venue, codeOfConduct
}
fileprivate enum AcknowledgementsRow: Int {
case organizers, libraries
}
fileprivate enum FeedbackRow: Int {
case app, conference
}
fileprivate enum SlackRow: Int {
case open
}
override func awakeFromNib() {
super.awakeFromNib()
title = "More".localized()
}
override func viewDidLoad() {
super.viewDidLoad()
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
guard
let isCollapsed = splitViewController?.isCollapsed,
!isCollapsed,
!didShowDetail else { return }
didShowDetail = true
showAbout()
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
guard segue.identifier == moreDetailSegue,
let navigationVC = segue.destination as? UINavigationController,
let vc = sender as? UIViewController else { return }
navigationVC.pushViewController(vc, animated: true)
}
}
// MARK: - Table view data source
extension MoreTableViewController {
override func numberOfSections(in tableView: UITableView) -> Int {
return 4
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
switch MoreSection(rawValue: section)! {
case .eventDetails:
return 3
case .acknowledgements:
return 2
case .feedback:
return 2
case .slack:
return 1
}
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: cellIdentifier, for: indexPath)
switch MoreSection(rawValue: indexPath.section)! {
case .eventDetails:
switch EventDetailsRow(rawValue: indexPath.row)! {
case .about:
cell.textLabel?.text = "About".localized()
case .venue:
cell.textLabel?.text = "Venues".localized()
case .codeOfConduct:
cell.textLabel?.text = "Code of Conduct".localized()
}
case .acknowledgements:
switch AcknowledgementsRow(rawValue: indexPath.row)! {
case .organizers:
cell.textLabel?.text = "Organizers".localized()
case .libraries:
cell.textLabel?.text = "Acknowledgements".localized()
}
case .feedback:
switch FeedbackRow(rawValue: indexPath.row)! {
case .app:
cell.textLabel?.text = "App Feedback".localized()
case .conference:
cell.textLabel?.text = "Conference Feedback".localized()
}
case .slack:
switch SlackRow(rawValue: indexPath.row)! {
case .open:
cell.textLabel?.text = "Open Slack".localized()
}
}
return cell
}
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
tableView.deselectRow(at: indexPath, animated: true)
switch MoreSection(rawValue: indexPath.section)! {
case .eventDetails:
switch EventDetailsRow(rawValue: indexPath.row)! {
case .about:
showAbout()
case .venue:
showVenues()
case .codeOfConduct:
showCodeOfConduct()
}
case .acknowledgements:
switch AcknowledgementsRow(rawValue: indexPath.row)! {
case .organizers:
showOrganizers()
case .libraries:
showLibraries()
}
case .feedback:
switch FeedbackRow(rawValue: indexPath.row)! {
case .app:
showAppFeedback()
case .conference:
showConferenceFeedback()
}
case .slack:
switch SlackRow(rawValue: indexPath.row)! {
case .open:
openSlack()
}
}
}
}
private extension MoreTableViewController {
func showAbout() {
let aboutViewController = AboutTableViewController()
performSegue(withIdentifier: moreDetailSegue, sender: aboutViewController)
}
func showVenues() {
let venueController = VenuesViewController()
performSegue(withIdentifier: moreDetailSegue, sender: venueController)
}
func showCodeOfConduct() {
let webViewController = WebDisplayViewController()
webViewController.url = URL(string: "https://github.com/NatashaTheRobot/trySwiftCodeOfConduct/blob/master/README.md")!
webViewController.displayTitle = "Code of Conduct".localized()
performSegue(withIdentifier: moreDetailSegue, sender: webViewController)
}
func showOrganizers() {
let organizerViewController = OrganizersTableViewController()
performSegue(withIdentifier: moreDetailSegue, sender: organizerViewController)
}
func showLibraries() {
let path = Bundle.main.path(forResource: "Pods-trySwift-acknowledgements", ofType: "plist")
let acknowledgementesViewController = AcknowListViewController(acknowledgementsPlistPath: path)
acknowledgementesViewController.edgesForExtendedLayout = []
if #available(iOS 9.2, *) {
acknowledgementesViewController.headerText = "We 🤗 Open Source Software"
} else {
acknowledgementesViewController.headerText = "We ❤️ Open Source Software"
}
performSegue(withIdentifier: moreDetailSegue, sender: acknowledgementesViewController)
}
func showAppFeedback() {
let url = URL(string: "https://github.com/tryswift/trySwiftAppFinal/issues")!
openSafariViewController(withURL: url)
}
func showConferenceFeedback() {
let configuration = MailConfiguration(recipients: ["info@tryswift.co"], subject: "Conference feedback via try! Conference app")
sendMail(withConfiguration: configuration)
}
func openSlack() {
let application = UIApplication.shared
let appURL = URL(string: "slack://open")!
if application.canOpenURL(appURL) {
application.open(appURL)
} else {
let url = URL(string: "https://tryswiftjp2017.slack.com")!
openSafariViewController(withURL: url)
}
}
}