This repository has been archived by the owner on May 10, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 442
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
d5276e8
commit 87e7718
Showing
7 changed files
with
374 additions
and
131 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
// Copyright 2020 The Brave Authors. All rights reserved. | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
|
||
import UIKit | ||
import Shared | ||
import BraveUI | ||
import Lottie | ||
import NetworkExtension | ||
import GuardianConnect | ||
|
||
class BraveVPNPickerViewController: UIViewController { | ||
|
||
private var overlayView: UIView? | ||
let tableView: UITableView = .init(frame: .zero, style: .insetGrouped) | ||
|
||
deinit { | ||
NotificationCenter.default.removeObserver(self) | ||
} | ||
|
||
var isLoading: Bool = false { | ||
didSet { | ||
overlayView?.removeFromSuperview() | ||
|
||
navigationItem.hidesBackButton = isLoading | ||
|
||
// Prevent dismissing the modal by swipe when the VPN is being configured | ||
navigationController?.isModalInPresentation = isLoading | ||
|
||
if !isLoading { return } | ||
|
||
let overlay = UIView().then { | ||
$0.backgroundColor = UIColor.black.withAlphaComponent(0.5) | ||
let activityIndicator = UIActivityIndicatorView().then { indicator in | ||
indicator.startAnimating() | ||
indicator.autoresizingMask = [.flexibleWidth, .flexibleHeight] | ||
} | ||
|
||
$0.addSubview(activityIndicator) | ||
} | ||
|
||
view.addSubview(overlay) | ||
overlay.snp.makeConstraints { | ||
$0.edges.equalToSuperview() | ||
} | ||
|
||
overlayView = overlay | ||
} | ||
} | ||
|
||
init() { | ||
super.init(nibName: nil, bundle: nil) | ||
} | ||
|
||
@available(*, unavailable) | ||
required init?(coder: NSCoder) { fatalError() } | ||
|
||
override func viewDidLoad() { | ||
tableView.register(VPNRegionCell.self) | ||
|
||
NotificationCenter.default.addObserver(self, selector: #selector(vpnConfigChanged(notification:)), | ||
name: .NEVPNStatusDidChange, object: nil) | ||
|
||
view.addSubview(tableView) | ||
tableView.snp.makeConstraints { | ||
$0.edges.equalToSuperview() | ||
} | ||
} | ||
|
||
override func viewWillAppear(_ animated: Bool) { | ||
super.viewWillAppear(animated) | ||
tableView.reloadData() | ||
} | ||
|
||
@objc func vpnConfigChanged(notification: NSNotification) { } | ||
|
||
func showSuccessAlert(text: String) { | ||
let animation = AnimationView(name: "vpncheckmark", bundle: .module).then { | ||
$0.bounds = CGRect(x: 0, y: 0, width: 300, height: 200) | ||
$0.contentMode = .scaleAspectFill | ||
$0.play() | ||
} | ||
|
||
let popup = AlertPopupView(imageView: animation, | ||
title: text, message: "", | ||
titleWeight: .semibold, titleSize: 18, | ||
dismissHandler: { true }) | ||
|
||
popup.showWithType(showType: .flyUp, autoDismissTime: 1.5) | ||
} | ||
|
||
func showErrorAlert(title: String, message: String?) { | ||
DispatchQueue.main.async { | ||
let alert = AlertController(title: Strings.VPN.regionPickerErrorTitle, | ||
message: Strings.VPN.regionPickerErrorMessage, | ||
preferredStyle: .alert) | ||
let okAction = UIAlertAction(title: Strings.OKString, style: .default) { _ in | ||
self.dismiss(animated: true) | ||
} | ||
alert.addAction(okAction) | ||
|
||
self.present(alert, animated: true) | ||
} | ||
} | ||
} | ||
|
||
class VPNRegionCell: UITableViewCell, TableViewReusable { | ||
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) { | ||
super.init(style: .value1, reuseIdentifier: reuseIdentifier) | ||
} | ||
@available(*, unavailable) | ||
required init(coder: NSCoder) { | ||
fatalError() | ||
} | ||
} |
Oops, something went wrong.