passforios/passAutoFillExtension/Controllers/PasswordsViewController.swift

72 lines
2.2 KiB
Swift
Raw Permalink Normal View History

2020-12-31 21:46:50 -08:00
//
// PasswordsViewController.swift
// passAutoFillExtension
//
// Created by Sun, Mingshen on 12/31/20.
// Copyright © 2020 Bob Sun. All rights reserved.
//
import AuthenticationServices
import passKit
2021-01-31 13:17:37 +01:00
import UIKit
2020-12-31 21:46:50 -08:00
class PasswordsViewController: UIViewController {
@IBOutlet var tableView: UITableView!
var dataSource: PasswordsTableDataSource!
weak var selectionDelegate: PasswordSelectionDelegate?
2021-01-01 12:18:17 -08:00
lazy var searchController: UISearchController = {
2020-12-31 21:46:50 -08:00
let uiSearchController = UISearchController(searchResultsController: nil)
uiSearchController.searchBar.isTranslucent = true
uiSearchController.obscuresBackgroundDuringPresentation = false
uiSearchController.searchBar.sizeToFit()
uiSearchController.searchBar.searchTextField.clearButtonMode = .whileEditing
2020-12-31 21:46:50 -08:00
return uiSearchController
2021-01-01 12:18:17 -08:00
}()
2020-12-31 21:46:50 -08:00
lazy var searchBar: UISearchBar = self.searchController.searchBar
2021-01-02 22:13:48 -08:00
2020-12-31 21:46:50 -08:00
override func viewDidLoad() {
super.viewDidLoad()
navigationItem.searchController = searchController
navigationItem.hidesSearchBarWhenScrolling = false
2021-01-02 22:13:48 -08:00
searchBar.delegate = self
2020-12-31 21:46:50 -08:00
tableView.delegate = self
tableView.dataSource = dataSource
}
2021-08-26 23:12:13 +02:00
func showPasswordsWithSuggestion(matching text: String) {
2021-01-03 22:01:24 -08:00
dataSource.showTableEntriesWithSuggestion(matching: text)
2021-01-02 22:13:48 -08:00
tableView.reloadData()
}
2020-12-31 21:46:50 -08:00
}
extension PasswordsViewController: UISearchBarDelegate {
func searchBar(_: UISearchBar, textDidChange searchText: String) {
dataSource.showTableEntries(matching: searchText)
tableView.reloadData()
}
func searchBarSearchButtonClicked(_ searchBar: UISearchBar) {
searchBar.resignFirstResponder()
}
func searchBarCancelButtonClicked(_: UISearchBar) {
dataSource.showTableEntries(matching: "")
tableView.reloadData()
}
}
extension PasswordsViewController: UITableViewDelegate {
func tableView(_: UITableView, didSelectRowAt indexPath: IndexPath) {
tableView.deselectRow(at: indexPath, animated: true)
let entry = dataSource.tableEntry(at: indexPath)
2020-12-31 21:46:50 -08:00
UIImpactFeedbackGenerator(style: .medium).impactOccurred()
2021-01-31 13:17:37 +01:00
selectionDelegate?.selected(password: entry)
2020-12-31 21:46:50 -08:00
}
}