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

Refactor

parent 27661b66
This diff is collapsed.
......@@ -32,32 +32,10 @@ class DashboardViewController: AutolayoutViewController {
@IBOutlet private weak var collectionView: UICollectionView!
// iPad only
@IBOutlet private weak var viewPublicIP: UIView!
@IBOutlet private weak var labelPublicIPCaption: UILabel!
@IBOutlet private weak var labelPublicIP: UILabel!
@IBOutlet private weak var activityPublicIP: UIActivityIndicatorView!
@IBOutlet private weak var viewCurrentRegion: UIView!
@IBOutlet private weak var labelRegionCaption: UILabel!
@IBOutlet private weak var labelRegion: UILabel!
@IBOutlet private weak var imvRegion: UIImageView!
@IBOutlet private weak var buttonChangeRegion: UIButton!
private var currentPageIndex = 0
private var currentStatus: VPNStatus = .disconnected
private var currentIP: String?
deinit {
NotificationCenter.default.removeObserver(self)
}
......@@ -81,14 +59,8 @@ class DashboardViewController: AutolayoutViewController {
viewContent.isHidden = true
viewRows.isHidden = true
labelRegionCaption.text = L10n.Dashboard.Connection.Region.caption
buttonChangeRegion.setTitle(L10n.Dashboard.Connection.Region.change, for: .normal)
labelPublicIPCaption.text = L10n.Dashboard.Connection.Ip.caption
currentPageIndex = 0
buttonChangeRegion.accessibilityIdentifier = "uitests.main.pick_region";
SideMenuManager.default.menuLeftNavigationController = StoryboardScene.Main.sideMenuNavigationController.instantiate()
SideMenuManager.default.menuAddPanGestureToPresent(toView: self.navigationController!.navigationBar)
SideMenuManager.default.menuAddScreenEdgePanGesturesToPresent(toView: self.navigationController!.view)
......@@ -98,7 +70,6 @@ class DashboardViewController: AutolayoutViewController {
nc.addObserver(self, selector: #selector(vpnDidInstall(notification:)), name: .PIAVPNDidInstall, object: nil)
nc.addObserver(self, selector: #selector(applicationDidBecomeActive(notification:)), name: .UIApplicationDidBecomeActive, object: nil)
nc.addObserver(self, selector: #selector(vpnStatusDidChange(notification:)), name: .PIADaemonsDidUpdateVPNStatus, object: nil)
nc.addObserver(self, selector: #selector(updateCurrentIP), name: .PIADaemonsDidUpdateConnectivity, object: nil)
nc.addObserver(self, selector: #selector(viewHasRotated), name: .UIDeviceOrientationDidChange, object: nil)
nc.addObserver(self, selector: #selector(updateCurrentStatus), name: .PIAThemeDidChange, object: nil)
......@@ -140,7 +111,6 @@ class DashboardViewController: AutolayoutViewController {
// self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:buttonMenu];
updateCurrentStatus()
updateCurrentIP()
}
override func viewDidAppear(_ animated: Bool) {
......@@ -315,6 +285,7 @@ class DashboardViewController: AutolayoutViewController {
resetNavigationBar()
case .connecting:
Macros.postNotification(.PIADaemonsDidUpdateConnectivity)
toggleConnection.isOn = false
toggleConnection.isIndeterminate = true
toggleConnection.startButtonAnimation()
......@@ -348,50 +319,15 @@ class DashboardViewController: AutolayoutViewController {
// labelStatus.text = L10n.Dashboard.Vpn.changingRegion
}
let server = Client.preferences.displayedServer
labelRegion.text = server.name(forStatus: currentStatus)
imvRegion.setImage(fromServer: server.flagServer(forStatus: currentStatus))
// XXX hack to suppress "ellipsis"
//viewConnectionArea.accessibilityLabel = labelStatus.text
viewConnectionArea.accessibilityLabel = viewConnectionArea.accessibilityLabel?.replacingOccurrences(of: "...", with: "")
UIAccessibilityPostNotification(UIAccessibilityLayoutChangedNotification, viewConnectionArea)
// iPad accessibility wrappers
if Macros.isDevicePad {
viewCurrentRegion.accessibilityLabel = "\(labelRegionCaption.text ?? ""), \(labelRegion.text ?? "")"
}
// non-iPad bottom table
collectionView.reloadData()
}
@objc private func updateCurrentIP() {
let vpn = Client.providers.vpnProvider
if (vpn.vpnStatus == .connected) {
currentIP = Client.daemons.vpnIP
} else if (!Client.daemons.isInternetReachable && (vpn.vpnStatus == .disconnected)) {
currentIP = L10n.Dashboard.Connection.Ip.unreachable
} else {
currentIP = Client.daemons.publicIP
}
// iPad custom bottom view
self.labelPublicIP.text = self.currentIP;
if let _ = currentIP {
activityPublicIP.stopAnimating()
} else {
activityPublicIP.startAnimating()
}
// iPad accessibility wrappers
if Macros.isDevicePad {
viewPublicIP.accessibilityLabel = "\(labelPublicIPCaption.text ?? ""), \(labelPublicIP.text ?? "")"
}
// non-iPad bottom table
collectionView.reloadData()
}
// MARK: Restylable
......@@ -403,13 +339,7 @@ class DashboardViewController: AutolayoutViewController {
Theme.current.applyLightBackground(viewContainer!)
Theme.current.applyLightNavigationBar(navigationController!.navigationBar)
Theme.current.applyCaption(labelPublicIPCaption, appearance: .dark)
Theme.current.applyTitle(labelPublicIP, appearance: .dark)
Theme.current.applyCaption(labelRegionCaption, appearance: .dark)
Theme.current.applyTitle(labelRegion, appearance: .dark)
Theme.current.applyCaption(buttonChangeRegion, appearance: .emphasis)
Theme.current.applyTextButton(buttonChangeRegion)
// XXX: emulate native UITableView separator
//Theme.current.applyDividerToSeparator(tableRows)
collectionView.collectionViewLayout.invalidateLayout()
......@@ -548,7 +478,7 @@ extension DashboardViewController: UICollectionViewDelegate, UICollectionViewDat
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return AvailableTiles.countCases()
return 21//AvailableTiles.countCases()
}
}
......@@ -11,6 +11,7 @@ import PIALibrary
class IPTile: UIView, Tileable {
private let emptyIPValue = "---"
var detailViewAction: Func!
var view: UIView!
var detailSegueIdentifier: String!
......@@ -19,7 +20,7 @@ class IPTile: UIView, Tileable {
@IBOutlet private weak var localIpValue: UILabel!
@IBOutlet private weak var vpnIpTitle: UILabel!
@IBOutlet private weak var vpnIpValue: UILabel!
override init(frame: CGRect) {
super.init(frame: frame)
self.xibSetup()
......@@ -39,19 +40,21 @@ class IPTile: UIView, Tileable {
let nc = NotificationCenter.default
nc.addObserver(self, selector: #selector(updateCurrentIP), name: .PIADaemonsDidUpdateConnectivity, object: nil)
nc.addObserver(self, selector: #selector(updateActivityViews), name: .PIADaemonsDidUpdateVPNStatus, object: nil)
nc.addObserver(self, selector: #selector(viewShouldRestyle), name: .PIAThemeDidChange, object: nil)
viewShouldRestyle()
self.detailViewAction = {}
self.localIpTitle.text = "IP"
self.vpnIpTitle.text = "VPN IP"
self.localIpValue.text = "---"
self.vpnIpValue.text = "---"
self.localIpValue.text = Client.daemons.publicIP ?? emptyIPValue
self.vpnIpValue.text = emptyIPValue
}
@objc private func viewShouldRestyle() {
Theme.current.applySubtitle(localIpTitle)
Theme.current.applySubtitle(vpnIpTitle)
localIpTitle.style(style: TextStyle.textStyle21)
vpnIpTitle.style(style: TextStyle.textStyle21)
Theme.current.applySubtitle(localIpValue)
Theme.current.applySettingsCellTitle(vpnIpValue, appearance: .dark)
Theme.current.applyLightBackground(self)
......@@ -61,15 +64,21 @@ class IPTile: UIView, Tileable {
self.localIpValue.text = Client.daemons.publicIP
let vpn = Client.providers.vpnProvider
if (vpn.vpnStatus == .connected) {
self.vpnIpValue.text = Client.daemons.vpnIP
self.localIpValue.text = Client.daemons.publicIP
self.vpnIpValue.text = Client.daemons.vpnIP ?? self.emptyIPValue
} else if (!Client.daemons.isInternetReachable && (vpn.vpnStatus == .disconnected)) {
self.vpnIpValue.text = L10n.Dashboard.Connection.Ip.unreachable
self.localIpValue.text = "---"
} else {
self.vpnIpValue.text = "---"
self.localIpValue.text = "---"
}
}
@objc private func updateActivityViews() {
let vpn = Client.providers.vpnProvider
switch vpn.vpnStatus {
case .connecting, .disconnecting:
self.vpnIpValue.text = self.emptyIPValue
default:
break
}
}
}
......@@ -65,6 +65,7 @@
<constraint firstItem="Eay-Yz-Xzw" firstAttribute="leading" secondItem="tN8-Zr-Ghy" secondAttribute="trailing" constant="25" id="f4S-Uh-IWi"/>
<constraint firstItem="vUN-kp-3ea" firstAttribute="bottom" secondItem="Eay-Yz-Xzw" secondAttribute="bottom" constant="25" id="hwQ-GU-FEE"/>
<constraint firstItem="tN8-Zr-Ghy" firstAttribute="leading" secondItem="jwP-tn-mQv" secondAttribute="trailing" constant="10" id="kQA-aY-eE4"/>
<constraint firstItem="Eay-Yz-Xzw" firstAttribute="centerY" secondItem="xR4-ef-XuZ" secondAttribute="centerY" id="v5e-Rt-IgA"/>
<constraint firstItem="ltV-Wi-R5o" firstAttribute="top" secondItem="vUN-kp-3ea" secondAttribute="top" constant="25" id="wB5-JM-g0c"/>
<constraint firstItem="jwP-tn-mQv" firstAttribute="top" secondItem="vUN-kp-3ea" secondAttribute="top" constant="25" id="wcu-HH-Nfl"/>
</constraints>
......
......@@ -9,13 +9,15 @@
import UIKit
import PIALibrary
private let separatorDecorationView = "separator"
private let separatorDecorationViewTop = "separator-top"
private let separatorDecorationViewBottom = "separator-bottom"
final class TileFlowLayout: UICollectionViewFlowLayout {
override func awakeFromNib() {
super.awakeFromNib()
register(SeparatorView.self, forDecorationViewOfKind: separatorDecorationView)
register(SeparatorView.self, forDecorationViewOfKind: separatorDecorationViewTop)
register(SeparatorView.self, forDecorationViewOfKind: separatorDecorationViewBottom)
}
override func layoutAttributesForElements(in rect: CGRect) -> [UICollectionViewLayoutAttributes]? {
......@@ -24,15 +26,28 @@ final class TileFlowLayout: UICollectionViewFlowLayout {
var decorationAttributes: [UICollectionViewLayoutAttributes] = []
for layoutAttribute in layoutAttributes {
let separatorAttribute = UICollectionViewLayoutAttributes(forDecorationViewOfKind: separatorDecorationView,
//bottom
let separatorAttribute = UICollectionViewLayoutAttributes(forDecorationViewOfKind: separatorDecorationViewBottom,
with: layoutAttribute.indexPath)
let cellFrame = layoutAttribute.frame
separatorAttribute.frame = CGRect(x: cellFrame.origin.x,
y: cellFrame.origin.y - lineWidth,
y: cellFrame.origin.y + cellFrame.size.height,
width: cellFrame.size.width,
height: lineWidth)
separatorAttribute.zIndex = Int.max
decorationAttributes.append(separatorAttribute)
//top
let separatorAttributeTop = UICollectionViewLayoutAttributes(forDecorationViewOfKind: separatorDecorationViewTop,
with: layoutAttribute.indexPath)
let cellFrameTop = layoutAttribute.frame
separatorAttributeTop.frame = CGRect(x: cellFrameTop.origin.x,
y: cellFrame.origin.y,
width: cellFrameTop.size.width,
height: lineWidth)
separatorAttributeTop.zIndex = Int.max - 1
decorationAttributes.append(separatorAttributeTop)
}
return layoutAttributes + decorationAttributes
......
This diff is collapsed.
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