diff --git a/enzevalos_iphone/Base.lproj/Main.storyboard b/enzevalos_iphone/Base.lproj/Main.storyboard index 48c225f9593cf3c98ebeac59f51109905d23d9ab..d5c8054a01a5fa99d7f7c70beeda173d2fa3ec87 100644 --- a/enzevalos_iphone/Base.lproj/Main.storyboard +++ b/enzevalos_iphone/Base.lproj/Main.storyboard @@ -182,7 +182,7 @@ </constraints> </view> <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="qTi-rO-CH3"> - <rect key="frame" x="187.66666666666663" y="0.0" width="186.33333333333337" height="44"/> + <rect key="frame" x="187.66666666666663" y="5.6666666666666679" width="186.33333333333337" height="33"/> <constraints> <constraint firstAttribute="height" constant="44" id="voC-CF-ncN"/> </constraints> @@ -487,13 +487,13 @@ <scene sceneID="9n5-zf-74L"> <objects> <tableViewController storyboardIdentifier="CryptoManagementViewController" title="CryptoManagementView" useStoryboardIdentifierAsRestorationIdentifier="YES" id="J6h-r6-ak0" customClass="CryptoManagementViewController" customModule="enzevalos_iphone" customModuleProvider="target" sceneMemberID="viewController"> - <tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="-1" estimatedRowHeight="-1" sectionHeaderHeight="28" sectionFooterHeight="28" id="hCi-Jy-3k1"> + <tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="grouped" separatorStyle="default" rowHeight="-1" estimatedRowHeight="-1" sectionHeaderHeight="18" sectionFooterHeight="18" id="hCi-Jy-3k1"> <rect key="frame" x="0.0" y="0.0" width="414" height="896"/> <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> - <color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/> + <color key="backgroundColor" cocoaTouchSystemColor="groupTableViewBackgroundColor"/> <prototypes> <tableViewCell clipsSubviews="YES" contentMode="scaleToFill" restorationIdentifier="InfoField" preservesSuperviewLayoutMargins="YES" selectionStyle="default" indentationWidth="10" reuseIdentifier="InfoField" textLabel="BkP-vb-Ubx" style="IBUITableViewCellStyleDefault" id="r9b-bf-cdZ"> - <rect key="frame" x="0.0" y="28" width="414" height="44"/> + <rect key="frame" x="0.0" y="55.333333333333343" width="414" height="44"/> <autoresizingMask key="autoresizingMask"/> <tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="r9b-bf-cdZ" id="VrR-2E-Xac"> <rect key="frame" x="0.0" y="0.0" width="414" height="43.666666666666664"/> @@ -510,7 +510,7 @@ </tableViewCellContentView> </tableViewCell> <tableViewCell clipsSubviews="YES" contentMode="scaleToFill" restorationIdentifier="YourID" preservesSuperviewLayoutMargins="YES" selectionStyle="default" accessoryType="disclosureIndicator" indentationWidth="10" reuseIdentifier="YourID" textLabel="68q-L5-TMh" style="IBUITableViewCellStyleDefault" id="y3q-au-Ig2"> - <rect key="frame" x="0.0" y="72" width="414" height="44"/> + <rect key="frame" x="0.0" y="99.333333333333343" width="414" height="44"/> <autoresizingMask key="autoresizingMask"/> <tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="y3q-au-Ig2" id="YNh-FM-nf1"> <rect key="frame" x="0.0" y="0.0" width="376" height="43.666666666666664"/> @@ -531,7 +531,7 @@ </connections> </tableViewCell> <tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="default" accessoryType="disclosureIndicator" indentationWidth="10" reuseIdentifier="OtherID" textLabel="3EJ-XV-Cfb" style="IBUITableViewCellStyleDefault" id="aOA-2G-mEN"> - <rect key="frame" x="0.0" y="116" width="414" height="44"/> + <rect key="frame" x="0.0" y="143.33333333333334" width="414" height="44"/> <autoresizingMask key="autoresizingMask"/> <tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="aOA-2G-mEN" id="s3T-ci-UcE"> <rect key="frame" x="0.0" y="0.0" width="376" height="43.666666666666664"/> @@ -684,8 +684,8 @@ <constraint firstAttribute="width" constant="15" id="ons-Pp-k3n"/> </constraints> </imageView> - <imageView userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="sfv-2Q-95I"> - <rect key="frame" x="0.0" y="18" width="15" height="15"/> + <imageView userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" ambiguous="YES" translatesAutoresizingMaskIntoConstraints="NO" id="sfv-2Q-95I"> + <rect key="frame" x="0.0" y="15" width="15" height="18"/> <constraints> <constraint firstAttribute="height" constant="15" id="SmT-9e-ovi"/> <constraint firstAttribute="width" constant="15" id="uKU-PK-flD"/> @@ -859,7 +859,7 @@ <!--Contact View Controller--> <scene sceneID="6er-JI-0Op"> <objects> - <tableViewController storyboardIdentifier="UITableViewController-8Di-x2-cWQ" id="8Di-x2-cWQ" customClass="ContactViewController" customModule="enzevalos_iphone" customModuleProvider="target" sceneMemberID="viewController"> + <tableViewController storyboardIdentifier="UITableViewController-8Di-x2-cWQ" useStoryboardIdentifierAsRestorationIdentifier="YES" id="8Di-x2-cWQ" customClass="ContactViewController" customModule="enzevalos_iphone" customModuleProvider="target" sceneMemberID="viewController"> <tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="grouped" separatorStyle="default" rowHeight="44" sectionHeaderHeight="18" sectionFooterHeight="18" id="lK7-ug-OyQ"> <rect key="frame" x="0.0" y="0.0" width="414" height="808"/> <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> @@ -1237,24 +1237,24 @@ <rect key="frame" x="0.0" y="809.33333333333337" width="414" height="44"/> <autoresizingMask key="autoresizingMask"/> <tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="hTc-vs-AIl" id="pJ9-4e-7at"> - <rect key="frame" x="0.0" y="0.0" width="388" height="43.666666666666664"/> + <rect key="frame" x="0.0" y="0.0" width="376" height="43.666666666666664"/> <autoresizingMask key="autoresizingMask"/> <subviews> <imageView userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="Ll6-yF-xkq"> - <rect key="frame" x="16" y="8" width="38" height="28"/> + <rect key="frame" x="28" y="8" width="38" height="28"/> <constraints> <constraint firstAttribute="height" constant="28" id="QdS-hg-KWv"/> <constraint firstAttribute="width" constant="38" id="zKm-1g-WHC"/> </constraints> </imageView> <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="751" verticalHuggingPriority="751" text="Label" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="coq-va-tcb"> - <rect key="frame" x="60" y="11" width="42" height="21"/> + <rect key="frame" x="72" y="14" width="42" height="21"/> <fontDescription key="fontDescription" type="system" pointSize="17"/> <nil key="textColor"/> <nil key="highlightedColor"/> </label> <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" horizontalCompressionResistancePriority="250" verticalCompressionResistancePriority="250" text="Label" textAlignment="right" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Wnj-Bb-1Ox"> - <rect key="frame" x="102" y="13.666666666666664" width="271" height="18"/> + <rect key="frame" x="114" y="16.666666666666668" width="259" height="18.000000000000004"/> <fontDescription key="fontDescription" style="UICTFontTextStyleSubhead"/> <color key="textColor" white="0.66666666666666663" alpha="1" colorSpace="calibratedWhite"/> <nil key="highlightedColor"/> @@ -1977,7 +1977,7 @@ Um deine sicheren E-Mails auch auf einem anderen Gerät lesen zu können, muss d </connections> </barButtonItem> <button key="titleView" opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" id="iUk-lk-1LN"> - <rect key="frame" x="161.66666666666666" y="6" width="91" height="32"/> + <rect key="frame" x="162" y="6" width="91" height="32"/> <autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMaxX="YES" flexibleMaxY="YES"/> <connections> <action selector="iconButtonPressed:" destination="4Ey-v4-VeB" eventType="touchUpInside" id="Opj-Y1-Vtg"/> @@ -2064,6 +2064,6 @@ Um deine sicheren E-Mails auch auf einem anderen Gerät lesen zu können, muss d <segue reference="DcR-GX-scc"/> <segue reference="NPH-pL-mw2"/> <segue reference="7Fo-Cp-0Kl"/> - <segue reference="6Ug-AV-lba"/> + <segue reference="PxQ-Nb-6Fq"/> </inferredMetricsTieBreakers> </document> diff --git a/enzevalos_iphone/CryptoManagementViewController.swift b/enzevalos_iphone/CryptoManagementViewController.swift index b66b871fc4d89eea2c46cfece61a0fb8f10b0868..78d9fcd8b4b490fc8f7fe25067e90d207bc50f8a 100644 --- a/enzevalos_iphone/CryptoManagementViewController.swift +++ b/enzevalos_iphone/CryptoManagementViewController.swift @@ -37,10 +37,34 @@ class CryptoManagementViewController: UITableViewController { } } } + + enum SectionType { + case Info, KeyLists + var numberOfRows: Int { + switch self { + case .Info: + return 1 + case .KeyLists: + return 2 + } + } + static func findSectionType(numberOfSection: Int) -> SectionType { + if numberOfSection == 0 { + return .Info + } + else { + return .KeyLists + } + } + } override func viewDidLoad() { super.viewDidLoad() self.title = NSLocalizedString("Management.Crypto.Title", comment: "") + let infoButton = UIButton(type: .infoLight) + //infoButton.addTarget(self, action: #selector(infoButtonTapped), forControlEvents: .TouchUpInside) + let barButton = UIBarButtonItem(customView: infoButton) + self.navigationItem.rightBarButtonItem = barButton // Uncomment the following line to preserve selection between presentations //self.clearsSelectionOnViewWillAppear = false @@ -52,23 +76,27 @@ class CryptoManagementViewController: UITableViewController { // MARK: - Table view data source override func numberOfSections(in tableView: UITableView) -> Int { - return 1 + return 2 } override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { - return 3 + return SectionType.findSectionType(numberOfSection: section).numberOfRows } override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { - if indexPath.row == 0 { + let sectionType = SectionType.findSectionType(numberOfSection: indexPath.section) + if sectionType == .Info { return infoCell(cellForRowAt: indexPath) } - else if indexPath.row == 1 { - return yourIDCell(cellForRowAt: indexPath) - } - else { - return otherIDCell(cellForRowAt: indexPath) + else{ + // key lists + if indexPath.row == 0 { + return yourIDCell(cellForRowAt: indexPath) + } + else { + return otherIDCell(cellForRowAt: indexPath) + } } } diff --git a/enzevalos_iphone/DateExtension.swift b/enzevalos_iphone/DateExtension.swift index 19749531ba9e45c0e84f0d1a04c6fb38fb3e20ec..e4c361792260ee7e83067b12834734fa6b43c839 100644 --- a/enzevalos_iphone/DateExtension.swift +++ b/enzevalos_iphone/DateExtension.swift @@ -51,7 +51,8 @@ extension Date{ return NSLocalizedString("Time.Day.One", comment: "one day") } else { - return String(format: NSLocalizedString("Time.day.Multiple", comment: "multiple days"), days) + let s = NSLocalizedString("Time.Day.Multiple", comment: "multiple days") + return String(format: s, days) } } return self.description(with: .autoupdatingCurrent) diff --git a/enzevalos_iphone/KeyCell.swift b/enzevalos_iphone/KeyCell.swift index 82e10b61ddcb569143f106db45cc215419a0ea9f..1ed94750c931bc1a6905928a0ea73303b9880b4e 100644 --- a/enzevalos_iphone/KeyCell.swift +++ b/enzevalos_iphone/KeyCell.swift @@ -10,14 +10,71 @@ import Foundation class KeyCell: UITableViewCell { @IBOutlet weak var idLabel: UILabel! - @IBOutlet weak var originLabel: UILabel! @IBOutlet weak var dateLabel: UILabel! @IBOutlet weak var prefIcon: UIImageView! - @IBOutlet weak var orignName: UILabel! @IBOutlet weak var dateName: UILabel! + @IBOutlet weak var mailAddress: UILabel! + func setLabels(key: PersistentKey) { + var mailAddrString: String? + var id = key.keyID + let date = key.discoveryDate + let pref = false + if let record = key.keyRecord { + mailAddrString = record.addressNames.first + id = record.myNick + + } else { + if let addresses = key.mailaddresses { + for addr in addresses { + if let mail = addr as? MailAddress { + mailAddrString = mail.mailAddress + break + } + } + } + } + setLabels(id: id, addr: mailAddrString, date: date, origin: nil, pref: pref) + } + func setLabels(key: SecretKey) { + var id = key.keyID + var mail: String? = nil + let date = key.importDate + let pref = DataHandler.handler.prefSecretKey()?.keyID == key.keyID + if let addr = UserManager.loadUserValue(.userAddr) as? String { + mail = addr + let record = DataHandler.handler.getKeyRecord(addr: addr, keyID: id) + id = record.myNick + } + setLabels(id: id, addr: mail, date: date, origin: nil, pref: pref) + } + + private func setLabels(id: String, addr: String?, date: Date?, origin: String?, pref: Bool) { + idLabel.text = id + if let addr = addr { + mailAddress.text = addr + mailAddress.isHidden = false + } else { + mailAddress.isHidden = true + } + if let date = date { + //dateLabel.text = date.timeAgoText() + //dateName.text = NSLocalizedString("SecretKeyCell.date", comment: "known since") + dateLabel.isHidden = true + dateName.isHidden = true + } else { + dateLabel.isHidden = true + dateName.isHidden = true + } + if pref { + prefIcon.image = NoSecIconStyleKit.imageOfFavorite + prefIcon.isHidden = false + } else { + prefIcon.isHidden = true + } + } } diff --git a/enzevalos_iphone/KeyCell.xib b/enzevalos_iphone/KeyCell.xib index 1fc1eacec612df2cb012034d7dcf208ea8e21fab..8c7f33dc15a9eacdccb26e886b41f883d5ea51d3 100644 --- a/enzevalos_iphone/KeyCell.xib +++ b/enzevalos_iphone/KeyCell.xib @@ -1,6 +1,6 @@ <?xml version="1.0" encoding="UTF-8"?> <document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="14490.70" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES"> - <device id="retina4_7" orientation="portrait"> + <device id="retina4_0" orientation="portrait"> <adaptation id="fullscreen"/> </device> <dependencies> @@ -12,65 +12,62 @@ <objects> <placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/> <placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/> - <tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="default" indentationWidth="10" rowHeight="148" id="wRd-M0-fdb" customClass="KeyCell" customModule="enzevalos_iphone" customModuleProvider="target"> - <rect key="frame" x="0.0" y="0.0" width="406" height="148"/> + <tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="default" accessoryType="disclosureIndicator" indentationWidth="10" id="wRd-M0-fdb" customClass="KeyCell" customModule="enzevalos_iphone" customModuleProvider="target"> + <rect key="frame" x="0.0" y="0.0" width="406" height="90"/> <autoresizingMask key="autoresizingMask"/> <tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="wRd-M0-fdb" id="Emm-NH-1K1"> - <rect key="frame" x="0.0" y="0.0" width="406" height="147.5"/> + <rect key="frame" x="0.0" y="0.0" width="368" height="89.5"/> <autoresizingMask key="autoresizingMask"/> <subviews> - <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" ambiguous="YES" misplaced="YES" text="ID" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="1WN-Xm-ow9"> - <rect key="frame" x="20" y="17" width="259" height="51"/> - <fontDescription key="fontDescription" type="system" pointSize="17"/> - <nil key="textColor"/> + <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" verticalCompressionResistancePriority="749" text="mailAddr" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="y5Q-hJ-QtK"> + <rect key="frame" x="49" y="39" width="68" height="16"/> + <fontDescription key="fontDescription" name=".AppleSystemUIFont" family=".AppleSystemUIFont" pointSize="17"/> + <color key="textColor" white="0.66666666666666663" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/> <nil key="highlightedColor"/> </label> - <imageView hidden="YES" userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" ambiguous="YES" insetsLayoutMarginsFromSafeArea="NO" translatesAutoresizingMaskIntoConstraints="NO" id="vo5-ax-qtB"> - <rect key="frame" x="305" y="37" width="80" height="80"/> + <imageView hidden="YES" userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" insetsLayoutMarginsFromSafeArea="NO" translatesAutoresizingMaskIntoConstraints="NO" id="vo5-ax-qtB"> + <rect key="frame" x="20" y="35" width="20" height="19"/> + <autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMaxX="YES" heightSizable="YES" flexibleMaxY="YES"/> + </imageView> + <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="yesterday" textAlignment="right" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontForContentSizeCategory="YES" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="QMx-FE-uVs"> + <rect key="frame" x="233" y="63" width="107" height="16"/> <constraints> - <constraint firstAttribute="width" secondItem="vo5-ax-qtB" secondAttribute="height" multiplier="1:1" id="lxE-e0-5DU"/> + <constraint firstAttribute="width" constant="107" id="sMn-QV-KHF"/> </constraints> - </imageView> - <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" ambiguous="YES" text="known since" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontForContentSizeCategory="YES" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="LBs-As-DEo"> - <rect key="frame" x="20" y="63" width="75" height="16"/> - <fontDescription key="fontDescription" style="UICTFontTextStyleFootnote"/> - <nil key="textColor"/> - <nil key="highlightedColor"/> - </label> - <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" ambiguous="YES" text="origin:" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="z7A-kG-Hmf"> - <rect key="frame" x="20" y="79" width="38" height="16"/> <fontDescription key="fontDescription" style="UICTFontTextStyleFootnote"/> - <nil key="textColor"/> + <color key="textColor" white="0.66666666666666663" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/> <nil key="highlightedColor"/> </label> - <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" ambiguous="YES" text="yesterday" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontForContentSizeCategory="YES" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="QMx-FE-uVs"> - <rect key="frame" x="105" y="63" width="59.5" height="16"/> + <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="known since" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontForContentSizeCategory="YES" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="LBs-As-DEo"> + <rect key="frame" x="49" y="63" width="136" height="16"/> + <constraints> + <constraint firstAttribute="width" constant="136" id="9WB-RJ-9II"/> + </constraints> <fontDescription key="fontDescription" style="UICTFontTextStyleFootnote"/> - <nil key="textColor"/> + <color key="textColor" white="0.66666666666666663" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/> <nil key="highlightedColor"/> </label> - <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" ambiguous="YES" text="iTunes import" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontForContentSizeCategory="YES" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="n9T-OX-sTx"> - <rect key="frame" x="68" y="79" width="83" height="16"/> - <fontDescription key="fontDescription" style="UICTFontTextStyleFootnote"/> + <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="ID" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="1WN-Xm-ow9"> + <rect key="frame" x="49" y="11" width="68" height="25"/> + <constraints> + <constraint firstAttribute="height" constant="25" id="n9y-OV-Dut"/> + </constraints> + <fontDescription key="fontDescription" type="system" pointSize="17"/> <nil key="textColor"/> <nil key="highlightedColor"/> </label> </subviews> <constraints> - <constraint firstItem="1WN-Xm-ow9" firstAttribute="width" secondItem="Emm-NH-1K1" secondAttribute="width" id="A9A-XA-qVq"/> - <constraint firstItem="1WN-Xm-ow9" firstAttribute="top" secondItem="lA0-Xm-beh" secondAttribute="top" constant="10" id="AkA-nz-1cY"/> - <constraint firstItem="n9T-OX-sTx" firstAttribute="leading" secondItem="z7A-kG-Hmf" secondAttribute="trailing" constant="10" id="BG2-Vl-rvF"/> - <constraint firstItem="1WN-Xm-ow9" firstAttribute="leading" secondItem="Emm-NH-1K1" secondAttribute="leading" constant="20" id="CKO-wk-Szk"/> - <constraint firstItem="z7A-kG-Hmf" firstAttribute="leading" secondItem="Emm-NH-1K1" secondAttribute="leading" constant="20" id="D5n-Vf-TMR"/> - <constraint firstItem="lA0-Xm-beh" firstAttribute="trailing" secondItem="vo5-ax-qtB" secondAttribute="trailing" constant="20" id="Fml-F6-GtS"/> - <constraint firstItem="LBs-As-DEo" firstAttribute="leading" secondItem="Emm-NH-1K1" secondAttribute="leading" constant="20" id="Qdx-37-iHt"/> - <constraint firstItem="z7A-kG-Hmf" firstAttribute="firstBaseline" secondItem="LBs-As-DEo" secondAttribute="baseline" constant="16" symbolType="layoutAnchor" id="Vn3-iv-9rd"/> - <constraint firstItem="lA0-Xm-beh" firstAttribute="bottom" secondItem="z7A-kG-Hmf" secondAttribute="bottom" constant="10" id="Wgb-NL-oZY"/> - <constraint firstItem="QMx-FE-uVs" firstAttribute="centerY" secondItem="LBs-As-DEo" secondAttribute="centerY" id="b7W-wn-XxQ"/> - <constraint firstItem="LBs-As-DEo" firstAttribute="firstBaseline" secondItem="1WN-Xm-ow9" secondAttribute="baseline" constant="20" symbolType="layoutAnchor" id="hse-xA-Xhf"/> - <constraint firstItem="vo5-ax-qtB" firstAttribute="centerY" secondItem="lA0-Xm-beh" secondAttribute="centerY" id="qmq-gD-8Cp"/> - <constraint firstItem="n9T-OX-sTx" firstAttribute="centerY" secondItem="z7A-kG-Hmf" secondAttribute="centerY" id="seT-Da-i22"/> - <constraint firstItem="QMx-FE-uVs" firstAttribute="leading" secondItem="LBs-As-DEo" secondAttribute="trailing" constant="10" id="zR3-OB-U9G"/> + <constraint firstItem="y5Q-hJ-QtK" firstAttribute="top" secondItem="1WN-Xm-ow9" secondAttribute="bottom" constant="3" id="8Dk-Zu-Sgo"/> + <constraint firstItem="LBs-As-DEo" firstAttribute="bottom" secondItem="Emm-NH-1K1" secondAttribute="bottomMargin" id="EUf-9W-bV4"/> + <constraint firstItem="LBs-As-DEo" firstAttribute="leading" secondItem="1WN-Xm-ow9" secondAttribute="leading" id="KWF-Ms-Gqy"/> + <constraint firstItem="LBs-As-DEo" firstAttribute="leading" secondItem="y5Q-hJ-QtK" secondAttribute="leading" id="du5-Zz-gSZ"/> + <constraint firstItem="LBs-As-DEo" firstAttribute="leading" secondItem="lA0-Xm-beh" secondAttribute="leading" constant="49" id="ihW-Gw-ujK"/> + <constraint firstItem="1WN-Xm-ow9" firstAttribute="trailing" secondItem="y5Q-hJ-QtK" secondAttribute="trailing" id="oiD-iP-aoR"/> + <constraint firstItem="QMx-FE-uVs" firstAttribute="leading" secondItem="LBs-As-DEo" secondAttribute="trailing" constant="48" id="ov5-zd-AfS"/> + <constraint firstItem="LBs-As-DEo" firstAttribute="top" secondItem="y5Q-hJ-QtK" secondAttribute="bottom" constant="8" symbolic="YES" id="teq-YB-6BV"/> + <constraint firstItem="1WN-Xm-ow9" firstAttribute="top" secondItem="Emm-NH-1K1" secondAttribute="topMargin" id="xJF-7V-bP2"/> + <constraint firstItem="LBs-As-DEo" firstAttribute="baseline" secondItem="QMx-FE-uVs" secondAttribute="baseline" id="zdi-Er-AsQ"/> </constraints> <viewLayoutGuide key="safeArea" id="lA0-Xm-beh"/> </tableViewCellContentView> @@ -78,11 +75,10 @@ <outlet property="dateLabel" destination="QMx-FE-uVs" id="7Qh-1w-o7v"/> <outlet property="dateName" destination="LBs-As-DEo" id="aDY-hl-8AS"/> <outlet property="idLabel" destination="1WN-Xm-ow9" id="9ug-Yf-pyT"/> - <outlet property="originLabel" destination="n9T-OX-sTx" id="xki-TX-CL7"/> - <outlet property="orignName" destination="z7A-kG-Hmf" id="ZM1-jZ-ura"/> + <outlet property="mailAddress" destination="y5Q-hJ-QtK" id="RLY-m9-mnu"/> <outlet property="prefIcon" destination="vo5-ax-qtB" id="NVe-Hh-iZP"/> </connections> - <point key="canvasLocation" x="121.59999999999999" y="-107.0464767616192"/> + <point key="canvasLocation" x="120" y="-107.74647887323944"/> </tableViewCell> </objects> </document> diff --git a/enzevalos_iphone/KeyTableViewController.swift b/enzevalos_iphone/KeyTableViewController.swift index 6deb4d01491a960f1b58c2294a91d3291f93e1c1..c3449dbc58cacc7ba4a83e41d94611b3ef0ed8f7 100644 --- a/enzevalos_iphone/KeyTableViewController.swift +++ b/enzevalos_iphone/KeyTableViewController.swift @@ -11,36 +11,21 @@ import UIKit class KeyTableViewController: UITableViewController { var showYourIDs = true - var keys: [DisplayKey] = [] - var currentPrefKeyRow = IndexPath() - var secretKeyPasswordField: UITextField? = nil - - - var prefKeyID: String? { - get { - if showYourIDs { - return DataHandler.handler.prefSecretKey()?.keyID - } else { - return nil - } - } - } + var publicKeys: [PersistentKey] = [] + var secretKeys: [SecretKey] = [] override func viewDidLoad() { super.viewDidLoad() + var title = "Your IDs" if showYourIDs { - keys = DataHandler.handler.findSecretKeys() + secretKeys = DataHandler.handler.findSecretKeys() } else { - keys = DataHandler.handler.findPublicKeys() + publicKeys = DataHandler.handler.findPublicKeys() + title = "Other people's IDs" } - - - // Uncomment the following line to preserve selection between presentations - // self.clearsSelectionOnViewWillAppear = false - - // Uncomment the following line to display an Edit button in the navigation bar for this view controller. - // self.navigationItem.rightBarButtonItem = self.editButtonItem + self.title = title + self.navigationItem.rightBarButtonItem = UIBarButtonItem(barButtonSystemItem: .add, target: nil, action: nil) } // MARK: - Table view data source @@ -51,7 +36,11 @@ class KeyTableViewController: UITableViewController { override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { // #warning Incomplete implementation, return the number of rows - return keys.count + if showYourIDs { + return secretKeys.count + } else { + return publicKeys.count + } } @@ -64,103 +53,55 @@ class KeyTableViewController: UITableViewController { tableView.register(UINib.init(nibName: "KeyCell", bundle: nil), forCellReuseIdentifier: "KeyCell") cell = tableView.dequeueReusableCell(withIdentifier: "KeyCell") as! KeyCell } - let item = keys[indexPath.row] - cell.idLabel.text = item.keyID - cell.dateLabel.text = item.importDate.description - cell.dateName.text = NSLocalizedString("SecretKeyCell.date", comment: "date") - cell.originLabel.isHidden = true - cell.orignName.text = NSLocalizedString("SecretKeyCell.origin", comment: "origin") - cell.orignName.isHidden = true - if let prefID = prefKeyID, prefID == item.keyID && keys.count > 1{ - currentPrefKeyRow = indexPath - cell.accessoryType = .checkmark + + if showYourIDs { + cell.setLabels(key: secretKeys[indexPath.row]) + } else { + cell.setLabels(key: publicKeys[indexPath.row]) } + return cell } override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { - guard showYourIDs else { - return - } - guard tableView.numberOfRows(inSection: indexPath.section) >= 2 else { - // Only one key -> we can not change the prefered key. - tableView.reloadRows(at: [indexPath], with: .none) - return - } - let newPrefKey = keys[indexPath.row] - let id = newPrefKey.keyID - - let pgp = SwiftPGP.init() - if pgp.checkPasswordFor(secretKeyID: id, password: nil, secretkey: newPrefKey.pgpKey) { - changePrefKey(tableView: tableView, indexPath: indexPath) - } - else { - // PW input. - inputPassword(first: true, pgp: pgp, pgpKey: newPrefKey.pgpKey, id: id, indexPath: indexPath, tableView: tableView) - return - } - } - - - private func changePrefKey(tableView: UITableView, indexPath: IndexPath) { - guard showYourIDs else { - if let cell = tableView.cellForRow(at: indexPath) { - cell.selectionStyle = .none + let keyID: String + let addr: String + if showYourIDs { + let key = secretKeys[indexPath.row] + keyID = key.keyID + addr = UserManager.loadUserValue(.userAddr) as? String ?? keyID + } else { + let key = publicKeys[indexPath.row] + keyID = key.keyID + var mail: String? + if let addrs = key.mailaddresses { + for addr in addrs { + if let addr = addr as? MailAddress { + mail = addr.mailAddress + break + } + } } - return - } - if let newPrefKey = keys[indexPath.row].save() { - DataHandler.handler.changePrefKey(newPrefKey: newPrefKey) - } - var reloadCells = [IndexPath]() - if let oldPrefCell = tableView.cellForRow(at: currentPrefKeyRow) as? KeyCell { - oldPrefCell.accessoryType = .none - reloadCells.append(currentPrefKeyRow) - } - if let newPrefCell = tableView.cellForRow(at: indexPath) as? KeyCell { - newPrefCell.accessoryType = .checkmark - reloadCells.append(indexPath) + if mail == nil { + print("Error: \(keyID)") + } + addr = mail ?? keyID + } - tableView.reloadRows(at: reloadCells, with: .automatic) - } - private func stopChangePrefKey(tableView: UITableView, indexPath: IndexPath) { + // GOTO Key Details + let mainStoryboard = UIStoryboard(name: "Main", bundle: Bundle.main) + if let viewController = mainStoryboard.instantiateViewController(withIdentifier: "UITableViewController-8Di-x2-cWQ") as? ContactViewController { + viewController.keyRecord = DataHandler.handler.getKeyRecord(addr: addr, keyID: keyID) + self.navigationController?.pushViewController(viewController, animated: true) + } + tableView.cellForRow(at: indexPath)?.selectionStyle = .default tableView.reloadRows(at: [indexPath], with: .automatic) + } - private func inputPassword(first: Bool, pgp: SwiftPGP, pgpKey: Key?, id: String, indexPath: IndexPath, tableView: UITableView) { - guard showYourIDs else { - return - } - var message = String(format: NSLocalizedString("Read.Import.Secret.Body.PW", comment: "NewSecretKeyMessage"), id) - if !first { - message = NSLocalizedString("Read.Import.Secret.Body.Wrong", comment: "NewSecretKeyMessage") - } - let alert = UIAlertController(title: NSLocalizedString("Read.Import.Secret.Title", comment: "NewSecretKeyTitle"), message: message, preferredStyle: UIAlertController.Style.alert) - alert.addAction(UIAlertAction(title: NSLocalizedString("Cancel", comment: "NoSecretKeyImport"), style: UIAlertAction.Style.destructive, handler: { (_: UIAlertAction) -> Void in - return self.stopChangePrefKey(tableView: tableView, indexPath: indexPath) - })) - - alert.addAction(UIAlertAction(title: NSLocalizedString("Read.Import.Secret.Ok", comment: "Import secret Key"), style: UIAlertAction.Style.default, handler: {(_:UIAlertAction) -> Void in - if let pw = self.secretKeyPasswordField?.text, pgp.checkPasswordFor(secretKeyID: id, password: pw, secretkey: pgpKey ) { - self.changePrefKey(tableView: tableView, indexPath: indexPath) - } - else { - self.inputPassword(first: false, pgp: pgp, pgpKey: pgpKey, id: id, indexPath: indexPath, tableView: tableView) - } - })) - alert.addTextField(configurationHandler: newSecretkeyPassword(textField:)) - self.present(alert, animated: true, completion: nil) - } - - private func newSecretkeyPassword(textField: UITextField!) { - if let tField = textField { - tField.isSecureTextEntry = true - secretKeyPasswordField = tField - } - } /* // Override to support conditional editing of the table view. diff --git a/enzevalos_iphone/SecretKeyTableViewController.swift b/enzevalos_iphone/SecretKeyTableViewController.swift index 9fa4595684d9c2263b3242eff5aa761c3e6cc76e..06b0c3ca7726de1527914e102af8512d5834dd7b 100644 --- a/enzevalos_iphone/SecretKeyTableViewController.swift +++ b/enzevalos_iphone/SecretKeyTableViewController.swift @@ -57,9 +57,6 @@ class SecretKeyTableViewController: UITableViewController { cell.idLabel.text = item.keyID cell.dateLabel.text = item.importDate.description cell.dateName.text = NSLocalizedString("SecretKeyCell.date", comment: "date") - cell.originLabel.isHidden = true - cell.orignName.text = NSLocalizedString("SecretKeyCell.origin", comment: "origin") - cell.orignName.isHidden = true if let prefID = prefKeyID, prefID == item.keyID { currentPrefKeyRow = indexPath cell.prefIcon.image = NoSecIconStyleKit.imageOfFavorite diff --git a/enzevalos_iphone/TempKey.swift b/enzevalos_iphone/TempKey.swift index 199244358153a94c36d7e6255f26ddd464a5cd89..33979b6de98c03ad2a1534591279e0ed205674df 100644 --- a/enzevalos_iphone/TempKey.swift +++ b/enzevalos_iphone/TempKey.swift @@ -19,6 +19,7 @@ protocol DisplayKey { var pgpKey: Key? { get } + func save() -> SecretKey? } diff --git a/enzevalos_iphone/de.lproj/Localizable.strings b/enzevalos_iphone/de.lproj/Localizable.strings index 9d3571482bb81a63db990d3a06c2c4ecdfa5182e..8e0ea55958ee2540c94949773e047f4eeaf95a24 100644 --- a/enzevalos_iphone/de.lproj/Localizable.strings +++ b/enzevalos_iphone/de.lproj/Localizable.strings @@ -295,10 +295,10 @@ "SecretKeyCell.origin" = "Importiert aus "; "SecretKeyCell.generated" = "Auf diesem Gerät erzeugt."; "Time.Year.One" = "ein Jahr"; -"Time.Year.Multiple" = "%@ Jahre"; +"Time.Year.Multiple" = "%d Jahre"; "Time.Month.One" = "ein Monat"; -"Time.Month.Multiple" = "%@ Monate"; +"Time.Month.Multiple" = "%d Monate"; "Time.Day.One" = "ein Tag"; -"Time.Day.Multiple" = "%@ Tage"; +"Time.Day.Multiple" = "%d Tage"; "Time.Day.Today" = "heute"; "Management.Crypto.Title" = "Management"; diff --git a/enzevalos_iphone/en.lproj/Localizable.strings b/enzevalos_iphone/en.lproj/Localizable.strings index aeef80f33908ab72d40539bd7bc34c00c8567b15..d25abbc4647aaf8eef80497fe64dcc139046fe50 100644 --- a/enzevalos_iphone/en.lproj/Localizable.strings +++ b/enzevalos_iphone/en.lproj/Localizable.strings @@ -264,10 +264,10 @@ "SecretKeyCell.origin" = "Imported using "; "SecretKeyCell.generated" = "Generated on this device."; "Time.Year.One" = "one year"; -"Time.Year.Multiple" = "%@ years"; +"Time.Year.Multiple" = "%d years"; "Time.Month.One" = "one month"; -"Time.Month.Multiple" = "%@ months"; +"Time.Month.Multiple" = "%d months"; "Time.Day.One" = "one day"; -"Time.Day.Multiple" = "%@ days"; +"Time.Day.Multiple" = "%d days"; "Time.Day.Today" = "today"; "Management.Crypto.Title" = "Management";