81 lines
2.7 KiB
Swift
81 lines
2.7 KiB
Swift
//
|
|
// ModalPresenter.swift
|
|
// PrivadoVPN
|
|
//
|
|
// Created by Juraldinio on 4/15/21.
|
|
// Copyright © 2021 Privado LLC. All rights reserved.
|
|
//
|
|
|
|
import Foundation
|
|
|
|
protocol ModalModuleOutput: AnyObject {
|
|
func openUrl(url: URL)
|
|
}
|
|
|
|
protocol ModalModuleInput {
|
|
var isModalVisible: Bool { get }
|
|
func showModal(settings: Route.ModalSettings)
|
|
func hide()
|
|
}
|
|
// swiftlint:enable function_parameter_count
|
|
|
|
final class ModalPresenter {
|
|
|
|
private weak var output: ModalModuleOutput?
|
|
private let viewInput: ModalControllerInput
|
|
private var actionUrl: URL?
|
|
|
|
init(viewInput: ModalControllerInput, output: ModalModuleOutput?) {
|
|
self.viewInput = viewInput
|
|
self.output = output
|
|
}
|
|
}
|
|
|
|
// MARK: - ModalModuleInput
|
|
|
|
extension ModalPresenter: ModalModuleInput {
|
|
|
|
var isModalVisible: Bool { self.viewInput.modalIsVisible }
|
|
|
|
func showModal(settings: Route.ModalSettings) {
|
|
|
|
self.viewInput.modalShow()
|
|
|
|
switch settings {
|
|
case let .image(named: image, title: title, buttonTitle: buttonTitle, action: action):
|
|
self.actionUrl = action
|
|
self.viewInput.modalUpdate(closable: true, imageName: image, title: title, description: "", action: buttonTitle)
|
|
case let .modalNotification(closable: closable, title: title):
|
|
self.viewInput.modalUpdate(closable: closable, imageName: nil, title: nil, description: title, action: nil)
|
|
case let .modal(title: title, description: description, buttonTitle: buttonTitle, action: action):
|
|
self.actionUrl = action
|
|
self.viewInput.modalUpdate(closable: false, imageName: nil, title: title, description: description, action: buttonTitle)
|
|
case let .closable(title: title, description: description, buttonTitle: buttonTitle, action: action):
|
|
self.actionUrl = action
|
|
self.viewInput.modalUpdate(closable: true, imageName: nil, title: title, description: description, action: buttonTitle)
|
|
}
|
|
}
|
|
|
|
func hide() {
|
|
self.viewInput.modalHide()
|
|
}
|
|
|
|
}
|
|
|
|
// MARK: - ModalControllerOutput
|
|
|
|
extension ModalPresenter: ModalControllerOutput {
|
|
|
|
func modalControllerClose(_ controller: ModalControllerInput) {
|
|
self.viewInput.modalHide()
|
|
}
|
|
|
|
func modalControllerAction(_ controller: ModalControllerInput) {
|
|
guard let url = self.actionUrl, let output = self.output else { return }
|
|
CometLogger.shared.event(name: PrivadoConstants.Event.Statistic.Application.upgradeButton,
|
|
attributes: [ PrivadoConstants.Event.Attributes.extradata: [ PrivadoConstants.Event.Attributes.screenId: PrivadoConstants.Event.Screen.overlay ] ],
|
|
secured: nil)
|
|
output.openUrl(url: url)
|
|
}
|
|
}
|