2023-08-24 14:18:04 -07:00
|
|
|
//
|
|
|
|
|
// Copyright RevenueCat Inc. All Rights Reserved.
|
|
|
|
|
//
|
|
|
|
|
// Licensed under the MIT License (the "License");
|
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
|
//
|
|
|
|
|
// https://opensource.org/licenses/MIT
|
|
|
|
|
//
|
|
|
|
|
// ProcessedLocalizedConfiguration.swift
|
|
|
|
|
|
2023-07-21 06:52:48 +02:00
|
|
|
import Foundation
|
2023-07-12 21:35:35 -07:00
|
|
|
import RevenueCat
|
|
|
|
|
|
|
|
|
|
/// A `PaywallData.LocalizedConfiguration` with processed variables
|
2023-11-08 07:35:19 -08:00
|
|
|
@available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, *)
|
2023-07-12 21:35:35 -07:00
|
|
|
struct ProcessedLocalizedConfiguration: PaywallLocalizedConfiguration {
|
|
|
|
|
|
2023-07-28 00:13:33 +02:00
|
|
|
typealias Feature = PaywallData.LocalizedConfiguration.Feature
|
|
|
|
|
|
2023-07-12 21:35:35 -07:00
|
|
|
var title: String
|
2023-07-28 00:14:23 +02:00
|
|
|
var subtitle: String?
|
2023-07-12 21:35:35 -07:00
|
|
|
var callToAction: String
|
2023-07-13 14:03:00 -07:00
|
|
|
var callToActionWithIntroOffer: String?
|
2023-08-03 13:23:59 -07:00
|
|
|
var offerDetails: String?
|
2023-07-13 14:03:00 -07:00
|
|
|
var offerDetailsWithIntroOffer: String?
|
2023-07-26 12:48:52 +02:00
|
|
|
var offerName: String?
|
2024-07-17 07:04:42 -05:00
|
|
|
var offerBadge: String?
|
2023-07-28 00:13:33 +02:00
|
|
|
var features: [Feature]
|
2024-07-01 12:37:21 -07:00
|
|
|
var tierName: String?
|
2024-08-20 09:44:27 -05:00
|
|
|
var locale: Locale
|
2023-07-12 21:35:35 -07:00
|
|
|
|
|
|
|
|
init(
|
|
|
|
|
_ configuration: PaywallData.LocalizedConfiguration,
|
2023-07-21 06:52:48 +02:00
|
|
|
_ dataProvider: VariableDataProvider,
|
2023-09-08 12:57:34 -07:00
|
|
|
_ context: VariableHandler.Context,
|
2023-07-21 06:52:48 +02:00
|
|
|
_ locale: Locale
|
2023-07-12 21:35:35 -07:00
|
|
|
) {
|
2024-07-17 07:04:42 -05:00
|
|
|
let packageIdentifier = dataProvider.packageIdentifier
|
|
|
|
|
let offerOverrides = configuration.offerOverrides[packageIdentifier]
|
|
|
|
|
|
|
|
|
|
let offerDetails = offerOverrides?.offerDetails ?? configuration.offerDetails
|
|
|
|
|
let offerDetailsWithIntroOffer = offerOverrides?.offerDetailsWithIntroOffer
|
|
|
|
|
?? configuration.offerDetailsWithIntroOffer
|
|
|
|
|
let offerName = offerOverrides?.offerName ?? configuration.offerName
|
|
|
|
|
|
|
|
|
|
let offerBadge: String?
|
|
|
|
|
if let offerOverrides {
|
|
|
|
|
offerBadge = offerOverrides.offerBadge
|
|
|
|
|
} else if let discount = context.discountRelativeToMostExpensivePerMonth {
|
|
|
|
|
offerBadge = dataProvider.localizedRelativeDiscount(discount, locale)
|
|
|
|
|
} else {
|
|
|
|
|
offerBadge = nil
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-12 21:35:35 -07:00
|
|
|
self.init(
|
2023-09-08 12:57:34 -07:00
|
|
|
title: configuration.title.processed(with: dataProvider, context: context, locale: locale),
|
|
|
|
|
subtitle: configuration.subtitle?.processed(with: dataProvider, context: context, locale: locale),
|
|
|
|
|
callToAction: configuration.callToAction.processed(with: dataProvider, context: context, locale: locale),
|
2023-07-21 06:52:48 +02:00
|
|
|
callToActionWithIntroOffer: configuration.callToActionWithIntroOffer?.processed(with: dataProvider,
|
2023-09-08 12:57:34 -07:00
|
|
|
context: context,
|
2023-07-21 06:52:48 +02:00
|
|
|
locale: locale),
|
2024-07-17 07:04:42 -05:00
|
|
|
offerDetails: offerDetails?.processed(with: dataProvider, context: context, locale: locale),
|
|
|
|
|
offerDetailsWithIntroOffer: offerDetailsWithIntroOffer?.processed(with: dataProvider,
|
|
|
|
|
|
|
|
|
|
context: context,
|
|
|
|
|
|
|
|
|
|
locale: locale),
|
|
|
|
|
offerName: offerName?.processed(with: dataProvider, context: context, locale: locale),
|
|
|
|
|
offerBadge: offerBadge?.processed(with: dataProvider, context: context, locale: locale),
|
2023-07-28 00:13:33 +02:00
|
|
|
features: configuration.features.map {
|
2023-09-08 12:57:34 -07:00
|
|
|
.init(title: $0.title.processed(with: dataProvider, context: context, locale: locale),
|
|
|
|
|
content: $0.content?.processed(with: dataProvider, context: context, locale: locale),
|
2023-07-28 00:13:33 +02:00
|
|
|
iconID: $0.iconID)
|
2024-07-01 12:37:21 -07:00
|
|
|
},
|
2024-08-20 09:44:27 -05:00
|
|
|
tierName: configuration.tierName,
|
|
|
|
|
locale: locale
|
2023-07-12 21:35:35 -07:00
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-13 10:08:22 -07:00
|
|
|
private init(
|
|
|
|
|
title: String,
|
2023-07-28 00:14:23 +02:00
|
|
|
subtitle: String?,
|
2023-07-13 10:08:22 -07:00
|
|
|
callToAction: String,
|
2023-07-13 14:03:00 -07:00
|
|
|
callToActionWithIntroOffer: String?,
|
2023-08-03 13:23:59 -07:00
|
|
|
offerDetails: String?,
|
2023-07-26 12:48:52 +02:00
|
|
|
offerDetailsWithIntroOffer: String?,
|
2023-07-28 00:13:33 +02:00
|
|
|
offerName: String?,
|
2024-07-17 07:04:42 -05:00
|
|
|
offerBadge: String?,
|
2024-07-01 12:37:21 -07:00
|
|
|
features: [Feature],
|
2024-08-20 09:44:27 -05:00
|
|
|
tierName: String?,
|
|
|
|
|
locale: Locale
|
2023-07-13 10:08:22 -07:00
|
|
|
) {
|
2023-07-12 21:35:35 -07:00
|
|
|
self.title = title
|
|
|
|
|
self.subtitle = subtitle
|
|
|
|
|
self.callToAction = callToAction
|
2023-07-13 10:08:22 -07:00
|
|
|
self.callToActionWithIntroOffer = callToActionWithIntroOffer
|
2023-07-12 21:35:35 -07:00
|
|
|
self.offerDetails = offerDetails
|
2023-07-13 10:08:22 -07:00
|
|
|
self.offerDetailsWithIntroOffer = offerDetailsWithIntroOffer
|
2023-07-26 12:48:52 +02:00
|
|
|
self.offerName = offerName
|
2024-07-17 07:04:42 -05:00
|
|
|
self.offerBadge = offerBadge
|
2023-07-28 00:13:33 +02:00
|
|
|
self.features = features
|
2024-07-01 12:37:21 -07:00
|
|
|
self.tierName = tierName
|
2024-08-20 09:44:27 -05:00
|
|
|
self.locale = locale
|
2023-07-12 21:35:35 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
2023-07-24 14:41:43 +02:00
|
|
|
|
2023-11-08 07:35:19 -08:00
|
|
|
@available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, *)
|
2023-07-24 14:41:43 +02:00
|
|
|
extension ProcessedLocalizedConfiguration: Equatable {}
|