Commit b887ab29 authored by Jose Blaya's avatar Jose Blaya
Browse files

Update the navigation bar of the DashboardViewController depending of the status of the VPN

parent aa70042a
......@@ -160,6 +160,8 @@
DD1AA4972180AD92005116D7 /* CustomDNSSettingsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD1AA4952180AD92005116D7 /* CustomDNSSettingsViewController.swift */; };
DD58F4BF21B12CFE00D043F7 /* PIAConnectionButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD58F4BE21B12CFE00D043F7 /* PIAConnectionButton.swift */; };
DD58F4C021B12CFE00D043F7 /* PIAConnectionButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD58F4BE21B12CFE00D043F7 /* PIAConnectionButton.swift */; };
DD58F4C221B190D000D043F7 /* CAGradientLayer+Image.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD58F4C121B190D000D043F7 /* CAGradientLayer+Image.swift */; };
DD58F4C321B190D000D043F7 /* CAGradientLayer+Image.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD58F4C121B190D000D043F7 /* CAGradientLayer+Image.swift */; };
DD746957217F070700B7BD73 /* DNS.plist in Resources */ = {isa = PBXBuildFile; fileRef = DD746956217F070700B7BD73 /* DNS.plist */; };
DD746958217F070700B7BD73 /* DNS.plist in Resources */ = {isa = PBXBuildFile; fileRef = DD746956217F070700B7BD73 /* DNS.plist */; };
DD74695A217F07AC00B7BD73 /* DNSList.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD746959217F07AC00B7BD73 /* DNSList.swift */; };
......@@ -412,6 +414,7 @@
D0E3B16D09433B9FD02705DB /* Pods_PIA_VPN_dev.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_PIA_VPN_dev.framework; sourceTree = BUILT_PRODUCTS_DIR; };
DD1AA4952180AD92005116D7 /* CustomDNSSettingsViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomDNSSettingsViewController.swift; sourceTree = "<group>"; };
DD58F4BE21B12CFE00D043F7 /* PIAConnectionButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PIAConnectionButton.swift; sourceTree = "<group>"; };
DD58F4C121B190D000D043F7 /* CAGradientLayer+Image.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "CAGradientLayer+Image.swift"; sourceTree = "<group>"; };
DD746956217F070700B7BD73 /* DNS.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = DNS.plist; sourceTree = "<group>"; };
DD746959217F07AC00B7BD73 /* DNSList.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DNSList.swift; sourceTree = "<group>"; };
DDC8124B2176185000CB290C /* SwiftGen+SeguesStoryboards.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "SwiftGen+SeguesStoryboards.swift"; sourceTree = "<group>"; };
......@@ -776,6 +779,7 @@
DDC8124E21761B0B00CB290C /* SwiftGen+ScenesStoryboards.swift */,
0E2215C820084CD700F5FB4D /* SwiftGen+Strings.swift */,
DD58F4BE21B12CFE00D043F7 /* PIAConnectionButton.swift */,
DD58F4C121B190D000D043F7 /* CAGradientLayer+Image.swift */,
);
name = Shared;
sourceTree = "<group>";
......@@ -1397,6 +1401,7 @@
0E8DCA06204D94E800B086DE /* ContentBlockerViewController.swift in Sources */,
0EA660091FEC7A9500CB2B0D /* PIATunnelProvider+UI.swift in Sources */,
0E7361EC1FD99A1000706BFF /* MenuViewController.swift in Sources */,
DD58F4C321B190D000D043F7 /* CAGradientLayer+Image.swift in Sources */,
0EB966781FDF11B80086ABC2 /* Server+UI.swift in Sources */,
0E9452AC1FDB5EF600891948 /* UINavigationItem+Shortcuts.swift in Sources */,
0E2215CD2008C01D00F5FB4D /* SwiftGen+Assets.swift in Sources */,
......@@ -1482,6 +1487,7 @@
0E8DCA05204D94E800B086DE /* ContentBlockerViewController.swift in Sources */,
0EA660081FEC7A9500CB2B0D /* PIATunnelProvider+UI.swift in Sources */,
0E441E312055B8A7007528D5 /* Theme+Extension.swift in Sources */,
DD58F4C221B190D000D043F7 /* CAGradientLayer+Image.swift in Sources */,
0E7361EB1FD99A1000706BFF /* MenuViewController.swift in Sources */,
0EB966771FDF11B80086ABC2 /* Server+UI.swift in Sources */,
0E9452AB1FDB5EF600891948 /* UINavigationItem+Shortcuts.swift in Sources */,
......
//
// CAGradientLayer+Image.swift
// PIA VPN
//
// Created by Jose Antonio Blaya Garcia on 30/11/2018.
// Copyright © 2018 London Trust Media. All rights reserved.
//
import Foundation
extension CAGradientLayer {
convenience init(frame: CGRect, colors: [UIColor]) {
self.init()
self.frame = frame
self.colors = []
for color in colors {
self.colors?.append(color.cgColor)
}
startPoint = CGPoint(x: 0, y: 0)
endPoint = CGPoint(x: 0, y: 1)
}
func createGradientImage() -> UIImage? {
var image: UIImage? = nil
UIGraphicsBeginImageContext(bounds.size)
if let context = UIGraphicsGetCurrentContext() {
render(in: context)
image = UIGraphicsGetImageFromCurrentImageContext()
}
UIGraphicsEndImageContext()
return image
}
}
......@@ -272,25 +272,54 @@ class DashboardViewController: AutolayoutViewController {
toggleConnection.isOn = true
toggleConnection.isIndeterminate = false
toggleConnection.stopButtonAnimation()
// labelStatus.text = L10n.Dashboard.Vpn.connected
AppPreferences.shared.lastVPNConnectionStatus = .connected
let titleLabelView = UILabel(frame: CGRect.zero)
titleLabelView.style(style: TextStyle.textStyle6)
titleLabelView.text = L10n.Dashboard.Vpn.on.uppercased()
Theme.current.applyCustomNavigationBar(navigationController!.navigationBar,
withTintColor: .white,
andBarTintColors: [UIColor.piaGreen,
UIColor.piaGreenDark20])
navigationItem.titleView = titleLabelView
setNeedsStatusBarAppearanceUpdate()
case .disconnected:
toggleConnection.isOn = false
toggleConnection.isIndeterminate = false
toggleConnection.stopButtonAnimation()
// labelStatus.text = L10n.Dashboard.Vpn.disconnected
AppPreferences.shared.lastVPNConnectionStatus = .disconnected
navigationItem.titleView = NavigationLogoView()
Theme.current.applyLightNavigationBar(navigationController!.navigationBar)
setNeedsStatusBarAppearanceUpdate()
case .connecting:
toggleConnection.isOn = true
toggleConnection.isIndeterminate = true
toggleConnection.startButtonAnimation()
// labelStatus.text = L10n.Dashboard.Vpn.connecting
AppPreferences.shared.lastVPNConnectionStatus = .connecting
let titleLabelView = UILabel(frame: CGRect.zero)
titleLabelView.style(style: TextStyle.textStyle7)
titleLabelView.text = L10n.Dashboard.Vpn.connecting.uppercased()
Theme.current.applyCustomNavigationBar(navigationController!.navigationBar,
withTintColor: nil,
andBarTintColors: nil)
navigationItem.titleView = titleLabelView
setNeedsStatusBarAppearanceUpdate()
case .disconnecting:
toggleConnection.isOn = true
toggleConnection.isIndeterminate = true
toggleConnection.startButtonAnimation()
// labelStatus.text = L10n.Dashboard.Vpn.disconnecting
AppPreferences.shared.lastVPNConnectionStatus = .disconnecting
let titleLabelView = UILabel(frame: CGRect.zero)
titleLabelView.style(style: TextStyle.textStyle7)
titleLabelView.text = L10n.Dashboard.Vpn.disconnecting.uppercased()
Theme.current.applyCustomNavigationBar(navigationController!.navigationBar,
withTintColor: nil,
andBarTintColors: nil)
navigationItem.titleView = titleLabelView
setNeedsStatusBarAppearanceUpdate()
// case .changingServer:
// powerConnection.powerState = .pending
......
......@@ -141,6 +141,8 @@ internal enum L10n {
internal static let disconnected = L10n.tr("Localizable", "dashboard.vpn.disconnected")
/// Disconnecting...
internal static let disconnecting = L10n.tr("Localizable", "dashboard.vpn.disconnecting")
/// VPN: ON
internal static let on = L10n.tr("Localizable", "dashboard.vpn.on")
}
}
......
......@@ -18,8 +18,45 @@ extension Theme {
public func applyLightNavigationBar(_ navigationBar: UINavigationBar) {
navigationBar.tintColor = palette.textColor(forRelevance: 1, appearance: .dark)
navigationBar.barTintColor = palette.lightBackground
}
/**
Set color values for a custom navigation bar.
- Parameter navigationBar: The navigationBar where the changes are going to be applied.
- Parameter tintColor: The tintColor for the navigationBar. If nil: self.palette.textColor(forRelevance: 1, appearance: .dark)
- Parameter barTintColors: Array of colors for the background of the navigationBar. If the array contains 2 colors, it will generate a gradient. If the array contains more than 2 colors or nil, it will set the default value: self.palette.lightBackground. If the array only contains 1 color, a solid background color will be set.
*/
public func applyCustomNavigationBar(_ navigationBar: UINavigationBar,
withTintColor tintColor: UIColor?,
andBarTintColors barTintColors: [UIColor]?) {
UIView.animate(withDuration: 0.3) {
if let tintColor = tintColor {
navigationBar.tintColor = tintColor
} else {
navigationBar.tintColor = self.palette.textColor(forRelevance: 1, appearance: .dark)
}
if let barTintColors = barTintColors,
barTintColors.count > 0,
barTintColors.count <= 2 {
if barTintColors.count == 1 {
navigationBar.barTintColor = barTintColors.first
} else {
var updatedFrame = navigationBar.bounds
updatedFrame.size.height += navigationBar.frame.origin.y
let gradientLayer = CAGradientLayer(frame: updatedFrame, colors: barTintColors)
navigationBar.setBackgroundImage(gradientLayer.createGradientImage(), for: UIBarMetrics.default)
}
} else {
navigationBar.barTintColor = self.palette.lightBackground
}
navigationBar.layoutIfNeeded()
}
}
public func applyLightBrandLogoNavigationBar(_ navigationBar: UINavigationBar) {
navigationBar.tintColor = palette.textColor(forRelevance: 1, appearance: .dark)
......
......@@ -51,7 +51,6 @@ private struct LightThemeStrategy: ThemeStrategy {
func statusBarAppearance(for viewController: AutolayoutViewController) -> UIStatusBarStyle {
switch viewController {
case is WalkthroughViewController,
is DashboardViewController,
is PIAWelcomeViewController,
is GetStartedViewController,
is SignupInProgressViewController,
......@@ -62,6 +61,11 @@ private struct LightThemeStrategy: ThemeStrategy {
is VPNPermissionViewController,
is ConfirmVPNPlanViewController:
return .default
case is DashboardViewController:
if AppPreferences.shared.lastVPNConnectionStatus == VPNStatus.connected {
return .lightContent
}
return .default
default:
return .lightContent
}
......
......@@ -167,6 +167,7 @@
"dashboard.vpn.disconnected" = "Disconnected";
"dashboard.vpn.connecting" = "Connecting...";
"dashboard.vpn.connected" = "Connected to VPN";
"dashboard.vpn.on" = "VPN: ON";
"dashboard.vpn.disconnecting" = "Disconnecting...";
"dashboard.vpn.changing_region" = "Changing region...";
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment