Skip to content
This repository was archived by the owner on Sep 20, 2023. It is now read-only.

Commit 0831550

Browse files
jdishornystrom
authored andcommitted
Change UISwitches colour to blue in Settings πŸ’…πŸ» (#2510)
* make all the functions under Private API private * use switch instead of if else * make the switches color blue * refactor more code in settings * apply some minor improvements
1 parent 5a1a2e2 commit 0831550

File tree

3 files changed

+59
-81
lines changed

3 files changed

+59
-81
lines changed

β€ŽClasses/Settings/DefaultReactionDetailController.swift

+25-40
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,35 @@ class DefaultReactionDetailController: UITableViewController {
2626

2727
override func viewDidLoad() {
2828
super.viewDidLoad()
29+
2930
checkCurrentDefault()
30-
tableView.reloadData()
3131
}
3232

3333
override func numberOfSections(in tableView: UITableView) -> Int {
3434
return enabledSwitch.isOn ? 2 : 1
3535
}
3636

37+
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
38+
tableView.deselectRow(at: indexPath, animated: trueUnlessReduceMotionEnabled)
39+
let cell = tableView.cellForRow(at: indexPath)
40+
41+
switch cell {
42+
case thumbsUpCell: updateDefault(reaction: .thumbsUp)
43+
case thumbsDownCell: updateDefault(reaction: .thumbsDown)
44+
case laughCell: updateDefault(reaction: .laugh)
45+
case hoorayCell: updateDefault(reaction: .hooray)
46+
case confusedCell: updateDefault(reaction: .confused)
47+
case heartCell: updateDefault(reaction: .heart)
48+
default: break
49+
}
50+
}
51+
52+
// MARK: Private API
53+
@IBAction private func toggleDefaultReaction(_ sender: Any) {
54+
enabledSwitch.isOn ? updateDefault(reaction: .thumbsUp) : disableReaction()
55+
updateSections()
56+
}
57+
3758
private func checkCurrentDefault() {
3859
guard let reaction = ReactionContent.defaultReaction else {
3960
enabledSwitch.isOn = false
@@ -56,48 +77,12 @@ class DefaultReactionDetailController: UITableViewController {
5677
rz_smoothlyDeselectRows(tableView: self.tableView)
5778

5879
// Reset all to none
59-
thumbsUpCell.accessoryType = .none
60-
thumbsDownCell.accessoryType = .none
61-
laughCell.accessoryType = .none
62-
hoorayCell.accessoryType = .none
63-
confusedCell.accessoryType = .none
64-
heartCell.accessoryType = .none
80+
[thumbsUpCell, thumbsDownCell, laughCell, hoorayCell, confusedCell, heartCell].forEach { $0.accessoryType = .none }
6581

6682
// Set proper cell to check
6783
cell.accessoryType = .checkmark
6884
}
6985

70-
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
71-
tableView.deselectRow(at: indexPath, animated: trueUnlessReduceMotionEnabled)
72-
let cell = tableView.cellForRow(at: indexPath)
73-
74-
switch cell {
75-
case thumbsUpCell:
76-
updateDefault(reaction: .thumbsUp)
77-
case thumbsDownCell:
78-
updateDefault(reaction: .thumbsDown)
79-
case laughCell:
80-
updateDefault(reaction: .laugh)
81-
case hoorayCell:
82-
updateDefault(reaction: .hooray)
83-
case confusedCell:
84-
updateDefault(reaction: .confused)
85-
case heartCell:
86-
updateDefault(reaction: .heart)
87-
default:
88-
break
89-
}
90-
}
91-
92-
@IBAction func toggleDefaultReaction(_ sender: Any) {
93-
if enabledSwitch.isOn {
94-
updateDefault(reaction: .thumbsUp)
95-
} else {
96-
disableReaction()
97-
}
98-
updateSections()
99-
}
100-
10186
private func updateDefault(reaction: ReactionContent) {
10287
UserDefaults.standard.setDefault(reaction: reaction)
10388
checkCurrentDefault()
@@ -111,10 +96,10 @@ class DefaultReactionDetailController: UITableViewController {
11196

11297
private func updateSections() {
11398
tableView.performBatchUpdates({
114-
if enabledSwitch.isOn {
99+
if enabledSwitch.isOn {
115100
self.tableView.insertSections(IndexSet(integer: 1), with: .top)
116101
} else {
117-
self.tableView.deleteSections(IndexSet(integer: 1), with: .top)
102+
self.tableView.deleteSections(IndexSet(integer: 1), with: .top)
118103
}
119104
}, completion: nil)
120105
}

β€ŽClasses/Settings/SettingsViewController.swift

+33-40
Original file line numberDiff line numberDiff line change
@@ -109,39 +109,32 @@ GitHubSessionListener {
109109
tableView.deselectRow(at: indexPath, animated: trueUnlessReduceMotionEnabled)
110110
let cell = tableView.cellForRow(at: indexPath)
111111

112-
if cell === reviewAccessCell {
113-
onReviewAccess()
114-
} else if cell === accountsCell {
115-
onAccounts()
116-
} else if cell === githubStatusCell {
117-
onGitHubStatus()
118-
} else if cell === reviewOnAppStoreCell {
119-
onReviewOnAppStore()
120-
} else if cell === reportBugCell {
121-
onReportBug()
122-
} else if cell === viewSourceCell {
123-
onViewSource()
124-
} else if cell === setDefaultReaction {
125-
onSetDefaultReaction()
126-
} else if cell === signOutCell {
127-
onSignOut()
128-
} else if cell === tryTestFlightBetaCell {
129-
onTryTestFlightBeta()
112+
switch cell {
113+
case reviewAccessCell: onReviewAccess()
114+
case accountsCell: onAccounts()
115+
case githubStatusCell: onGitHubStatus()
116+
case reviewOnAppStoreCell: onReviewOnAppStore()
117+
case reportBugCell: onReportBug()
118+
case viewSourceCell: onViewSource()
119+
case setDefaultReaction: onSetDefaultReaction()
120+
case signOutCell: onSignOut()
121+
case tryTestFlightBetaCell: onTryTestFlightBeta()
122+
default: break
130123
}
131124
}
132125

133126
// MARK: Private API
134127

135-
func updateDefaultReaction() {
128+
private func updateDefaultReaction() {
136129
defaultReactionLabel.text = ReactionContent.defaultReaction?.emoji
137130
?? NSLocalizedString("Off", comment: "")
138131
}
139132

140-
func onReviewAccess() {
133+
private func onReviewAccess() {
141134
UIApplication.shared.openReviewAccess()
142135
}
143136

144-
func onAccounts() {
137+
private func onAccounts() {
145138
if let navigationController = UIStoryboard(name: "Settings", bundle: nil).instantiateViewController(withIdentifier: "accountsNavigationController") as? UINavigationController,
146139
let accountsController = navigationController.topViewController as? SettingsAccountsViewController,
147140
let client = self.client {
@@ -150,17 +143,17 @@ GitHubSessionListener {
150143
}
151144
}
152145

153-
func onGitHubStatus() {
146+
private func onGitHubStatus() {
154147
guard let url = URLBuilder(host: "status.github.com").add(path: "messages").url
155148
else { return }
156149
presentSafari(url: url)
157150
}
158151

159-
func onReviewOnAppStore() {
152+
private func onReviewOnAppStore() {
160153
UIApplication.shared.openWriteReview()
161154
}
162155

163-
func onReportBug() {
156+
private func onReportBug() {
164157
guard let viewController = NewIssueTableViewController.create(
165158
client: GithubClient(userSession: sessionManager.focusedUserSession),
166159
owner: "GitHawkApp",
@@ -176,7 +169,7 @@ GitHubSessionListener {
176169
route_present(to: navController)
177170
}
178171

179-
func onViewSource() {
172+
private func onViewSource() {
180173
guard let client = client else {
181174
Squawk.showGenericError()
182175
return
@@ -189,7 +182,7 @@ GitHubSessionListener {
189182
route_detail(to: RepositoryViewController(client: client, repo: repo))
190183
}
191184

192-
func onSetDefaultReaction() {
185+
private func onSetDefaultReaction() {
193186
let storyboard = UIStoryboard(name: "Settings", bundle: nil)
194187
guard let viewController = storyboard.instantiateViewController(withIdentifier: "DefaultReactionDetailController") as? DefaultReactionDetailController else {
195188
fatalError("Cannot instantiate DefaultReactionDetailController instance")
@@ -198,7 +191,7 @@ GitHubSessionListener {
198191
route_detail(to: viewController)
199192
}
200193

201-
func onTryTestFlightBeta() {
194+
private func onTryTestFlightBeta() {
202195
#if TESTFLIGHT
203196
Squawk.showAlreadyOnBeta()
204197
#else
@@ -208,7 +201,7 @@ GitHubSessionListener {
208201
#endif
209202
}
210203

211-
func onSignOut() {
204+
private func onSignOut() {
212205
let title = NSLocalizedString("Are you sure?", comment: "")
213206
let message = NSLocalizedString("All of your accounts will be signed out, and their bookmarks will be removed. Do you want to continue?", comment: "")
214207
let alert = UIAlertController.configured(title: title, message: message, preferredStyle: .alert)
@@ -225,11 +218,11 @@ GitHubSessionListener {
225218
present(alert, animated: trueUnlessReduceMotionEnabled)
226219
}
227220

228-
func signout() {
221+
private func signout() {
229222
sessionManager.logout()
230223
}
231224

232-
@objc func updateBadge() {
225+
@objc private func updateBadge() {
233226
BadgeNotifications.check { result in
234227
let showSwitches: Bool
235228
let pushEnabled: Bool
@@ -258,41 +251,41 @@ GitHubSessionListener {
258251
}
259252
}
260253

261-
@IBAction func onBadgeChanged() {
254+
private func updateActiveAccount() {
255+
accountsCell.detailTextLabel?.text = sessionManager.focusedUserSession?.username ?? Constants.Strings.unknown
256+
}
257+
258+
@IBAction private func onBadgeChanged() {
262259
BadgeNotifications.isBadgeEnabled = badgeSwitch.isOn
263260
BadgeNotifications.configure { _ in
264261
self.updateBadge()
265262
}
266263
}
267264

268-
@IBAction func onPushChanged() {
265+
@IBAction private func onPushChanged() {
269266
BadgeNotifications.isLocalNotificationEnabled = pushSwitch.isOn
270267
BadgeNotifications.configure { _ in
271268
self.updateBadge()
272269
}
273270
}
274271

275-
@IBAction func onSettings(_ sender: Any) {
272+
@IBAction private func onSettings(_ sender: Any) {
276273
guard let url = URL(string: UIApplicationOpenSettingsURLString) else { return }
277274
UIApplication.shared.open(url)
278275
}
279276

280-
@IBAction func onMarkRead(_ sender: Any) {
277+
@IBAction private func onMarkRead(_ sender: Any) {
281278
NotificationModelController.setReadOnOpen(open: markReadSwitch.isOn)
282279
}
283280

284-
@IBAction func onSignature(_ sender: Any) {
281+
@IBAction private func onSignature(_ sender: Any) {
285282
Signature.enabled = signatureSwitch.isOn
286283
}
287284

288-
@IBAction func onPushNotificationsInfo(_ sender: Any) {
285+
@IBAction private func onPushNotificationsInfo(_ sender: Any) {
289286
showContextualMenu(PushNotificationsDisclaimerViewController())
290287
}
291288

292-
func updateActiveAccount() {
293-
accountsCell.detailTextLabel?.text = sessionManager.focusedUserSession?.username ?? Constants.Strings.unknown
294-
}
295-
296289
// MARK: NewIssueTableViewControllerDelegate
297290

298291
func didDismissAfterCreatingIssue(model: IssueDetailsModel) {

β€ŽClasses/Views/Styles.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ enum Styles {
125125
UINavigationBar.appearance().tintColor = Styles.Colors.Blue.medium.color
126126
UINavigationBar.appearance().titleTextAttributes =
127127
[NSAttributedStringKey.foregroundColor: Styles.Colors.Gray.dark.color]
128-
UISwitch.appearance().onTintColor = Styles.Colors.Green.medium.color
128+
UISwitch.appearance().onTintColor = Styles.Colors.Blue.medium.color
129129
UISearchBar.appearance().tintColor = Styles.Colors.Blue.medium.color
130130
DropdownTitleView.appearance().chevronTintColor = Styles.Colors.Gray.medium.color
131131
DropdownTitleView.appearance().titleColor = Styles.Colors.Gray.dark.color

0 commit comments

Comments
Β (0)