From 3ecb35e70186502a224f8ea96a028bf940b4d9d0 Mon Sep 17 00:00:00 2001 From: Mingshen Sun Date: Tue, 5 Jan 2021 20:54:51 -0800 Subject: [PATCH] Use PasswordTableViewCell for all password entries --- pass.xcodeproj/project.pbxproj | 18 +- pass/Base.lproj/Main.storyboard | 223 +++++++++--------- .../Controllers/PasswordsViewController.swift | 24 +- pass/Views/PasswordTableViewCell.swift | 29 +++ .../Views/PasswordTableViewCell.swift | 22 -- .../Base.lproj/MainInterface.storyboard | 2 +- .../Controllers/ExtensionViewController.swift | 14 +- 7 files changed, 164 insertions(+), 168 deletions(-) create mode 100644 pass/Views/PasswordTableViewCell.swift delete mode 100644 passAutoFillExtension/Views/PasswordTableViewCell.swift diff --git a/pass.xcodeproj/project.pbxproj b/pass.xcodeproj/project.pbxproj index c23c2f9..1cb1943 100644 --- a/pass.xcodeproj/project.pbxproj +++ b/pass.xcodeproj/project.pbxproj @@ -104,11 +104,13 @@ 9A55C158259E785600FA8FD9 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = DC917BDD1E2E8231000FDF54 /* Assets.xcassets */; }; 9A55C15F259E785700FA8FD9 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = DC917BDD1E2E8231000FDF54 /* Assets.xcassets */; }; 9A55C185259E8C5600FA8FD9 /* PasswordsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9A55C184259E8C5600FA8FD9 /* PasswordsViewController.swift */; }; + 9A5D06EE25A56F0800FA59D4 /* PasswordTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9A8F9EE1259EDD520027CE15 /* PasswordTableViewCell.swift */; }; + 9A5D06F525A56F0E00FA59D4 /* PasswordTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9A8F9EE1259EDD520027CE15 /* PasswordTableViewCell.swift */; }; + 9A5D070225A5769A00FA59D4 /* PasswordTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9A8F9EE1259EDD520027CE15 /* PasswordTableViewCell.swift */; }; 9A652414244BB33300DA0A41 /* UIAlertActionExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9A652413244BB33300DA0A41 /* UIAlertActionExtension.swift */; }; 9A8A8387402FCCCECB1232A4 /* Pods_passKitTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3B2B2F844061EFA534FE9506 /* Pods_passKitTests.framework */; }; 9A8F9EBD259EA4C50027CE15 /* PasswordsTableDataSource.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9A8F9EBC259EA4C50027CE15 /* PasswordsTableDataSource.swift */; }; 9A8F9ECC259ECB410027CE15 /* PasswordSelectionDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9A8F9ECB259ECB410027CE15 /* PasswordSelectionDelegate.swift */; }; - 9A8F9EE2259EDD520027CE15 /* PasswordTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9A8F9EE1259EDD520027CE15 /* PasswordTableViewCell.swift */; }; 9A8F9EF0259EE01A0027CE15 /* PasswordDecryptor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9A8F9EEF259EE01A0027CE15 /* PasswordDecryptor.swift */; }; 9A8F9F4025A1A91F0027CE15 /* CredentialProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9A8F9F3F25A1A91F0027CE15 /* CredentialProvider.swift */; }; 9ADC954124418A5F0005402E /* PasswordStoreTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9ADC954024418A5F0005402E /* PasswordStoreTest.swift */; }; @@ -721,14 +723,6 @@ path = Protocols; sourceTree = ""; }; - 9A8F9EE0259EDD390027CE15 /* Views */ = { - isa = PBXGroup; - children = ( - 9A8F9EE1259EDD520027CE15 /* PasswordTableViewCell.swift */, - ); - path = Views; - sourceTree = ""; - }; A2168A801EFD431A005EA873 /* Controllers */ = { isa = PBXGroup; children = ( @@ -749,7 +743,6 @@ A239F5972158C08C00576CBF /* passAutoFillExtension */ = { isa = PBXGroup; children = ( - 9A8F9EE0259EDD390027CE15 /* Views */, 9A8F9ECA259ECAFC0027CE15 /* Protocols */, 9A8F9EBB259EA4A80027CE15 /* Services */, A239F5A921591E3700576CBF /* Controllers */, @@ -918,6 +911,7 @@ DC19400F1E4B3A9E0077E0A3 /* Views */ = { isa = PBXGroup; children = ( + 9A8F9EE1259EDD520027CE15 /* PasswordTableViewCell.swift */, DCFB77AA1E503729008DE471 /* ContentProvider.swift */, DCFB779C1E4F40C7008DE471 /* FillPasswordTableViewCell.swift */, DCFB779D1E4F40C7008DE471 /* FillPasswordTableViewCell.xib */, @@ -1554,11 +1548,11 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 9A8F9EE2259EDD520027CE15 /* PasswordTableViewCell.swift in Sources */, 9A8F9F4025A1A91F0027CE15 /* CredentialProvider.swift in Sources */, 9A8F9ECC259ECB410027CE15 /* PasswordSelectionDelegate.swift in Sources */, 30697C5421F63E0B0064FCAC /* CredentialProviderViewController.swift in Sources */, 9A55C185259E8C5600FA8FD9 /* PasswordsViewController.swift in Sources */, + 9A5D06F525A56F0E00FA59D4 /* PasswordTableViewCell.swift in Sources */, 9A8F9EBD259EA4C50027CE15 /* PasswordsTableDataSource.swift in Sources */, 30697C5321F63E0B0064FCAC /* PasscodeExtensionDisplay.swift in Sources */, 9A8F9EF0259EE01A0027CE15 /* PasswordDecryptor.swift in Sources */, @@ -1643,6 +1637,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 9A5D070225A5769A00FA59D4 /* PasswordTableViewCell.swift in Sources */, 30697C4C21F63D460064FCAC /* PasscodeExtensionDisplay.swift in Sources */, 30697C5021F63D7F0064FCAC /* OnePasswordExtensionConstants.swift in Sources */, 30697C4B21F63D460064FCAC /* ExtensionViewController.swift in Sources */, @@ -1684,6 +1679,7 @@ 308800C324EDA5F600E87ED3 /* QRKeyScanner.swift in Sources */, DC4914991E434600007FF592 /* PasswordDetailTableViewController.swift in Sources */, 30C25DD821F4834D00BB27BB /* UICodeHighlightingLabel.swift in Sources */, + 9A5D06EE25A56F0800FA59D4 /* PasswordTableViewCell.swift in Sources */, DC962CDF1E4B62C10033B5D8 /* AboutTableViewController.swift in Sources */, 30C25DD721F4834D00BB27BB /* UILocalizedLabel.swift in Sources */, DC5734AE1E439AD400D09270 /* PasswordsViewController.swift in Sources */, diff --git a/pass/Base.lproj/Main.storyboard b/pass/Base.lproj/Main.storyboard index 91cfd92..2bcb803 100644 --- a/pass/Base.lproj/Main.storyboard +++ b/pass/Base.lproj/Main.storyboard @@ -1,16 +1,17 @@ - + - + + - + @@ -24,25 +25,25 @@ - + - + @@ -71,11 +72,11 @@ - + - + @@ -83,11 +84,11 @@ - + diff --git a/pass/Controllers/PasswordsViewController.swift b/pass/Controllers/PasswordsViewController.swift index b5222c4..ee16352 100644 --- a/pass/Controllers/PasswordsViewController.swift +++ b/pass/Controllers/PasswordsViewController.swift @@ -262,6 +262,7 @@ class PasswordsViewController: UIViewController, UITableViewDataSource, UITableV SVProgressHUD.setDefaultMaskType(.black) tableView.register(UINib(nibName: "PasswordWithFolderTableViewCell", bundle: nil), forCellReuseIdentifier: "passwordWithFolderTableViewCell") + tableView.register(PasswordTableViewCell.self, forCellReuseIdentifier: "passwordTableViewCell") // initialize the password table reloadTableView(parent: nil) @@ -356,25 +357,10 @@ class PasswordsViewController: UIViewController, UITableViewDataSource, UITableV return recognizer }() let entry = getPasswordEntry(by: indexPath) - let passwordEntity = entry.passwordEntity - let cell = tableView.dequeueReusableCell(withIdentifier: "passwordTableViewCell", for: indexPath) - - cell.textLabel?.text = passwordEntity.synced ? entry.title : "↻ \(entry.title)" - cell.textLabel?.font = UIFont.preferredFont(forTextStyle: .body) - cell.textLabel?.adjustsFontForContentSizeCategory = true - cell.accessoryType = .none - cell.detailTextLabel?.font = UIFont.preferredFont(forTextStyle: .footnote) - cell.detailTextLabel?.adjustsFontForContentSizeCategory = true - cell.addGestureRecognizer(longPressGestureRecognizer) - - if entry.isDir { - cell.accessoryType = .disclosureIndicator - cell.textLabel?.font = UIFont.systemFont(ofSize: UIFont.preferredFont(forTextStyle: .body).pointSize, weight: .medium) - cell.detailTextLabel?.font = UIFont.preferredFont(forTextStyle: .body) - cell.detailTextLabel?.text = "\(passwordEntity.children?.count ?? 0)" - cell.removeGestureRecognizer(longPressGestureRecognizer) - } else { - cell.detailTextLabel?.text = passwordEntity.getCategoryText() + let cell = tableView.dequeueReusableCell(withIdentifier: "passwordTableViewCell", for: indexPath) as! PasswordTableViewCell + cell.configure(with: entry) + if !entry.isDir { + cell.addGestureRecognizer(longPressGestureRecognizer) } return cell diff --git a/pass/Views/PasswordTableViewCell.swift b/pass/Views/PasswordTableViewCell.swift new file mode 100644 index 0000000..4962153 --- /dev/null +++ b/pass/Views/PasswordTableViewCell.swift @@ -0,0 +1,29 @@ +// +// PasswordCell.swift +// passAutoFillExtension +// +// Created by Sun, Mingshen on 12/31/20. +// Copyright © 2020 Bob Sun. All rights reserved. +// + +import passKit + +class PasswordTableViewCell: UITableViewCell { + func configure(with entry: PasswordTableEntry) { + textLabel?.font = UIFont.preferredFont(forTextStyle: .body) + textLabel?.text = entry.passwordEntity.synced ? entry.title : "↻ \(entry.title)" + textLabel?.adjustsFontForContentSizeCategory = true + + accessoryType = .none + detailTextLabel?.font = UIFont.preferredFont(forTextStyle: .footnote) + detailTextLabel?.adjustsFontForContentSizeCategory = true + detailTextLabel?.text = entry.categoryText + + if entry.isDir { + accessoryType = .disclosureIndicator + textLabel?.font = UIFont.systemFont(ofSize: UIFont.preferredFont(forTextStyle: .body).pointSize, weight: .medium) + detailTextLabel?.font = UIFont.preferredFont(forTextStyle: .body) + detailTextLabel?.text = "\(entry.passwordEntity.children?.count ?? 0)" + } + } +} diff --git a/passAutoFillExtension/Views/PasswordTableViewCell.swift b/passAutoFillExtension/Views/PasswordTableViewCell.swift deleted file mode 100644 index 3368e8a..0000000 --- a/passAutoFillExtension/Views/PasswordTableViewCell.swift +++ /dev/null @@ -1,22 +0,0 @@ -// -// PasswordCell.swift -// passAutoFillExtension -// -// Created by Sun, Mingshen on 12/31/20. -// Copyright © 2020 Bob Sun. All rights reserved. -// - -import passKit - -class PasswordTableViewCell: UITableViewCell { - func configure(with entry: PasswordTableEntry) { - if entry.passwordEntity.synced { - textLabel?.text = entry.title - } else { - textLabel?.text = "↻ \(entry.title)" - } - accessoryType = .none - detailTextLabel?.font = UIFont.preferredFont(forTextStyle: .footnote) - detailTextLabel?.text = entry.categoryText - } -} diff --git a/passExtension/Base.lproj/MainInterface.storyboard b/passExtension/Base.lproj/MainInterface.storyboard index f1603d2..69199f4 100644 --- a/passExtension/Base.lproj/MainInterface.storyboard +++ b/passExtension/Base.lproj/MainInterface.storyboard @@ -30,7 +30,7 @@ - + diff --git a/passExtension/Controllers/ExtensionViewController.swift b/passExtension/Controllers/ExtensionViewController.swift index 78a136b..c2f7414 100644 --- a/passExtension/Controllers/ExtensionViewController.swift +++ b/passExtension/Controllers/ExtensionViewController.swift @@ -52,7 +52,7 @@ class ExtensionViewController: UIViewController, UITableViewDataSource, UITableV searchBar.delegate = self tableView.delegate = self tableView.dataSource = self - tableView.register(UINib(nibName: "PasswordWithFolderTableViewCell", bundle: nil), forCellReuseIdentifier: "passwordWithFolderTableViewCell") + tableView.register(PasswordTableViewCell.self, forCellReuseIdentifier: "passwordTableViewCell") // initialize table entries initPasswordsTableEntries() @@ -109,16 +109,10 @@ class ExtensionViewController: UIViewController, UITableViewDataSource, UITableV // define cell contents, and set long press action func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { - let cell = tableView.dequeueReusableCell(withIdentifier: "passwordTableViewCell", for: indexPath) + let cell = tableView.dequeueReusableCell(withIdentifier: "passwordTableViewCell", for: indexPath) as! PasswordTableViewCell let entry = getPasswordEntry(by: indexPath) - if entry.synced { - cell.textLabel?.text = entry.title - } else { - cell.textLabel?.text = "↻ \(entry.title)" - } - cell.accessoryType = .none - cell.detailTextLabel?.font = UIFont.preferredFont(forTextStyle: .footnote) - cell.detailTextLabel?.text = entry.categoryText + cell.configure(with: entry) + return cell }