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

- Tileable protocol and extensions

- EnumsBuilder protocol to add util method to Enums
- First empty Tile
parent 818c8109
This diff is collapsed.
//
// EnumsBuilder.swift
// PIA VPN
//
// Created by Jose Antonio Blaya Garcia on 18/12/2018.
// Copyright © 2018 London Trust Media. All rights reserved.
//
import Foundation
/// Usage example:
/// private enum Cells: Int, EnumsBuilder {
/// case updateAmount = 0
/// case totalAmount = 1
/// var identifier: String {
/// switch self {
/// case .updateAmount: return "updateAmountCell"
/// case .totalAmount: return "totalAmountCell"
/// }
/// }
/// }
///
/// Cells.objectIdentifyBy(index: indexPath.row).identifier // eg. "totalAmountCell"
protocol EnumsBuilder {}
extension EnumsBuilder where Self: RawRepresentable, Self.RawValue == Int {
static func objectIdentifyBy(index: Int) -> Self {
guard let object = Self(rawValue: index) else {
fatalError("Object identifier not implemented")
}
return object
}
static func countCases() -> Int {
var numCases = 0
while Self(rawValue: numCases) != nil {
numCases += 1
}
return numCases
}
}
extension EnumsBuilder where Self: RawRepresentable, Self.RawValue == String {
static func objectIdentifyBy(name: String) -> Self {
guard let object = Self(rawValue: name) else {
fatalError("Object identifier not implemented")
}
return object
}
}
//
// AvailableTiles.swift
// PIA VPN
//
// Created by Jose Antonio Blaya Garcia on 09/01/2019.
// Copyright © 2019 London Trust Media. All rights reserved.
//
import Foundation
enum TileSections: Int, EnumsBuilder {
case power
case tiles
}
enum AvailablePowerTiles: Int, EnumsBuilder {
case power
}
enum AvailableTiles: Int, EnumsBuilder {
case regions
case ip
}
//
// PowerTile.swift
// PIA VPN
//
// Created by Jose Antonio Blaya Garcia on 09/01/2019.
// Copyright © 2019 London Trust Media. All rights reserved.
//
import UIKit
import PIALibrary
class PowerTile: UIView, Tileable {
var detailViewAction: Func!
var view: UIView!
var detailSegueIdentifier: String!
@IBOutlet private weak var toggleConnection: PIAConnectionButton!
override init(frame: CGRect) {
super.init(frame: frame)
self.setupView()
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
self.setupView()
}
private func setupView() {
self.detailViewAction = {}
let currentStatus = Client.providers.vpnProvider.vpnStatus
//Theme.current.applyVPNStatus(labelStatus, forStatus: currentStatus)
switch currentStatus {
case .connected:
toggleConnection.isOn = true
toggleConnection.isIndeterminate = false
toggleConnection.stopButtonAnimation()
case .disconnected:
toggleConnection.isOn = false
toggleConnection.isIndeterminate = false
toggleConnection.stopButtonAnimation()
case .connecting:
toggleConnection.isOn = false
toggleConnection.isIndeterminate = true
toggleConnection.startButtonAnimation()
case .disconnecting:
toggleConnection.isOn = true
toggleConnection.isIndeterminate = true
toggleConnection.startButtonAnimation()
}
}
@IBAction func vpnButtonClicked(_ sender: Any?) {
if !toggleConnection.isOn {
Client.providers.vpnProvider.connect(nil)
} else {
Client.providers.vpnProvider.disconnect(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"/>
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
<view contentMode="scaleToFill" id="iN0-l3-epB" customClass="PowerTile" customModule="PIA_VPN" customModuleProvider="target">
<rect key="frame" x="0.0" y="0.0" width="365" height="190"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="65q-NB-vbd" customClass="PIAConnectionButton" customModule="PIA_VPN" customModuleProvider="target">
<rect key="frame" x="107.5" y="20" width="150" height="150"/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<constraints>
<constraint firstAttribute="width" secondItem="65q-NB-vbd" secondAttribute="height" multiplier="1:1" id="AUZ-Lr-sBA"/>
<constraint firstAttribute="height" priority="750" constant="150" id="vzP-f6-1TG"/>
</constraints>
<connections>
<action selector="vpnButtonClicked:" destination="iN0-l3-epB" eventType="touchUpInside" id="Uan-rZ-Gde"/>
</connections>
</view>
</subviews>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<constraints>
<constraint firstItem="vUN-kp-3ea" firstAttribute="bottom" secondItem="65q-NB-vbd" secondAttribute="bottom" constant="20" id="4vc-sa-DeL"/>
<constraint firstItem="65q-NB-vbd" firstAttribute="top" secondItem="vUN-kp-3ea" secondAttribute="top" constant="20" id="dj3-eR-Cu3"/>
<constraint firstItem="65q-NB-vbd" firstAttribute="centerX" secondItem="iN0-l3-epB" secondAttribute="centerX" id="mrF-ex-cAg"/>
<constraint firstItem="65q-NB-vbd" firstAttribute="width" secondItem="65q-NB-vbd" secondAttribute="height" multiplier="1:1" id="weu-ce-Ofp"/>
</constraints>
<freeformSimulatedSizeMetrics key="simulatedDestinationMetrics"/>
<viewLayoutGuide key="safeArea" id="vUN-kp-3ea"/>
<connections>
<outlet property="toggleConnection" destination="65q-NB-vbd" id="vny-xE-wcW"/>
</connections>
<point key="canvasLocation" x="264.80000000000001" y="-654.87256371814101"/>
</view>
</objects>
</document>
//
// Tileable.swift
// PIA VPN
//
// Created by Jose Antonio Blaya Garcia on 09/01/2019.
// Copyright © 2019 London Trust Media. All rights reserved.
//
import Foundation
import UIKit
typealias Func = () -> Void
protocol Tileable {
var detailViewAction: Func! {get}
var view: UIView! {get set}
var detailSegueIdentifier: String! {get set}
mutating func xibSetup()
func loadViewFromNib() -> UIView
func isEditable() -> Bool
func isExpandable() -> Bool
func hasDetailView() -> Bool
}
extension Tileable {
///Check if the tile can change the visibility or the order in the list
/// - Returns: Bool
func isEditable() -> Bool {
return false
}
///Check if the tile can change the size inside the list
/// - Returns: Bool
func isExpandable() -> Bool {
return false
}
///Check if the tile has a detail view controller
/// - Returns: Bool
func hasDetailView() -> Bool {
return false
}
}
extension Tileable where Self: UIView {
/// The initial setup
mutating func xibSetup() {
self.view = loadViewFromNib()
self.view.frame = bounds
self.view.autoresizingMask = [UIViewAutoresizing.flexibleWidth,
UIViewAutoresizing.flexibleHeight]
addSubview(self.view)
}
/// The method used to load the xib file
/// - Returns: The view of the xib file
func loadViewFromNib() -> UIView {
let bundle = Bundle(for: type(of: self))
let nib = UINib(nibName: "PowerTile",
bundle: bundle)
let view = nib.instantiate(withOwner: self,
options: nil)[0] as? UIView
return view!
}
}
......@@ -191,6 +191,6 @@ SPEC CHECKSUMS:
SwiftyBeaver: ccfcdf85a04d429f1633f668650b0ce8020bda3a
TPKeyboardAvoiding: cb69d5ddbe90ce0170e4bc2db1e5e41d4a3ad9a4
PODFILE CHECKSUM: 87fc45c9dcad7b255ea49de23cf784af7b7efa83
PODFILE CHECKSUM: 7ab2b5283cf748dc8ba29903129293a3dcabe712
COCOAPODS: 1.5.3
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