117 lines
3.7 KiB
Swift
117 lines
3.7 KiB
Swift
//
|
|
// PurchaseVerifyController.swift
|
|
// OpenVPN
|
|
//
|
|
// Created by Zhandos Bolatbekov on 23.08.2021.
|
|
// Copyright © 2021 Privado LLC. All rights reserved.
|
|
//
|
|
|
|
import UIKit
|
|
|
|
protocol PurchaseVerifyControllerInput: AnyObject {
|
|
func showLoader(_ show: Bool)
|
|
}
|
|
|
|
protocol PurchaseVerifyControllerOutput: AnyObject {
|
|
func viewIsReady()
|
|
}
|
|
|
|
final class PurchaseVerifyController: UIViewController, PurchaseVerifyControllerInput {
|
|
|
|
private enum Constants {
|
|
enum Color {
|
|
static let background = UIColor(rgb: 0x03072a).withAlphaComponent(0.9)
|
|
static let titleText = UIColor.white
|
|
}
|
|
enum Font {
|
|
static let title = UIFont(name: "SFProText-Regular", size: 21.3)
|
|
}
|
|
enum Geometry {
|
|
static let titleTop: CGFloat = 16
|
|
static let titleHorizontalOffset: CGFloat = 24
|
|
}
|
|
enum LocalizedString {
|
|
static let title = "purchaseVerify.title.processing"
|
|
}
|
|
}
|
|
|
|
private let output: PurchaseVerifyControllerOutput
|
|
|
|
private var activity: UIActivityIndicatorView?
|
|
|
|
// MARK: - Init
|
|
|
|
init(output: PurchaseVerifyControllerOutput) {
|
|
self.output = output
|
|
super.init(nibName: nil, bundle: nil)
|
|
}
|
|
|
|
required init?(coder: NSCoder) { nil }
|
|
|
|
// MARK: - Life-cycle
|
|
|
|
override func viewDidLoad() {
|
|
super.viewDidLoad()
|
|
self.configureUI()
|
|
self.output.viewIsReady()
|
|
}
|
|
|
|
// MARK: - PurchaseVerifyControllerInput
|
|
|
|
func showLoader(_ show: Bool) {
|
|
DispatchQueue.main.async { [weak self] in
|
|
show ? self?.activity?.startAnimating() : self?.activity?.stopAnimating()
|
|
}
|
|
}
|
|
|
|
// MARK: - Private
|
|
|
|
private func configureUI() {
|
|
self.view.backgroundColor = Constants.Color.background
|
|
|
|
var constraints = [NSLayoutConstraint]()
|
|
|
|
let activity = self.initActivityIndicator()
|
|
constraints.append(contentsOf: [
|
|
activity.centerXAnchor.constraint(equalTo: self.view.centerXAnchor),
|
|
activity.centerYAnchor.constraint(equalTo: self.view.centerYAnchor)
|
|
])
|
|
|
|
let label = self.initTitleLabel()
|
|
constraints.append(contentsOf: [
|
|
label.topAnchor.constraint(equalTo: activity.bottomAnchor,
|
|
constant: Constants.Geometry.titleTop),
|
|
label.centerXAnchor.constraint(equalTo: self.view.centerXAnchor),
|
|
label.leadingAnchor.constraint(equalTo: self.view.leadingAnchor,
|
|
constant: Constants.Geometry.titleHorizontalOffset),
|
|
label.trailingAnchor.constraint(equalTo: self.view.trailingAnchor,
|
|
constant: -Constants.Geometry.titleHorizontalOffset)
|
|
|
|
])
|
|
|
|
NSLayoutConstraint.activate(constraints)
|
|
}
|
|
|
|
private func initActivityIndicator() -> UIActivityIndicatorView {
|
|
let activity = UIActivityIndicatorView(style: .whiteLarge)
|
|
activity.hidesWhenStopped = true
|
|
activity.translatesAutoresizingMaskIntoConstraints = false
|
|
self.activity = activity
|
|
self.view.addSubview(activity)
|
|
return activity
|
|
}
|
|
|
|
private func initTitleLabel() -> UILabel {
|
|
let label = UILabel()
|
|
label.translatesAutoresizingMaskIntoConstraints = false
|
|
label.numberOfLines = 0
|
|
label.textColor = Constants.Color.titleText
|
|
label.font = Constants.Font.title
|
|
label.textAlignment = .center
|
|
label.text = NSLocalizedString(Constants.LocalizedString.title,
|
|
comment: "Processing subscription...")
|
|
self.view.addSubview(label)
|
|
return label
|
|
}
|
|
}
|