Do not show 0 if numbers in "About Repository" cannot be obtained properly
This commit is contained in:
parent
f47e7d384c
commit
744b46adc2
3 changed files with 18 additions and 12 deletions
|
|
@ -11,6 +11,8 @@ import passKit
|
||||||
|
|
||||||
class AboutRepositoryTableViewController: BasicStaticTableViewController {
|
class AboutRepositoryTableViewController: BasicStaticTableViewController {
|
||||||
|
|
||||||
|
private static let VALUE_NOT_AVAILABLE = "Value not available"
|
||||||
|
|
||||||
private var needRefresh = false
|
private var needRefresh = false
|
||||||
private var indicator: UIActivityIndicatorView = {
|
private var indicator: UIActivityIndicatorView = {
|
||||||
let indicator = UIActivityIndicatorView(activityIndicatorStyle: .gray)
|
let indicator = UIActivityIndicatorView(activityIndicatorStyle: .gray)
|
||||||
|
|
@ -85,7 +87,10 @@ class AboutRepositoryTableViewController: BasicStaticTableViewController {
|
||||||
}
|
}
|
||||||
|
|
||||||
private func numberOfLocalCommitsString() -> String {
|
private func numberOfLocalCommitsString() -> String {
|
||||||
return String(passwordStore.numberOfLocalCommits)
|
if let numberOfLocalCommits = passwordStore.numberOfLocalCommits {
|
||||||
|
return String(numberOfLocalCommits)
|
||||||
|
}
|
||||||
|
return AboutRepositoryTableViewController.VALUE_NOT_AVAILABLE
|
||||||
}
|
}
|
||||||
|
|
||||||
private func lastSyncedTimeString() -> String {
|
private func lastSyncedTimeString() -> String {
|
||||||
|
|
@ -99,7 +104,10 @@ class AboutRepositoryTableViewController: BasicStaticTableViewController {
|
||||||
}
|
}
|
||||||
|
|
||||||
private func numberOfCommitsString() -> String {
|
private func numberOfCommitsString() -> String {
|
||||||
return String(passwordStore.numberOfCommits)
|
if let numberOfCommits = passwordStore.numberOfCommits {
|
||||||
|
return String(numberOfCommits)
|
||||||
|
}
|
||||||
|
return AboutRepositoryTableViewController.VALUE_NOT_AVAILABLE
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc func setNeedRefresh() {
|
@objc func setNeedRefresh() {
|
||||||
|
|
|
||||||
|
|
@ -138,7 +138,6 @@ class PasswordsViewController: UIViewController, UITableViewDataSource, UITableV
|
||||||
SVProgressHUD.setDefaultMaskType(.black)
|
SVProgressHUD.setDefaultMaskType(.black)
|
||||||
SVProgressHUD.setDefaultStyle(.light)
|
SVProgressHUD.setDefaultStyle(.light)
|
||||||
SVProgressHUD.show(withStatus: "Sync Password Store")
|
SVProgressHUD.show(withStatus: "Sync Password Store")
|
||||||
let numberOfLocalCommits = self.passwordStore.numberOfLocalCommits
|
|
||||||
var gitCredential: GitCredential
|
var gitCredential: GitCredential
|
||||||
if SharedDefaults[.gitAuthenticationMethod] == "Password" {
|
if SharedDefaults[.gitAuthenticationMethod] == "Password" {
|
||||||
gitCredential = GitCredential(credential: GitCredential.Credential.http(userName: SharedDefaults[.gitUsername]!))
|
gitCredential = GitCredential(credential: GitCredential.Credential.http(userName: SharedDefaults[.gitUsername]!))
|
||||||
|
|
@ -157,7 +156,7 @@ class PasswordsViewController: UIViewController, UITableViewDataSource, UITableV
|
||||||
SVProgressHUD.showProgress(Float(git_transfer_progress.pointee.received_objects)/Float(git_transfer_progress.pointee.total_objects), status: "Pull Remote Repository")
|
SVProgressHUD.showProgress(Float(git_transfer_progress.pointee.received_objects)/Float(git_transfer_progress.pointee.total_objects), status: "Pull Remote Repository")
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
if numberOfLocalCommits > 0 {
|
if self.passwordStore.numberOfLocalCommits ?? 0 > 0 {
|
||||||
try self.passwordStore.pushRepository(credential: gitCredential, requestGitPassword: self.requestGitPassword(credential:lastPassword:), transferProgressBlock: {(current, total, bytes, stop) in
|
try self.passwordStore.pushRepository(credential: gitCredential, requestGitPassword: self.requestGitPassword(credential:lastPassword:), transferProgressBlock: {(current, total, bytes, stop) in
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
SVProgressHUD.showProgress(Float(current)/Float(total), status: "Push Remote Repository")
|
SVProgressHUD.showProgress(Float(current)/Float(total), status: "Push Remote Repository")
|
||||||
|
|
@ -518,11 +517,10 @@ class PasswordsViewController: UIViewController, UITableViewDataSource, UITableV
|
||||||
|
|
||||||
private func reloadTableView(data: [PasswordsTableEntry], anim: CAAnimation? = nil) {
|
private func reloadTableView(data: [PasswordsTableEntry], anim: CAAnimation? = nil) {
|
||||||
// set navigation item
|
// set navigation item
|
||||||
let numberOfLocalCommits = self.passwordStore.numberOfLocalCommits
|
if let numberOfLocalCommits = passwordStore.numberOfLocalCommits, numberOfLocalCommits != 0 {
|
||||||
if numberOfLocalCommits == 0 {
|
|
||||||
navigationController?.tabBarItem.badgeValue = nil
|
|
||||||
} else {
|
|
||||||
navigationController?.tabBarItem.badgeValue = "\(numberOfLocalCommits)"
|
navigationController?.tabBarItem.badgeValue = "\(numberOfLocalCommits)"
|
||||||
|
} else {
|
||||||
|
navigationController?.tabBarItem.badgeValue = nil
|
||||||
}
|
}
|
||||||
if parentPasswordEntity != nil {
|
if parentPasswordEntity != nil {
|
||||||
navigationItem.leftBarButtonItem = backUIBarButtonItem
|
navigationItem.leftBarButtonItem = backUIBarButtonItem
|
||||||
|
|
|
||||||
|
|
@ -105,16 +105,16 @@ public class PasswordStore {
|
||||||
return (try? fm.allocatedSizeOfDirectoryAtURL(directoryURL: self.storeURL)) ?? 0
|
return (try? fm.allocatedSizeOfDirectoryAtURL(directoryURL: self.storeURL)) ?? 0
|
||||||
}
|
}
|
||||||
|
|
||||||
public var numberOfLocalCommits: Int {
|
public var numberOfLocalCommits: Int? {
|
||||||
return (try? getLocalCommits()?.count ?? 0) ?? 0
|
return (try? getLocalCommits())?.flatMap { $0.count }
|
||||||
}
|
}
|
||||||
|
|
||||||
public var lastSyncedTime: Date? {
|
public var lastSyncedTime: Date? {
|
||||||
return SharedDefaults[.lastSyncedTime]
|
return SharedDefaults[.lastSyncedTime]
|
||||||
}
|
}
|
||||||
|
|
||||||
public var numberOfCommits: UInt {
|
public var numberOfCommits: UInt? {
|
||||||
return storeRepository?.numberOfCommits(inCurrentBranch: nil) ?? 0
|
return storeRepository?.numberOfCommits(inCurrentBranch: nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
private init() {
|
private init() {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue