passforios/pass/Controllers/CommitLogsTableViewController.swift

59 lines
2 KiB
Swift
Raw Normal View History

//
// CommitLogsTableViewController.swift
// pass
//
// Created by Mingshen Sun on 28/2/2017.
// Copyright © 2017 Bob Sun. All rights reserved.
//
import UIKit
import ObjectiveGit
import passKit
class CommitLogsTableViewController: UITableViewController {
var commits: [GTCommit] = []
let passwordStore = PasswordStore.shared
2018-12-09 16:59:07 -08:00
override func viewDidLoad() {
super.viewDidLoad()
NotificationCenter.default.addObserver(self, selector: #selector(updateCommitLogs), name: .passwordStoreUpdated, object: nil)
commits = getCommitLogs()
2017-04-06 20:48:06 -07:00
self.tableView.estimatedRowHeight = 50
2019-05-01 17:49:27 +02:00
self.tableView.rowHeight = UITableView.automaticDimension
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return commits.count
}
2018-12-09 16:59:07 -08:00
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "commitLogCell", for: indexPath)
let formatter = DateFormatter()
2017-04-06 20:48:06 -07:00
formatter.dateStyle = DateFormatter.Style.medium
formatter.timeStyle = .medium
let dateString = formatter.string(from: commits[indexPath.row].commitDate)
2018-12-09 16:59:07 -08:00
2017-04-24 10:56:18 -07:00
let author = cell.contentView.viewWithTag(200) as? UILabel
let dateLabel = cell.contentView.viewWithTag(201) as? UILabel
let messageLabel = cell.contentView.viewWithTag(202) as? UILabel
2017-04-06 20:48:06 -07:00
author?.text = commits[indexPath.row].author?.name
2017-04-04 00:52:51 +08:00
dateLabel?.text = dateString
messageLabel?.text = commits[indexPath.row].message?.trimmed
return cell
}
2018-12-09 16:59:07 -08:00
@objc func updateCommitLogs() {
commits = getCommitLogs()
tableView.reloadData()
}
2018-12-09 16:59:07 -08:00
private func getCommitLogs() -> [GTCommit] {
do {
return try passwordStore.getRecentCommits(count: 20)
} catch {
2019-01-14 20:57:45 +01:00
Utils.alert(title: "Error".localize(), message: error.localizedDescription, controller: self, completion: nil)
return []
}
}
}