2020-11-09 06:03:59 +01:00
|
|
|
import UIKit
|
2020-05-27 08:48:29 +02:00
|
|
|
|
|
|
|
final class PathStatusView : UIView {
|
|
|
|
|
|
|
|
override init(frame: CGRect) {
|
|
|
|
super.init(frame: frame)
|
|
|
|
setUpViewHierarchy()
|
2020-05-28 03:01:42 +02:00
|
|
|
registerObservers()
|
2020-05-27 08:48:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
required init?(coder: NSCoder) {
|
|
|
|
super.init(coder: coder)
|
|
|
|
setUpViewHierarchy()
|
2020-05-28 03:01:42 +02:00
|
|
|
registerObservers()
|
2020-05-27 08:48:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private func setUpViewHierarchy() {
|
2020-05-28 03:01:42 +02:00
|
|
|
layer.cornerRadius = Values.pathStatusViewSize / 2
|
|
|
|
layer.masksToBounds = false
|
2020-10-09 01:10:01 +02:00
|
|
|
if OnionRequestAPI.paths.isEmpty {
|
2020-11-19 05:24:09 +01:00
|
|
|
OnionRequestAPI.paths = Storage.shared.getOnionRequestPaths()
|
2020-05-28 04:02:30 +02:00
|
|
|
}
|
2020-10-09 01:10:01 +02:00
|
|
|
let color = (!OnionRequestAPI.paths.isEmpty) ? Colors.accent : Colors.pathsBuilding
|
2020-05-28 03:01:42 +02:00
|
|
|
setColor(to: color, isAnimated: false)
|
|
|
|
}
|
|
|
|
|
|
|
|
private func registerObservers() {
|
|
|
|
let notificationCenter = NotificationCenter.default
|
|
|
|
notificationCenter.addObserver(self, selector: #selector(handleBuildingPathsNotification), name: .buildingPaths, object: nil)
|
|
|
|
notificationCenter.addObserver(self, selector: #selector(handlePathsBuiltNotification), name: .pathsBuilt, object: nil)
|
|
|
|
}
|
|
|
|
|
|
|
|
deinit {
|
|
|
|
NotificationCenter.default.removeObserver(self)
|
|
|
|
}
|
|
|
|
|
|
|
|
private func setColor(to color: UIColor, isAnimated: Bool) {
|
|
|
|
backgroundColor = color
|
2020-05-27 08:48:29 +02:00
|
|
|
let size = Values.pathStatusViewSize
|
2020-05-28 03:01:42 +02:00
|
|
|
let glowConfiguration = UIView.CircularGlowConfiguration(size: size, color: color, isAnimated: isAnimated, radius: isLightMode ? 6 : 8)
|
2020-05-28 01:52:13 +02:00
|
|
|
setCircularGlow(with: glowConfiguration)
|
2020-05-28 03:01:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@objc private func handleBuildingPathsNotification() {
|
2020-05-28 03:07:31 +02:00
|
|
|
setColor(to: Colors.pathsBuilding, isAnimated: true)
|
2020-05-28 03:01:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@objc private func handlePathsBuiltNotification() {
|
|
|
|
setColor(to: Colors.accent, isAnimated: true)
|
2020-05-27 08:48:29 +02:00
|
|
|
}
|
|
|
|
}
|