Skip to content

Commit 0e01b02

Browse files
committed
Dynamically update Account tab after action was taken
1 parent cd79ac6 commit 0e01b02

10 files changed

+109
-366
lines changed

LockdowniOS.xcodeproj/project.pbxproj

+5-1
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@
168168
7C422EA525279724007F9C22 /* Align.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C422EA425279724007F9C22 /* Align.swift */; };
169169
7C422EAF252797A6007F9C22 /* AccountVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C422EAE252797A6007F9C22 /* AccountVC.swift */; };
170170
7C422EB72527A2D1007F9C22 /* MainTabBarViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C422EB62527A2D1007F9C22 /* MainTabBarViewController.swift */; };
171+
7C4D9BBB252C8748004175EA /* AccountUI.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C4D9BBA252C8748004175EA /* AccountUI.swift */; };
171172
7C6619BC247810E2005E8BB1 /* BlockDayLog.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C6619BB247810E2005E8BB1 /* BlockDayLog.swift */; };
172173
7C6619BD247810EE005E8BB1 /* BlockDayLog.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C6619BB247810E2005E8BB1 /* BlockDayLog.swift */; };
173174
7C6619BE247810EE005E8BB1 /* BlockDayLog.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C6619BB247810E2005E8BB1 /* BlockDayLog.swift */; };
@@ -525,6 +526,7 @@
525526
7C422EA425279724007F9C22 /* Align.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Align.swift; sourceTree = "<group>"; };
526527
7C422EAE252797A6007F9C22 /* AccountVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccountVC.swift; sourceTree = "<group>"; };
527528
7C422EB62527A2D1007F9C22 /* MainTabBarViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainTabBarViewController.swift; sourceTree = "<group>"; };
529+
7C4D9BBA252C8748004175EA /* AccountUI.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccountUI.swift; sourceTree = "<group>"; };
528530
7C6619BB247810E2005E8BB1 /* BlockDayLog.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BlockDayLog.swift; sourceTree = "<group>"; };
529531
7C9A936A251E1EC700DA5721 /* LockdownFirewallWidgetExtension.appex */ = {isa = PBXFileReference; explicitFileType = "wrapper.app-extension"; includeInIndex = 0; path = LockdownFirewallWidgetExtension.appex; sourceTree = BUILT_PRODUCTS_DIR; };
530532
7C9A936B251E1EC700DA5721 /* WidgetKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = WidgetKit.framework; path = System/Library/Frameworks/WidgetKit.framework; sourceTree = SDKROOT; };
@@ -985,7 +987,9 @@
985987
7C422EAC25279755007F9C22 /* Screens */ = {
986988
isa = PBXGroup;
987989
children = (
990+
3D9FC67A23E521E5004122D3 /* Account */,
988991
7C422EAD2527975E007F9C22 /* Main */,
992+
7C4D9BBA252C8748004175EA /* AccountUI.swift */,
989993
);
990994
name = Screens;
991995
sourceTree = "<group>";
@@ -1058,7 +1062,6 @@
10581062
7C422E95252796E2007F9C22 /* Views */,
10591063
7C1AE07E248028E40000A7D3 /* Extensions */,
10601064
3DFD0F8422F0F773002A3F25 /* Main */,
1061-
3D9FC67A23E521E5004122D3 /* Account */,
10621065
3DBD57A322FBB97D00DE189F /* Firewall */,
10631066
3D0711B922FE79FF00391C6E /* Why Trust */,
10641067
3DBD57A422FBBA4600DE189F /* VPN */,
@@ -1996,6 +1999,7 @@
19961999
3D9FC67923E521DE004122D3 /* ForgotPasswordViewController.swift in Sources */,
19972000
3D47CDC122F3C3F3003BD7F7 /* NVActivityIndicatorAnimationSemiCircleSpin.swift in Sources */,
19982001
3DBD57B422FCFF2500DE189F /* SetRegionViewController.swift in Sources */,
2002+
7C4D9BBB252C8748004175EA /* AccountUI.swift in Sources */,
19992003
3D47CDBE22F3C3F3003BD7F7 /* NVActivityIndicatorAnimationBallScale.swift in Sources */,
20002004
7C1AE073247FD82A0000A7D3 /* PushNotificationsAuthorization.swift in Sources */,
20012005
3D47CDBC22F3C3F3003BD7F7 /* NVActivityIndicatorAnimationLineSpinFadeLoader.swift in Sources */,

LockdowniOS/Account/EmailSignInViewController.swift

+7-4
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ import CocoaLumberjackSwift
1515

1616
class EmailSignInViewController: BaseViewController, UITextFieldDelegate, Loadable {
1717

18+
struct Delegate {
19+
var accountStateDidChange: () -> () = { }
20+
}
21+
22+
var delegate = Delegate()
23+
1824
@IBOutlet weak var emailField: UITextField!
1925
@IBOutlet weak var passwordField: UITextField!
2026

@@ -64,12 +70,9 @@ class EmailSignInViewController: BaseViewController, UITextFieldDelegate, Loadab
6470
try setAPICredentials(email: email, password: password)
6571
setAPICredentialsConfirmed(confirmed: true)
6672
self.hideLoadingView()
67-
73+
self.delegate.accountStateDidChange()
6874
self.showPopupDialog(title: "Success! 🎉", message: "You've successfully signed in.", acceptButton: "Okay") {
69-
let presenting = self.presentingViewController as? HomeViewController
7075
self.dismiss(animated: true, completion: {
71-
presenting?.reloadMenuDot()
72-
7376
// logged in and confirmed - update this email with the receipt and refresh VPN credentials
7477
firstly { () -> Promise<SubscriptionEvent> in
7578
try Client.subscriptionEvent()

LockdowniOS/Account/EmailSignUpViewController.swift

+9-2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@ import PromiseKit
1414

1515
class EmailSignUpViewController: BaseViewController, UITextFieldDelegate, Loadable {
1616

17+
struct Delegate {
18+
var accountStateDidChange: () -> () = { }
19+
var showSignIn: () -> () = { }
20+
}
21+
22+
var delegate = Delegate()
23+
1724
@IBOutlet weak var emailField: UITextField!
1825
@IBOutlet weak var passwordField: UITextField!
1926
@IBOutlet weak var lblPasswordValidation: UILabel!
@@ -117,6 +124,7 @@ class EmailSignUpViewController: BaseViewController, UITextFieldDelegate, Loadab
117124
}
118125
])
119126
self.present(popup, animated: true, completion: nil)
127+
self.delegate.accountStateDidChange()
120128
}
121129
catch {
122130
self.showPopupDialog(title: "Error Saving Credentials", message: "Couldn't save credentials to local keychain. Please report this error to team@lockdownhq.com.", acceptButton: "Okay")
@@ -134,9 +142,8 @@ class EmailSignUpViewController: BaseViewController, UITextFieldDelegate, Loadab
134142
}
135143

136144
@IBAction func signInClicked(_ sender: Any) {
137-
let presenting = self.presentingViewController
138145
dismiss(animated: true, completion: {
139-
presenting?.performSegue(withIdentifier: "showSignInFromHome", sender: nil)
146+
self.delegate.showSignIn()
140147
})
141148
}
142149

LockdowniOS/AccountUI.swift

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
//
2+
// AccountUI.swift
3+
// Lockdown
4+
//
5+
// Created by Oleg Dreyman on 06.10.2020.
6+
// Copyright © 2020 Confirmed Inc. All rights reserved.
7+
//
8+
9+
import UIKit
10+
11+
enum AccountUI {
12+
13+
static func presentCreateAccount(on vc: UIViewController, completion: @escaping () -> () = { }) {
14+
let storyboard = UIStoryboard.main
15+
let viewController = storyboard.instantiateViewController(withIdentifier: "emailSignUpViewController") as! EmailSignUpViewController
16+
viewController.delegate.showSignIn = { [weak vc] in
17+
if let strongVC = vc {
18+
AccountUI.presentSignInToAccount(on: strongVC, completion: completion)
19+
}
20+
}
21+
viewController.delegate.accountStateDidChange = completion
22+
23+
vc.present(viewController, animated: true, completion: nil)
24+
}
25+
26+
static func presentSignInToAccount(on vc: UIViewController, completion: @escaping () -> () = { }) {
27+
let storyboard = UIStoryboard.main
28+
let viewController = storyboard.instantiateViewController(withIdentifier: "emailSignInViewController") as! EmailSignInViewController
29+
viewController.delegate.accountStateDidChange = completion
30+
31+
vc.present(viewController, animated: true, completion: nil)
32+
}
33+
}

LockdowniOS/AccountVC.swift

+24-19
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,18 @@ final class AccountViewController: BaseViewController {
2424
tableView.anchors.edges.pin()
2525
tableView.separatorStyle = .singleLine
2626
tableView.cellLayoutMarginsFollowReadableWidth = true
27-
// tableView.delaysContentTouches = false
2827
tableView.deselectsCellsAutomatically = true
28+
tableView.tableFooterView = UIView()
2929

3030
createTable()
3131
}
3232
}
3333

3434
func reloadTable() {
35+
guard isViewLoaded else {
36+
return
37+
}
38+
3539
tableView.rows = []
3640
createTable()
3741
tableView.reloadData()
@@ -43,7 +47,9 @@ final class AccountViewController: BaseViewController {
4347
var title = "⚠️ Not Signed In"
4448
var message: String? = "Sign up below to unlock benefits of a Lockdown account."
4549
var firstButton = DefaultCell(title: NSLocalizedString("Sign Up | Sign In", comment: ""), height: buttonHeight, dismissOnTap: true) {
46-
self.performSegue(withIdentifier: "showCreateAccountFromHome", sender: self)
50+
AccountUI.presentCreateAccount(on: self) { [weak self] in
51+
self?.reloadTable()
52+
}
4753
}
4854

4955
if let apiCredentials = getAPICredentials() {
@@ -120,7 +126,7 @@ final class AccountViewController: BaseViewController {
120126
completion: nil)
121127
popup.addButtons([
122128
DefaultButton(title: NSLocalizedString("Okay", comment: ""), dismissOnTap: true) {
123-
// self.reloadMenuDot()
129+
self.reloadTable()
124130
}
125131
])
126132
self.present(popup, animated: true, completion: nil)
@@ -144,8 +150,8 @@ final class AccountViewController: BaseViewController {
144150
Client.clearCookies()
145151
clearAPICredentials()
146152
setAPICredentialsConfirmed(confirmed: false)
147-
// self.reloadMenuDot()
148-
// self.showPopupDialog(title: "Success", message: "Signed out successfully.", acceptButton: NSLocalizedString("Okay", comment: ""))
153+
self.reloadTable()
154+
self.showPopupDialog(title: "Success", message: "Signed out successfully.", acceptButton: NSLocalizedString("Okay", comment: ""))
149155
},
150156
DefaultButton(title: NSLocalizedString("Re-send", comment: ""), dismissOnTap: true) {
151157
firstly {
@@ -156,20 +162,20 @@ final class AccountViewController: BaseViewController {
156162
if (success == false) {
157163
message = "Failed to re-send email confirmation."
158164
}
159-
// self.showPopupDialog(title: "", message: message, acceptButton: NSLocalizedString("Okay", comment: ""))
165+
self.showPopupDialog(title: "", message: message, acceptButton: NSLocalizedString("Okay", comment: ""))
160166
}
161167
.catch { error in
162-
// if (self.popupErrorAsNSURLError(error)) {
163-
// return
164-
// }
165-
// else if let apiError = error as? ApiError {
166-
// _ = self.popupErrorAsApiError(apiError)
167-
// }
168-
// else {
169-
// self.showPopupDialog(title: NSLocalizedString("Error Re-sending Email Confirmation", comment: ""),
170-
// message: "\(error)",
171-
// acceptButton: NSLocalizedString("Okay", comment: ""))
172-
// }
168+
if (self.popupErrorAsNSURLError(error)) {
169+
return
170+
}
171+
else if let apiError = error as? ApiError {
172+
_ = self.popupErrorAsApiError(apiError)
173+
}
174+
else {
175+
self.showPopupDialog(title: NSLocalizedString("Error Re-sending Email Confirmation", comment: ""),
176+
message: "\(error)",
177+
acceptButton: NSLocalizedString("Okay", comment: ""))
178+
}
173179
}
174180
},
175181
])
@@ -344,9 +350,8 @@ func DefaultButtonCell(title: String, height: Int, dismissOnTap: Bool, action: @
344350
cell.button.isUserInteractionEnabled = false
345351
cell.button.titleLabel?.font = fontSemiBold17
346352
cell.button.tintColor = .tunnelsBlue
347-
// cell.label.textColor = .tunnelsBlue
348-
// cell.label.textAlignment = .center
349353
cell.contentView.addSubview(cell.button)
354+
cell.button.anchors.height.equal(21)
350355
cell.button.anchors.edges.marginsPin(insets: .init(top: 8, left: 0, bottom: 8, right: 0))
351356
return cell.onSelect(callback: action)
352357
}

LockdowniOS/AppDelegate.swift

+4-1
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
400400
popup.addButtons([
401401
DefaultButton(title: NSLocalizedString("Okay", comment: ""), dismissOnTap: true) {
402402
if let hvc = self.getCurrentViewController() as? HomeViewController {
403-
hvc.performSegue(withIdentifier: "showSignInFromHome", sender: nil)
403+
AccountUI.presentSignInToAccount(on: hvc)
404404
}
405405
}
406406
])
@@ -488,6 +488,9 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
488488
DefaultButton(title: NSLocalizedString("Okay", comment: ""), dismissOnTap: true) {}
489489
])
490490
self.getCurrentViewController()?.present(popup, animated: true, completion: nil)
491+
DispatchQueue.main.async {
492+
(self.window?.rootViewController as? MainTabBarController)?.accountViewController.reloadTable()
493+
}
491494
}
492495
.catch { error in
493496

0 commit comments

Comments
 (0)