// // NotificationsBellModuleViewIPAD.swift // PrivadoVPN // // Created by Zhandos Bolatbekov on 08.07.2021. // Copyright © 2021 Privado LLC. All rights reserved. // import UIKit final class NotificationsBellModuleViewIPAD: UIButton, NotificationsBellViewInput { private enum Constants { enum ImageName { static let highlightedBell = "notificationBell.light.ipad" static let bell = "notificationBell.ipad" } enum Color { static let badgeFill = UIColor(rgb: 0xFF0000) } enum Geometry { static let badgeSize: CGFloat = 7.5 static let badgeTop: CGFloat = 7.51 static let badgeTrailing: CGFloat = 9.41 static let bellSize: CGFloat = 34 } } var output: NotificationsBellModuleOutput private var bellImageView: UIImageView? private var badgeView: UIView? // MARK: - Init init(output: NotificationsBellModuleOutput) { self.output = output super.init(frame: .zero) self.configureUI() self.addTarget(self, action: #selector(self.notificationsButtonClick), for: .touchUpInside) } required init?(coder: NSCoder) { nil } override func didMoveToSuperview() { super.didMoveToSuperview() self.output.viewIsReady() } // MARK: - NotificationsBellViewInput func showBadge(_ show: Bool) { self.badgeView?.isHidden = !show } func set(highlighted: Bool) { self.bellImageView?.image = UIImage(named: highlighted ? Constants.ImageName.highlightedBell : Constants.ImageName.bell) } // MARK: - Private private func configureUI() { self.translatesAutoresizingMaskIntoConstraints = false let bellImageView = self.initializeBell() NSLayoutConstraint.activate([ bellImageView.heightAnchor.constraint(equalToConstant: Constants.Geometry.bellSize), bellImageView.widthAnchor.constraint(equalToConstant: Constants.Geometry.bellSize), bellImageView.centerXAnchor.constraint(equalTo: self.centerXAnchor), bellImageView.centerYAnchor.constraint(equalTo: self.centerYAnchor) ]) let badgeView = self.initializeBadge() NSLayoutConstraint.activate([ badgeView.topAnchor.constraint(equalTo: bellImageView.topAnchor, constant: Constants.Geometry.badgeTop), badgeView.rightAnchor.constraint(equalTo: bellImageView.rightAnchor, constant: -Constants.Geometry.badgeTrailing), badgeView.heightAnchor.constraint(equalToConstant: Constants.Geometry.badgeSize), badgeView.widthAnchor.constraint(equalToConstant: Constants.Geometry.badgeSize) ]) } private func initializeBell() -> UIImageView { let bellImage = UIImage(named: Constants.ImageName.bell) let bellImageView = UIImageView(image: bellImage) bellImageView.translatesAutoresizingMaskIntoConstraints = false self.addSubview(bellImageView) self.bellImageView = bellImageView return bellImageView } private func initializeBadge() -> UIView { let view = UIView() view.translatesAutoresizingMaskIntoConstraints = false view.layer.cornerRadius = Constants.Geometry.badgeSize / 2 view.layer.backgroundColor = Constants.Color.badgeFill.cgColor view.clipsToBounds = true view.isHidden = true self.addSubview(view) self.badgeView = view return view } @objc private func notificationsButtonClick() { self.output.openNotificationsList() } }