Merge branch 'master' of github.com:mssun/passforios

This commit is contained in:
Bob Sun 2017-03-15 13:10:28 -07:00
commit 83e55403e5
15 changed files with 315 additions and 139 deletions

View file

@ -9,23 +9,49 @@
import UIKit
class AboutRepositoryTableViewController: BasicStaticTableViewController {
var needRefresh = false
var indicatorLabel: UILabel!
var indicator: UIActivityIndicatorView!
override func viewDidLoad() {
navigationItemTitle = "About Repository"
super.viewDidLoad()
let indicatorLable = UILabel(frame: CGRect(x: 0, y: 0, width: view.frame.width, height: 21))
indicatorLable.center = CGPoint(x: view.frame.size.width / 2, y: view.frame.size.height * 0.382 + 22)
indicatorLable.backgroundColor = UIColor.clear
indicatorLable.textColor = UIColor.gray
indicatorLable.text = "calculating"
indicatorLable.textAlignment = .center
indicatorLable.font = UIFont.preferredFont(forTextStyle: .footnote)
let indicator = UIActivityIndicatorView(activityIndicatorStyle: .gray)
indicatorLabel = UILabel(frame: CGRect(x: 0, y: 0, width: view.frame.width, height: 21))
indicatorLabel.center = CGPoint(x: view.frame.size.width / 2, y: view.frame.size.height * 0.382 + 22)
indicatorLabel.backgroundColor = UIColor.clear
indicatorLabel.textColor = UIColor.gray
indicatorLabel.text = "calculating"
indicatorLabel.textAlignment = .center
indicatorLabel.font = UIFont.preferredFont(forTextStyle: .footnote)
indicator = UIActivityIndicatorView(activityIndicatorStyle: .gray)
indicator.center = CGPoint(x: view.frame.size.width / 2, y: view.frame.size.height * 0.382)
indicator.startAnimating()
tableView.addSubview(indicator)
tableView.addSubview(indicatorLable)
tableView.addSubview(indicatorLabel)
setTableData()
addNotificationObservers()
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
if needRefresh {
indicatorLabel.text = "reloading"
setTableData()
needRefresh = false
}
}
private func setTableData() {
// clear current contents (if any)
self.tableData.removeAll(keepingCapacity: true)
self.tableView.reloadData()
indicatorLabel.isHidden = false
indicator.startAnimating()
// reload the table
DispatchQueue.global(qos: .userInitiated).async {
let numberFormatter = NumberFormatter()
numberFormatter.numberStyle = NumberFormatter.Style.decimal
@ -46,8 +72,8 @@ class AboutRepositoryTableViewController: BasicStaticTableViewController {
let numberOfCommits = PasswordStore.shared.storeRepository?.numberOfCommits(inCurrentBranch: NSErrorPointer(nilLiteral: ())) ?? 0
let numberOfCommitsString = numberFormatter.string(from: NSNumber(value: numberOfCommits))!
DispatchQueue.main.async { [weak self] in
let type = UITableViewCellAccessoryType.none
self?.tableData = [
@ -59,11 +85,19 @@ class AboutRepositoryTableViewController: BasicStaticTableViewController {
[.title: "Commit Logs", .action: "segue", .link: "showCommitLogsSegue"],
],
]
indicator.stopAnimating()
indicatorLable.isHidden = true
self?.indicator.stopAnimating()
self?.indicatorLabel.isHidden = true
self?.tableView.reloadData()
}
}
}
private func addNotificationObservers() {
NotificationCenter.default.addObserver(self, selector: #selector(setNeedRefresh), name: NSNotification.Name(rawValue: "passwordUpdated"), object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(setNeedRefresh), name: NSNotification.Name(rawValue: "passwordStoreErased"), object: nil)
}
func setNeedRefresh() {
needRefresh = true
}
}

View file

@ -35,15 +35,24 @@ class AdvancedSettingsTableViewController: UITableViewController {
tableView.deselectRow(at: indexPath, animated: true)
} else if tableView.cellForRow(at: indexPath) == discardChangesTableViewCell {
let alert = UIAlertController(title: "Discard All Changes?", message: "Do you want to permanently discard all changes to the local copy of your password data? You cannot undo this action.", preferredStyle: UIAlertControllerStyle.alert)
alert.addAction(UIAlertAction(title: "Discard All Changesa", style: UIAlertActionStyle.destructive, handler: {[unowned self] (action) -> Void in
alert.addAction(UIAlertAction(title: "Discard All Changes", style: UIAlertActionStyle.destructive, handler: {[unowned self] (action) -> Void in
DispatchQueue.global(qos: .userInitiated).async {
SVProgressHUD.show(withStatus: "Resetting ...")
DispatchQueue.main.async {
do {
let numberDiscarded = try PasswordStore.shared.reset()
NotificationCenter.default.post(Notification(name: Notification.Name("passwordStoreChangeDiscarded")))
if numberDiscarded > 0 {
NotificationCenter.default.post(Notification(name: Notification.Name("passwordStoreChangeDiscarded")))
}
self.navigationController!.popViewController(animated: true)
SVProgressHUD.showSuccess(withStatus: "Discarded \(numberDiscarded) commits")
switch numberDiscarded {
case 0:
SVProgressHUD.showSuccess(withStatus: "No local commits")
case 1:
SVProgressHUD.showSuccess(withStatus: "Discarded 1 commit")
default:
SVProgressHUD.showSuccess(withStatus: "Discarded \(numberDiscarded) commits")
}
SVProgressHUD.dismiss(withDelay: 1)
} catch {
DispatchQueue.main.async {

View file

@ -29,8 +29,10 @@ class CommitLogsTableViewController: UITableViewController {
formatter.dateStyle = DateFormatter.Style.short
formatter.timeStyle = .none
let dateString = formatter.string(from: commits[indexPath.row].commitDate)
cell.textLabel?.text = dateString
cell.detailTextLabel?.text = commits[indexPath.row].message
let dateLabel = cell.viewWithTag(101) as! UILabel
let messageLabel = cell.viewWithTag(102) as! UILabel
dateLabel.text = dateString
messageLabel.text = commits[indexPath.row].message
return cell
}
}

View file

@ -154,7 +154,7 @@ class GeneralSettingsTableViewController: BasicStaticTableViewController {
}
func tapHideUnknownSwitchDetailButton(_ sender: Any?) {
let alertMessage = "Only \"key: value\" format in additional fields is supported. Unsupported fields will be given \"unkown\" keys. Turn on this switch to hide unsupported fields."
let alertMessage = "Only \"key: value\" format in additional fields is supported. Unsupported fields will be given \"unknown\" keys. Turn on this switch to hide unsupported fields."
let alertTitle = "Hide Unknown Fields"
Utils.alert(title: alertTitle, message: alertMessage, controller: self, completion: nil)
}

View file

@ -17,6 +17,7 @@ class PasswordDetailTableViewController: UITableViewController, UIGestureRecogni
var password: Password?
var passwordImage: UIImage?
var oneTimePasswordIndexPath : IndexPath?
var shouldPopCurrentView = false
let indicatorLable: UILabel = {
let label = UILabel(frame: CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: 21))
@ -62,23 +63,12 @@ class PasswordDetailTableViewController: UITableViewController, UIGestureRecogni
var tableData = Array<TableSection>()
private func generateCategoryText() -> String {
var passwordCategoryArray: [String] = []
var parent = passwordEntity?.parent
while parent != nil {
passwordCategoryArray.append(parent!.name!)
parent = parent!.parent
}
passwordCategoryArray.reverse()
return passwordCategoryArray.joined(separator: " > ")
}
override func viewDidLoad() {
super.viewDidLoad()
tableView.register(UINib(nibName: "LabelTableViewCell", bundle: nil), forCellReuseIdentifier: "labelCell")
tableView.register(UINib(nibName: "PasswordDetailTitleTableViewCell", bundle: nil), forCellReuseIdentifier: "passwordDetailTitleTableViewCell")
passwordCategoryText = generateCategoryText()
passwordCategoryText = passwordEntity!.getCategoryText()
let tapGesture = UITapGestureRecognizer(target: self, action: #selector(PasswordDetailTableViewController.tapMenu(recognizer:)))
tableView.addGestureRecognizer(tapGesture)
@ -118,6 +108,7 @@ class PasswordDetailTableViewController: UITableViewController, UIGestureRecogni
}
self.setupUpdateOneTimePassword()
self.addNotificationObservers()
}
@ -386,4 +377,22 @@ class PasswordDetailTableViewController: UITableViewController, UIGestureRecogni
return true
}
private func addNotificationObservers() {
NotificationCenter.default.addObserver(self, selector: #selector(setShouldPopCurrentView), name: NSNotification.Name(rawValue: "passwordStoreChangeDiscarded"), object: nil)
}
func setShouldPopCurrentView() {
self.shouldPopCurrentView = true
}
override func viewDidAppear(_ animated: Bool) {
super.viewWillAppear(animated)
if self.shouldPopCurrentView {
let alert = UIAlertController(title: "Notice", message: "All previous local changes have been discarded. Your current Password Store will be shown.", preferredStyle: UIAlertControllerStyle.alert)
alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler: {_ in
_ = self.navigationController?.popViewController(animated: true)
}))
self.present(alert, animated: true, completion: nil)
}
}
}

View file

@ -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 {
@ -222,7 +238,11 @@ class PasswordsViewController: UIViewController, UITableViewDataSource, UITableV
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let entry = getPasswordEntry(by: indexPath)
if !entry.isDir {
performSegue(withIdentifier: "showPasswordDetail", sender: tableView.cellForRow(at: indexPath))
let segueIdentifier = "showPasswordDetail"
let sender = tableView.cellForRow(at: indexPath)
if shouldPerformSegue(withIdentifier: segueIdentifier, sender: sender) {
performSegue(withIdentifier: segueIdentifier, sender: sender)
}
} else {
tableView.deselectRow(at: indexPath, animated: true)
searchController.isActive = false