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.
		
		
		
		
		
			
		
			
	
	
		
			100 lines
		
	
	
		
			2.9 KiB
		
	
	
	
		
			Swift
		
	
		
		
			
		
	
	
			100 lines
		
	
	
		
			2.9 KiB
		
	
	
	
		
			Swift
		
	
| 
								 
											9 years ago
										 
									 | 
							
								//
							 | 
						||
| 
								 
											8 years ago
										 
									 | 
							
								//  Copyright (c) 2018 Open Whisper Systems. All rights reserved.
							 | 
						||
| 
								 
											9 years ago
										 
									 | 
							
								//
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								import UIKit
							 | 
						||
| 
								 
											5 years ago
										 
									 | 
							
								import SignalUtilitiesKit
							 | 
						||
| 
								 
											9 years ago
										 
									 | 
							
								
							 | 
						||
| 
								 
											8 years ago
										 
									 | 
							
								@objc public class AudioProgressView: UIView {
							 | 
						||
| 
								 
											9 years ago
										 
									 | 
							
								
							 | 
						||
| 
								 
											8 years ago
										 
									 | 
							
								    @objc public override var bounds: CGRect {
							 | 
						||
| 
								 
											9 years ago
										 
									 | 
							
								        didSet {
							 | 
						||
| 
								 | 
							
								            if oldValue != bounds {
							 | 
						||
| 
								 | 
							
								                updateSubviews()
							 | 
						||
| 
								 | 
							
								            }
							 | 
						||
| 
								 | 
							
								        }
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 
											8 years ago
										 
									 | 
							
								    @objc public override var frame: CGRect {
							 | 
						||
| 
								 
											9 years ago
										 
									 | 
							
								        didSet {
							 | 
						||
| 
								 | 
							
								            if oldValue != frame {
							 | 
						||
| 
								 | 
							
								                updateSubviews()
							 | 
						||
| 
								 | 
							
								            }
							 | 
						||
| 
								 | 
							
								        }
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 
											8 years ago
										 
									 | 
							
								    @objc public var horizontalBarColor = UIColor.black {
							 | 
						||
| 
								 
											9 years ago
										 
									 | 
							
								        didSet {
							 | 
						||
| 
								 | 
							
								            updateContent()
							 | 
						||
| 
								 | 
							
								        }
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 
											8 years ago
										 
									 | 
							
								    @objc public var progressColor = UIColor.blue {
							 | 
						||
| 
								 
											9 years ago
										 
									 | 
							
								        didSet {
							 | 
						||
| 
								 | 
							
								            updateContent()
							 | 
						||
| 
								 | 
							
								        }
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    private let horizontalBarLayer: CAShapeLayer
							 | 
						||
| 
								 | 
							
								    private let progressLayer: CAShapeLayer
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 
											8 years ago
										 
									 | 
							
								    @objc public var progress: CGFloat = 0 {
							 | 
						||
| 
								 
											9 years ago
										 
									 | 
							
								        didSet {
							 | 
						||
| 
								 | 
							
								            if oldValue != progress {
							 | 
						||
| 
								 | 
							
								                updateContent()
							 | 
						||
| 
								 | 
							
								            }
							 | 
						||
| 
								 | 
							
								        }
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 
											8 years ago
										 
									 | 
							
								    @available(*, unavailable, message:"use other constructor instead.")
							 | 
						||
| 
								 
											8 years ago
										 
									 | 
							
								    @objc public required init?(coder aDecoder: NSCoder) {
							 | 
						||
| 
								 
											7 years ago
										 
									 | 
							
								        notImplemented()
							 | 
						||
| 
								 
											9 years ago
										 
									 | 
							
								    }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    public required init() {
							 | 
						||
| 
								 | 
							
								        self.horizontalBarLayer = CAShapeLayer()
							 | 
						||
| 
								 | 
							
								        self.progressLayer = CAShapeLayer()
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 
											8 years ago
										 
									 | 
							
								        super.init(frame: CGRect.zero)
							 | 
						||
| 
								 
											9 years ago
										 
									 | 
							
								
							 | 
						||
| 
								 | 
							
								        self.layer.addSublayer(self.horizontalBarLayer)
							 | 
						||
| 
								 | 
							
								        self.layer.addSublayer(self.progressLayer)
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    internal func updateSubviews() {
							 | 
						||
| 
								 
											7 years ago
										 
									 | 
							
								        AssertIsOnMainThread()
							 | 
						||
| 
								 
											9 years ago
										 
									 | 
							
								
							 | 
						||
| 
								 | 
							
								        self.horizontalBarLayer.frame = self.bounds
							 | 
						||
| 
								 | 
							
								        self.progressLayer.frame = self.bounds
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								        updateContent()
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    internal func updateContent() {
							 | 
						||
| 
								 
											7 years ago
										 
									 | 
							
								        AssertIsOnMainThread()
							 | 
						||
| 
								 
											9 years ago
										 
									 | 
							
								
							 | 
						||
| 
								 
											8 years ago
										 
									 | 
							
								        // Prevent the shape layer from animating changes.
							 | 
						||
| 
								 | 
							
								        CATransaction.begin()
							 | 
						||
| 
								 
											8 years ago
										 
									 | 
							
								        CATransaction.setDisableActions(true)
							 | 
						||
| 
								 
											8 years ago
										 
									 | 
							
								
							 | 
						||
| 
								 
											9 years ago
										 
									 | 
							
								        let horizontalBarPath = UIBezierPath()
							 | 
						||
| 
								 | 
							
								        let horizontalBarHeightFraction = CGFloat(0.25)
							 | 
						||
| 
								 | 
							
								        let horizontalBarHeight = bounds.size.height * horizontalBarHeightFraction
							 | 
						||
| 
								 
											8 years ago
										 
									 | 
							
								        horizontalBarPath.append(UIBezierPath(rect: CGRect(x: 0, y: (bounds.size.height - horizontalBarHeight) * 0.5, width: bounds.size.width, height: horizontalBarHeight)))
							 | 
						||
| 
								 
											9 years ago
										 
									 | 
							
								        horizontalBarLayer.path = horizontalBarPath.cgPath
							 | 
						||
| 
								 | 
							
								        horizontalBarLayer.fillColor = horizontalBarColor.cgColor
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								        let progressHeight = bounds.self.height
							 | 
						||
| 
								 | 
							
								        let progressWidth = progressHeight * 0.15
							 | 
						||
| 
								 | 
							
								        let progressX = (bounds.self.width - progressWidth) * max(0.0, min(1.0, progress))
							 | 
						||
| 
								 
											8 years ago
										 
									 | 
							
								        let progressBounds = CGRect(x: progressX, y: 0, width: progressWidth, height: progressHeight)
							 | 
						||
| 
								 
											9 years ago
										 
									 | 
							
								        let progressCornerRadius = progressWidth * 0.5
							 | 
						||
| 
								 | 
							
								        let progressPath = UIBezierPath()
							 | 
						||
| 
								 | 
							
								        progressPath.append(UIBezierPath(roundedRect: progressBounds, cornerRadius: progressCornerRadius))
							 | 
						||
| 
								 | 
							
								        progressLayer.path = progressPath.cgPath
							 | 
						||
| 
								 | 
							
								        progressLayer.fillColor = progressColor.cgColor
							 | 
						||
| 
								 
											8 years ago
										 
									 | 
							
								
							 | 
						||
| 
								 | 
							
								        CATransaction.commit()
							 | 
						||
| 
								 
											9 years ago
										 
									 | 
							
								    }
							 | 
						||
| 
								 | 
							
								}
							 |