mirror of https://github.com/oxen-io/session-ios
				
				
				
			
			You cannot select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
	
	
		
			52 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			Swift
		
	
		
		
			
		
	
	
			52 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			Swift
		
	
| 
											5 years ago
										 | import UIKit | ||
| 
											6 years ago
										 | 
 | ||
|  | final class PathStatusView : UIView { | ||
|  |      | ||
|  |     override init(frame: CGRect) { | ||
|  |         super.init(frame: frame) | ||
|  |         setUpViewHierarchy() | ||
| 
											6 years ago
										 |         registerObservers() | ||
| 
											6 years ago
										 |     } | ||
|  | 
 | ||
|  |     required init?(coder: NSCoder) { | ||
|  |         super.init(coder: coder) | ||
|  |         setUpViewHierarchy() | ||
| 
											6 years ago
										 |         registerObservers() | ||
| 
											6 years ago
										 |     } | ||
|  |      | ||
|  |     private func setUpViewHierarchy() { | ||
| 
											6 years ago
										 |         layer.cornerRadius = Values.pathStatusViewSize / 2 | ||
|  |         layer.masksToBounds = false | ||
| 
											5 years ago
										 |         if OnionRequestAPI.paths.isEmpty { | ||
| 
											5 years ago
										 |             OnionRequestAPI.paths = Storage.shared.getOnionRequestPaths() | ||
| 
											6 years ago
										 |         } | ||
| 
											5 years ago
										 |         let color = (!OnionRequestAPI.paths.isEmpty) ? Colors.accent : Colors.pathsBuilding | ||
| 
											6 years ago
										 |         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 | ||
| 
											6 years ago
										 |         let size = Values.pathStatusViewSize | ||
| 
											6 years ago
										 |         let glowConfiguration = UIView.CircularGlowConfiguration(size: size, color: color, isAnimated: isAnimated, radius: isLightMode ? 6 : 8) | ||
| 
											6 years ago
										 |         setCircularGlow(with: glowConfiguration) | ||
| 
											6 years ago
										 |     } | ||
|  | 
 | ||
|  |     @objc private func handleBuildingPathsNotification() { | ||
| 
											6 years ago
										 |         setColor(to: Colors.pathsBuilding, isAnimated: true) | ||
| 
											6 years ago
										 |     } | ||
|  | 
 | ||
|  |     @objc private func handlePathsBuiltNotification() { | ||
|  |         setColor(to: Colors.accent, isAnimated: true) | ||
| 
											6 years ago
										 |     } | ||
|  | } |