Ditch rebuild path button

This commit is contained in:
nielsandriesse 2020-06-02 11:25:19 +10:00
parent e2740d78e8
commit 6d3ca84f48
2 changed files with 11 additions and 33 deletions

View File

@ -21,10 +21,10 @@ final class PathVC : BaseVC {
return result return result
}() }()
private lazy var rebuildPathButton: Button = { private lazy var learnMoreButton: Button = {
let result = Button(style: .prominentOutline, size: .large) let result = Button(style: .prominentOutline, size: .large)
result.setTitle(NSLocalizedString("Rebuild Path", comment: ""), for: UIControl.State.normal) result.setTitle(NSLocalizedString("Learn More", comment: ""), for: UIControl.State.normal)
result.addTarget(self, action: #selector(rebuildPath), for: UIControl.Event.touchUpInside) result.addTarget(self, action: #selector(learnMore), for: UIControl.Event.touchUpInside)
return result return result
}() }()
@ -44,9 +44,6 @@ final class PathVC : BaseVC {
let closeButton = UIBarButtonItem(image: #imageLiteral(resourceName: "X"), style: .plain, target: self, action: #selector(close)) let closeButton = UIBarButtonItem(image: #imageLiteral(resourceName: "X"), style: .plain, target: self, action: #selector(close))
closeButton.tintColor = Colors.text closeButton.tintColor = Colors.text
navigationItem.leftBarButtonItem = closeButton navigationItem.leftBarButtonItem = closeButton
let learnMoreButton = UIBarButtonItem(image: #imageLiteral(resourceName: "QuestionMark").scaled(to: CGSize(width: 24, height: 24)), style: .plain, target: self, action: #selector(learnMore))
learnMoreButton.tintColor = Colors.text
navigationItem.rightBarButtonItem = learnMoreButton
} }
private func setUpViewHierarchy() { private func setUpViewHierarchy() {
@ -72,17 +69,17 @@ final class PathVC : BaseVC {
pathStackViewContainer.bottomAnchor.constraint(greaterThanOrEqualTo: spinner.bottomAnchor).isActive = true pathStackViewContainer.bottomAnchor.constraint(greaterThanOrEqualTo: spinner.bottomAnchor).isActive = true
spinner.center(in: pathStackViewContainer) spinner.center(in: pathStackViewContainer)
// Set up rebuild path button // Set up rebuild path button
let rebuildPathButtonContainer = UIView() let learnMoreButtonContainer = UIView()
rebuildPathButtonContainer.addSubview(rebuildPathButton) learnMoreButtonContainer.addSubview(learnMoreButton)
rebuildPathButton.pin(.leading, to: .leading, of: rebuildPathButtonContainer, withInset: 80) learnMoreButton.pin(.leading, to: .leading, of: learnMoreButtonContainer, withInset: 80)
rebuildPathButton.pin(.top, to: .top, of: rebuildPathButtonContainer) learnMoreButton.pin(.top, to: .top, of: learnMoreButtonContainer)
rebuildPathButtonContainer.pin(.trailing, to: .trailing, of: rebuildPathButton, withInset: 80) learnMoreButtonContainer.pin(.trailing, to: .trailing, of: learnMoreButton, withInset: 80)
rebuildPathButtonContainer.pin(.bottom, to: .bottom, of: rebuildPathButton) learnMoreButtonContainer.pin(.bottom, to: .bottom, of: learnMoreButton)
// Set up spacers // Set up spacers
let topSpacer = UIView.vStretchingSpacer() let topSpacer = UIView.vStretchingSpacer()
let bottomSpacer = UIView.vStretchingSpacer() let bottomSpacer = UIView.vStretchingSpacer()
// Set up main stack view // Set up main stack view
let mainStackView = UIStackView(arrangedSubviews: [ explanationLabel, topSpacer, pathStackViewContainer, bottomSpacer, rebuildPathButtonContainer ]) let mainStackView = UIStackView(arrangedSubviews: [ explanationLabel, topSpacer, pathStackViewContainer, bottomSpacer, learnMoreButtonContainer ])
mainStackView.axis = .vertical mainStackView.axis = .vertical
mainStackView.alignment = .fill mainStackView.alignment = .fill
mainStackView.layoutMargins = UIEdgeInsets(top: Values.largeSpacing, left: Values.largeSpacing, bottom: Values.largeSpacing, right: Values.largeSpacing) mainStackView.layoutMargins = UIEdgeInsets(top: Values.largeSpacing, left: Values.largeSpacing, bottom: Values.largeSpacing, right: Values.largeSpacing)
@ -125,18 +122,12 @@ final class PathVC : BaseVC {
spinner.stopAnimating() spinner.stopAnimating()
UIView.animate(withDuration: 0.25) { UIView.animate(withDuration: 0.25) {
self.spinner.alpha = 0 self.spinner.alpha = 0
self.rebuildPathButton.layer.borderColor = Colors.accent.cgColor
self.rebuildPathButton.setTitleColor(Colors.accent, for: UIControl.State.normal)
} }
rebuildPathButton.isEnabled = true
} else { } else {
spinner.startAnimating() spinner.startAnimating()
UIView.animate(withDuration: 0.25) { UIView.animate(withDuration: 0.25) {
self.spinner.alpha = 1 self.spinner.alpha = 1
self.rebuildPathButton.layer.borderColor = Colors.text.withAlphaComponent(Values.unimportantElementOpacity).cgColor
self.rebuildPathButton.setTitleColor(Colors.text.withAlphaComponent(Values.unimportantElementOpacity), for: UIControl.State.normal)
} }
rebuildPathButton.isEnabled = false
} }
} }
@ -201,19 +192,6 @@ final class PathVC : BaseVC {
let url = URL(string: urlAsString)! let url = URL(string: urlAsString)!
UIApplication.shared.open(url) UIApplication.shared.open(url)
} }
@objc private func rebuildPath() {
// Dispatch async on the main queue to avoid nested write transactions
DispatchQueue.main.async {
let storage = OWSPrimaryStorage.shared()
storage.dbReadWriteConnection.readWrite { transaction in
storage.clearOnionRequestPaths(in: transaction)
}
}
OnionRequestAPI.guardSnodes = []
OnionRequestAPI.paths = []
let _ = OnionRequestAPI.buildPaths()
}
} }
// MARK: Line View // MARK: Line View

View File

@ -2839,4 +2839,4 @@
"Service Node" = "Service Node"; "Service Node" = "Service Node";
"You" = "You"; "You" = "You";
"Destination" = "Destination"; "Destination" = "Destination";
"Rebuild Path" = "Rebuild Path"; "Learn More" = "Learn More";