Files
Morgan Pretty 1b8d6ead1e Added in initial AppStore purchase logic, cleaned up some code
• Added in the actual Session Pro AppStore purchase call
• Cleaned up the SessionProManager interface
• Fixed an issue where enabling Session Pro wouldn't update the settings screen
• Fixed a few issues with performing UI actions on background threads (mentions "@You badge")
2025-12-02 16:22:11 +11:00

125 lines
4.0 KiB
Swift

// Copyright © 2025 Rangeproof Pty Ltd. All rights reserved.
import UIKit
public class SessionProBadge: UIView {
public static let accessibilityLabel: String = Constants.app_pro
public static let identifier: String = "ProBadge" // stringlint:ignore
public enum Size {
case mini, small, medium, large
// stringlint:ignore_contents
public var cacheKey: String {
switch self {
case .mini: return "SessionProBadge.Mini"
case .small: return "SessionProBadge.Small"
case .medium: return "SessionProBadge.Medium"
case .large: return "SessionProBadge.Large"
}
}
public var width: CGFloat {
switch self {
case .mini: return 24
case .small: return 32
case .medium: return 40
case .large: return 52
}
}
public var height: CGFloat {
switch self {
case .mini: return 11
case .small: return 14.5
case .medium: return 18
case .large: return 26
}
}
public var cornerRadius: CGFloat {
switch self {
case .mini: return 2.5
case .small: return 3.5
case .medium: return 4
case .large: return 6
}
}
public var proFontHeight: CGFloat {
switch self {
case .mini: return 5
case .small: return 6
case .medium: return 7
case .large: return 11
}
}
public var proFontWidth: CGFloat {
switch self {
case .mini: return 17
case .small: return 24
case .medium: return 28
case .large: return 40
}
}
}
public var size: Size {
didSet {
widthConstraint.constant = size.width
heightConstraint.constant = size.height
proImageWidthConstraint.constant = size.proFontWidth
proImageHeightConstraint.constant = size.proFontHeight
self.layer.cornerRadius = size.cornerRadius
}
}
// MARK: - Initialization
public init(size: Size, themeBackgroundColor: ThemeValue = .primary) {
self.size = size
super.init(frame: CGRect(x: 0, y: 0, width: size.width, height: size.height))
setUpViewHierarchy()
self.themeBackgroundColor = themeBackgroundColor
}
public override init(frame: CGRect) {
preconditionFailure("Use init(size:) instead.")
}
public required init?(coder: NSCoder) {
preconditionFailure("Use init(size:) instead.")
}
// MARK: - UI
private lazy var proImageView: UIImageView = {
let result: UIImageView = UIImageView(image: UIImage(named: "session_pro"))
result.contentMode = .scaleAspectFit
return result
}()
private var widthConstraint: NSLayoutConstraint!
private var heightConstraint: NSLayoutConstraint!
private var proImageWidthConstraint: NSLayoutConstraint!
private var proImageHeightConstraint: NSLayoutConstraint!
private func setUpViewHierarchy() {
self.addSubview(proImageView)
proImageHeightConstraint = proImageView.set(.height, to: self.size.proFontHeight)
proImageWidthConstraint = proImageView.set(.width, to: self.size.proFontWidth)
proImageView.center(in: self)
self.clipsToBounds = true
self.layer.cornerRadius = self.size.cornerRadius
widthConstraint = self.set(.width, to: self.size.width)
heightConstraint = self.set(.height, to: self.size.height)
self.proImageView.frame = CGRect(
x: (size.width - size.proFontWidth) / 2,
y: (size.height - size.proFontHeight) / 2,
width: size.proFontWidth,
height: size.proFontHeight
)
}
}