From 3964ca64ed3545a809d26f097eefd3962f198077 Mon Sep 17 00:00:00 2001 From: Bob Sun Date: Fri, 10 Mar 2017 23:07:56 -0800 Subject: [PATCH] Show category info after an password entry when show password folder is off --- pass.xcodeproj/project.pbxproj | 8 +++ .../Controllers/PasswordsViewController.swift | 50 ++++++++++++------ .../PasswordWithFolderTableViewCell.swift | 27 ++++++++++ .../Views/PasswordWithFolderTableViewCell.xib | 52 +++++++++++++++++++ 4 files changed, 120 insertions(+), 17 deletions(-) create mode 100644 pass/Views/PasswordWithFolderTableViewCell.swift create mode 100644 pass/Views/PasswordWithFolderTableViewCell.xib diff --git a/pass.xcodeproj/project.pbxproj b/pass.xcodeproj/project.pbxproj index 8bea2c6..97b70a9 100644 --- a/pass.xcodeproj/project.pbxproj +++ b/pass.xcodeproj/project.pbxproj @@ -53,6 +53,8 @@ DCC408C71E307DBB00F29B0E /* SVProgressHUD.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DCC408C61E307DBB00F29B0E /* SVProgressHUD.framework */; }; DCDDEAB01E4639F300F68193 /* LabelTableViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = DCDDEAAF1E4639F300F68193 /* LabelTableViewCell.xib */; }; DCDDEAB31E4896BF00F68193 /* PasswordDetailTitleTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = DCDDEAB11E4896BF00F68193 /* PasswordDetailTitleTableViewCell.swift */; }; + DCE6C2671E71261C003038C6 /* PasswordWithFolderTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = DCE6C2651E71261C003038C6 /* PasswordWithFolderTableViewCell.swift */; }; + DCE6C2681E71261C003038C6 /* PasswordWithFolderTableViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = DCE6C2661E71261C003038C6 /* PasswordWithFolderTableViewCell.xib */; }; DCFB779A1E4F3BCF008DE471 /* TitleTextFieldTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = DCFB77981E4F3BCF008DE471 /* TitleTextFieldTableViewCell.swift */; }; DCFB779B1E4F3BCF008DE471 /* TitleTextFieldTableViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = DCFB77991E4F3BCF008DE471 /* TitleTextFieldTableViewCell.xib */; }; DCFB779E1E4F40C7008DE471 /* FillPasswordTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = DCFB779C1E4F40C7008DE471 /* FillPasswordTableViewCell.swift */; }; @@ -116,6 +118,8 @@ DCC408C91E30BA1300F29B0E /* pass.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = pass.xcdatamodel; sourceTree = ""; }; DCDDEAAF1E4639F300F68193 /* LabelTableViewCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = LabelTableViewCell.xib; sourceTree = ""; }; DCDDEAB11E4896BF00F68193 /* PasswordDetailTitleTableViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PasswordDetailTitleTableViewCell.swift; sourceTree = ""; }; + DCE6C2651E71261C003038C6 /* PasswordWithFolderTableViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PasswordWithFolderTableViewCell.swift; sourceTree = ""; }; + DCE6C2661E71261C003038C6 /* PasswordWithFolderTableViewCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = PasswordWithFolderTableViewCell.xib; sourceTree = ""; }; DCFB77981E4F3BCF008DE471 /* TitleTextFieldTableViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TitleTextFieldTableViewCell.swift; sourceTree = ""; }; DCFB77991E4F3BCF008DE471 /* TitleTextFieldTableViewCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = TitleTextFieldTableViewCell.xib; sourceTree = ""; }; DCFB779C1E4F40C7008DE471 /* FillPasswordTableViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FillPasswordTableViewCell.swift; sourceTree = ""; }; @@ -222,6 +226,8 @@ DC037CBD1E4ED4E100609409 /* TextViewTableViewCell.swift */, DC037CBE1E4ED4E100609409 /* TextViewTableViewCell.xib */, DCFB77AA1E503729008DE471 /* ContentTableViewCell.swift */, + DCE6C2651E71261C003038C6 /* PasswordWithFolderTableViewCell.swift */, + DCE6C2661E71261C003038C6 /* PasswordWithFolderTableViewCell.xib */, ); path = Views; sourceTree = ""; @@ -348,6 +354,7 @@ DCDDEAB01E4639F300F68193 /* LabelTableViewCell.xib in Resources */, DC917BDC1E2E8231000FDF54 /* Main.storyboard in Resources */, A2802BFA1E70813A00879216 /* SliderTableViewCell.xib in Resources */, + DCE6C2681E71261C003038C6 /* PasswordWithFolderTableViewCell.xib in Resources */, DCFB779B1E4F3BCF008DE471 /* TitleTextFieldTableViewCell.xib in Resources */, DCFB779F1E4F40C7008DE471 /* FillPasswordTableViewCell.xib in Resources */, DC037CC01E4ED4E100609409 /* TextViewTableViewCell.xib in Resources */, @@ -441,6 +448,7 @@ DC4914961E434301007FF592 /* LabelTableViewCell.swift in Sources */, DC5F385B1E56AADB00C69ACA /* PGPKeyArmorSettingTableViewController.swift in Sources */, DCAAF7451E2FA66800AB94BC /* SettingsTableViewController.swift in Sources */, + DCE6C2671E71261C003038C6 /* PasswordWithFolderTableViewCell.swift in Sources */, DCFB77A71E502DF9008DE471 /* EditPasswordTableViewController.swift in Sources */, DCA0499A1E335CC800522E8F /* GitServerSettingTableViewController.swift in Sources */, DCDDEAB31E4896BF00F68193 /* PasswordDetailTitleTableViewCell.swift in Sources */, diff --git a/pass/Controllers/PasswordsViewController.swift b/pass/Controllers/PasswordsViewController.swift index 4ce6de7..105daa5 100644 --- a/pass/Controllers/PasswordsViewController.swift +++ b/pass/Controllers/PasswordsViewController.swift @@ -162,6 +162,7 @@ class PasswordsViewController: UIViewController, UITableViewDataSource, UITableV tableView.insertSubview(refreshControl, at: 0) SVProgressHUD.setDefaultMaskType(.black) updateRefreshControlTitle() + tableView.register(UINib(nibName: "PasswordWithFolderTableViewCell", bundle: nil), forCellReuseIdentifier: "passwordWithFolderTableViewCell") } override func viewWillAppear(_ animated: Bool) { @@ -186,26 +187,41 @@ class PasswordsViewController: UIViewController, UITableViewDataSource, UITableV } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { - let cell = tableView.dequeueReusableCell(withIdentifier: "passwordTableViewCell", for: indexPath) - let entry = getPasswordEntry(by: indexPath) - if !entry.isDir { - if entry.passwordEntity!.synced { - cell.textLabel?.text = entry.title - } else { - cell.textLabel?.text = "↻ \(entry.title)" - } + let longPressGestureRecognizer = UILongPressGestureRecognizer(target: self, action: #selector(longPressAction(_:))) + longPressGestureRecognizer.minimumPressDuration = 0.6 + if Defaults[.isShowFolderOn] { + let cell = tableView.dequeueReusableCell(withIdentifier: "passwordTableViewCell", for: indexPath) - let longPressGestureRecognizer = UILongPressGestureRecognizer(target: self, action: #selector(longPressAction(_:))) - longPressGestureRecognizer.minimumPressDuration = 0.6 - cell.addGestureRecognizer(longPressGestureRecognizer) - cell.accessoryType = .none - cell.detailTextLabel?.text = "" + let entry = getPasswordEntry(by: indexPath) + if !entry.isDir { + if entry.passwordEntity!.synced { + cell.textLabel?.text = entry.title + } else { + cell.textLabel?.text = "↻ \(entry.title)" + } + + cell.addGestureRecognizer(longPressGestureRecognizer) + cell.accessoryType = .none + cell.detailTextLabel?.text = "" + } else { + cell.textLabel?.text = "\(entry.title)" + cell.accessoryType = .disclosureIndicator + cell.detailTextLabel?.text = "\(entry.passwordEntity?.children?.count ?? 0)" + } + return cell } else { - cell.textLabel?.text = "\(entry.title)" - cell.accessoryType = .disclosureIndicator - cell.detailTextLabel?.text = "\(entry.passwordEntity?.children?.count ?? 0)" + let passwordWithFolderCell = tableView.dequeueReusableCell(withIdentifier: "passwordWithFolderTableViewCell", for: indexPath) as! PasswordWithFolderTableViewCell + let entry = getPasswordEntry(by: indexPath) + if entry.passwordEntity!.synced { + passwordWithFolderCell.passwordLabel?.text = entry.title + } else { + passwordWithFolderCell.passwordLabel?.text = "↻ \(entry.title)" + } + passwordWithFolderCell.folderLabel.text = entry.passwordEntity?.getCategoryText() + passwordWithFolderCell.addGestureRecognizer(longPressGestureRecognizer) + return passwordWithFolderCell } - return cell + } private func getPasswordEntry(by indexPath: IndexPath) -> PasswordsTableEntry { diff --git a/pass/Views/PasswordWithFolderTableViewCell.swift b/pass/Views/PasswordWithFolderTableViewCell.swift new file mode 100644 index 0000000..b1b9c1e --- /dev/null +++ b/pass/Views/PasswordWithFolderTableViewCell.swift @@ -0,0 +1,27 @@ +// +// PasswordTableViewCell.swift +// pass +// +// Created by Mingshen Sun on 8/3/2017. +// Copyright © 2017 Bob Sun. All rights reserved. +// + +import UIKit + +class PasswordWithFolderTableViewCell: UITableViewCell { + + @IBOutlet weak var passwordLabel: UILabel! + @IBOutlet weak var folderLabel: UILabel! + + override func awakeFromNib() { + super.awakeFromNib() + // Initialization code + } + + override func setSelected(_ selected: Bool, animated: Bool) { + super.setSelected(selected, animated: animated) + + // Configure the view for the selected state + } + +} diff --git a/pass/Views/PasswordWithFolderTableViewCell.xib b/pass/Views/PasswordWithFolderTableViewCell.xib new file mode 100644 index 0000000..74957c5 --- /dev/null +++ b/pass/Views/PasswordWithFolderTableViewCell.xib @@ -0,0 +1,52 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +