use TableView to show password detail

This commit is contained in:
Bob Sun 2017-02-02 21:04:31 +08:00
parent 35a9c84b63
commit 8f23f609a7
No known key found for this signature in database
GPG key ID: 1F86BA2052FED3B4
8 changed files with 156 additions and 60 deletions

View file

@ -10,7 +10,9 @@
94BA784B85E071D25EE89B59 /* libPods-pass.a in Frameworks */ = {isa = PBXBuildFile; fileRef = ADCE7A5C3CCC67D7D21BB3C4 /* libPods-pass.a */; };
DC1208561E35D0BA0042942E /* PasswordsTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DC1208551E35D0BA0042942E /* PasswordsTableViewController.swift */; };
DC1208581E35EBE60042942E /* ObjectiveGit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DC1208571E35EBE60042942E /* ObjectiveGit.framework */; };
DC3DC8391E2F63240062A988 /* PasswordDetailViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DC3DC8381E2F63240062A988 /* PasswordDetailViewController.swift */; };
DC4914961E434301007FF592 /* LabelTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = DC4914941E434301007FF592 /* LabelTableViewCell.swift */; };
DC4914971E434301007FF592 /* LabelTableViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = DC4914951E434301007FF592 /* LabelTableViewCell.xib */; };
DC4914991E434600007FF592 /* PasswordDetailTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DC4914981E434600007FF592 /* PasswordDetailTableViewController.swift */; };
DC7E6EEA1E432E48006C2443 /* Password.swift in Sources */ = {isa = PBXBuildFile; fileRef = DC7E6EE91E432E48006C2443 /* Password.swift */; };
DC8963BE1E38AD8300828B09 /* GitRepositoryAuthenticationSettingTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DC8963BD1E38AD8300828B09 /* GitRepositoryAuthenticationSettingTableViewController.swift */; };
DC8963C01E38EEB900828B09 /* SSHKeySettingTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DC8963BF1E38EEB900828B09 /* SSHKeySettingTableViewController.swift */; };
@ -36,7 +38,9 @@
AEAD6B31EAF5D061447A68CC /* Pods-pass.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-pass.release.xcconfig"; path = "Pods/Target Support Files/Pods-pass/Pods-pass.release.xcconfig"; sourceTree = "<group>"; };
DC1208551E35D0BA0042942E /* PasswordsTableViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PasswordsTableViewController.swift; sourceTree = "<group>"; };
DC1208571E35EBE60042942E /* ObjectiveGit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = ObjectiveGit.framework; path = Carthage/Build/iOS/ObjectiveGit.framework; sourceTree = "<group>"; };
DC3DC8381E2F63240062A988 /* PasswordDetailViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PasswordDetailViewController.swift; sourceTree = "<group>"; };
DC4914941E434301007FF592 /* LabelTableViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LabelTableViewCell.swift; sourceTree = "<group>"; };
DC4914951E434301007FF592 /* LabelTableViewCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = LabelTableViewCell.xib; sourceTree = "<group>"; };
DC4914981E434600007FF592 /* PasswordDetailTableViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PasswordDetailTableViewController.swift; sourceTree = "<group>"; };
DC4A746D1E30FBDE00E8EB18 /* Objective-CBridgingHeader.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Objective-CBridgingHeader.h"; sourceTree = "<group>"; };
DC7E6EE91E432E48006C2443 /* Password.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Password.swift; sourceTree = "<group>"; };
DC8963BD1E38AD8300828B09 /* GitRepositoryAuthenticationSettingTableViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GitRepositoryAuthenticationSettingTableViewController.swift; sourceTree = "<group>"; };
@ -105,6 +109,7 @@
DC917BD51E2E8231000FDF54 /* pass */ = {
isa = PBXGroup;
children = (
DC4914941E434301007FF592 /* LabelTableViewCell.swift */,
DC4A746D1E30FBDE00E8EB18 /* Objective-CBridgingHeader.h */,
DC1208551E35D0BA0042942E /* PasswordsTableViewController.swift */,
DC917BD61E2E8231000FDF54 /* AppDelegate.swift */,
@ -113,7 +118,7 @@
DCA0499B1E3362F400522E8F /* PGPKeySettingTableViewController.swift */,
DCA049991E335CC800522E8F /* GitServerSettingTableViewController.swift */,
DCAAF7441E2FA66800AB94BC /* SettingsTableViewController.swift */,
DC3DC8381E2F63240062A988 /* PasswordDetailViewController.swift */,
DC4914981E434600007FF592 /* PasswordDetailTableViewController.swift */,
DCC408A31E2FCC9E00F29B0E /* PasswordStore.swift */,
DC7E6EE91E432E48006C2443 /* Password.swift */,
DCA049971E33586A00522E8F /* DefaultKeys.swift */,
@ -121,6 +126,7 @@
DCC408C81E30BA1300F29B0E /* pass.xcdatamodeld */,
DC917BDD1E2E8231000FDF54 /* Assets.xcassets */,
DC917BDA1E2E8231000FDF54 /* Main.storyboard */,
DC4914951E434301007FF592 /* LabelTableViewCell.xib */,
DC917BDF1E2E8231000FDF54 /* LaunchScreen.storyboard */,
DC917BE21E2E8231000FDF54 /* Info.plist */,
);
@ -205,6 +211,7 @@
files = (
DC917BE11E2E8231000FDF54 /* LaunchScreen.storyboard in Resources */,
DC917BDE1E2E8231000FDF54 /* Assets.xcassets in Resources */,
DC4914971E434301007FF592 /* LabelTableViewCell.xib in Resources */,
DC917BDC1E2E8231000FDF54 /* Main.storyboard in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
@ -285,15 +292,16 @@
DC8963C01E38EEB900828B09 /* SSHKeySettingTableViewController.swift in Sources */,
DCA0499C1E3362F400522E8F /* PGPKeySettingTableViewController.swift in Sources */,
DC7E6EEA1E432E48006C2443 /* Password.swift in Sources */,
DC4914961E434301007FF592 /* LabelTableViewCell.swift in Sources */,
DC1208561E35D0BA0042942E /* PasswordsTableViewController.swift in Sources */,
DCAAF7451E2FA66800AB94BC /* SettingsTableViewController.swift in Sources */,
DCA0499A1E335CC800522E8F /* GitServerSettingTableViewController.swift in Sources */,
DCC277D21E30D6EA00402246 /* pass.xcdatamodeld in Sources */,
DC4914991E434600007FF592 /* PasswordDetailTableViewController.swift in Sources */,
DC8963BE1E38AD8300828B09 /* GitRepositoryAuthenticationSettingTableViewController.swift in Sources */,
DC917BD71E2E8231000FDF54 /* AppDelegate.swift in Sources */,
DCA049981E33586A00522E8F /* DefaultKeys.swift in Sources */,
DCA0499E1E33BAC100522E8F /* Globals.swift in Sources */,
DC3DC8391E2F63240062A988 /* PasswordDetailViewController.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};

View file

@ -36,7 +36,7 @@
</subviews>
</tableViewCellContentView>
<connections>
<segue destination="Jts-IV-D1A" kind="show" identifier="showPasswordDetail" id="i0a-rZ-Bqd"/>
<segue destination="tW4-E9-CGv" kind="show" identifier="showPasswordDetail" id="OrR-Ve-XMm"/>
</connections>
</tableViewCell>
</prototypes>
@ -497,39 +497,22 @@
</objects>
<point key="canvasLocation" x="4414" y="3286"/>
</scene>
<!--Password Detail View Controller-->
<scene sceneID="9b5-fu-vx9">
<!--Password Detail Table View Controller-->
<scene sceneID="9wY-d0-fB1">
<objects>
<viewController id="Jts-IV-D1A" customClass="PasswordDetailViewController" customModule="pass" customModuleProvider="target" sceneMemberID="viewController">
<layoutGuides>
<viewControllerLayoutGuide type="top" id="Vhp-eB-nlX"/>
<viewControllerLayoutGuide type="bottom" id="AwD-QU-ZDy"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="aAM-Iy-xPP">
<tableViewController id="tW4-E9-CGv" customClass="PasswordDetailTableViewController" customModule="pass" 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="hfi-6O-04U">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<textView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" editable="NO" textAlignment="natural" translatesAutoresizingMaskIntoConstraints="NO" id="kMN-7r-0CD">
<rect key="frame" x="16" y="0.0" width="359" height="667"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<string key="text">Lorem ipsum dolor sit er elit lamet, consectetaur cillium adipisicing pecu, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Nam liber te conscient to factor tum poen legum odioque civiuda.</string>
<fontDescription key="fontDescription" style="UICTFontTextStyleBody"/>
<textInputTraits key="textInputTraits" autocapitalizationType="sentences"/>
</textView>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<constraints>
<constraint firstItem="kMN-7r-0CD" firstAttribute="leading" secondItem="aAM-Iy-xPP" secondAttribute="leadingMargin" id="Kd2-e2-ou5"/>
<constraint firstItem="kMN-7r-0CD" firstAttribute="top" secondItem="aAM-Iy-xPP" secondAttribute="top" id="UYu-K1-orN"/>
<constraint firstAttribute="bottom" secondItem="kMN-7r-0CD" secondAttribute="bottom" id="XBs-6b-j50"/>
<constraint firstAttribute="trailing" secondItem="kMN-7r-0CD" secondAttribute="trailing" id="u1d-Of-tmc"/>
</constraints>
</view>
<connections>
<outlet property="passwordTextView" destination="kMN-7r-0CD" id="nSW-kn-X8u"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="ek1-Cw-dZH" userLabel="First Responder" sceneMemberID="firstResponder"/>
<color key="backgroundColor" cocoaTouchSystemColor="groupTableViewBackgroundColor"/>
<sections/>
<connections>
<outlet property="dataSource" destination="tW4-E9-CGv" id="5QL-0S-PR1"/>
<outlet property="delegate" destination="tW4-E9-CGv" id="7PQ-0M-SCC"/>
</connections>
</tableView>
</tableViewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="9sC-44-OKL" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="3430" y="993"/>
</scene>

View file

@ -0,0 +1,24 @@
//
// LabelTableViewCell.swift
// pass
//
// Created by Mingshen Sun on 2/2/2017.
// Copyright © 2017 Bob Sun. All rights reserved.
//
import UIKit
class LabelTableViewCell: UITableViewCell {
@IBOutlet weak var contentLabel: UILabel!
@IBOutlet weak var titleLabel: UILabel!
override func awakeFromNib() {
super.awakeFromNib()
}
override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
}
}

View file

@ -0,0 +1,51 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="11762" systemVersion="16D32" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11757"/>
<capability name="Constraints to layout margins" minToolsVersion="6.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"/>
<tableViewCell contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" reuseIdentifier="labelCell" id="KGk-i7-Jjw" customClass="LabelTableViewCell" customModule="pass" customModuleProvider="target">
<rect key="frame" x="0.0" y="0.0" width="333" height="52"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="KGk-i7-Jjw" id="H2p-sc-9uM">
<rect key="frame" x="0.0" y="0.0" width="333" height="51"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="content" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="yyr-cF-QN0">
<rect key="frame" x="15" y="23" width="310" height="21"/>
<fontDescription key="fontDescription" style="UICTFontTextStyleBody"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="title" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Dqz-7n-uEZ">
<rect key="frame" x="15" y="8" width="310" height="15"/>
<fontDescription key="fontDescription" style="UICTFontTextStyleCaption1"/>
<color key="textColor" white="0.33333333333333331" alpha="1" colorSpace="calibratedWhite"/>
<nil key="highlightedColor"/>
</label>
</subviews>
<constraints>
<constraint firstAttribute="trailingMargin" secondItem="Dqz-7n-uEZ" secondAttribute="trailing" id="228-VM-Z8Y"/>
<constraint firstItem="Dqz-7n-uEZ" firstAttribute="leading" secondItem="H2p-sc-9uM" secondAttribute="leadingMargin" constant="7" id="CVm-uc-iVo"/>
<constraint firstAttribute="topMargin" secondItem="Dqz-7n-uEZ" secondAttribute="top" id="N4y-iT-CiY"/>
<constraint firstItem="yyr-cF-QN0" firstAttribute="leading" secondItem="Dqz-7n-uEZ" secondAttribute="leading" id="TpW-bu-QIx"/>
<constraint firstItem="yyr-cF-QN0" firstAttribute="width" secondItem="Dqz-7n-uEZ" secondAttribute="width" id="ZXa-fK-0Bg"/>
<constraint firstItem="yyr-cF-QN0" firstAttribute="top" secondItem="Dqz-7n-uEZ" secondAttribute="bottom" id="sgc-hN-i8t"/>
</constraints>
</tableViewCellContentView>
<connections>
<outlet property="contentLabel" destination="yyr-cF-QN0" id="lhr-oA-ofC"/>
<outlet property="titleLabel" destination="Dqz-7n-uEZ" id="Hac-od-A7K"/>
</connections>
<point key="canvasLocation" x="27.5" y="58"/>
</tableViewCell>
</objects>
</document>

View file

@ -12,9 +12,9 @@ import SwiftyUserDefaults
class Password {
var name = ""
var password = ""
var additions: [String: String]?
var additions: [String: String]
init(name: String, password: String, additions: [String: String]?) {
init(name: String, password: String, additions: [String: String]) {
self.name = name
self.password = password
self.additions = additions

View file

@ -0,0 +1,52 @@
//
// PasswordDetailTableViewController.swift
// pass
//
// Created by Mingshen Sun on 2/2/2017.
// Copyright © 2017 Bob Sun. All rights reserved.
//
import UIKit
class PasswordDetailTableViewController: UITableViewController {
var passwordEntity: PasswordEntity?
struct FormCell {
var title: String
var content: String
}
var formData = [[FormCell]]()
override func viewDidLoad() {
super.viewDidLoad()
tableView.register(UINib(nibName: "LabelTableViewCell", bundle: nil), forCellReuseIdentifier: "labelCell")
let password = passwordEntity!.decrypt()!
formData.append([])
if let username = password.additions["Username"] {
formData[0].append(FormCell(title: "username", content: username))
}
formData[0].append(FormCell(title: "password", content: password.password))
}
override func numberOfSections(in tableView: UITableView) -> Int {
return formData.count
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return formData[section].count
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "labelCell", for: indexPath) as! LabelTableViewCell
cell.titleLabel.text = formData[indexPath.section][indexPath.row].title
cell.contentLabel.text = formData[indexPath.section][indexPath.row].content
return cell
}
override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 52
}
}

View file

@ -1,22 +0,0 @@
//
// PasswordDetailViewController.swift
// pass
//
// Created by Mingshen Sun on 18/1/2017.
// Copyright © 2017 Bob Sun. All rights reserved.
//
import UIKit
import SwiftyUserDefaults
class PasswordDetailViewController: UIViewController {
@IBOutlet weak var passwordTextView: UITextView!
var passwordEntity: PasswordEntity?
override func viewDidLoad() {
super.viewDidLoad()
let password = passwordEntity!.decrypt()!
passwordTextView.text = password.password
}
}

View file

@ -134,7 +134,7 @@ class PasswordsTableViewController: UITableViewController {
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "showPasswordDetail" {
if let viewController = segue.destination as? PasswordDetailViewController {
if let viewController = segue.destination as? PasswordDetailTableViewController {
let selectedIndexPath = self.tableView.indexPath(for: sender as! UITableViewCell)!
let index = sections[selectedIndexPath.section].index + selectedIndexPath.row
let password: PasswordEntity