From 629c156eedcdbf5d5842aeeed08b9f790ed40904 Mon Sep 17 00:00:00 2001 From: Juraj Hilje Date: Tue, 10 Sep 2024 10:38:22 +0200 Subject: [PATCH 1/6] feat(account): update AccountViewController.swift --- .../AccountScreen/AccountViewController.swift | 81 +++++++++++++++++++ .../AccountScreen/View/AccountView.swift | 1 + IVPNClient/Scenes/Base.lproj/Main.storyboard | 28 +++++-- 3 files changed, 104 insertions(+), 6 deletions(-) diff --git a/IVPNClient/Scenes/AccountScreen/AccountViewController.swift b/IVPNClient/Scenes/AccountScreen/AccountViewController.swift index 36072ab40..9ca8c6a14 100644 --- a/IVPNClient/Scenes/AccountScreen/AccountViewController.swift +++ b/IVPNClient/Scenes/AccountScreen/AccountViewController.swift @@ -37,6 +37,7 @@ class AccountViewController: UITableViewController { private var serviceType = ServiceType.getType(currentPlan: Application.shared.serviceStatus.currentPlan) private var deleteSettings = false private var forceLogOut = false + private var accountHidden = false var sessionManager: SessionManager { let sessionManager = SessionManager() @@ -77,6 +78,24 @@ class AccountViewController: UITableViewController { } } + @IBAction func toggleAccountHidden(_ sender: Any) { + if accountHidden { + accountView.hideAccountButton.setImage(UIImage.init(systemName: "eye.fill"), for: .normal) + accountView.accountIdLabel.removeBlur() + accountView.accountIdLabel.alpha = 1 + accountView.qrCodeImage.removeBlur() + accountView.qrCodeImage.alpha = 1 + } else { + accountView.hideAccountButton.setImage(UIImage.init(systemName: "eye.slash.fill"), for: .normal) + accountView.accountIdLabel.addBlur(2) + accountView.accountIdLabel.alpha = 0.7 + accountView.qrCodeImage.addBlur(2) + accountView.qrCodeImage.alpha = 0.5 + } + + accountHidden = !accountHidden + } + // MARK: - View Lifecycle - override func viewDidLoad() { @@ -219,3 +238,65 @@ extension AccountViewController: JGProgressHUDDelegate { } } + +class BlurEffectView: UIVisualEffectView { + + var animator = UIViewPropertyAnimator(duration: 1, curve: .linear) + + var intensity = 1.0 + + override func layoutSubviews() { + super.layoutSubviews() + frame = superview?.bounds ?? CGRect.zero + setupBlur() + } + + override func didMoveToSuperview() { + guard superview != nil else { return } + backgroundColor = .clear + setupBlur() + } + + private func setupBlur() { + animator.stopAnimation(true) + effect = nil + + animator.addAnimations { [weak self] in + self?.effect = UIBlurEffect(style: .regular) + } + + if intensity > 0 && intensity <= 10 { + + let value = CGFloat(intensity)/10 + animator.fractionComplete = value + + } + else { + animator.fractionComplete = 0.05 + } + + } + + deinit { + animator.stopAnimation(true) + } + +} + +extension UIView { + + func addBlur(_ intensity: Double = 1.0) { + let blurEffectView = BlurEffectView() + blurEffectView.intensity = intensity + self.addSubview(blurEffectView) + } + + func removeBlur() { + for subview in self.subviews { + if subview is UIVisualEffectView { + subview.removeFromSuperview() + } + } + } + +} diff --git a/IVPNClient/Scenes/AccountScreen/View/AccountView.swift b/IVPNClient/Scenes/AccountScreen/View/AccountView.swift index a7e7d5066..a86739d4d 100644 --- a/IVPNClient/Scenes/AccountScreen/View/AccountView.swift +++ b/IVPNClient/Scenes/AccountScreen/View/AccountView.swift @@ -37,6 +37,7 @@ class AccountView: UITableView { @IBOutlet weak var deviceNameTitle: UILabel! @IBOutlet weak var deviceName: UILabel! @IBOutlet weak var header: UIView! + @IBOutlet weak var hideAccountButton: UIButton! // MARK: - Properties - diff --git a/IVPNClient/Scenes/Base.lproj/Main.storyboard b/IVPNClient/Scenes/Base.lproj/Main.storyboard index d360ed775..24fdd99ef 100644 --- a/IVPNClient/Scenes/Base.lproj/Main.storyboard +++ b/IVPNClient/Scenes/Base.lproj/Main.storyboard @@ -1,9 +1,9 @@ - + - + @@ -3069,13 +3069,13 @@ - @@ -4501,6 +4514,8 @@ + + @@ -4510,7 +4525,6 @@ - @@ -4641,6 +4655,7 @@ + @@ -4894,6 +4909,7 @@ + From 45a4f5de6db10af0c17e32f6f9ae2734398cd1c1 Mon Sep 17 00:00:00 2001 From: Juraj Hilje Date: Tue, 10 Sep 2024 10:46:31 +0200 Subject: [PATCH 2/6] feat(account): update AccountView.swift --- .../AccountScreen/AccountViewController.swift | 77 +------------------ .../AccountScreen/View/AccountView.swift | 16 ++++ .../Utilities/Extensions/UIView+Ext.swift | 62 +++++++++++++++ 3 files changed, 79 insertions(+), 76 deletions(-) diff --git a/IVPNClient/Scenes/AccountScreen/AccountViewController.swift b/IVPNClient/Scenes/AccountScreen/AccountViewController.swift index 9ca8c6a14..0168cec15 100644 --- a/IVPNClient/Scenes/AccountScreen/AccountViewController.swift +++ b/IVPNClient/Scenes/AccountScreen/AccountViewController.swift @@ -79,20 +79,7 @@ class AccountViewController: UITableViewController { } @IBAction func toggleAccountHidden(_ sender: Any) { - if accountHidden { - accountView.hideAccountButton.setImage(UIImage.init(systemName: "eye.fill"), for: .normal) - accountView.accountIdLabel.removeBlur() - accountView.accountIdLabel.alpha = 1 - accountView.qrCodeImage.removeBlur() - accountView.qrCodeImage.alpha = 1 - } else { - accountView.hideAccountButton.setImage(UIImage.init(systemName: "eye.slash.fill"), for: .normal) - accountView.accountIdLabel.addBlur(2) - accountView.accountIdLabel.alpha = 0.7 - accountView.qrCodeImage.addBlur(2) - accountView.qrCodeImage.alpha = 0.5 - } - + accountView.toggleAccountVisibility(hide: accountHidden) accountHidden = !accountHidden } @@ -238,65 +225,3 @@ extension AccountViewController: JGProgressHUDDelegate { } } - -class BlurEffectView: UIVisualEffectView { - - var animator = UIViewPropertyAnimator(duration: 1, curve: .linear) - - var intensity = 1.0 - - override func layoutSubviews() { - super.layoutSubviews() - frame = superview?.bounds ?? CGRect.zero - setupBlur() - } - - override func didMoveToSuperview() { - guard superview != nil else { return } - backgroundColor = .clear - setupBlur() - } - - private func setupBlur() { - animator.stopAnimation(true) - effect = nil - - animator.addAnimations { [weak self] in - self?.effect = UIBlurEffect(style: .regular) - } - - if intensity > 0 && intensity <= 10 { - - let value = CGFloat(intensity)/10 - animator.fractionComplete = value - - } - else { - animator.fractionComplete = 0.05 - } - - } - - deinit { - animator.stopAnimation(true) - } - -} - -extension UIView { - - func addBlur(_ intensity: Double = 1.0) { - let blurEffectView = BlurEffectView() - blurEffectView.intensity = intensity - self.addSubview(blurEffectView) - } - - func removeBlur() { - for subview in self.subviews { - if subview is UIVisualEffectView { - subview.removeFromSuperview() - } - } - } - -} diff --git a/IVPNClient/Scenes/AccountScreen/View/AccountView.swift b/IVPNClient/Scenes/AccountScreen/View/AccountView.swift index a86739d4d..5c6089720 100644 --- a/IVPNClient/Scenes/AccountScreen/View/AccountView.swift +++ b/IVPNClient/Scenes/AccountScreen/View/AccountView.swift @@ -65,4 +65,20 @@ class AccountView: UITableView { qrCodeImage.image = UIImage.generateQRCode(from: viewModel.accountId) } + func toggleAccountVisibility(hide: Bool) { + if hide { + hideAccountButton.setImage(UIImage.init(systemName: "eye.fill"), for: .normal) + accountIdLabel.removeBlur() + accountIdLabel.alpha = 1 + qrCodeImage.removeBlur() + qrCodeImage.alpha = 1 + } else { + hideAccountButton.setImage(UIImage.init(systemName: "eye.slash.fill"), for: .normal) + accountIdLabel.addBlur(2) + accountIdLabel.alpha = 0.7 + qrCodeImage.addBlur(2) + qrCodeImage.alpha = 0.5 + } + } + } diff --git a/IVPNClient/Utilities/Extensions/UIView+Ext.swift b/IVPNClient/Utilities/Extensions/UIView+Ext.swift index b6f721a43..7df47390e 100644 --- a/IVPNClient/Utilities/Extensions/UIView+Ext.swift +++ b/IVPNClient/Utilities/Extensions/UIView+Ext.swift @@ -48,3 +48,65 @@ extension UIView { } } + +extension UIView { + + func addBlur(_ intensity: Double = 1.0) { + let blurEffectView = BlurEffectView() + blurEffectView.intensity = intensity + self.addSubview(blurEffectView) + } + + func removeBlur() { + for subview in self.subviews { + if subview is UIVisualEffectView { + subview.removeFromSuperview() + } + } + } + +} + +class BlurEffectView: UIVisualEffectView { + + var animator = UIViewPropertyAnimator(duration: 1, curve: .linear) + + var intensity = 1.0 + + override func layoutSubviews() { + super.layoutSubviews() + frame = superview?.bounds ?? CGRect.zero + setupBlur() + } + + override func didMoveToSuperview() { + guard superview != nil else { return } + backgroundColor = .clear + setupBlur() + } + + private func setupBlur() { + animator.stopAnimation(true) + effect = nil + + animator.addAnimations { [weak self] in + self?.effect = UIBlurEffect(style: .regular) + } + + if intensity > 0 && intensity <= 10 { + + let value = CGFloat(intensity)/10 + animator.fractionComplete = value + + } + else { + animator.fractionComplete = 0.05 + } + + } + + deinit { + animator.stopAnimation(true) + } + +} From 5e3a9d917063275cc3c6b9c44dc42e5962d48363 Mon Sep 17 00:00:00 2001 From: Juraj Hilje Date: Tue, 10 Sep 2024 10:54:08 +0200 Subject: [PATCH 3/6] feat(account): update UserDefaults+Ext.swift --- .../Scenes/AccountScreen/AccountViewController.swift | 7 ++++--- IVPNClient/Utilities/Extensions/UserDefaults+Ext.swift | 7 +++++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/IVPNClient/Scenes/AccountScreen/AccountViewController.swift b/IVPNClient/Scenes/AccountScreen/AccountViewController.swift index 0168cec15..5f251cd8e 100644 --- a/IVPNClient/Scenes/AccountScreen/AccountViewController.swift +++ b/IVPNClient/Scenes/AccountScreen/AccountViewController.swift @@ -37,7 +37,6 @@ class AccountViewController: UITableViewController { private var serviceType = ServiceType.getType(currentPlan: Application.shared.serviceStatus.currentPlan) private var deleteSettings = false private var forceLogOut = false - private var accountHidden = false var sessionManager: SessionManager { let sessionManager = SessionManager() @@ -79,8 +78,9 @@ class AccountViewController: UITableViewController { } @IBAction func toggleAccountHidden(_ sender: Any) { - accountView.toggleAccountVisibility(hide: accountHidden) - accountHidden = !accountHidden + let hidden = UserDefaults.shared.isAccountHidden + accountView.toggleAccountVisibility(hide: hidden) + UserDefaults.shared.set(!hidden, forKey: UserDefaults.Key.isAccountHidden) } // MARK: - View Lifecycle - @@ -96,6 +96,7 @@ class AccountViewController: UITableViewController { override func viewDidAppear(_ animated: Bool) { super.viewDidAppear(animated) accountView.initQRCode(viewModel: viewModel) + accountView.toggleAccountVisibility(hide: UserDefaults.shared.isAccountHidden) sessionManager.getSessionStatus() } diff --git a/IVPNClient/Utilities/Extensions/UserDefaults+Ext.swift b/IVPNClient/Utilities/Extensions/UserDefaults+Ext.swift index ec4449b09..551e40c57 100644 --- a/IVPNClient/Utilities/Extensions/UserDefaults+Ext.swift +++ b/IVPNClient/Utilities/Extensions/UserDefaults+Ext.swift @@ -95,6 +95,7 @@ extension UserDefaults { static let v2rayProtocol = "v2rayProtocol" static let isV2ray = "isV2ray" static let disableWidgetPrompt = "disableWidgetPrompt" + static let isAccountHidden = "isAccountHidden" } @objc dynamic var wireguardTunnelProviderError: String { @@ -261,6 +262,10 @@ extension UserDefaults { return bool(forKey: Key.disableWidgetPrompt) } + @objc dynamic var isAccountHidden: Bool { + return bool(forKey: Key.isAccountHidden) + } + static func registerUserDefaults() { shared.register(defaults: [Key.networkProtectionUntrustedConnect: true]) shared.register(defaults: [Key.networkProtectionTrustedDisconnect: true]) @@ -268,6 +273,7 @@ extension UserDefaults { shared.register(defaults: [Key.wgRegenerationRate: Config.wgKeyRegenerationRate]) shared.register(defaults: [Key.wgKeyTimestamp: Date()]) shared.register(defaults: [Key.serversSort: "city"]) + shared.register(defaults: [Key.isAccountHidden: true]) standard.register(defaults: [Key.selectedServerFastest: true]) standard.register(defaults: [Key.showIPv4Servers: true]) standard.register(defaults: [Key.preventSameCountryMultiHop: true]) @@ -302,6 +308,7 @@ extension UserDefaults { shared.removeObject(forKey: Key.v2rayProtocol) shared.removeObject(forKey: Key.isV2ray) shared.removeObject(forKey: Key.disableWidgetPrompt) + shared.removeObject(forKey: Key.isAccountHidden) standard.removeObject(forKey: Key.serviceStatus) standard.removeObject(forKey: Key.selectedHost) standard.removeObject(forKey: Key.selectedExitHost) From bd9c62205a05c594a77229ee33da0d834088af78 Mon Sep 17 00:00:00 2001 From: Juraj Hilje Date: Tue, 10 Sep 2024 11:08:36 +0200 Subject: [PATCH 4/6] feat(account): update AccountView.swift --- .../AccountScreen/AccountViewController.swift | 3 +-- .../Scenes/AccountScreen/View/AccountView.swift | 16 ++++++++++------ 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/IVPNClient/Scenes/AccountScreen/AccountViewController.swift b/IVPNClient/Scenes/AccountScreen/AccountViewController.swift index 5f251cd8e..91487df3f 100644 --- a/IVPNClient/Scenes/AccountScreen/AccountViewController.swift +++ b/IVPNClient/Scenes/AccountScreen/AccountViewController.swift @@ -79,7 +79,7 @@ class AccountViewController: UITableViewController { @IBAction func toggleAccountHidden(_ sender: Any) { let hidden = UserDefaults.shared.isAccountHidden - accountView.toggleAccountVisibility(hide: hidden) + accountView.toggleAccountVisibility(hide: !hidden) UserDefaults.shared.set(!hidden, forKey: UserDefaults.Key.isAccountHidden) } @@ -96,7 +96,6 @@ class AccountViewController: UITableViewController { override func viewDidAppear(_ animated: Bool) { super.viewDidAppear(animated) accountView.initQRCode(viewModel: viewModel) - accountView.toggleAccountVisibility(hide: UserDefaults.shared.isAccountHidden) sessionManager.getSessionStatus() } diff --git a/IVPNClient/Scenes/AccountScreen/View/AccountView.swift b/IVPNClient/Scenes/AccountScreen/View/AccountView.swift index 5c6089720..632297743 100644 --- a/IVPNClient/Scenes/AccountScreen/View/AccountView.swift +++ b/IVPNClient/Scenes/AccountScreen/View/AccountView.swift @@ -59,25 +59,29 @@ class AccountView: UITableView { header.frame = CGRect(x: 0, y: 0, width: Int(header.frame.width), height: headerHeight) reloadData() layoutIfNeeded() + toggleAccountVisibility(hide: UserDefaults.shared.isAccountHidden) } func initQRCode(viewModel: AccountViewModel) { qrCodeImage.image = UIImage.generateQRCode(from: viewModel.accountId) + toggleAccountVisibility(hide: UserDefaults.shared.isAccountHidden) } func toggleAccountVisibility(hide: Bool) { if hide { - hideAccountButton.setImage(UIImage.init(systemName: "eye.fill"), for: .normal) - accountIdLabel.removeBlur() - accountIdLabel.alpha = 1 - qrCodeImage.removeBlur() - qrCodeImage.alpha = 1 - } else { hideAccountButton.setImage(UIImage.init(systemName: "eye.slash.fill"), for: .normal) + accountIdLabel.removeBlur() accountIdLabel.addBlur(2) accountIdLabel.alpha = 0.7 + qrCodeImage.removeBlur() qrCodeImage.addBlur(2) qrCodeImage.alpha = 0.5 + } else { + hideAccountButton.setImage(UIImage.init(systemName: "eye.fill"), for: .normal) + accountIdLabel.removeBlur() + accountIdLabel.alpha = 1 + qrCodeImage.removeBlur() + qrCodeImage.alpha = 1 } } From cfa7e44414abe4e326156f52bd79db83f08703ca Mon Sep 17 00:00:00 2001 From: Juraj Hilje Date: Tue, 10 Sep 2024 17:15:27 +0200 Subject: [PATCH 5/6] feat(account): update AccountViewController.swift --- IVPNClient/Scenes/AccountScreen/AccountViewController.swift | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/IVPNClient/Scenes/AccountScreen/AccountViewController.swift b/IVPNClient/Scenes/AccountScreen/AccountViewController.swift index 91487df3f..108819e21 100644 --- a/IVPNClient/Scenes/AccountScreen/AccountViewController.swift +++ b/IVPNClient/Scenes/AccountScreen/AccountViewController.swift @@ -88,6 +88,7 @@ class AccountViewController: UITableViewController { override func viewDidLoad() { super.viewDidLoad() tableView.backgroundColor = UIColor.init(named: Theme.ivpnBackgroundQuaternary) + NotificationCenter.default.addObserver(self, selector: #selector(willEnterForeground), name: UIApplication.willEnterForegroundNotification, object: nil) initNavigationBar() addObservers() accountView.setupView(viewModel: viewModel) @@ -99,6 +100,10 @@ class AccountViewController: UITableViewController { sessionManager.getSessionStatus() } + @objc func willEnterForeground(notification: NSNotification) { + accountView.setupView(viewModel: viewModel) + } + // MARK: - Observers - func addObservers() { From 8c123609ace2a7a906bf1834d9ad82aabc2ed428 Mon Sep 17 00:00:00 2001 From: Juraj Hilje Date: Wed, 11 Sep 2024 14:51:37 +0200 Subject: [PATCH 6/6] feat(account): update AccountView.swift --- .../Scenes/AccountScreen/AccountViewController.swift | 4 ++-- IVPNClient/Scenes/AccountScreen/View/AccountView.swift | 5 +++-- IVPNClient/Utilities/Extensions/UserDefaults+Ext.swift | 7 ------- 3 files changed, 5 insertions(+), 11 deletions(-) diff --git a/IVPNClient/Scenes/AccountScreen/AccountViewController.swift b/IVPNClient/Scenes/AccountScreen/AccountViewController.swift index 108819e21..48992e634 100644 --- a/IVPNClient/Scenes/AccountScreen/AccountViewController.swift +++ b/IVPNClient/Scenes/AccountScreen/AccountViewController.swift @@ -78,9 +78,9 @@ class AccountViewController: UITableViewController { } @IBAction func toggleAccountHidden(_ sender: Any) { - let hidden = UserDefaults.shared.isAccountHidden + let hidden = accountView.isAccountHidden accountView.toggleAccountVisibility(hide: !hidden) - UserDefaults.shared.set(!hidden, forKey: UserDefaults.Key.isAccountHidden) + accountView.isAccountHidden = !hidden } // MARK: - View Lifecycle - diff --git a/IVPNClient/Scenes/AccountScreen/View/AccountView.swift b/IVPNClient/Scenes/AccountScreen/View/AccountView.swift index 632297743..eaf74bc7e 100644 --- a/IVPNClient/Scenes/AccountScreen/View/AccountView.swift +++ b/IVPNClient/Scenes/AccountScreen/View/AccountView.swift @@ -41,6 +41,7 @@ class AccountView: UITableView { // MARK: - Properties - + var isAccountHidden = true private var serviceType = ServiceType.getType(currentPlan: Application.shared.serviceStatus.currentPlan) // MARK: - Methods - @@ -59,12 +60,12 @@ class AccountView: UITableView { header.frame = CGRect(x: 0, y: 0, width: Int(header.frame.width), height: headerHeight) reloadData() layoutIfNeeded() - toggleAccountVisibility(hide: UserDefaults.shared.isAccountHidden) + toggleAccountVisibility(hide: isAccountHidden) } func initQRCode(viewModel: AccountViewModel) { qrCodeImage.image = UIImage.generateQRCode(from: viewModel.accountId) - toggleAccountVisibility(hide: UserDefaults.shared.isAccountHidden) + toggleAccountVisibility(hide: isAccountHidden) } func toggleAccountVisibility(hide: Bool) { diff --git a/IVPNClient/Utilities/Extensions/UserDefaults+Ext.swift b/IVPNClient/Utilities/Extensions/UserDefaults+Ext.swift index 551e40c57..ec4449b09 100644 --- a/IVPNClient/Utilities/Extensions/UserDefaults+Ext.swift +++ b/IVPNClient/Utilities/Extensions/UserDefaults+Ext.swift @@ -95,7 +95,6 @@ extension UserDefaults { static let v2rayProtocol = "v2rayProtocol" static let isV2ray = "isV2ray" static let disableWidgetPrompt = "disableWidgetPrompt" - static let isAccountHidden = "isAccountHidden" } @objc dynamic var wireguardTunnelProviderError: String { @@ -262,10 +261,6 @@ extension UserDefaults { return bool(forKey: Key.disableWidgetPrompt) } - @objc dynamic var isAccountHidden: Bool { - return bool(forKey: Key.isAccountHidden) - } - static func registerUserDefaults() { shared.register(defaults: [Key.networkProtectionUntrustedConnect: true]) shared.register(defaults: [Key.networkProtectionTrustedDisconnect: true]) @@ -273,7 +268,6 @@ extension UserDefaults { shared.register(defaults: [Key.wgRegenerationRate: Config.wgKeyRegenerationRate]) shared.register(defaults: [Key.wgKeyTimestamp: Date()]) shared.register(defaults: [Key.serversSort: "city"]) - shared.register(defaults: [Key.isAccountHidden: true]) standard.register(defaults: [Key.selectedServerFastest: true]) standard.register(defaults: [Key.showIPv4Servers: true]) standard.register(defaults: [Key.preventSameCountryMultiHop: true]) @@ -308,7 +302,6 @@ extension UserDefaults { shared.removeObject(forKey: Key.v2rayProtocol) shared.removeObject(forKey: Key.isV2ray) shared.removeObject(forKey: Key.disableWidgetPrompt) - shared.removeObject(forKey: Key.isAccountHidden) standard.removeObject(forKey: Key.serviceStatus) standard.removeObject(forKey: Key.selectedHost) standard.removeObject(forKey: Key.selectedExitHost)