Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

[IP-368] Update VPN view designs

  • Loading branch information
mahmoud-adam85 committed Apr 2, 2019
1 parent 6a3ab01 commit eba688237c3d4577433bb3019cc979124aee5968
@@ -63,6 +63,7 @@
1E2C435A21F89E6500891FB2 /* LumenWhiteTheme.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1E2C435921F89E6500891FB2 /* LumenWhiteTheme.swift */; };
1E2C435C21F89E8100891FB2 /* LumenDarkTheme.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1E2C435B21F89E8100891FB2 /* LumenDarkTheme.swift */; };
1E2E551221187407003B50BE /* UIImageViewAligned.m in Sources */ = {isa = PBXBuildFile; fileRef = D8C75DF2207584C300BB8AD0 /* UIImageViewAligned.m */; };
1E2F488B225256C400B717B7 /* VPNInfoView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1E2F488A225256C400B717B7 /* VPNInfoView.swift */; };
1E351C3A21CA994800275941 /* BrowserViewController+ReaderMode.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1E351C3821CA994800275941 /* BrowserViewController+ReaderMode.swift */; };
1E351C3B21CA994800275941 /* BrowserViewController+FindInPage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1E351C3921CA994800275941 /* BrowserViewController+FindInPage.swift */; };
1E351C4321CC0F5E00275941 /* CliqzTrayToolbar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1E351C4221CC0F5D00275941 /* CliqzTrayToolbar.swift */; };
@@ -1489,6 +1490,7 @@
1E2C435721F89B4D00891FB2 /* GhosteryDarkTheme.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GhosteryDarkTheme.swift; sourceTree = "<group>"; };
1E2C435921F89E6500891FB2 /* LumenWhiteTheme.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LumenWhiteTheme.swift; sourceTree = "<group>"; };
1E2C435B21F89E8100891FB2 /* LumenDarkTheme.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LumenDarkTheme.swift; sourceTree = "<group>"; };
1E2F488A225256C400B717B7 /* VPNInfoView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VPNInfoView.swift; sourceTree = "<group>"; };
1E351C3821CA994800275941 /* BrowserViewController+ReaderMode.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "BrowserViewController+ReaderMode.swift"; sourceTree = "<group>"; };
1E351C3921CA994800275941 /* BrowserViewController+FindInPage.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "BrowserViewController+FindInPage.swift"; sourceTree = "<group>"; };
1E351C4221CC0F5D00275941 /* CliqzTrayToolbar.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CliqzTrayToolbar.swift; sourceTree = "<group>"; };
@@ -3802,6 +3804,7 @@
AF6C8AF921873B5C006F8166 /* VPNCountryController.swift */,
AF6C8AFB21873B5D006F8166 /* VPNViewController.swift */,
4FDC331821F8BAAD001215EF /* VPNCredentialsService.swift */,
1E2F488A225256C400B717B7 /* VPNInfoView.swift */,
);
path = VPN;
sourceTree = "<group>";
EB11A1062044A90E0018F749 /* ContentBlockerHelper+TabContentScript.swift in Sources */,
E689C6FA1E0C6E98008BAADB /* FxAContentViewController.swift in Sources */,
1E4CFBF92073A5BD00B26E85 /* AddConnectionViewController.swift in Sources */,
1E2F488B225256C400B717B7 /* VPNInfoView.swift in Sources */,
C4E3983D1D21F1E7004E89BA /* TopTabsViews.swift in Sources */,
3B0943811D6CC4FC004F24E1 /* FilledPageControl.swift in Sources */,
FA9293D41D6580E100AC8D33 /* QRCodeViewController.swift in Sources */,
@@ -38,12 +38,20 @@ class OrientationManager {
}
}
}
extension BrowserViewController: VPNViewControllerDelegate{
func vpnOpenURLInNewTab(_ url: URL) {
self.hidePrivacyPanel()
self.openURLInNewTab(url, isPrivileged: false)
}
}

extension BrowserViewController {
func showVpnPanel() {
hideControlCenter()
#if PAID
let controller = UINavigationController(rootViewController: VPNViewController())
let vPNViewController = VPNViewController()
vPNViewController.delegate = self
let controller = UINavigationController(rootViewController: vPNViewController)
controller.setNavigationBarHidden(true, animated: false)

self.addChildViewController(controller)
@@ -44,6 +44,12 @@ extension String {
return boundingRect.height
}

func width(usingFont font: UIFont) -> CGFloat {
let fontAttributes = [NSAttributedString.Key.font: font]
let size = self.size(withAttributes: fontAttributes)
return size.width
}

func md5() -> String {
var digest = [UInt8](repeating: 0, count: Int(CC_MD5_DIGEST_LENGTH))
if let data = self.data(using: String.Encoding.utf8) {
@@ -99,6 +99,23 @@ extension VPNCountryController: UITableViewDataSource {
tableView.selectRow(at: indexPath, animated: true, scrollPosition: .none)
}
}

func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
let headerView = UIView()
let headerLabel = UILabel()
headerLabel.font = UIFont.systemFont(ofSize: 12, weight: .medium)
headerLabel.textColor = UIColor.lumenBrightBlue
headerLabel.numberOfLines = 0
headerLabel.text = NSLocalizedString("Choose your virtual location. Protection from hackers is on for any location while the VPN is active.", tableName: "Lumen", comment:"VPN locations selection header")

headerView.addSubview(headerLabel)
headerLabel.snp.makeConstraints { (make) in
make.leading.trailing.equalToSuperview().inset(15)
make.top.bottom.equalToSuperview()
}

return headerView
}
}

extension VPNCountryController: UITableViewDelegate {
@@ -0,0 +1,107 @@
//
// VPNInfoView.swift
// Client
//
// Created by Mahmoud Adam on 4/1/19.
// Copyright © 2019 Cliqz. All rights reserved.
//
import UIKit

class UILabelWithIcon: UIView {
let label = UILabel()
let iconView = UIImageView()
let font = UIFont.systemFont(ofSize: 18, weight: .medium)
var width: CGFloat = 0

init(text: String, icon: UIImage? = nil) {
super.init(frame: CGRect.zero)
self.label.text = text
self.label.font = font
self.label.textAlignment = .center

self.addSubview(label)
self.addSubview(iconView)

setConstrains(text.width(usingFont: font) + 10)
self.updateIcon(icon)
}

func setConstrains(_ textWidth: CGFloat) {
width = textWidth + 11
label.snp.makeConstraints { (make) in
make.centerY.trailing.equalToSuperview()
make.width.equalTo(textWidth)
}

iconView.snp.makeConstraints { (make) in
make.centerY.leading.equalToSuperview()
make.size.equalTo(11)
}
}

func updateIcon( _ icon: UIImage?) {
self.iconView.image = icon
}

func updateTextColor(_ textColor: UIColor) {
label.textColor = textColor
}


required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}

class VPNInfoView: UIView {

let vpnInfoLabel1 = UILabelWithIcon(text: NSLocalizedString("Protection from hackers", tableName: "Lumen", comment: "[VPN] Protection from hackers"))
let vpnInfoLabel2 = UILabelWithIcon(text: NSLocalizedString("Video streaming from other countries", tableName: "Lumen", comment: "[VPN] Video streaming from other countries"))


init() {
super.init(frame: CGRect.zero)
self.addSubview(vpnInfoLabel1)
self.addSubview(vpnInfoLabel2)
setConstrains()
}

required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

func updateView(_ isVPNConnected: Bool) {
if isVPNConnected {
vpnInfoLabel1.updateTextColor(UIColor.white)
vpnInfoLabel1.updateIcon(UIImage(named: "VPN_Checkmark"))

vpnInfoLabel2.updateTextColor(UIColor.white)
vpnInfoLabel2.updateIcon(UIImage(named: "VPN_Checkmark"))

} else {
vpnInfoLabel1.updateTextColor(UIColor.gray)
vpnInfoLabel1.updateIcon(UIImage(named: "Protection_X"))

vpnInfoLabel2.updateTextColor(UIColor.gray)
vpnInfoLabel2.updateIcon(UIImage(named: "Protection_X"))
}
}

private func setConstrains() {
vpnInfoLabel1.snp.makeConstraints { (make) in
make.centerX.equalToSuperview()
make.centerY.equalToSuperview().offset(-15)
make.height.equalTo(20)
make.width.equalTo(vpnInfoLabel1.width)
}

vpnInfoLabel2.snp.makeConstraints { (make) in
make.centerX.equalToSuperview()
make.centerY.equalToSuperview().offset(15)
make.height.equalTo(20)
make.width.equalTo(vpnInfoLabel2.width)
}
}

}
@@ -278,19 +278,34 @@ class VPNEndPointManager {
keychain[country.passwordHash] = password
}
}

protocol VPNViewControllerDelegate: class {
func vpnOpenURLInNewTab(_ url: URL)
}

class VPNViewController: UIViewController {

//used to reconnect when changing countries
var shouldVPNReconnect = false

let tableView = UITableView()
let mapView = UIImageView()
weak var delegate: VPNViewControllerDelegate?

let connectButton = VPNButton()
let infoLabel = UILabel()
lazy var vpnDefinitionButton: ButtonWithUnderlinedText = {
let title = NSLocalizedString("VPN is short for Virtual Private Network", tableName: "Lumen", comment: "VPN definition")
let action = NSLocalizedString("LEARN MORE", tableName: "Lumen", comment: "LEARN MORE action")
let vpnDefinitionButton = ButtonWithUnderlinedText(startText: (title, UIColor.lumenTextBlue),
underlinedText: (action, UIColor.lumenTextBlue),
position: .bottom)
vpnDefinitionButton.addTarget(self, action: #selector(openVPNLearnMore), for: .touchUpInside)
return vpnDefinitionButton
}()



let countryButtonHeight: CGFloat = 50.0
let vpnInfoView = VPNInfoView()

var upgradeView: UpgradeView?
var upgradeButton: ButtonWithUnderlinedText?
@@ -330,7 +345,7 @@ class VPNViewController: UIViewController {

updateMapView()
updateConnectButton()
updateInfoLabel()
updateVPNInfoView()

LegacyTelemetryHelper.logVPN(action: "show")
}
@@ -349,14 +364,20 @@ class VPNViewController: UIViewController {
self.view.alpha = 1.0
updateMapView()
updateConnectButton()
updateInfoLabel()
updateVPNInfoView()
}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}


@objc func openVPNLearnMore() {
if let url = URL(string: "https://lumenbrowser.com/faq.html#vpn") {
self.delegate?.vpnOpenURLInNewTab(url)
}
}

private func setupComponents() {
tableView.register(CustomVPNCell.self, forCellReuseIdentifier: "VPNCell")
tableView.delegate = self
@@ -371,8 +392,10 @@ class VPNViewController: UIViewController {
view.addSubview(gradient)
view.addSubview(tableView)
view.addSubview(mapView)
view.addSubview(infoLabel)
view.addSubview(vpnDefinitionButton)
view.addSubview(connectButton)
view.addSubview(vpnInfoView)

#if PAID
let currentSubscription = SubscriptionController.shared.getCurrentSubscription()
switch currentSubscription {
@@ -383,7 +406,7 @@ class VPNViewController: UIViewController {
view.addSubview(upgradeView!)
}
case .limited:
infoLabel.removeFromSuperview()
vpnDefinitionButton.removeFromSuperview()
let title = NSLocalizedString("Unlock the VPN feature to get the best out of Lumen.", tableName: "Lumen", comment: "Unlock the VPN feature text")
let action = NSLocalizedString("LEARN MORE", tableName: "Lumen", comment: "LEARN MORE action")
upgradeButton = ButtonWithUnderlinedText(startText: (title, UIColor.theme.lumenSubscription.upgradeLabel),
@@ -415,6 +438,11 @@ class VPNViewController: UIViewController {
make.height.equalTo(countryButtonHeight)
}
}
vpnInfoView.snp.makeConstraints { (make) in
make.centerY.equalToSuperview()
make.leading.trailing.equalToSuperview().inset(25)
make.height.equalTo(60)
}

mapView.snp.remakeConstraints { (make) in
make.trailing.equalToSuperview().offset(-20)
@@ -438,9 +466,9 @@ class VPNViewController: UIViewController {
} else {
connectButton.snp.remakeConstraints { (make) in
make.centerX.equalToSuperview()
make.bottom.equalTo(infoLabel.snp.top).offset(-16)
make.bottom.equalTo(vpnDefinitionButton.snp.top).offset(-16)
}
infoLabel.snp.remakeConstraints { (make) in
vpnDefinitionButton.snp.remakeConstraints { (make) in
make.bottom.equalToSuperview().offset(-26)
make.width.equalToSuperview().dividedBy(1.25)
make.centerX.equalToSuperview()
@@ -458,12 +486,6 @@ class VPNViewController: UIViewController {
// self.view.backgroundColor = .clear
self.tableView.backgroundColor = .clear
self.tableView.separatorColor = .clear

infoLabel.textAlignment = .center
infoLabel.numberOfLines = 0
infoLabel.textColor = Lumen.VPN.infoLabelTextColor(lumenTheme, .Normal)
infoLabel.font = UIFont.systemFont(ofSize: 14)

mapView.contentMode = .scaleAspectFill
}

@@ -512,25 +534,13 @@ class VPNViewController: UIViewController {
}
}

func updateInfoLabel() {
let connectedText = NSLocalizedString("You are safely connected to the Internet.", tableName: "Lumen", comment: "VPN connected text")
let retryText = NSLocalizedString("Oh, something went wrong. Please try again.", tableName: "Lumen", comment: "VPN retry text")
let defaultText = NSLocalizedString("Tap 'connect' to browse the Internet with VPN protection.", tableName: "Lumen", comment: "VPN default text")

if VPNStatus == .connected {
self.infoLabel.text = connectedText
}
else if VPNStatus == .disconnected && (self.connectButton.currentState == .Connecting || self.connectButton.currentState == .Connect) {
self.infoLabel.text = retryText
}
else {
self.infoLabel.text = defaultText
}
func updateVPNInfoView() {
self.vpnInfoView.updateView(VPNStatus == .connected)
}

@objc func VPNStatusDidChange(notification: Notification) {
//keep button up to date.
updateInfoLabel()
updateVPNInfoView()
updateConnectButton()
updateMapView()

@@ -702,7 +712,6 @@ extension VPNViewController: VPNCountryControllerProtocol {
extension VPNViewController: Themeable {
func applyTheme() {
self.updateMapView()
infoLabel.textColor = Lumen.VPN.infoLabelTextColor(lumenTheme, .Normal)
upgradeView?.applyTheme()
self.tableView.reloadData()
}
@@ -0,0 +1,23 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "Protection_X.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "Protection_X@2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "Protection_X@3x.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 comments on commit eba6882

Please sign in to comment.