Commit 40d3392e authored by Jose Blaya's avatar Jose Blaya
Browse files

Quick settings tile

parent 0c748fe8
This diff is collapsed.
......@@ -27,7 +27,8 @@ class DashboardViewController: AutolayoutViewController {
case subscription
case usage
case networkManagementTool
case quickSettings
var identifier: String {
switch self {
case .ipTile: return "IPTileCell"
......@@ -36,6 +37,7 @@ class DashboardViewController: AutolayoutViewController {
case .subscription: return "SubscriptionTileCell"
case .usage: return "UsageTileCell"
case .networkManagementTool: return "NMTTileCell"
case .quickSettings: return "QuickSettingsTileCell"
}
}
......@@ -47,6 +49,7 @@ class DashboardViewController: AutolayoutViewController {
case .subscription: return "SubscriptionTileCollectionViewCell"
case .usage: return "UsageTileCollectionViewCell"
case .networkManagementTool: return "NetworkManagementToolTileCollectionViewCell"
case .quickSettings: return "QuickSettingsTileCollectionViewCell"
}
}
}
......@@ -245,6 +248,9 @@ class DashboardViewController: AutolayoutViewController {
collectionView.register(UINib(nibName: Cells.networkManagementTool.className,
bundle: nil),
forCellWithReuseIdentifier: Cells.networkManagementTool.identifier)
collectionView.register(UINib(nibName: Cells.quickSettings.className,
bundle: nil),
forCellWithReuseIdentifier: Cells.quickSettings.identifier)
collectionView.backgroundColor = .clear
}
......
{
"images" : [
{
"idiom" : "universal",
"filename" : "Killswitch-active (1).pdf"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
{
"images" : [
{
"idiom" : "universal",
"filename" : "killswitch-inactive (1).pdf"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
{
"images" : [
{
"idiom" : "universal",
"filename" : "Network Management-active (1).pdf"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
{
"images" : [
{
"idiom" : "universal",
"filename" : "Network Management-inactive-dark theme (1).pdf"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
{
"images" : [
{
"idiom" : "universal",
"filename" : "Network Management-active (1).pdf"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
{
"images" : [
{
"idiom" : "universal",
"filename" : "Network Management-inactive-light theme (1).pdf"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
{
"images" : [
{
"idiom" : "universal",
"filename" : "fill136.pdf"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
{
"images" : [
{
"idiom" : "universal",
"filename" : "fill128.pdf"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
{
"images" : [
{
"idiom" : "universal",
"filename" : "fill120Copy3.pdf"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
{
"images" : [
{
"idiom" : "universal",
"filename" : "fill119Copy3.pdf"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
{
"images" : [
{
"idiom" : "universal",
"filename" : "combinedShapeCopy4-2.pdf"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
{
"images" : [
{
"idiom" : "universal",
"filename" : "group38Copy9.pdf"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
......@@ -117,13 +117,25 @@ enum Asset {
static let iconBack = ImageAsset(name: "icon-back")
static let iconEditTile = ImageAsset(name: "icon-edit-tile")
static let iconFilter = ImageAsset(name: "icon-filter")
static let killswitchDarkActive = ImageAsset(name: "killswitch-dark-active")
static let killswitchDarkInactive = ImageAsset(name: "killswitch-dark-inactive")
static let nmtDarkActive = ImageAsset(name: "nmt-dark-active")
static let nmtDarkInactive = ImageAsset(name: "nmt-dark-inactive")
static let nmtLightActive = ImageAsset(name: "nmt-light-active")
static let nmtLightInactive = ImageAsset(name: "nmt-light-inactive")
static let pagecontrolSelectedDot = ImageAsset(name: "pagecontrol-selected-dot")
static let pagecontrolUnselectedDot = ImageAsset(name: "pagecontrol-unselected-dot")
static let regionSelected = ImageAsset(name: "region-selected")
static let scrollableMapDark = ImageAsset(name: "scrollableMap-dark")
static let scrollableMapLight = ImageAsset(name: "scrollableMap-light")
static let trustedIcon = ImageAsset(name: "trusted-icon")
static let untrustedIcon = ImageAsset(name: "untrusted-icon")
static let themeDarkActive = ImageAsset(name: "theme-dark-active")
static let themeDarkInactive = ImageAsset(name: "theme-dark-inactive")
static let themeLightActive = ImageAsset(name: "theme-light-active")
static let themeLightInactive = ImageAsset(name: "theme-light-inactive")
static let trustedDarkIcon = ImageAsset(name: "trusted-dark-icon")
static let trustedLightIcon = ImageAsset(name: "trusted-light-icon")
static let untrustedDarkIcon = ImageAsset(name: "untrusted-dark-icon")
static let untrustedLightIcon = ImageAsset(name: "untrusted-light-icon")
}
enum LightMap {
static let lightMapAUMelbourne = ImageAsset(name: "Light-Map-AU Melbourne")
......@@ -506,13 +518,25 @@ enum Asset {
Piax.Global.iconBack,
Piax.Global.iconEditTile,
Piax.Global.iconFilter,
Piax.Global.killswitchDarkActive,
Piax.Global.killswitchDarkInactive,
Piax.Global.nmtDarkActive,
Piax.Global.nmtDarkInactive,
Piax.Global.nmtLightActive,
Piax.Global.nmtLightInactive,
Piax.Global.pagecontrolSelectedDot,
Piax.Global.pagecontrolUnselectedDot,
Piax.Global.regionSelected,
Piax.Global.scrollableMapDark,
Piax.Global.scrollableMapLight,
Piax.Global.trustedIcon,
Piax.Global.untrustedIcon,
Piax.Global.themeDarkActive,
Piax.Global.themeDarkInactive,
Piax.Global.themeLightActive,
Piax.Global.themeLightInactive,
Piax.Global.trustedDarkIcon,
Piax.Global.trustedLightIcon,
Piax.Global.untrustedDarkIcon,
Piax.Global.untrustedLightIcon,
Piax.LightMap.lightMapAUMelbourne,
Piax.LightMap.lightMapAUSydney,
Piax.LightMap.lightMapAustria,
......
......@@ -337,6 +337,10 @@ internal enum L10n {
internal enum ApplicationSettings {
/// APPLICATION SETTINGS
internal static let title = L10n.tr("Localizable", "settings.application_settings.title")
internal enum ActiveTheme {
/// Active theme
internal static let title = L10n.tr("Localizable", "settings.application_settings.active_theme.title")
}
internal enum DarkTheme {
/// Dark theme
internal static let title = L10n.tr("Localizable", "settings.application_settings.dark_theme.title")
......@@ -593,6 +597,10 @@ internal enum L10n {
internal static let title = L10n.tr("Localizable", "tiles.quick.connect.title")
}
}
internal enum Quicksettings {
/// Quick settings
internal static let title = L10n.tr("Localizable", "tiles.quicksettings.title")
}
internal enum Region {
/// VPN Server
internal static let title = L10n.tr("Localizable", "tiles.region.title")
......
......@@ -78,10 +78,12 @@ class NetworkManagementToolTile: UIView, Tileable {
networkLabel.text = ssid.uppercased()
if Client.preferences.useWiFiProtection {
if Client.preferences.trustedNetworks.contains(ssid) {
statusButton.setImage(Asset.Piax.Global.trustedIcon.image, for: [])
statusButton.setImage(Theme.current.palette.appearance == .light ? Asset.Piax.Global.trustedLightIcon.image :
Asset.Piax.Global.trustedDarkIcon.image, for: [])
statusButton.accessibilityLabel = L10n.Tiles.Nmt.Accessibility.trusted
} else {
statusButton.setImage(Asset.Piax.Global.untrustedIcon.image, for: [])
statusButton.setImage(Theme.current.palette.appearance == .light ? Asset.Piax.Global.untrustedLightIcon.image :
Asset.Piax.Global.untrustedDarkIcon.image, for: [])
statusButton.accessibilityLabel = L10n.Tiles.Nmt.Accessibility.untrusted
}
} else {
......@@ -92,10 +94,12 @@ class NetworkManagementToolTile: UIView, Tileable {
} else {
networkLabel.text = L10n.Tiles.Nmt.cellular
if Client.preferences.trustCellularData {
statusButton.setImage(Asset.Piax.Global.trustedIcon.image, for: [])
statusButton.setImage(Theme.current.palette.appearance == .light ? Asset.Piax.Global.trustedLightIcon.image :
Asset.Piax.Global.trustedDarkIcon.image, for: [])
statusButton.accessibilityLabel = L10n.Tiles.Nmt.Accessibility.trusted
} else {
statusButton.setImage(Asset.Piax.Global.untrustedIcon.image, for: [])
statusButton.setImage(Theme.current.palette.appearance == .light ? Asset.Piax.Global.untrustedLightIcon.image :
Asset.Piax.Global.untrustedDarkIcon.image, for: [])
statusButton.accessibilityLabel = L10n.Tiles.Nmt.Accessibility.untrusted
}
}
......@@ -116,7 +120,8 @@ class NetworkManagementToolTile: UIView, Tileable {
} else {
hotspotHelper.saveTrustedNetwork(ssid)
}
statusButton.setImage(Asset.Piax.Global.trustedIcon.image, for: [])
statusButton.setImage(Theme.current.palette.appearance == .light ? Asset.Piax.Global.trustedLightIcon.image :
Asset.Piax.Global.trustedDarkIcon.image, for: [])
}
} else { // cellular
let preferences = Client.preferences.editable()
......
......@@ -40,7 +40,7 @@
<constraint firstAttribute="width" constant="44" id="2oR-IQ-nEX"/>
<constraint firstAttribute="height" constant="44" id="jNx-SM-We8"/>
</constraints>
<state key="normal" image="trusted-icon"/>
<state key="normal" image="trusted-dark-icon"/>
<connections>
<action selector="changeNetworkTrustMode:" destination="-1" eventType="touchUpInside" id="lJi-6x-b5f"/>
</connections>
......@@ -62,6 +62,6 @@
</view>
</objects>
<resources>
<image name="trusted-icon" width="23" height="28"/>
<image name="trusted-dark-icon" width="23" height="27"/>
</resources>
</document>
//
// QuickSettingsTile.swift
// PIA VPN
//
// Created by Jose Antonio Blaya Garcia on 20/03/2019.
// Copyright © 2019 London Trust Media. All rights reserved.
//
import UIKit
import PIALibrary
class QuickSettingsTile: UIView, Tileable {
var view: UIView!
var detailSegueIdentifier: String!
var status: TileStatus = .normal
@IBOutlet private weak var themeButton: UIButton!
@IBOutlet private weak var killSwitchButton: UIButton!
@IBOutlet private weak var nmtButton: UIButton!
@IBOutlet private weak var themeLabel: UILabel!
@IBOutlet private weak var killSwitchLabel: UILabel!
@IBOutlet private weak var nmtLabel: UILabel!
override init(frame: CGRect) {
super.init(frame: frame)
self.xibSetup()
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
self.xibSetup()
self.setupView()
}
deinit {
NotificationCenter.default.removeObserver(self)
}
func hasDetailView() -> Bool {
return false
}
private func setupView() {
let nc = NotificationCenter.default
nc.addObserver(self, selector: #selector(viewShouldRestyle), name: .PIAThemeDidChange, object: nil)
nc.addObserver(self, selector: #selector(updateButtons), name: .PIASettingsHaveChanged, object: nil)
viewShouldRestyle()
}
@objc private func viewShouldRestyle() {
Theme.current.applySubtitleTileUsage(themeLabel, appearance: .dark)
Theme.current.applySubtitleTileUsage(killSwitchLabel, appearance: .dark)
Theme.current.applySubtitleTileUsage(nmtLabel, appearance: .dark)
Theme.current.applyPrincipalBackground(self)
updateButtons()
}
@objc private func updateButtons() {
themeLabel.text = L10n.Settings.ApplicationSettings.ActiveTheme.title
themeLabel.textAlignment = .center
killSwitchLabel.text = L10n.Settings.ApplicationSettings.KillSwitch.title
killSwitchLabel.textAlignment = .center
nmtLabel.text = L10n.Settings.Hotspothelper.title
nmtLabel.textAlignment = .center
if AppPreferences.shared.currentThemeCode == ThemeCode.light {
themeButton.setImage(Theme.current.palette.appearance == .light ? Asset.Piax.Global.themeLightActive.image :
Asset.Piax.Global.themeDarkActive.image, for: [])
themeButton.accessibilityLabel = L10n.Tiles.Nmt.Accessibility.trusted
} else {
themeButton.setImage(Theme.current.palette.appearance == .light ? Asset.Piax.Global.themeLightInactive.image :
Asset.Piax.Global.themeDarkInactive.image, for: [])
themeButton.accessibilityLabel = L10n.Tiles.Nmt.Accessibility.trusted
}
if Client.preferences.isPersistentConnection {
killSwitchButton.setImage(Asset.Piax.Global.killswitchDarkActive.image, for: [])
killSwitchButton.accessibilityLabel = L10n.Tiles.Nmt.Accessibility.trusted
} else {
killSwitchButton.setImage(Asset.Piax.Global.killswitchDarkInactive.image, for: [])
killSwitchButton.accessibilityLabel = L10n.Tiles.Nmt.Accessibility.trusted
}
if Client.preferences.nmtRulesEnabled {
nmtButton.setImage(Theme.current.palette.appearance == .light ? Asset.Piax.Global.nmtLightActive.image :
Asset.Piax.Global.nmtDarkActive.image, for: [])
nmtButton.accessibilityLabel = L10n.Tiles.Nmt.Accessibility.trusted
} else {
nmtButton.setImage(Theme.current.palette.appearance == .light ? Asset.Piax.Global.nmtLightInactive.image :
Asset.Piax.Global.nmtDarkInactive.image, for: [])
nmtButton.accessibilityLabel = L10n.Tiles.Nmt.Accessibility.trusted
}
}
@IBAction func changeTheme(_ sender: Any) {
if AppPreferences.shared.currentThemeCode == ThemeCode.light {
AppPreferences.shared.transitionTheme(to: ThemeCode.dark)
} else {
AppPreferences.shared.transitionTheme(to: ThemeCode.light)
}
updateButtons()
}
@IBAction func updateKillSwitchSetting(_ sender: Any) {
let preferences = Client.preferences.editable()
preferences.isPersistentConnection = !Client.preferences.isPersistentConnection
preferences.commit()
updateProfile()
updateButtons()
}
@IBAction func updateNMTSetting(_ sender: Any) {
let preferences = Client.preferences.editable()
preferences.nmtRulesEnabled = !Client.preferences.nmtRulesEnabled
preferences.commit()
updateProfile()
updateButtons()
}
private func updateProfile() {
NotificationCenter.default.post(name: .PIASettingsHaveChanged,
object: self,
userInfo: nil)
}
}
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="14460.31" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14460.20"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="QuickSettingsTile" customModule="PIA_VPN" customModuleProvider="target">
<connections>
<outlet property="killSwitchButton" destination="aBB-hV-AgG" id="HeK-0V-a7q"/>
<outlet property="killSwitchLabel" destination="xCg-aj-fZU" id="FfY-fp-Fva"/>
<outlet property="nmtButton" destination="gaA-K4-g4k" id="MZh-Wr-daf"/>
<outlet property="nmtLabel" destination="Y04-a5-Osi" id="e18-9y-vcR"/>
<outlet property="themeButton" destination="5Bu-uZ-L11" id="3JV-eF-LvL"/>
<outlet property="themeLabel" destination="zt5-Ml-2aq" id="Ej0-b3-f5B"/>
</connections>
</placeholder>
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
<view contentMode="scaleToFill" id="iN0-l3-epB">
<rect key="frame" x="0.0" y="0.0" width="375" height="89"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<stackView opaque="NO" contentMode="scaleToFill" distribution="fillEqually" spacing="20" translatesAutoresizingMaskIntoConstraints="NO" id="0Qp-uW-eAj">
<rect key="frame" x="20" y="0.0" width="335" height="89"/>
<subviews>
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" distribution="fillEqually" translatesAutoresizingMaskIntoConstraints="NO" id="KWs-z3-TeP">
<rect key="frame" x="0.0" y="0.0" width="98.5" height="89"/>
<subviews>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="bottom" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="5Bu-uZ-L11">
<rect key="frame" x="0.0" y="0.0" width="98.5" height="44.5"/>
<state key="normal" image="theme-dark-active"/>
<connections>
<action selector="changeTheme:" destination="-1" eventType="touchUpInside" id="yMQ-vt-Pvt"/>
</connections>
</button>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Sett" textAlignment="center" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="zt5-Ml-2aq">
<rect key="frame" x="0.0" y="44.5" width="98.5" height="44.5"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
</stackView>
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" distribution="fillEqually" translatesAutoresizingMaskIntoConstraints="NO" id="Wag-UL-Rel">
<rect key="frame" x="118.5" y="0.0" width="98" height="89"/>
<subviews>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="bottom" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="aBB-hV-AgG">
<rect key="frame" x="0.0" y="0.0" width="98" height="44.5"/>
<state key="normal" image="killswitch-dark-active"/>
<connections>
<action selector="updateKillSwitchSetting:" destination="-1" eventType="touchUpInside" id="ELb-to-qnb"/>
</connections>
</button>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Sett" textAlignment="center" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="xCg-aj-fZU">
<rect key="frame" x="0.0" y="44.5" width="98" height="44.5"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>