diff options
| author | Andrej Mihajlov <and@mullvad.net> | 2020-01-08 14:21:52 +0100 |
|---|---|---|
| committer | Andrej Mihajlov <and@mullvad.net> | 2020-01-10 10:48:22 +0100 |
| commit | ea30af3326eca5b89aa30448aadea4dcef94e9fb (patch) | |
| tree | 05fc44ddd85709321c40d92ffb076149bf668434 /ios | |
| parent | 9f4f3f327e1d629d5a49e771c2142b4004b84463 (diff) | |
| download | mullvadvpn-ea30af3326eca5b89aa30448aadea4dcef94e9fb.tar.xz mullvadvpn-ea30af3326eca5b89aa30448aadea4dcef94e9fb.zip | |
Add function to copy account token to pasteboard
Diffstat (limited to 'ios')
| -rw-r--r-- | ios/MullvadVPN/AccountViewController.swift | 42 | ||||
| -rw-r--r-- | ios/MullvadVPN/Base.lproj/Main.storyboard | 33 |
2 files changed, 45 insertions, 30 deletions
diff --git a/ios/MullvadVPN/AccountViewController.swift b/ios/MullvadVPN/AccountViewController.swift index 51d8013737..6a423e2b9a 100644 --- a/ios/MullvadVPN/AccountViewController.swift +++ b/ios/MullvadVPN/AccountViewController.swift @@ -11,15 +11,28 @@ import UIKit class AccountViewController: UIViewController { - @IBOutlet var accountLabel: UILabel! + @IBOutlet var accountTokenButton: UIButton! @IBOutlet var expiryLabel: UILabel! private var logoutSubscriber: AnyCancellable? + private var copyToPasteboardSubscriber: AnyCancellable? override func viewDidLoad() { super.viewDidLoad() - updateView() + accountTokenButton.setTitle(Account.shared.token, for: .normal) + + if let expiryDate = Account.shared.expiry { + let accountExpiry = AccountExpiry(date: expiryDate) + + if accountExpiry.isExpired { + expiryLabel.text = NSLocalizedString("OUT OF TIME", comment: "") + expiryLabel.textColor = .dangerColor + } else { + expiryLabel.text = accountExpiry.formattedDate + expiryLabel.textColor = .white + } + } } // MARK: - Actions @@ -42,21 +55,18 @@ class AccountViewController: UIViewController { }) } - // MARK: - Private + @IBAction func copyAccountToken() { + UIPasteboard.general.string = Account.shared.token - private func updateView() { - accountLabel.text = Account.shared.token + accountTokenButton.setTitle( + NSLocalizedString("COPIED TO PASTEBOARD!", comment: ""), + for: .normal) - if let expiryDate = Account.shared.expiry { - let accountExpiry = AccountExpiry(date: expiryDate) - - if accountExpiry.isExpired { - expiryLabel.text = NSLocalizedString("OUT OF TIME", comment: "") - expiryLabel.textColor = .dangerColor - } else { - expiryLabel.text = accountExpiry.formattedDate - expiryLabel.textColor = .white - } - } + copyToPasteboardSubscriber = + Just(()).delay(for: .seconds(3), scheduler: DispatchQueue.main) + .sink(receiveValue: { _ in + self.accountTokenButton.setTitle(Account.shared.token, for: .normal) + }) } + } diff --git a/ios/MullvadVPN/Base.lproj/Main.storyboard b/ios/MullvadVPN/Base.lproj/Main.storyboard index 8b19d7ab4e..846746b2a1 100644 --- a/ios/MullvadVPN/Base.lproj/Main.storyboard +++ b/ios/MullvadVPN/Base.lproj/Main.storyboard @@ -1,8 +1,8 @@ <?xml version="1.0" encoding="UTF-8"?> -<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="15505" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="ZwP-1v-DUg"> +<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="15702" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="ZwP-1v-DUg"> <device id="retina4_7" orientation="portrait" appearance="light"/> <dependencies> - <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="15510"/> + <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="15704"/> <capability name="Named colors" minToolsVersion="9.0"/> <capability name="Safe area layout guides" minToolsVersion="9.0"/> <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/> @@ -708,16 +708,16 @@ <rect key="frame" x="0.0" y="0.0" width="375" height="647"/> <subviews> <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="rkG-Xa-pEO" userLabel="Container"> - <rect key="frame" x="0.0" y="0.0" width="375" height="295"/> + <rect key="frame" x="0.0" y="0.0" width="375" height="307.5"/> <subviews> <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="nkx-Eb-7le" userLabel="Content"> - <rect key="frame" x="24" y="24" width="327" height="247"/> + <rect key="frame" x="24" y="24" width="327" height="259.5"/> <subviews> <view contentMode="scaleToFill" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="HzF-8Z-UBs" userLabel="Account number"> - <rect key="frame" x="0.0" y="0.0" width="327" height="45.5"/> + <rect key="frame" x="0.0" y="0.0" width="327" height="58"/> <subviews> <stackView opaque="NO" contentMode="scaleToFill" axis="vertical" spacing="8" translatesAutoresizingMaskIntoConstraints="NO" id="5ux-jY-AC5"> - <rect key="frame" x="0.0" y="0.0" width="327" height="45.5"/> + <rect key="frame" x="0.0" y="0.0" width="327" height="58"/> <subviews> <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Account number" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="0L8-AT-A51"> <rect key="frame" x="0.0" y="0.0" width="327" height="17"/> @@ -725,12 +725,17 @@ <color key="textColor" white="1" alpha="0.59999999999999998" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/> <nil key="highlightedColor"/> </label> - <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" text="123456789" textAlignment="natural" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="jvc-8m-jM5"> - <rect key="frame" x="0.0" y="25" width="327" height="20.5"/> + <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="leading" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="XNH-JJ-9gR"> + <rect key="frame" x="0.0" y="25" width="327" height="21"/> <fontDescription key="fontDescription" type="system" weight="medium" pointSize="17"/> - <color key="textColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/> - <nil key="highlightedColor"/> - </label> + <inset key="contentEdgeInsets" minX="0.01" minY="0.0" maxX="1" maxY="0.0"/> + <state key="normal" title="123456789"> + <color key="titleColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/> + </state> + <connections> + <action selector="copyAccountToken" destination="ruh-Q2-P39" eventType="touchUpInside" id="jox-eA-A3D"/> + </connections> + </button> </subviews> </stackView> </subviews> @@ -742,7 +747,7 @@ </constraints> </view> <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="459-0n-9V2" userLabel="Expiry"> - <rect key="frame" x="0.0" y="69.5" width="327" height="45.5"/> + <rect key="frame" x="0.0" y="82" width="327" height="45.5"/> <subviews> <stackView opaque="NO" contentMode="scaleToFill" axis="vertical" spacing="8" translatesAutoresizingMaskIntoConstraints="NO" id="NMg-f0-BTW"> <rect key="frame" x="0.0" y="0.0" width="327" height="45.5"/> @@ -770,7 +775,7 @@ </constraints> </view> <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="Acd-vw-Pu7" userLabel="Buttons"> - <rect key="frame" x="0.0" y="139" width="327" height="108"/> + <rect key="frame" x="0.0" y="151.5" width="327" height="108"/> <subviews> <stackView opaque="NO" contentMode="scaleToFill" axis="vertical" spacing="24" translatesAutoresizingMaskIntoConstraints="NO" id="wNk-FP-mVD"> <rect key="frame" x="0.0" y="0.0" width="327" height="108"/> @@ -851,7 +856,7 @@ </view> <navigationItem key="navigationItem" title="Account" id="rL3-Y8-3g8"/> <connections> - <outlet property="accountLabel" destination="jvc-8m-jM5" id="HnU-i4-BRj"/> + <outlet property="accountTokenButton" destination="XNH-JJ-9gR" id="yCU-t3-ayW"/> <outlet property="expiryLabel" destination="8Vg-dd-ZpW" id="3n5-2Z-J8y"/> <segue destination="P2i-eG-jQx" kind="unwind" identifier="Logout" unwindAction="unwindFromAccountWithSegue:" id="5li-wk-yRM"/> </connections> |
