Do not show 0 if numbers in "About Repository" cannot be obtained properly

This commit is contained in:
Danny Moesch 2019-01-07 20:21:04 +01:00 committed by Mingshen Sun
parent f47e7d384c
commit 744b46adc2
3 changed files with 18 additions and 12 deletions

View file

@ -11,6 +11,8 @@ import passKit
class AboutRepositoryTableViewController: BasicStaticTableViewController {
private static let VALUE_NOT_AVAILABLE = "Value not available"
private var needRefresh = false
private var indicator: UIActivityIndicatorView = {
let indicator = UIActivityIndicatorView(activityIndicatorStyle: .gray)
@ -85,7 +87,10 @@ class AboutRepositoryTableViewController: BasicStaticTableViewController {
}
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 {
@ -99,7 +104,10 @@ class AboutRepositoryTableViewController: BasicStaticTableViewController {
}
private func numberOfCommitsString() -> String {
return String(passwordStore.numberOfCommits)
if let numberOfCommits = passwordStore.numberOfCommits {
return String(numberOfCommits)
}
return AboutRepositoryTableViewController.VALUE_NOT_AVAILABLE
}
@objc func setNeedRefresh() {

View file

@ -138,7 +138,6 @@ class PasswordsViewController: UIViewController, UITableViewDataSource, UITableV
SVProgressHUD.setDefaultMaskType(.black)
SVProgressHUD.setDefaultStyle(.light)
SVProgressHUD.show(withStatus: "Sync Password Store")
let numberOfLocalCommits = self.passwordStore.numberOfLocalCommits
var gitCredential: GitCredential
if SharedDefaults[.gitAuthenticationMethod] == "Password" {
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")
}
})
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
DispatchQueue.main.async {
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) {
// set navigation item
let numberOfLocalCommits = self.passwordStore.numberOfLocalCommits
if numberOfLocalCommits == 0 {
navigationController?.tabBarItem.badgeValue = nil
} else {
if let numberOfLocalCommits = passwordStore.numberOfLocalCommits, numberOfLocalCommits != 0 {
navigationController?.tabBarItem.badgeValue = "\(numberOfLocalCommits)"
} else {
navigationController?.tabBarItem.badgeValue = nil
}
if parentPasswordEntity != nil {
navigationItem.leftBarButtonItem = backUIBarButtonItem