mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-23 06:35:51 +00:00
Ads toggle for premium users
This commit is contained in:
@@ -11891,3 +11891,4 @@ Sorry for the inconvenience.";
|
|||||||
"Business.AdsTitle" = "ADS IN CHANNELS";
|
"Business.AdsTitle" = "ADS IN CHANNELS";
|
||||||
"Business.DontHideAds" = "Do Not Hide Ads";
|
"Business.DontHideAds" = "Do Not Hide Ads";
|
||||||
"Business.AdsInfo" = "As a Premium subscriber, you don't see any ads on Telegram, but you can turn them on, for example, to view your own ads that you launched on the [Telegram Ad Platform >]()";
|
"Business.AdsInfo" = "As a Premium subscriber, you don't see any ads on Telegram, but you can turn them on, for example, to view your own ads that you launched on the [Telegram Ad Platform >]()";
|
||||||
|
"Business.AdsInfo_URL" = "https://promote.telegram.org";
|
||||||
|
|||||||
@@ -1463,6 +1463,7 @@ private final class PremiumIntroScreenContentComponent: CombinedComponent {
|
|||||||
|
|
||||||
var isPremium: Bool?
|
var isPremium: Bool?
|
||||||
var peer: EnginePeer?
|
var peer: EnginePeer?
|
||||||
|
var adsEnabled = false
|
||||||
|
|
||||||
private var disposable: Disposable?
|
private var disposable: Disposable?
|
||||||
private(set) var configuration = PremiumIntroConfiguration.defaultValue
|
private(set) var configuration = PremiumIntroConfiguration.defaultValue
|
||||||
@@ -1470,6 +1471,7 @@ private final class PremiumIntroScreenContentComponent: CombinedComponent {
|
|||||||
private var stickersDisposable: Disposable?
|
private var stickersDisposable: Disposable?
|
||||||
private var newPerksDisposable: Disposable?
|
private var newPerksDisposable: Disposable?
|
||||||
private var preloadDisposableSet = DisposableSet()
|
private var preloadDisposableSet = DisposableSet()
|
||||||
|
private var adsEnabledDisposable: Disposable?
|
||||||
|
|
||||||
var price: String? {
|
var price: String? {
|
||||||
return self.products?.first(where: { $0.id == self.selectedProductId })?.price
|
return self.products?.first(where: { $0.id == self.selectedProductId })?.price
|
||||||
@@ -1491,6 +1493,8 @@ private final class PremiumIntroScreenContentComponent: CombinedComponent {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var cachedChevronImage: (UIImage, PresentationTheme)?
|
||||||
|
|
||||||
init(
|
init(
|
||||||
context: AccountContext,
|
context: AccountContext,
|
||||||
source: PremiumSource,
|
source: PremiumSource,
|
||||||
@@ -1581,6 +1585,15 @@ private final class PremiumIntroScreenContentComponent: CombinedComponent {
|
|||||||
self.newPerks = newPerks
|
self.newPerks = newPerks
|
||||||
self.updated()
|
self.updated()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
self.adsEnabledDisposable = (context.engine.data.subscribe(TelegramEngine.EngineData.Item.Peer.AdsEnabled(id: context.account.peerId))
|
||||||
|
|> deliverOnMainQueue).start(next: { [weak self] adsEnabled in
|
||||||
|
guard let self else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
self.adsEnabled = adsEnabled
|
||||||
|
self.updated()
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
deinit {
|
deinit {
|
||||||
@@ -1588,6 +1601,7 @@ private final class PremiumIntroScreenContentComponent: CombinedComponent {
|
|||||||
self.preloadDisposableSet.dispose()
|
self.preloadDisposableSet.dispose()
|
||||||
self.stickersDisposable?.dispose()
|
self.stickersDisposable?.dispose()
|
||||||
self.newPerksDisposable?.dispose()
|
self.newPerksDisposable?.dispose()
|
||||||
|
self.adsEnabledDisposable?.dispose()
|
||||||
}
|
}
|
||||||
|
|
||||||
private var updatedPeerStatus: PeerEmojiStatus?
|
private var updatedPeerStatus: PeerEmojiStatus?
|
||||||
@@ -2491,13 +2505,27 @@ private final class PremiumIntroScreenContentComponent: CombinedComponent {
|
|||||||
maximumNumberOfLines: 1
|
maximumNumberOfLines: 1
|
||||||
))),
|
))),
|
||||||
], alignment: .left, spacing: 2.0)),
|
], alignment: .left, spacing: 2.0)),
|
||||||
accessory: .toggle(ListActionItemComponent.Toggle(style: .regular, isOn: false, action: { [weak state] value in
|
accessory: .toggle(ListActionItemComponent.Toggle(style: .regular, isOn: state.adsEnabled, action: { [weak state] value in
|
||||||
let _ = accountContext.engine.accountData.updateAdMessagesEnabled(enabled: value).startStandalone()
|
let _ = accountContext.engine.accountData.updateAdMessagesEnabled(enabled: value).startStandalone()
|
||||||
state?.updated(transition: .immediate)
|
state?.updated(transition: .immediate)
|
||||||
})),
|
})),
|
||||||
action: nil
|
action: nil
|
||||||
))))
|
))))
|
||||||
|
|
||||||
|
let adsInfoString = NSMutableAttributedString(attributedString: parseMarkdownIntoAttributedString(environment.strings.Business_AdsInfo, attributes: termsMarkdownAttributes, textAlignment: .natural
|
||||||
|
))
|
||||||
|
if state.cachedChevronImage == nil || state.cachedChevronImage?.1 !== theme {
|
||||||
|
state.cachedChevronImage = (generateTintedImage(image: UIImage(bundleImageName: "Contact List/SubtitleArrow"), color: environment.theme.list.itemAccentColor)!, theme)
|
||||||
|
}
|
||||||
|
if let range = adsInfoString.string.range(of: ">"), let chevronImage = state.cachedChevronImage?.0 {
|
||||||
|
adsInfoString.addAttribute(.attachment, value: chevronImage, range: NSRange(range, in: adsInfoString.string))
|
||||||
|
}
|
||||||
|
let controller = environment.controller
|
||||||
|
let adsInfoTapActionImpl: ([NSAttributedString.Key: Any]) -> Void = { _ in
|
||||||
|
if let controller = controller() as? PremiumIntroScreen {
|
||||||
|
controller.context.sharedContext.openExternalUrl(context: controller.context, urlContext: .generic, url: environment.strings.Business_AdsInfo_URL, forceExternal: true, presentationData: controller.context.sharedContext.currentPresentationData.with({$0}), navigationController: nil, dismissInput: {})
|
||||||
|
}
|
||||||
|
}
|
||||||
let adsSettingsSection = adsSettingsSection.update(
|
let adsSettingsSection = adsSettingsSection.update(
|
||||||
component: ListSectionComponent(
|
component: ListSectionComponent(
|
||||||
theme: environment.theme,
|
theme: environment.theme,
|
||||||
@@ -2510,8 +2538,19 @@ private final class PremiumIntroScreenContentComponent: CombinedComponent {
|
|||||||
maximumNumberOfLines: 0
|
maximumNumberOfLines: 0
|
||||||
)),
|
)),
|
||||||
footer: AnyComponent(MultilineTextComponent(
|
footer: AnyComponent(MultilineTextComponent(
|
||||||
text: .markdown(text: environment.strings.Business_AdsInfo, attributes: termsMarkdownAttributes),
|
text: .plain(adsInfoString),
|
||||||
maximumNumberOfLines: 0
|
maximumNumberOfLines: 0,
|
||||||
|
highlightColor: environment.theme.list.itemAccentColor.withAlphaComponent(0.2),
|
||||||
|
highlightAction: { attributes in
|
||||||
|
if let _ = attributes[NSAttributedString.Key(rawValue: TelegramTextAttributes.URL)] {
|
||||||
|
return NSAttributedString.Key(rawValue: TelegramTextAttributes.URL)
|
||||||
|
} else {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
},
|
||||||
|
tapAction: { attributes, _ in
|
||||||
|
adsInfoTapActionImpl(attributes)
|
||||||
|
}
|
||||||
)),
|
)),
|
||||||
items: adsSettingsItems
|
items: adsSettingsItems
|
||||||
),
|
),
|
||||||
|
|||||||
Reference in New Issue
Block a user