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.
		
		
		
		
		
			
		
			
	
	
		
			111 lines
		
	
	
		
			3.4 KiB
		
	
	
	
		
			Swift
		
	
		
		
			
		
	
	
			111 lines
		
	
	
		
			3.4 KiB
		
	
	
	
		
			Swift
		
	
| 
											8 years ago
										 | // | ||
| 
											7 years ago
										 | //  Copyright (c) 2019 Open Whisper Systems. All rights reserved. | ||
| 
											8 years ago
										 | // | ||
|  | 
 | ||
|  | import UIKit | ||
|  | import PureLayout | ||
|  | 
 | ||
|  | class SAELoadViewController: UIViewController { | ||
|  | 
 | ||
| 
											8 years ago
										 |     weak var delegate: ShareViewDelegate? | ||
| 
											8 years ago
										 | 
 | ||
| 
											8 years ago
										 |     var activityIndicator: UIActivityIndicatorView! | ||
|  |     var progressView: UIProgressView! | ||
|  | 
 | ||
|  |     var progress: Progress? { | ||
|  |         didSet { | ||
|  |             guard progressView != nil else { | ||
|  |                 return | ||
|  |             } | ||
|  | 
 | ||
|  |             updateProgressViewVisability() | ||
|  |             progressView.observedProgress = progress | ||
|  |         } | ||
|  |     } | ||
|  | 
 | ||
|  |     func updateProgressViewVisability() { | ||
|  |         guard progressView != nil, activityIndicator != nil else { | ||
|  |             return | ||
|  |         } | ||
|  | 
 | ||
|  |         // Prefer to show progress view when progress is present | ||
|  |         if self.progress == nil { | ||
|  |             activityIndicator.startAnimating() | ||
|  |             self.progressView.isHidden = true | ||
|  |             self.activityIndicator.isHidden = false | ||
|  |         } else { | ||
|  |             activityIndicator.stopAnimating() | ||
|  |             self.progressView.isHidden = false | ||
|  |             self.activityIndicator.isHidden = true | ||
|  |         } | ||
|  |     } | ||
| 
											8 years ago
										 | 
 | ||
|  |     // MARK: Initializers and Factory Methods | ||
|  | 
 | ||
| 
											8 years ago
										 |     init(delegate: ShareViewDelegate) { | ||
| 
											8 years ago
										 |         self.delegate = delegate | ||
|  |         super.init(nibName: nil, bundle: nil) | ||
|  |     } | ||
|  | 
 | ||
| 
											8 years ago
										 |     @available(*, unavailable, message:"use other constructor instead.") | ||
| 
											8 years ago
										 |     required init?(coder aDecoder: NSCoder) { | ||
| 
											7 years ago
										 |         notImplemented() | ||
| 
											8 years ago
										 |     } | ||
|  | 
 | ||
|  |     override func loadView() { | ||
|  |         super.loadView() | ||
|  | 
 | ||
|  |         self.navigationItem.leftBarButtonItem = UIBarButtonItem(barButtonSystemItem: .cancel, | ||
|  |                                                                 target: self, | ||
|  |                                                                 action: #selector(cancelPressed)) | ||
| 
											6 years ago
										 |         self.navigationItem.title = "Session" | ||
| 
											8 years ago
										 | 
 | ||
| 
											8 years ago
										 |         self.view.backgroundColor = UIColor.ows_signalBrandBlue | ||
| 
											8 years ago
										 | 
 | ||
| 
											7 years ago
										 |         let activityIndicator = UIActivityIndicatorView(style: .whiteLarge) | ||
| 
											8 years ago
										 |         self.activityIndicator = activityIndicator | ||
|  |         self.view.addSubview(activityIndicator) | ||
|  |         activityIndicator.autoCenterInSuperview() | ||
|  | 
 | ||
| 
											8 years ago
										 |         progressView = UIProgressView(progressViewStyle: .default) | ||
|  |         progressView.observedProgress = progress | ||
|  | 
 | ||
|  |         self.view.addSubview(progressView) | ||
|  |         progressView.autoVCenterInSuperview() | ||
|  |         progressView.autoPinWidthToSuperview(withMargin: ScaleFromIPhone5(30)) | ||
|  |         progressView.progressTintColor = UIColor.white | ||
|  | 
 | ||
|  |         updateProgressViewVisability() | ||
|  | 
 | ||
| 
											8 years ago
										 |         let label = UILabel() | ||
|  |         label.textColor = UIColor.white | ||
|  |         label.font = UIFont.ows_mediumFont(withSize: 18) | ||
|  |         label.text = NSLocalizedString("SHARE_EXTENSION_LOADING", | ||
|  |                                        comment: "Indicates that the share extension is still loading.") | ||
|  |         self.view.addSubview(label) | ||
|  |         label.autoHCenterInSuperview() | ||
|  |         label.autoPinEdge(.top, to: .bottom, of: activityIndicator, withOffset: 25) | ||
|  |     } | ||
|  | 
 | ||
|  |     override func viewWillAppear(_ animated: Bool) { | ||
|  |         super.viewWillAppear(animated) | ||
|  | 
 | ||
|  |         self.navigationController?.isNavigationBarHidden = false | ||
|  |     } | ||
|  | 
 | ||
|  |     override func viewDidDisappear(_ animated: Bool) { | ||
|  |         super.viewDidDisappear(animated) | ||
|  | 
 | ||
|  |     } | ||
|  | 
 | ||
|  |     // MARK: - Event Handlers | ||
|  | 
 | ||
|  |     @objc func cancelPressed(sender: UIButton) { | ||
|  |         guard let delegate = delegate else { | ||
| 
											7 years ago
										 |             owsFailDebug("missing delegate") | ||
| 
											8 years ago
										 |             return | ||
|  |         } | ||
| 
											8 years ago
										 |         delegate.shareViewWasCancelled() | ||
| 
											8 years ago
										 |     } | ||
|  | } |