Skip to content

Commit d30dc36

Browse files
committed
Bug 1156894 - Advance Firefox Account state when opening settings, and allow refresh. r=st3fan
2 parents 3ab72ff + e1a480a commit d30dc36

File tree

2 files changed

+39
-2
lines changed

2 files changed

+39
-2
lines changed

Account/FirefoxAccount.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ public class FirefoxAccount {
155155
}
156156
}
157157

158-
func advance() -> Deferred<FxAState> {
158+
public func advance() -> Deferred<FxAState> {
159159
let client = FxAClient10(endpoint: configuration.authEndpointURL)
160160
let stateMachine = FxALoginStateMachine(client: client)
161161
let now = NSDate.now()

Client/Frontend/Settings/SettingsTableViewController.swift

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,11 @@ private class AccountSetting: Setting, FxAContentViewControllerDelegate {
106106
let account = FirefoxAccount.fromConfigurationAndJSON(profile.accountConfiguration, data: data)!
107107
settings.profile.setAccount(account)
108108

109+
// Reload the data to reflect the new Account immediately.
109110
settings.tableView.reloadData()
111+
// And start advancing the Account state in the background as well.
112+
settings.SELrefresh()
113+
110114
settings.navigationController?.popToRootViewControllerAnimated(true)
111115
}
112116

@@ -160,7 +164,8 @@ private class DisconnectSetting: WithAccountSetting {
160164
alertController.addAction(
161165
UIAlertAction(title: NSLocalizedString("Disconnect", comment: "Disconnect button in the 'disconnect firefox account' alert"), style: .Destructive) { (action) in
162166
self.settings.profile.setAccount(nil)
163-
self.settings.tableView.reloadData()
167+
// Refresh, to show that we no longer have an Account immediately.
168+
self.settings.SELrefresh()
164169
})
165170
navigationController?.presentViewController(alertController, animated: true, completion: nil)
166171
}
@@ -328,6 +333,38 @@ class SettingsTableViewController: UITableViewController {
328333
tableView.registerClass(SettingsTableViewCell.self, forCellReuseIdentifier: Identifier)
329334
}
330335

336+
override func viewDidAppear(animated: Bool) {
337+
super.viewDidAppear(animated)
338+
SELrefresh()
339+
}
340+
341+
@objc private func SELrefresh() {
342+
// Through-out, be aware that modifying the control while a refresh is in progress is /not/ supported and will likely crash the app.
343+
if let account = self.profile.getAccount() {
344+
// Add the refresh control right away.
345+
if refreshControl == nil {
346+
refreshControl = UIRefreshControl()
347+
refreshControl?.addTarget(self, action: "SELrefresh", forControlEvents: UIControlEvents.ValueChanged)
348+
}
349+
350+
refreshControl?.beginRefreshing()
351+
account.advance().upon { _ in
352+
dispatch_async(dispatch_get_main_queue()) { () -> Void in
353+
self.tableView.reloadData()
354+
self.refreshControl?.endRefreshing()
355+
}
356+
}
357+
} else {
358+
// Remove the refresh control immediately after ending the refresh.
359+
refreshControl?.endRefreshing()
360+
if let refreshControl = self.refreshControl {
361+
refreshControl.removeFromSuperview()
362+
}
363+
refreshControl = nil
364+
self.tableView.reloadData()
365+
}
366+
}
367+
331368
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
332369
let section = settings[indexPath.section]
333370
if let setting = section[indexPath.row] {

0 commit comments

Comments
 (0)