update basictableviewcontroller

This commit is contained in:
Bob Sun 2017-02-10 16:44:59 +08:00
parent 24139e932b
commit 2487b23a10
No known key found for this signature in database
GPG key ID: 1F86BA2052FED3B4
7 changed files with 46 additions and 28 deletions

View file

@ -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()

View file

@ -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()

View file

@ -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! {

View file

@ -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()
}

View file

@ -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"

View file

@ -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) {
}

View file

@ -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"