2017-02-28 17:10:27 +08:00
|
|
|
//
|
|
|
|
|
// CommitLogsTableViewController.swift
|
|
|
|
|
// pass
|
|
|
|
|
//
|
|
|
|
|
// Created by Mingshen Sun on 28/2/2017.
|
|
|
|
|
// Copyright © 2017 Bob Sun. All rights reserved.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
import UIKit
|
|
|
|
|
import ObjectiveGit
|
|
|
|
|
|
|
|
|
|
class CommitLogsTableViewController: UITableViewController {
|
|
|
|
|
var commits: [GTCommit] = []
|
2017-03-16 22:39:03 -07:00
|
|
|
let passwordStore = PasswordStore.shared
|
2017-02-28 17:10:27 +08:00
|
|
|
|
|
|
|
|
override func viewDidLoad() {
|
|
|
|
|
super.viewDidLoad()
|
2017-04-26 22:09:27 -07:00
|
|
|
NotificationCenter.default.addObserver(self, selector: #selector(updateCommitLogs), name: .passwordStoreUpdated, object: nil)
|
2017-03-16 22:39:03 -07:00
|
|
|
commits = passwordStore.getRecentCommits(count: 20)
|
2017-04-06 20:48:06 -07:00
|
|
|
self.tableView.estimatedRowHeight = 50
|
|
|
|
|
self.tableView.rowHeight = UITableViewAutomaticDimension
|
2017-02-28 17:10:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
|
|
|
|
return commits.count
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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
|
2017-02-28 17:10:27 +08:00
|
|
|
let dateString = formatter.string(from: commits[indexPath.row].commitDate)
|
2017-04-04 00:52:51 +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
|
2017-04-06 20:48:06 -07:00
|
|
|
messageLabel?.text = commits[indexPath.row].message?.trimmingCharacters(in: .whitespacesAndNewlines)
|
2017-02-28 17:10:27 +08:00
|
|
|
return cell
|
|
|
|
|
}
|
2017-04-26 22:09:27 -07:00
|
|
|
|
|
|
|
|
func updateCommitLogs () {
|
|
|
|
|
commits = passwordStore.getRecentCommits(count: 20)
|
|
|
|
|
tableView.reloadData()
|
|
|
|
|
}
|
2017-02-28 17:10:27 +08:00
|
|
|
}
|