2019-09-03 21:58:07 -07:00
|
|
|
//
|
|
|
|
|
// AppBannerView.swift
|
|
|
|
|
// AltStore
|
|
|
|
|
//
|
|
|
|
|
// Created by Riley Testut on 8/29/19.
|
|
|
|
|
// Copyright © 2019 Riley Testut. All rights reserved.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
import UIKit
|
2020-09-03 16:39:08 -07:00
|
|
|
|
|
|
|
|
import AltStoreCore
|
2019-09-03 21:58:07 -07:00
|
|
|
import Roxas
|
|
|
|
|
|
2023-10-16 18:59:43 -05:00
|
|
|
extension AppBannerView
|
|
|
|
|
{
|
|
|
|
|
enum Style
|
|
|
|
|
{
|
|
|
|
|
case app
|
|
|
|
|
case source
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-03 21:58:07 -07:00
|
|
|
class AppBannerView: RSTNibView
|
|
|
|
|
{
|
2020-08-27 15:23:21 -07:00
|
|
|
override var accessibilityLabel: String? {
|
|
|
|
|
get { return self.accessibilityView?.accessibilityLabel }
|
|
|
|
|
set { self.accessibilityView?.accessibilityLabel = newValue }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override open var accessibilityAttributedLabel: NSAttributedString? {
|
|
|
|
|
get { return self.accessibilityView?.accessibilityAttributedLabel }
|
|
|
|
|
set { self.accessibilityView?.accessibilityAttributedLabel = newValue }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override var accessibilityValue: String? {
|
|
|
|
|
get { return self.accessibilityView?.accessibilityValue }
|
|
|
|
|
set { self.accessibilityView?.accessibilityValue = newValue }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override open var accessibilityAttributedValue: NSAttributedString? {
|
|
|
|
|
get { return self.accessibilityView?.accessibilityAttributedValue }
|
|
|
|
|
set { self.accessibilityView?.accessibilityAttributedValue = newValue }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override open var accessibilityTraits: UIAccessibilityTraits {
|
|
|
|
|
get { return self.accessibilityView?.accessibilityTraits ?? [] }
|
|
|
|
|
set { self.accessibilityView?.accessibilityTraits = newValue }
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-16 18:59:43 -05:00
|
|
|
var style: Style = .app
|
|
|
|
|
|
2019-11-04 12:32:36 -08:00
|
|
|
private var originalTintColor: UIColor?
|
|
|
|
|
|
2019-09-03 21:58:07 -07:00
|
|
|
@IBOutlet var titleLabel: UILabel!
|
|
|
|
|
@IBOutlet var subtitleLabel: UILabel!
|
|
|
|
|
@IBOutlet var iconImageView: AppIconImageView!
|
|
|
|
|
@IBOutlet var button: PillButton!
|
2019-10-23 13:32:17 -07:00
|
|
|
@IBOutlet var buttonLabel: UILabel!
|
2019-09-03 21:58:07 -07:00
|
|
|
@IBOutlet var betaBadgeView: UIView!
|
|
|
|
|
|
2019-10-23 13:32:17 -07:00
|
|
|
@IBOutlet var backgroundEffectView: UIVisualEffectView!
|
2020-08-27 15:23:21 -07:00
|
|
|
|
2019-10-23 13:32:17 -07:00
|
|
|
@IBOutlet private var vibrancyView: UIVisualEffectView!
|
2023-10-16 18:59:43 -05:00
|
|
|
@IBOutlet private var stackView: UIStackView!
|
2020-08-27 15:23:21 -07:00
|
|
|
@IBOutlet private var accessibilityView: UIView!
|
|
|
|
|
|
2023-10-16 18:59:43 -05:00
|
|
|
@IBOutlet private var iconImageViewHeightConstraint: NSLayoutConstraint!
|
|
|
|
|
|
2020-08-27 15:23:21 -07:00
|
|
|
override init(frame: CGRect)
|
|
|
|
|
{
|
|
|
|
|
super.init(frame: frame)
|
|
|
|
|
|
|
|
|
|
self.initialize()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
required init?(coder: NSCoder)
|
|
|
|
|
{
|
|
|
|
|
super.init(coder: coder)
|
|
|
|
|
|
|
|
|
|
self.initialize()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private func initialize()
|
|
|
|
|
{
|
|
|
|
|
self.accessibilityView.accessibilityTraits.formUnion(.button)
|
|
|
|
|
|
|
|
|
|
self.isAccessibilityElement = false
|
|
|
|
|
self.accessibilityElements = [self.accessibilityView, self.button].compactMap { $0 }
|
|
|
|
|
|
|
|
|
|
self.betaBadgeView.isHidden = true
|
2023-10-16 18:59:43 -05:00
|
|
|
|
|
|
|
|
self.layoutMargins = self.stackView.layoutMargins
|
|
|
|
|
self.stackView.preservesSuperviewLayoutMargins = true
|
|
|
|
|
self.stackView.isLayoutMarginsRelativeArrangement = true
|
2020-08-27 15:23:21 -07:00
|
|
|
}
|
2019-10-23 13:32:17 -07:00
|
|
|
|
2019-09-03 21:58:07 -07:00
|
|
|
override func tintColorDidChange()
|
|
|
|
|
{
|
|
|
|
|
super.tintColorDidChange()
|
|
|
|
|
|
2019-11-04 12:32:36 -08:00
|
|
|
if self.tintAdjustmentMode != .dimmed
|
|
|
|
|
{
|
|
|
|
|
self.originalTintColor = self.tintColor
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-03 21:58:07 -07:00
|
|
|
self.update()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-27 15:23:21 -07:00
|
|
|
extension AppBannerView
|
|
|
|
|
{
|
|
|
|
|
func configure(for app: AppProtocol)
|
|
|
|
|
{
|
|
|
|
|
struct AppValues
|
|
|
|
|
{
|
|
|
|
|
var name: String
|
|
|
|
|
var developerName: String? = nil
|
|
|
|
|
var isBeta: Bool = false
|
|
|
|
|
|
|
|
|
|
init(app: AppProtocol)
|
|
|
|
|
{
|
|
|
|
|
self.name = app.name
|
|
|
|
|
|
|
|
|
|
guard let storeApp = (app as? StoreApp) ?? (app as? InstalledApp)?.storeApp else { return }
|
|
|
|
|
self.developerName = storeApp.developerName
|
|
|
|
|
|
|
|
|
|
if storeApp.isBeta
|
|
|
|
|
{
|
|
|
|
|
self.name = String(format: NSLocalizedString("%@ beta", comment: ""), app.name)
|
|
|
|
|
self.isBeta = true
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let values = AppValues(app: app)
|
|
|
|
|
self.titleLabel.text = app.name // Don't use values.name since that already includes "beta".
|
|
|
|
|
self.betaBadgeView.isHidden = !values.isBeta
|
|
|
|
|
|
|
|
|
|
if let developerName = values.developerName
|
|
|
|
|
{
|
|
|
|
|
self.subtitleLabel.text = developerName
|
|
|
|
|
self.accessibilityLabel = String(format: NSLocalizedString("%@ by %@", comment: ""), values.name, developerName)
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
self.subtitleLabel.text = NSLocalizedString("Sideloaded", comment: "")
|
|
|
|
|
self.accessibilityLabel = values.name
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-03 21:58:07 -07:00
|
|
|
private extension AppBannerView
|
|
|
|
|
{
|
|
|
|
|
func update()
|
|
|
|
|
{
|
|
|
|
|
self.clipsToBounds = true
|
|
|
|
|
self.layer.cornerRadius = 22
|
|
|
|
|
|
2023-10-16 18:59:43 -05:00
|
|
|
let tintColor = self.originalTintColor ?? self.tintColor
|
|
|
|
|
self.subtitleLabel.textColor = tintColor
|
|
|
|
|
|
|
|
|
|
switch self.style
|
|
|
|
|
{
|
|
|
|
|
case .app:
|
|
|
|
|
self.iconImageViewHeightConstraint.constant = 60
|
|
|
|
|
self.iconImageView.style = .icon
|
|
|
|
|
|
|
|
|
|
self.titleLabel.textColor = .label
|
|
|
|
|
|
|
|
|
|
self.backgroundEffectView.contentView.backgroundColor = UIColor(resource: .blurTint)
|
|
|
|
|
self.backgroundEffectView.backgroundColor = tintColor
|
|
|
|
|
|
|
|
|
|
case .source:
|
|
|
|
|
self.iconImageViewHeightConstraint.constant = 44
|
|
|
|
|
self.iconImageView.style = .circular
|
|
|
|
|
|
|
|
|
|
self.titleLabel.textColor = .white
|
|
|
|
|
|
|
|
|
|
self.backgroundEffectView.contentView.backgroundColor = tintColor?.adjustedForDisplay
|
|
|
|
|
self.backgroundEffectView.backgroundColor = nil
|
|
|
|
|
|
|
|
|
|
if let tintColor, tintColor.isTooBright
|
|
|
|
|
{
|
|
|
|
|
let textVibrancyEffect = UIVibrancyEffect(blurEffect: .init(style: .systemChromeMaterialLight), style: .fill)
|
|
|
|
|
self.vibrancyView.effect = textVibrancyEffect
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// Thinner == more dull
|
|
|
|
|
let textVibrancyEffect = UIVibrancyEffect(blurEffect: .init(style: .systemThinMaterialDark), style: .secondaryLabel)
|
|
|
|
|
self.vibrancyView.effect = textVibrancyEffect
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-09-03 21:58:07 -07:00
|
|
|
}
|
|
|
|
|
}
|