Files
2021-10-25 18:51:34 +03:00

166 lines
6.8 KiB
Swift

//
// LaunchScreenController.swift
// PrivadoVPN
//
// Created by Viktor on 09.12.2020.
// Copyright © 2020 Privado LLC. All rights reserved.
//
import Foundation
import UIKit
final class LaunchScreenController: UIViewController {
private enum Constants {
static let top: CGFloat = 45
static let left: CGFloat = 34
static let right: CGFloat = 6
static let bottom: CGFloat = 6
static let bottomView: CGFloat = 106
static let bottomButtonH: CGFloat = 32
static let bottomButtonV: CGFloat = 23
}
private let output: LaunchScreenControllerOutput
private let content: UITextView = {
let webview = UITextView()
webview.isEditable = false
webview.isSelectable = false
webview.backgroundColor = .clear
return webview
}()
private let bottomView: UIView = {
let bottom = UIView()
bottom.backgroundColor = UIColor(red: 25, green: 33, blue: 71)
return bottom
}()
private let bottomButton: UIButton = {
let button = UIButton()
button.backgroundColor = UIColor(red: 40, green: 215, blue: 153)
button.roundCorners(corners: [.layerMinXMinYCorner, .layerMaxXMinYCorner, .layerMinXMaxYCorner, .layerMaxXMaxYCorner], radius: 33)
return button
}()
// MARK: - Init
init(output: LaunchScreenControllerOutput) {
self.output = output
super.init(nibName: nil, bundle: nil)
}
override func loadView() {
let view = UIView(frame: .zero)
view.autoresizesSubviews = true
view.translatesAutoresizingMaskIntoConstraints = false
view.backgroundColor = .white
self.view = view
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
// MARK: - Lyfecycle
override func viewDidLoad() {
super.viewDidLoad()
self.configureUI()
self.output.viewIsReady()
}
override var preferredStatusBarStyle: UIStatusBarStyle {
return .lightContent // .default
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
if let superview = self.view.superview {
NSLayoutConstraint.activate([
self.view.topAnchor.constraint(equalTo: superview.topAnchor),
self.view.leadingAnchor.constraint(equalTo: superview.leadingAnchor),
self.view.trailingAnchor.constraint(equalTo: superview.trailingAnchor),
self.view.bottomAnchor.constraint(equalTo: superview.bottomAnchor)
])
}
}
// MARK: - UI
private func configureUI() {
self.view.backgroundColor = UIColor(red: 21, green: 25, blue: 53)
self.bottomView.translatesAutoresizingMaskIntoConstraints = false
self.view.addSubview(self.bottomView)
NSLayoutConstraint.activate([
self.bottomView.leadingAnchor.constraint(equalTo: self.view.leadingAnchor),
self.bottomView.trailingAnchor.constraint(equalTo: self.view.trailingAnchor),
self.bottomView.bottomAnchor.constraint(equalTo: self.view.bottomAnchor),
self.bottomView.heightAnchor.constraint(equalToConstant: Constants.bottomView)
])
self.bottomButton.translatesAutoresizingMaskIntoConstraints = false
self.bottomView.addSubview(self.bottomButton)
NSLayoutConstraint.activate([
self.bottomButton.leadingAnchor.constraint(equalTo: self.bottomView.leadingAnchor, constant: Constants.bottomButtonH),
self.bottomButton.trailingAnchor.constraint(equalTo: self.bottomView.trailingAnchor, constant: -Constants.bottomButtonH),
self.bottomButton.topAnchor.constraint(equalTo: self.bottomView.topAnchor, constant: Constants.bottomButtonV),
self.bottomButton.bottomAnchor.constraint(equalTo: self.bottomView.bottomAnchor, constant: -Constants.bottomButtonV)
])
let buttonTitle = NSAttributedString(string: "AGREE & CONTINUE", attributes: [
.font: UIFont.boldSystemFont(ofSize: 21),
.foregroundColor: UIColor.white
])
self.bottomButton.setAttributedTitle(buttonTitle, for: .normal)
self.bottomButton.addTarget(self, action: #selector(buttonClick), for: .touchUpInside)
self.content.translatesAutoresizingMaskIntoConstraints = false
self.view.addSubview(self.content)
NSLayoutConstraint.activate([
self.content.leadingAnchor.constraint(equalTo: self.view.leadingAnchor, constant: Constants.left),
self.content.trailingAnchor.constraint(equalTo: self.view.trailingAnchor, constant: -Constants.right),
self.content.topAnchor.constraint(equalTo: self.view.topAnchor, constant: Constants.top),
self.content.bottomAnchor.constraint(equalTo: self.bottomView.topAnchor, constant: -Constants.bottom)
])
let attributedString = NSMutableAttributedString(string: NSLocalizedString("launch.content", comment: "Content of First Start"), attributes: [
.font: UIFont.systemFont(ofSize: 16.67, weight: .regular),
.foregroundColor: UIColor(red: 122.0 / 255.0, green: 133.0 / 255.0, blue: 190.0 / 255.0, alpha: 1.0),
.kern: -0.83
])
attributedString.addAttribute(.font, value: UIFont.systemFont(ofSize: 16.67, weight: .bold), range: NSRange(location: 147, length: 22))
attributedString.addAttribute(.font, value: UIFont.systemFont(ofSize: 16.67, weight: .bold), range: NSRange(location: 302, length: 26))
attributedString.addAttribute(.font, value: UIFont.systemFont(ofSize: 16.67, weight: .bold), range: NSRange(location: 334, length: 6))
attributedString.addAttribute(.font, value: UIFont.systemFont(ofSize: 16.67, weight: .bold), range: NSRange(location: 501, length: 21))
attributedString.addAttribute(.font, value: UIFont.systemFont(ofSize: 16.67, weight: .bold), range: NSRange(location: 364+290, length: 46))
attributedString.addAttribute(.font, value: UIFont.systemFont(ofSize: 16.67, weight: .bold), range: NSRange(location: 477+291, length: 56))
attributedString.addAttribute(.font, value: UIFont.systemFont(ofSize: 16.67, weight: .bold), range: NSRange(location: 477+397, length: 71))
let titleAttributedString = NSMutableAttributedString(string: NSLocalizedString("launch.top", comment: "Title") + "\n\n", attributes: [
.font: UIFont.systemFont(ofSize: 30, weight: .regular),
.foregroundColor: UIColor.white
])
titleAttributedString.append(attributedString)
self.content.attributedText = titleAttributedString
self.content.contentOffset = .zero
}
@objc
func buttonClick() {
self.output.agreeClick()
}
}