72 lines
1.9 KiB
Swift
72 lines
1.9 KiB
Swift
//
|
|
// ModalPresenter.swift
|
|
// PrivadoVPN
|
|
//
|
|
// Created by Zhandos Bolatbekov on 23.09.2021.
|
|
// Copyright © 2021 Privado LLC. All rights reserved.
|
|
//
|
|
|
|
import Foundation
|
|
|
|
protocol ModalModuleInput: AnyObject {
|
|
var isModalVisible: Bool { get }
|
|
|
|
func showModal(settings: Route.ModalSettings)
|
|
}
|
|
|
|
protocol ModalModuleOutput: AnyObject {
|
|
func openURL(_ url: URL)
|
|
func modalClose()
|
|
}
|
|
|
|
final class ModalPresenter {
|
|
|
|
// MARK: - Properties
|
|
|
|
private weak var output: ModalModuleOutput?
|
|
weak var viewInput: ModalControllerInput?
|
|
private var actionUrl: URL?
|
|
|
|
// MARK: - Init
|
|
|
|
init(output: ModalModuleOutput?) {
|
|
self.output = output
|
|
}
|
|
}
|
|
|
|
// MARK: - ModalControllerOutput
|
|
|
|
extension ModalPresenter: ModalControllerOutput {
|
|
|
|
func didTapClose() {
|
|
self.output?.modalClose()
|
|
}
|
|
|
|
func didTapAction() {
|
|
guard let url = self.actionUrl, let output = self.output else { return }
|
|
|
|
// This modal is summoned after premium server click
|
|
let extradata = CTAClick(screenType: CTAScreenType.serversList).jsonString
|
|
CometLogger.shared.event(name: PrivadoConstants.Event.Statistic.Application.CTAClick, attributes: [PrivadoConstants.Event.Attributes.extradata: extradata], secured: nil)
|
|
|
|
self.output?.modalClose()
|
|
output.openURL(url)
|
|
}
|
|
}
|
|
|
|
// MARK: - ModalModuleInput
|
|
|
|
extension ModalPresenter: ModalModuleInput {
|
|
|
|
var isModalVisible: Bool { self.viewInput?.modalIsVisible ?? false }
|
|
|
|
func showModal(settings: Route.ModalSettings) {
|
|
|
|
self.actionUrl = settings.action
|
|
self.viewInput?.modalUpdate(closable: settings.type == .closable,
|
|
imageName: nil, title: settings.title,
|
|
description: settings.description,
|
|
action: settings.buttonTitle)
|
|
}
|
|
}
|