diff --git a/IVPNClient/Scenes/AccountScreen/AccountViewController.swift b/IVPNClient/Scenes/AccountScreen/AccountViewController.swift index 36072ab40..48992e634 100644 --- a/IVPNClient/Scenes/AccountScreen/AccountViewController.swift +++ b/IVPNClient/Scenes/AccountScreen/AccountViewController.swift @@ -77,11 +77,18 @@ class AccountViewController: UITableViewController { } } + @IBAction func toggleAccountHidden(_ sender: Any) { + let hidden = accountView.isAccountHidden + accountView.toggleAccountVisibility(hide: !hidden) + accountView.isAccountHidden = !hidden + } + // MARK: - View Lifecycle - 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) @@ -93,6 +100,10 @@ class AccountViewController: UITableViewController { sessionManager.getSessionStatus() } + @objc func willEnterForeground(notification: NSNotification) { + accountView.setupView(viewModel: viewModel) + } + // MARK: - Observers - func addObservers() { diff --git a/IVPNClient/Scenes/AccountScreen/View/AccountView.swift b/IVPNClient/Scenes/AccountScreen/View/AccountView.swift index a7e7d5066..eaf74bc7e 100644 --- a/IVPNClient/Scenes/AccountScreen/View/AccountView.swift +++ b/IVPNClient/Scenes/AccountScreen/View/AccountView.swift @@ -37,9 +37,11 @@ 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 - + var isAccountHidden = true private var serviceType = ServiceType.getType(currentPlan: Application.shared.serviceStatus.currentPlan) // MARK: - Methods - @@ -58,10 +60,30 @@ class AccountView: UITableView { header.frame = CGRect(x: 0, y: 0, width: Int(header.frame.width), height: headerHeight) reloadData() layoutIfNeeded() + toggleAccountVisibility(hide: isAccountHidden) } func initQRCode(viewModel: AccountViewModel) { qrCodeImage.image = UIImage.generateQRCode(from: viewModel.accountId) + toggleAccountVisibility(hide: isAccountHidden) + } + + func toggleAccountVisibility(hide: Bool) { + if hide { + 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 + } } } 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 @@ + 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) + } + +}