99 lines
3.8 KiB
Swift
99 lines
3.8 KiB
Swift
//
|
|
// SubscriptionsActiveTableViewCell.swift
|
|
// Earthquake Network
|
|
//
|
|
// Created by Busi Andrea on 30/07/2020.
|
|
// Copyright © 2020 Earthquake Network. All rights reserved.
|
|
//
|
|
|
|
import UIKit
|
|
import StoreKit
|
|
|
|
|
|
class SubscriptionsActiveTableViewCell: EQNBaseContainerTableViewCell {
|
|
|
|
override var headerText: String { NSLocalizedString("inapp_active", comment: "") }
|
|
|
|
var onTapRestore: () -> Void = { }
|
|
|
|
// MARK: - UI
|
|
|
|
private lazy var noSubscriptionsLabel: UILabel = {
|
|
let label = UILabel()
|
|
label.translatesAutoresizingMaskIntoConstraints = false
|
|
label.textColor = AppTheme.shared.cardTextColor
|
|
label.font = .preferredFont(forTextStyle: .body)
|
|
label.textAlignment = .center
|
|
label.numberOfLines = 0
|
|
return label
|
|
}()
|
|
|
|
private lazy var activeSubscriptionImageView: UIImageView = {
|
|
let imageView = UIImageView(frame: .zero)
|
|
imageView.translatesAutoresizingMaskIntoConstraints = false
|
|
imageView.contentMode = .scaleAspectFit
|
|
return imageView
|
|
}()
|
|
|
|
private lazy var restoreButton: UIButton = {
|
|
let button = UIButton(type: .system)
|
|
button.translatesAutoresizingMaskIntoConstraints = false
|
|
button.addTarget(self, action: #selector(restoreSubscriptionsTapped(_:)), for: .touchUpInside)
|
|
button.titleLabel?.font = .preferredFont(forTextStyle: .headline)
|
|
button.backgroundColor = .systemGroupedBackground
|
|
button.eqn_applyShadowAndRoundedCorners()
|
|
return button
|
|
}()
|
|
|
|
// MARK: - Internal
|
|
|
|
override func setupUI() {
|
|
super.setupUI()
|
|
|
|
let stackView = UIStackView(arrangedSubviews: [ activeSubscriptionImageView, noSubscriptionsLabel, restoreButton ])
|
|
stackView.translatesAutoresizingMaskIntoConstraints = false
|
|
stackView.alignment = .center
|
|
stackView.distribution = .equalSpacing
|
|
stackView.axis = .vertical
|
|
stackView.spacing = 20.0
|
|
containerView.addSubview(stackView)
|
|
|
|
activeSubscriptionImageView.widthAnchor.constraint(equalToConstant: 150.0).isActive = true
|
|
activeSubscriptionImageView.heightAnchor.constraint(equalToConstant: 50.0).isActive = true
|
|
restoreButton.heightAnchor.constraint(equalToConstant: 40.0).isActive = true
|
|
restoreButton.leadingAnchor.constraint(equalTo: stackView.leadingAnchor).isActive = true
|
|
restoreButton.trailingAnchor.constraint(equalTo: stackView.trailingAnchor).isActive = true
|
|
|
|
stackView.topAnchor.constraint(equalTo: topView.bottomAnchor, constant: .cardVerticalSpacing).isActive = true
|
|
stackView.leadingAnchor.constraint(equalTo: containerView.leadingAnchor, constant: .cardPadding).isActive = true
|
|
stackView.trailingAnchor.constraint(equalTo: containerView.trailingAnchor, constant: .cardPadding.negative).isActive = true
|
|
stackView.bottomAnchor.constraint(equalTo: containerView.bottomAnchor, constant: .cardVerticalSpacing.negative).isActive = true
|
|
}
|
|
|
|
override func updateUI() {
|
|
super.updateUI()
|
|
|
|
noSubscriptionsLabel.text = NSLocalizedString("inapp_nosub", comment: "")
|
|
restoreButton.setTitle(NSLocalizedString("purchase_pro_restore", comment: ""), for: .normal)
|
|
}
|
|
|
|
// MARK: - Actions
|
|
|
|
@objc private func restoreSubscriptionsTapped(_ sender: UIButton) {
|
|
onTapRestore()
|
|
}
|
|
|
|
// MARK: - Public
|
|
|
|
func update(with product: EQNInAppProducts?) {
|
|
if let product {
|
|
noSubscriptionsLabel.isHidden = true
|
|
activeSubscriptionImageView.isHidden = false
|
|
activeSubscriptionImageView.image = product.category.image
|
|
} else {
|
|
noSubscriptionsLabel.isHidden = false
|
|
activeSubscriptionImageView.isHidden = true
|
|
}
|
|
}
|
|
}
|