Commit 868d5599 authored by Jose Blaya's avatar Jose Blaya
Browse files

Refactor

parent de8a149c
......@@ -185,6 +185,8 @@
DD40197F221FEF650041EB30 /* NetworkManagementToolTileCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD40197C221FEF650041EB30 /* NetworkManagementToolTileCollectionViewCell.swift */; };
DD401980221FEF650041EB30 /* NetworkManagementToolTileCollectionViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = DD40197D221FEF650041EB30 /* NetworkManagementToolTileCollectionViewCell.xib */; };
DD401981221FEF650041EB30 /* NetworkManagementToolTileCollectionViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = DD40197D221FEF650041EB30 /* NetworkManagementToolTileCollectionViewCell.xib */; };
DD4E84572243BD1200929B39 /* DashboardCollectionViewUtil.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD4E84562243BD1200929B39 /* DashboardCollectionViewUtil.swift */; };
DD4E84582243BD1200929B39 /* DashboardCollectionViewUtil.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD4E84562243BD1200929B39 /* DashboardCollectionViewUtil.swift */; };
DD58F4B821AD579A00D043F7 /* GoogleService-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = DD58F4B721AD579A00D043F7 /* GoogleService-Info.plist */; };
DD58F4BF21B12CFE00D043F7 /* PIAConnectionButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD58F4BE21B12CFE00D043F7 /* PIAConnectionButton.swift */; };
DD58F4C021B12CFE00D043F7 /* PIAConnectionButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD58F4BE21B12CFE00D043F7 /* PIAConnectionButton.swift */; };
......@@ -510,6 +512,7 @@
DD401979221FEF390041EB30 /* NetworkManagementToolTile.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = NetworkManagementToolTile.xib; sourceTree = "<group>"; };
DD40197C221FEF650041EB30 /* NetworkManagementToolTileCollectionViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NetworkManagementToolTileCollectionViewCell.swift; sourceTree = "<group>"; };
DD40197D221FEF650041EB30 /* NetworkManagementToolTileCollectionViewCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = NetworkManagementToolTileCollectionViewCell.xib; sourceTree = "<group>"; };
DD4E84562243BD1200929B39 /* DashboardCollectionViewUtil.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DashboardCollectionViewUtil.swift; sourceTree = "<group>"; };
DD58F4B721AD579A00D043F7 /* GoogleService-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "GoogleService-Info.plist"; sourceTree = "<group>"; };
DD58F4BE21B12CFE00D043F7 /* PIAConnectionButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PIAConnectionButton.swift; sourceTree = "<group>"; };
DD606AB921C7A17900E0781D /* NetworkExtension.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = NetworkExtension.framework; path = System/Library/Frameworks/NetworkExtension.framework; sourceTree = SDKROOT; };
......@@ -637,6 +640,7 @@
isa = PBXGroup;
children = (
0E3A35271FD9A960000B0F99 /* DashboardViewController.swift */,
DD4E84562243BD1200929B39 /* DashboardCollectionViewUtil.swift */,
0EFB838F20209CF200980F69 /* VPNPermissionViewController.swift */,
);
name = Dashboard;
......@@ -1872,6 +1876,7 @@
DD1C139F21E6623D004004B3 /* XIBSetup.swift in Sources */,
DDB6B95421C95CD400DE8C5F /* EnumsBuilder.swift in Sources */,
0E9AEA6320683FDF00B6E59A /* AboutComponent.swift in Sources */,
DD4E84582243BD1200929B39 /* DashboardCollectionViewUtil.swift in Sources */,
DD74695B217F07AC00B7BD73 /* DNSList.swift in Sources */,
0E9452AF1FDB5F7A00891948 /* PIAPageControl.swift in Sources */,
DDD271F121D6718F00B6D20F /* RegionFilter.swift in Sources */,
......@@ -1977,6 +1982,7 @@
DD401977221FEF2C0041EB30 /* NetworkManagementToolTile.swift in Sources */,
DDB6B95321C95CD400DE8C5F /* EnumsBuilder.swift in Sources */,
0E9AEA6220683FDF00B6E59A /* AboutComponent.swift in Sources */,
DD4E84572243BD1200929B39 /* DashboardCollectionViewUtil.swift in Sources */,
DD74695A217F07AC00B7BD73 /* DNSList.swift in Sources */,
0E9452AE1FDB5F7A00891948 /* PIAPageControl.swift in Sources */,
DDD271F021D6718F00B6D20F /* RegionFilter.swift in Sources */,
......
//
// DashboardCollectionViewUtil.swift
// PIA VPN
//
// Created by Jose Antonio Blaya Garcia on 21/03/2019.
// Copyright © 2019 London Trust Media. All rights reserved.
//
import UIKit
enum Cells: Int, EnumsBuilder {
case region = 0
case quickConnect
case ipTile
case subscription
case usage
case networkManagementTool
case quickSettings
var identifier: String {
switch self {
case .ipTile: return "IPTileCell"
case .quickConnect: return "QuickConnectTileCell"
case .region: return "RegionTileCell"
case .subscription: return "SubscriptionTileCell"
case .usage: return "UsageTileCell"
case .networkManagementTool: return "NMTTileCell"
case .quickSettings: return "QuickSettingsTileCell"
}
}
var className: String {
switch self {
case .ipTile: return "IPTileCollectionViewCell"
case .quickConnect: return "QuickConnectTileCollectionViewCell"
case .region: return "RegionTileCollectionViewCell"
case .subscription: return "SubscriptionTileCollectionViewCell"
case .usage: return "UsageTileCollectionViewCell"
case .networkManagementTool: return "NetworkManagementToolTileCollectionViewCell"
case .quickSettings: return "QuickSettingsTileCollectionViewCell"
}
}
}
class DashboardCollectionViewUtil: NSObject {
func registerCellsFor(_ collectionView: UICollectionView) {
collectionView.register(UINib(nibName: Cells.ipTile.className,
bundle: nil),
forCellWithReuseIdentifier: Cells.ipTile.identifier)
collectionView.register(UINib(nibName: Cells.quickConnect.className,
bundle: nil),
forCellWithReuseIdentifier: Cells.quickConnect.identifier)
collectionView.register(UINib(nibName: Cells.region.className,
bundle: nil),
forCellWithReuseIdentifier: Cells.region.identifier)
collectionView.register(UINib(nibName: Cells.subscription.className,
bundle: nil),
forCellWithReuseIdentifier: Cells.subscription.identifier)
collectionView.register(UINib(nibName: Cells.usage.className,
bundle: nil),
forCellWithReuseIdentifier: Cells.usage.identifier)
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
}
}
......@@ -15,45 +15,10 @@ private let log = SwiftyBeaver.self
class DashboardViewController: AutolayoutViewController {
private enum TileSize: CGFloat {
enum TileSize: CGFloat {
case standard = 89.0
}
private enum Cells: Int, EnumsBuilder {
case region = 0
case quickConnect
case ipTile
case subscription
case usage
case networkManagementTool
case quickSettings
var identifier: String {
switch self {
case .ipTile: return "IPTileCell"
case .quickConnect: return "QuickConnectTileCell"
case .region: return "RegionTileCell"
case .subscription: return "SubscriptionTileCell"
case .usage: return "UsageTileCell"
case .networkManagementTool: return "NMTTileCell"
case .quickSettings: return "QuickSettingsTileCell"
}
}
var className: String {
switch self {
case .ipTile: return "IPTileCollectionViewCell"
case .quickConnect: return "QuickConnectTileCollectionViewCell"
case .region: return "RegionTileCollectionViewCell"
case .subscription: return "SubscriptionTileCollectionViewCell"
case .usage: return "UsageTileCollectionViewCell"
case .networkManagementTool: return "NetworkManagementToolTileCollectionViewCell"
case .quickSettings: return "QuickSettingsTileCollectionViewCell"
}
}
}
private var viewContentHeight: CGFloat = 0
@IBOutlet weak var viewContentHeightConstraint: NSLayoutConstraint!
@IBOutlet weak var viewContentLandscapeHeightConstraint: NSLayoutConstraint!
......@@ -179,6 +144,11 @@ class DashboardViewController: AutolayoutViewController {
}
// MARK: Actions
private func setupCollectionView() {
let collectionViewUtil = DashboardCollectionViewUtil()
collectionViewUtil.registerCellsFor(collectionView)
}
private func setupNavigationBarButtons() {
guard AppPreferences.shared.wasLaunched,
......@@ -229,31 +199,6 @@ class DashboardViewController: AutolayoutViewController {
}
private func setupCollectionView() {
collectionView.register(UINib(nibName: Cells.ipTile.className,
bundle: nil),
forCellWithReuseIdentifier: Cells.ipTile.identifier)
collectionView.register(UINib(nibName: Cells.quickConnect.className,
bundle: nil),
forCellWithReuseIdentifier: Cells.quickConnect.identifier)
collectionView.register(UINib(nibName: Cells.region.className,
bundle: nil),
forCellWithReuseIdentifier: Cells.region.identifier)
collectionView.register(UINib(nibName: Cells.subscription.className,
bundle: nil),
forCellWithReuseIdentifier: Cells.subscription.identifier)
collectionView.register(UINib(nibName: Cells.usage.className,
bundle: nil),
forCellWithReuseIdentifier: Cells.usage.identifier)
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
}
private func updateTileLayout() {
UIView.animate(withDuration: AppConfiguration.Animations.duration, animations: {
self.toggleConnection.alpha = self.tileModeStatus == .normal ? 1 : 0
......
......@@ -26,6 +26,9 @@
<constraint firstAttribute="width" constant="34" id="m3u-Bi-7qt"/>
</constraints>
<state key="normal" image="eye-active-dark"/>
<connections>
<action selector="changeTileVisibility" destination="gTV-IL-0wX" eventType="touchUpInside" id="Sai-xc-ttP"/>
</connections>
</button>
<imageView userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="open-tile-details" translatesAutoresizingMaskIntoConstraints="NO" id="C2G-Hq-Q6g">
<rect key="frame" x="641" y="58" width="12" height="12"/>
......
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