diff --git a/pass/Controllers/AboutRepositoryTableViewController.swift b/pass/Controllers/AboutRepositoryTableViewController.swift index 3f775dd..ed8450d 100644 --- a/pass/Controllers/AboutRepositoryTableViewController.swift +++ b/pass/Controllers/AboutRepositoryTableViewController.swift @@ -40,9 +40,9 @@ class AboutRepositoryTableViewController: BasicStaticTableViewController { let formatted = ByteCountFormatter.string(fromByteCount: Int64(size), countStyle: ByteCountFormatter.CountStyle.file) self?.tableData = [ // section 0 - [[.type: CellDataType.detail, .title: "Passwords", .detailText: String(passwordEntities.count)], - [.type: CellDataType.detail, .title: "Size", .detailText: formatted], - [.type: CellDataType.detail, .title: "Last Synced", .detailText: Utils.getLastUpdatedTimeString()], + [[.style: CellDataStyle.value1, .accessoryType: UITableViewCellAccessoryType.none, .title: "Passwords", .detailText: String(passwordEntities.count)], + [.style: CellDataStyle.value1, .accessoryType: UITableViewCellAccessoryType.none, .title: "Size", .detailText: formatted], + [.style: CellDataStyle.value1, .accessoryType: UITableViewCellAccessoryType.none, .title: "Last Synced", .detailText: Utils.getLastUpdatedTimeString()], ], ] indicator.stopAnimating() diff --git a/pass/Controllers/AboutTableViewController.swift b/pass/Controllers/AboutTableViewController.swift index 5fab408..ec38f77 100644 --- a/pass/Controllers/AboutTableViewController.swift +++ b/pass/Controllers/AboutTableViewController.swift @@ -13,12 +13,12 @@ class AboutTableViewController: BasicStaticTableViewController { override func viewDidLoad() { tableData = [ // section 0 - [[.type: CellDataType.link, .title: "Website", .link: "https://github.com/mssun/pass-ios.git"], - [.type: CellDataType.link, .title: "Contact Developer", .link: "mailto:bob@mssun.me?subject=passforiOS"],], + [[.title: "Website", .action: "link", .link: "https://github.com/mssun/pass-ios.git"], + [.title: "Contact Developer", .action: "link", .link: "mailto:bob@mssun.me?subject=passforiOS"],], // section 1, - [[.type: CellDataType.segue, .title: "Open Source Components", .link: "showOpenSourceComponentsSegue"], - [.type: CellDataType.segue, .title: "Special Thanks", .link: "showSpecialThanksSegue"],], + [[.title: "Open Source Components", .action: "segue", .link: "showOpenSourceComponentsSegue"], + [.title: "Special Thanks", .action: "segue", .link: "showSpecialThanksSegue"],], ] navigationItemTitle = "About" super.viewDidLoad() diff --git a/pass/Controllers/BasicStaticTableViewController.swift b/pass/Controllers/BasicStaticTableViewController.swift index 49ee6ed..8ede6a5 100644 --- a/pass/Controllers/BasicStaticTableViewController.swift +++ b/pass/Controllers/BasicStaticTableViewController.swift @@ -15,8 +15,12 @@ enum CellDataType { case link, segue, empty, detail } +enum CellDataStyle { + case value1, defaultStyle +} + enum CellDataKey { - case type, title, link, accessoryType, detailDisclosureAction, detailDisclosureData, detailText + case style, type, title, link, accessoryType, detailDisclosureAction, detailDisclosureData, detailText, action } class BasicStaticTableViewController: UITableViewController, MFMailComposeViewControllerDelegate { @@ -44,22 +48,25 @@ class BasicStaticTableViewController: UITableViewController, MFMailComposeViewCo override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cellData = tableData[indexPath.section][indexPath.row] - let cellDataType = cellData[CellDataKey.type] as? CellDataType + let cellDataStyle = cellData[CellDataKey.style] as? CellDataStyle var cell: UITableViewCell? - switch cellDataType! { - case .detail: + + switch cellDataStyle ?? .defaultStyle { + case .value1: cell = UITableViewCell(style: .value1, reuseIdentifier: "value1 cell") - cell?.accessoryType = .none - cell?.detailTextLabel?.text = cellData[CellDataKey.detailText] as? String default: cell = UITableViewCell(style: .default, reuseIdentifier: "default cell") - cell?.textLabel?.text = cellData[CellDataKey.title] as? String - if let accessoryType = cellData[CellDataKey.accessoryType] as? UITableViewCellAccessoryType { - cell?.accessoryType = accessoryType - } else { - cell?.accessoryType = .disclosureIndicator - } } + + if let detailText = cellData[CellDataKey.detailText] as? String { + cell?.detailTextLabel?.text = detailText + } + if let accessoryType = cellData[CellDataKey.accessoryType] as? UITableViewCellAccessoryType { + cell?.accessoryType = accessoryType + } else { + cell?.accessoryType = .disclosureIndicator + } + cell?.textLabel?.text = cellData[CellDataKey.title] as? String return cell ?? UITableViewCell() } @@ -73,12 +80,12 @@ class BasicStaticTableViewController: UITableViewController, MFMailComposeViewCo override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { tableView.deselectRow(at: indexPath, animated: true) let cellData = tableData[indexPath.section][indexPath.row] - let cellDataType = cellData[CellDataKey.type] as? CellDataType - switch cellDataType! { - case .segue: + let cellDataAction = cellData[CellDataKey.action] as? String + switch cellDataAction ?? "" { + case "segue": let link = cellData[CellDataKey.link] as? String performSegue(withIdentifier: link!, sender: self) - case .link: + case "link": let link = cellData[CellDataKey.link] as! String let url = URL(string: link)! switch url.scheme! { diff --git a/pass/Controllers/GeneralSettingsTableViewController.swift b/pass/Controllers/GeneralSettingsTableViewController.swift index 8ef71db..91d8652 100644 --- a/pass/Controllers/GeneralSettingsTableViewController.swift +++ b/pass/Controllers/GeneralSettingsTableViewController.swift @@ -14,7 +14,7 @@ class GeneralSettingsTableViewController: BasicStaticTableViewController { navigationItemTitle = "General" tableData = [ // section 0 - [[.type: CellDataType.segue, .title: "About Repository", .link: "showAboutRepositorySegue"],], + [[.title: "About Repository", .action: "segue", .link: "showAboutRepositorySegue"],], ] super.viewDidLoad() } diff --git a/pass/Controllers/OpenSourceComponentsTableViewController.swift b/pass/Controllers/OpenSourceComponentsTableViewController.swift index 102bad8..84cf5a1 100644 --- a/pass/Controllers/OpenSourceComponentsTableViewController.swift +++ b/pass/Controllers/OpenSourceComponentsTableViewController.swift @@ -35,7 +35,7 @@ class OpenSourceComponentsTableViewController: BasicStaticTableViewController { tableData.append([]) for item in openSourceComponents { tableData[0].append( - [CellDataKey.type: CellDataType.link, CellDataKey.title: item[0], CellDataKey.link: item[1], CellDataKey.accessoryType: UITableViewCellAccessoryType.detailDisclosureButton, CellDataKey.detailDisclosureAction: #selector(actOnDetailDisclosureButton(_:)), CellDataKey.detailDisclosureData: item[2]] + [CellDataKey.title: item[0], CellDataKey.action: "link", CellDataKey.link: item[1], CellDataKey.accessoryType: UITableViewCellAccessoryType.detailDisclosureButton, CellDataKey.detailDisclosureAction: #selector(actOnDetailDisclosureButton(_:)), CellDataKey.detailDisclosureData: item[2]] ) } navigationItemTitle = "Open Source Components" diff --git a/pass/Controllers/PasswordRepositorySettingsTableViewController.swift b/pass/Controllers/PasswordRepositorySettingsTableViewController.swift index 50087ec..161f370 100644 --- a/pass/Controllers/PasswordRepositorySettingsTableViewController.swift +++ b/pass/Controllers/PasswordRepositorySettingsTableViewController.swift @@ -12,14 +12,25 @@ import SVProgressHUD class PasswordRepositorySettingsTableViewController: BasicStaticTableViewController { override func viewDidLoad() { + let url = Defaults[.gitRepositoryURL]?.host tableData = [ - [[.type: CellDataType.segue, .title: "Git Server", .link: "showGitServerSettingSegue"], - [.type: CellDataType.segue, .title: "SSH Key", .link: "showSSHKeySettingSegue"],], + [[.style: CellDataStyle.value1, .title: "Git Server", .action: "segue", .link: "showGitServerSettingSegue", .detailText: url ?? ""], + [.title: "SSH Key", .action: "segue", .link: "showSSHKeySettingSegue"],], ] navigationItemTitle = "Repository" super.viewDidLoad() } + override func viewWillAppear(_ animated: Bool) { + super.viewWillAppear(animated) + if let url = Defaults[.gitRepositoryURL] { + if let cell = tableView.cellForRow(at: IndexPath(row: 0, section: 0)) { + cell.detailTextLabel!.text = url.host + } + } + } + + @IBAction func cancelGitServerSetting(segue: UIStoryboardSegue) { } diff --git a/pass/Controllers/SpecialThanksTableViewController.swift b/pass/Controllers/SpecialThanksTableViewController.swift index 880d966..c10ca93 100644 --- a/pass/Controllers/SpecialThanksTableViewController.swift +++ b/pass/Controllers/SpecialThanksTableViewController.swift @@ -20,7 +20,7 @@ class SpecialThanksTableViewController: BasicStaticTableViewController { tableData.append([]) for item in openSourceComponents { tableData[0].append( - [CellDataKey.type: CellDataType.link, CellDataKey.title: item[0], CellDataKey.link: item[1]] + [CellDataKey.action: "link", CellDataKey.title: item[0], CellDataKey.link: item[1]] ) } navigationItemTitle = "Special Thanks"