diff --git a/Telegram/Telegram-iOS/en.lproj/Localizable.strings b/Telegram/Telegram-iOS/en.lproj/Localizable.strings index 38d981ea08..73405bd474 100644 --- a/Telegram/Telegram-iOS/en.lproj/Localizable.strings +++ b/Telegram/Telegram-iOS/en.lproj/Localizable.strings @@ -15709,3 +15709,8 @@ Error: %8$@"; "SocksProxySetup.Warning.Title" = "Warning"; "SocksProxySetup.Warning.Text" = "This action will expose your IP address to the admin of the proxy server."; "SocksProxySetup.Warning.Proceed" = "Proceed"; + +"Gift.Variants.CollectionInfo.CraftableModel_1" = "**%@** craftable model"; +"Gift.Variants.CollectionInfo.CraftableModel_any" = "**%@** craftable models"; +"Gift.Variants.ViewCraftableModels" = "View Craftable Models"; +"Gift.Variants.ViewPrimaryModels" = "View Primary Models"; diff --git a/submodules/AccountContext/Sources/AccountContext.swift b/submodules/AccountContext/Sources/AccountContext.swift index c621d5458e..1b40090279 100644 --- a/submodules/AccountContext/Sources/AccountContext.swift +++ b/submodules/AccountContext/Sources/AccountContext.swift @@ -1454,13 +1454,13 @@ public protocol SharedAccountContext: AnyObject { func makeGiftViewScreen(context: AccountContext, message: EngineMessage, shareStory: ((StarGift.UniqueGift) -> Void)?) -> ViewController func makeGiftViewScreen(context: AccountContext, gift: StarGift.UniqueGift, shareStory: ((StarGift.UniqueGift) -> Void)?, openChatTheme: (() -> Void)?, dismissed: (() -> Void)?) -> ViewController func makeGiftWearPreviewScreen(context: AccountContext, gift: StarGift, attributes: [StarGift.UniqueGift.Attribute]?) -> ViewController - func makeGiftUpgradePreviewScreen(context: AccountContext, attributes: [StarGift.UniqueGift.Attribute], peerName: String) -> ViewController + func makeGiftUpgradePreviewScreen(context: AccountContext, gift: StarGift.Gift, attributes: [StarGift.UniqueGift.Attribute], peerName: String) -> ViewController func makeGiftAuctionInfoScreen(context: AccountContext, auctionContext: GiftAuctionContext, completion: (() -> Void)?) -> ViewController func makeGiftAuctionBidScreen(context: AccountContext, toPeerId: EnginePeer.Id, text: String?, entities: [MessageTextEntity]?, hideName: Bool, auctionContext: GiftAuctionContext, acquiredGifts: Signal<[GiftAuctionAcquiredGift], NoError>?) -> ViewController func makeGiftAuctionViewScreen(context: AccountContext, auctionContext: GiftAuctionContext, peerId: EnginePeer.Id?, completion: @escaping (Signal<[GiftAuctionAcquiredGift], NoError>, [StarGift.UniqueGift.Attribute]?) -> Void) -> ViewController func makeGiftAuctionActiveBidsScreen(context: AccountContext) -> ViewController func makeGiftOfferScreen(context: AccountContext, updatedPresentationData: (initial: PresentationData, signal: Signal)?, gift: StarGift.UniqueGift, peer: EnginePeer, amount: CurrencyAmount, commit: @escaping () -> Void) -> ViewController - func makeGiftUpgradeVariantsScreen(context: AccountContext, gift: StarGift, onlyCrafted: Bool, attributes: [StarGift.UniqueGift.Attribute], selectedAttributes: [StarGift.UniqueGift.Attribute]?, focusedAttribute: StarGift.UniqueGift.Attribute?) -> ViewController + func makeGiftUpgradeVariantsScreen(context: AccountContext, gift: StarGift, crafted: Bool, attributes: [StarGift.UniqueGift.Attribute], selectedAttributes: [StarGift.UniqueGift.Attribute]?, focusedAttribute: StarGift.UniqueGift.Attribute?) -> ViewController func makeGiftAuctionWearPreviewScreen(context: AccountContext, auctionContext: GiftAuctionContext, acquiredGifts: Signal<[GiftAuctionAcquiredGift], NoError>?, attributes: [StarGift.UniqueGift.Attribute], completion: @escaping () -> Void) -> ViewController func makeGiftCraftScreen(context: AccountContext, gift: StarGift.UniqueGift) -> ViewController func makeGiftDemoScreen(context: AccountContext) -> ViewController diff --git a/submodules/TelegramUI/Components/Gifts/GiftCraftScreen/Sources/GiftCraftScreen.swift b/submodules/TelegramUI/Components/Gifts/GiftCraftScreen/Sources/GiftCraftScreen.swift index 9af63b22e7..ada2db7a98 100644 --- a/submodules/TelegramUI/Components/Gifts/GiftCraftScreen/Sources/GiftCraftScreen.swift +++ b/submodules/TelegramUI/Components/Gifts/GiftCraftScreen/Sources/GiftCraftScreen.swift @@ -239,7 +239,7 @@ private final class CraftGiftPageContent: Component { let variantsController = component.context.sharedContext.makeGiftUpgradeVariantsScreen( context: component.context, gift: .generic(gift), - onlyCrafted: true, + crafted: true, attributes: attributes, selectedAttributes: nil, focusedAttribute: nil diff --git a/submodules/TelegramUI/Components/Gifts/GiftSetupScreen/Sources/GiftSetupScreen.swift b/submodules/TelegramUI/Components/Gifts/GiftSetupScreen/Sources/GiftSetupScreen.swift index 3cc6bfae11..a095f5449b 100644 --- a/submodules/TelegramUI/Components/Gifts/GiftSetupScreen/Sources/GiftSetupScreen.swift +++ b/submodules/TelegramUI/Components/Gifts/GiftSetupScreen/Sources/GiftSetupScreen.swift @@ -1605,7 +1605,7 @@ private final class GiftSetupScreenComponent: Component { guard let self, let component = self.component, let controller = self.environment?.controller(), let upgradePreview else { return } - let previewController = component.context.sharedContext.makeGiftUpgradePreviewScreen(context: component.context, attributes: upgradePreview.attributes, peerName: peerName) + let previewController = component.context.sharedContext.makeGiftUpgradePreviewScreen(context: component.context, gift: gift, attributes: upgradePreview.attributes, peerName: peerName) controller.push(previewController) }) } diff --git a/submodules/TelegramUI/Components/Gifts/GiftViewScreen/Sources/GiftAuctionViewScreen.swift b/submodules/TelegramUI/Components/Gifts/GiftViewScreen/Sources/GiftAuctionViewScreen.swift index 03093d1027..e4b70c9faf 100644 --- a/submodules/TelegramUI/Components/Gifts/GiftViewScreen/Sources/GiftAuctionViewScreen.swift +++ b/submodules/TelegramUI/Components/Gifts/GiftViewScreen/Sources/GiftAuctionViewScreen.swift @@ -1083,7 +1083,7 @@ private final class GiftAuctionViewSheetContent: CombinedComponent { guard let state, let attributes = state.giftUpgradeAttributes else { return } - let variantsController = component.context.sharedContext.makeGiftUpgradeVariantsScreen(context: component.context, gift: .generic(gift), onlyCrafted: false, attributes: attributes, selectedAttributes: nil, focusedAttribute: nil) + let variantsController = component.context.sharedContext.makeGiftUpgradeVariantsScreen(context: component.context, gift: .generic(gift), crafted: false, attributes: attributes, selectedAttributes: nil, focusedAttribute: nil) environment.controller()?.push(variantsController) }, animateScale: false), availableSize: CGSize(width: context.availableSize.width - 64.0, height: context.availableSize.height), diff --git a/submodules/TelegramUI/Components/Gifts/GiftViewScreen/Sources/GiftUpgradeVariantsScreen.swift b/submodules/TelegramUI/Components/Gifts/GiftViewScreen/Sources/GiftUpgradeVariantsScreen.swift index c4f51dbc38..dfb46929db 100644 --- a/submodules/TelegramUI/Components/Gifts/GiftViewScreen/Sources/GiftUpgradeVariantsScreen.swift +++ b/submodules/TelegramUI/Components/Gifts/GiftViewScreen/Sources/GiftUpgradeVariantsScreen.swift @@ -29,7 +29,7 @@ private final class GiftUpgradeVariantsScreenComponent: Component { let context: AccountContext let gift: StarGift - let onlyCrafted: Bool + let crafted: Bool let attributes: [StarGift.UniqueGift.Attribute] let selectedAttributes: [StarGift.UniqueGift.Attribute]? let focusedAttribute: StarGift.UniqueGift.Attribute? @@ -37,14 +37,14 @@ private final class GiftUpgradeVariantsScreenComponent: Component { init( context: AccountContext, gift: StarGift, - onlyCrafted: Bool, + crafted: Bool, attributes: [StarGift.UniqueGift.Attribute], selectedAttributes: [StarGift.UniqueGift.Attribute]?, focusedAttribute: StarGift.UniqueGift.Attribute? ) { self.context = context self.gift = gift - self.onlyCrafted = onlyCrafted + self.crafted = crafted self.attributes = attributes self.selectedAttributes = selectedAttributes self.focusedAttribute = focusedAttribute @@ -112,6 +112,7 @@ private final class GiftUpgradeVariantsScreenComponent: Component { private var giftItems: [AnyHashable: ComponentView] = [:] private var selectedSection: SelectedSection = .models + private var displayCraftableModels = false private let giftCompositionExternalState = GiftCompositionComponent.ExternalState() @@ -122,7 +123,8 @@ private final class GiftUpgradeVariantsScreenComponent: Component { private var previewBackdropIndex: Int = 0 private var previewSymbolIndex: Int = 0 - private var previewModels: [StarGift.UniqueGift.Attribute] = [] + private var previewPrimaryModels: [StarGift.UniqueGift.Attribute] = [] + private var previewCraftableModels: [StarGift.UniqueGift.Attribute] = [] private var previewBackdrops: [StarGift.UniqueGift.Attribute] = [] private var previewSymbols: [StarGift.UniqueGift.Attribute] = [] @@ -130,10 +132,15 @@ private final class GiftUpgradeVariantsScreenComponent: Component { private var selectedBackdrop: StarGift.UniqueGift.Attribute? private var selectedSymbol: StarGift.UniqueGift.Attribute? - private var modelCount: Int32 = 0 + private var craftableModelCount: Int32 = 0 + private var primaryModelCount: Int32 = 0 private var backdropCount: Int32 = 0 private var symbolCount: Int32 = 0 + private var currentDescriptionHeight: CGFloat = 0.0 + + private var cachedSmallChevronImage: (UIImage, PresentationTheme)? + private var ignoreScrolling: Bool = false private var component: GiftUpgradeVariantsScreenComponent? @@ -293,8 +300,9 @@ private final class GiftUpgradeVariantsScreenComponent: Component { } private func previewTimerTick() { - guard !self.previewModels.isEmpty else { return } - self.previewModelIndex = (self.previewModelIndex + 1) % self.previewModels.count + let previewModels = self.displayCraftableModels ? self.previewCraftableModels : self.previewPrimaryModels + guard !previewModels.isEmpty else { return } + self.previewModelIndex = (self.previewModelIndex + 1) % previewModels.count let previousSymbolIndex = self.previewSymbolIndex var randomSymbolIndex = previousSymbolIndex @@ -329,13 +337,15 @@ private final class GiftUpgradeVariantsScreenComponent: Component { } private var effectiveGifts: [[StarGift.UniqueGift.Attribute]] = [] - private func updateEffectiveGifts(attributes: [StarGift.UniqueGift.Attribute], onlyCrafted: Bool) { + private func updateEffectiveGifts(attributes: [StarGift.UniqueGift.Attribute]) { var effectiveGifts: [[StarGift.UniqueGift.Attribute]] = [] switch self.selectedSection { case .models: let models = Array(attributes.filter({ attribute in if case let .model(_, _, _, crafted) = attribute { - if onlyCrafted && !crafted { + if self.displayCraftableModels && !crafted { + return false + } else if !self.displayCraftableModels && crafted { return false } return true @@ -347,7 +357,8 @@ private final class GiftUpgradeVariantsScreenComponent: Component { effectiveGifts.append([model]) } case .backdrops: - let selectedModel = self.selectedModel ?? self.previewModels[self.previewModelIndex] + let previewModels = self.displayCraftableModels ? self.previewCraftableModels : previewPrimaryModels + let selectedModel = self.selectedModel ?? previewModels[self.previewModelIndex] let selectedSymbol = self.selectedSymbol ?? self.previewSymbols[self.previewSymbolIndex] let backdrops = Array(attributes.filter({ attribute in if case .backdrop = attribute { @@ -403,7 +414,7 @@ private final class GiftUpgradeVariantsScreenComponent: Component { let optionWidth = (fillingSize - 16.0 * 2.0 - optionSpacing * 2.0) / 3.0 let optionSize = CGSize(width: optionWidth, height: 126.0) - let topInset: CGFloat = 393.0 + let topInset: CGFloat = 375.0 + self.currentDescriptionHeight var validIds: [AnyHashable] = [] var itemFrame = CGRect(origin: CGPoint(x: sideInset, y: topInset + 9.0), size: optionSize) @@ -607,15 +618,19 @@ private final class GiftUpgradeVariantsScreenComponent: Component { let sideInset: CGFloat = rawSideInset + 16.0 if self.component == nil { - var modelCount: Int32 = 0 + self.displayCraftableModels = component.crafted + + var primaryModelCount: Int32 = 0 + var craftableModelCount: Int32 = 0 var backdropCount: Int32 = 0 var symbolCount: Int32 = 0 for attribute in component.attributes { switch attribute { case let .model(_, _, _, crafted): - if component.onlyCrafted && !crafted { + if crafted { + craftableModelCount += 1 } else { - modelCount += 1 + primaryModelCount += 1 } case .backdrop: backdropCount += 1 @@ -625,13 +640,14 @@ private final class GiftUpgradeVariantsScreenComponent: Component { break } } - self.modelCount = modelCount + self.primaryModelCount = primaryModelCount + self.craftableModelCount = craftableModelCount self.backdropCount = backdropCount self.symbolCount = symbolCount - let randomModels = Array(component.attributes.filter({ attribute in + let randomPrimaryModels = Array(component.attributes.filter({ attribute in if case let .model(_, _, _, crafted) = attribute { - if component.onlyCrafted && !crafted { + if crafted { return false } return true @@ -639,7 +655,19 @@ private final class GiftUpgradeVariantsScreenComponent: Component { return false } }).shuffled().prefix(15)) - self.previewModels = randomModels + self.previewPrimaryModels = randomPrimaryModels + + let randomCraftableModels = Array(component.attributes.filter({ attribute in + if case let .model(_, _, _, crafted) = attribute { + if !crafted { + return false + } + return true + } else { + return false + } + }).shuffled().prefix(15)) + self.previewCraftableModels = randomCraftableModels let randomBackdrops = Array(component.attributes.filter({ attribute in if case .backdrop = attribute { @@ -687,7 +715,7 @@ private final class GiftUpgradeVariantsScreenComponent: Component { } } - self.updateEffectiveGifts(attributes: component.attributes, onlyCrafted: component.onlyCrafted) + self.updateEffectiveGifts(attributes: component.attributes) } self.component = component @@ -708,14 +736,15 @@ private final class GiftUpgradeVariantsScreenComponent: Component { var badgeColor: UIColor = .white.withAlphaComponent(0.4) var attributes: [StarGift.UniqueGift.Attribute] = [] - if !self.previewModels.isEmpty { + let previewModels = self.displayCraftableModels ? self.previewCraftableModels : self.previewPrimaryModels + if !previewModels.isEmpty { if self.isPlaying { - attributes.append(self.previewModels[self.previewModelIndex]) + attributes.append(previewModels[self.previewModelIndex]) attributes.append(self.previewBackdrops[self.previewBackdropIndex]) attributes.append(self.previewSymbols[self.previewSymbolIndex]) } else { if self.selectedModel == nil { - self.selectedModel = self.previewModels[self.previewModelIndex] + self.selectedModel = previewModels[self.previewModelIndex] } if self.selectedBackdrop == nil { self.selectedBackdrop = self.previewBackdrops[self.previewBackdropIndex] @@ -789,8 +818,11 @@ private final class GiftUpgradeVariantsScreenComponent: Component { contentHeight += headerSize.height var titleText: String = "" - if case let .generic(gift) = component.gift { + switch component.gift { + case let .generic(gift): titleText = gift.title ?? "" + case let .unique(gift): + titleText = gift.title } let titleSize = self.title.update( @@ -841,7 +873,7 @@ private final class GiftUpgradeVariantsScreenComponent: Component { } let attributeSpacing: CGFloat = 10.0 - let attributeWidth: CGFloat = floor((fillingSize - attributeSpacing * CGFloat(attributes.count - 1)) / CGFloat(attributes.count)) + let attributeWidth: CGFloat = floor((fillingSize - 32.0 - attributeSpacing * CGFloat(attributes.count - 1)) / CGFloat(attributes.count)) let attributeHeight: CGFloat = 45.0 for i in 0 ..< attributes.count { @@ -914,7 +946,7 @@ private final class GiftUpgradeVariantsScreenComponent: Component { self.selectedSection = id self.isPlaying = false - self.updateEffectiveGifts(attributes: component.attributes, onlyCrafted: component.onlyCrafted) + self.updateEffectiveGifts(attributes: component.attributes) self.state?.updated(transition: ComponentTransition(animation: .curve(duration: 0.4, curve: .spring))) })), environment: {}, @@ -935,17 +967,22 @@ private final class GiftUpgradeVariantsScreenComponent: Component { let itemHeight: CGFloat = 126.0 let itemSpacing: CGFloat = 10.0 - let descriptionText: String + var descriptionText: String let itemCount: Int32 switch self.selectedSection { case .models: - //TODO:localize - if component.onlyCrafted { - descriptionText = environment.strings.Gift_Variants_CollectionInfo("**\(self.modelCount)** craftable models").string + if self.displayCraftableModels { + descriptionText = environment.strings.Gift_Variants_CollectionInfo(environment.strings.Gift_Variants_CollectionInfo_CraftableModel(self.craftableModelCount)).string + itemCount = self.craftableModelCount + descriptionText += "\n[\(environment.strings.Gift_Variants_ViewPrimaryModels) >]()" } else { - descriptionText = environment.strings.Gift_Variants_CollectionInfo(environment.strings.Gift_Variants_CollectionInfo_Model(self.modelCount)).string + descriptionText = environment.strings.Gift_Variants_CollectionInfo(environment.strings.Gift_Variants_CollectionInfo_Model(self.primaryModelCount)).string + itemCount = self.primaryModelCount + + if self.craftableModelCount > 0 { + descriptionText += "\n[\(environment.strings.Gift_Variants_ViewCraftableModels) >]()" + } } - itemCount = self.modelCount case .backdrops: descriptionText = environment.strings.Gift_Variants_CollectionInfo(environment.strings.Gift_Variants_CollectionInfo_Backdrop(self.backdropCount)).string itemCount = self.backdropCount @@ -957,14 +994,45 @@ private final class GiftUpgradeVariantsScreenComponent: Component { let descriptionFont = Font.regular(13.0) let descriptionBoldFont = Font.semibold(13.0) let descriptionTextColor = theme.list.itemSecondaryTextColor - let descriptionMarkdownAttributes = MarkdownAttributes(body: MarkdownAttributeSet(font: descriptionFont, textColor: descriptionTextColor), bold: MarkdownAttributeSet(font: descriptionBoldFont, textColor: descriptionTextColor), link: MarkdownAttributeSet(font: descriptionFont, textColor: descriptionTextColor), linkAttribute: { contents in + let descriptionLinkColor = theme.list.itemAccentColor + let descriptionMarkdownAttributes = MarkdownAttributes(body: MarkdownAttributeSet(font: descriptionFont, textColor: descriptionTextColor), bold: MarkdownAttributeSet(font: descriptionBoldFont, textColor: descriptionTextColor), link: MarkdownAttributeSet(font: descriptionFont, textColor: descriptionLinkColor), linkAttribute: { contents in return (TelegramTextAttributes.URL, contents) }) + if self.cachedSmallChevronImage == nil || self.cachedSmallChevronImage?.1 !== environment.theme { + self.cachedSmallChevronImage = (generateTintedImage(image: UIImage(bundleImageName: "Item List/InlineTextRightArrow"), color: descriptionLinkColor)!, theme) + } + + let descriptionAttributedString = parseMarkdownIntoAttributedString(descriptionText, attributes: descriptionMarkdownAttributes, textAlignment: .center).mutableCopy() as! NSMutableAttributedString + if let range = descriptionAttributedString.string.range(of: ">"), let chevronImage = self.cachedSmallChevronImage?.0 { + descriptionAttributedString.addAttribute(.attachment, value: chevronImage, range: NSRange(range, in: descriptionAttributedString.string)) + } + let descriptionSize = self.descriptionText.update( transition: .immediate, component: AnyComponent(MultilineTextComponent( - text: .markdown(text: descriptionText, attributes: descriptionMarkdownAttributes) + text: .plain(descriptionAttributedString), + horizontalAlignment: .center, + maximumNumberOfLines: 3, + lineSpacing: 0.2, + highlightColor: descriptionLinkColor.withAlphaComponent(0.1), + highlightInset: UIEdgeInsets(top: 0.0, left: 0.0, bottom: 0.0, right: -8.0), + highlightAction: { attributes in + if let _ = attributes[NSAttributedString.Key(rawValue: TelegramTextAttributes.URL)] { + return NSAttributedString.Key(rawValue: TelegramTextAttributes.URL) + } else { + return nil + } + }, + tapAction: { [weak self] attributes, _ in + if let self, let _ = attributes[NSAttributedString.Key(rawValue: TelegramTextAttributes.URL)] as? String { + self.displayCraftableModels = !self.displayCraftableModels + self.isPlaying = false + + self.updateEffectiveGifts(attributes: component.attributes) + self.state?.updated(transition: ComponentTransition(animation: .curve(duration: 0.4, curve: .spring))) + } + } )), environment: {}, containerSize: CGSize(width: availableSize.width - sideInset * 2.0, height: 100.0) @@ -976,6 +1044,7 @@ private final class GiftUpgradeVariantsScreenComponent: Component { } descriptionView.frame = descriptionFrame } + self.currentDescriptionHeight = descriptionSize.height contentHeight += descriptionSize.height contentHeight += 26.0 @@ -1166,7 +1235,7 @@ public class GiftUpgradeVariantsScreen: ViewControllerComponentContainer { public init( context: AccountContext, gift: StarGift, - onlyCrafted: Bool = false, + crafted: Bool = false, attributes: [StarGift.UniqueGift.Attribute], selectedAttributes: [StarGift.UniqueGift.Attribute]?, focusedAttribute: StarGift.UniqueGift.Attribute? @@ -1176,7 +1245,7 @@ public class GiftUpgradeVariantsScreen: ViewControllerComponentContainer { super.init(context: context, component: GiftUpgradeVariantsScreenComponent( context: context, gift: gift, - onlyCrafted: onlyCrafted, + crafted: crafted, attributes: attributes, selectedAttributes: selectedAttributes, focusedAttribute: focusedAttribute diff --git a/submodules/TelegramUI/Components/Gifts/GiftViewScreen/Sources/GiftViewScreen.swift b/submodules/TelegramUI/Components/Gifts/GiftViewScreen/Sources/GiftViewScreen.swift index 445f322d0f..9cbeafdeac 100644 --- a/submodules/TelegramUI/Components/Gifts/GiftViewScreen/Sources/GiftViewScreen.swift +++ b/submodules/TelegramUI/Components/Gifts/GiftViewScreen/Sources/GiftViewScreen.swift @@ -1405,15 +1405,26 @@ private final class GiftViewSheetContent: CombinedComponent { func openUpgradeVariants(attribute: StarGift.UniqueGift.Attribute? = nil) { - guard let controller = self.getController() as? GiftViewScreen, let arguments = self.subject.arguments else { + guard let controller = self.getController() as? GiftViewScreen else { return } + + var gift: StarGift? var selectedAttributes: [StarGift.UniqueGift.Attribute]? - if case let .unique(uniqueGift) = arguments.gift { - selectedAttributes = uniqueGift.attributes + if let arguments = self.subject.arguments { + gift = arguments.gift + if case let .unique(uniqueGift) = arguments.gift { + selectedAttributes = uniqueGift.attributes + } + } else if case let .upgradePreview(genericGift, _, _) = self.subject { + gift = .generic(genericGift) } - self.giftVariantsDisposable.set((self.context.engine.payments.getStarGiftUpgradeAttributes(giftId: arguments.gift.giftId) + guard let gift else { + return + } + + self.giftVariantsDisposable.set((self.context.engine.payments.getStarGiftUpgradeAttributes(giftId: gift.giftId) |> take(1) |> deliverOnMainQueue).start(next: { [weak self] attributes in guard let self, let attributes else { @@ -1421,8 +1432,8 @@ private final class GiftViewSheetContent: CombinedComponent { } let variantsController = self.context.sharedContext.makeGiftUpgradeVariantsScreen( context: self.context, - gift: arguments.gift, - onlyCrafted: false, + gift: gift, + crafted: false, attributes: attributes, selectedAttributes: selectedAttributes, focusedAttribute: attribute @@ -2592,7 +2603,7 @@ private final class GiftViewSheetContent: CombinedComponent { } else if state.inUpgradePreview, let attributes = state.upgradePreview?.attributes { headerHeight = 246.0 headerSubject = .preview(attributes) - } else if case let .upgradePreview(attributes, _) = component.subject { + } else if case let .upgradePreview(_, attributes, _) = component.subject { headerHeight = 246.0 headerSubject = .preview(attributes) } else if case let .wearPreview(_, attributes) = component.subject, let attributes { @@ -2857,7 +2868,7 @@ private final class GiftViewSheetContent: CombinedComponent { title = environment.strings.Gift_Upgrade_GiftTitle uniqueText = strings.Gift_Upgrade_Unique_GiftDescription(peerName).string tradableText = strings.Gift_Upgrade_Tradable_GiftDescription(peerName).string - } else if case let .upgradePreview(_, peerName) = component.subject { + } else if case let .upgradePreview(_, _, peerName) = component.subject { var peerName = peerName if peerName.count > 22 { peerName = "\(peerName.prefix(22))…" @@ -2871,28 +2882,27 @@ private final class GiftViewSheetContent: CombinedComponent { tradableText = strings.Gift_Upgrade_Tradable_Description } - let upgradeTitle = upgradeTitle.update( - component: MultilineTextComponent( - text: .plain(NSAttributedString( - string: title, - font: Font.bold(20.0), - textColor: .white, - paragraphAlignment: .center - )), - horizontalAlignment: .center, - maximumNumberOfLines: 1 - ), - availableSize: CGSize(width: context.availableSize.width - sideInset * 2.0 - 60.0, height: CGFloat.greatestFiniteMagnitude), - transition: .immediate - ) + var variant1: GiftItemComponent.Subject? + var variant2: GiftItemComponent.Subject? + var variant3: GiftItemComponent.Subject? - if case let .generic(gift) = component.subject.arguments?.gift, let upgradePreview = state.upgradePreview { - var variant1: GiftItemComponent.Subject = .starGift(gift: gift, price: "") - var variant2: GiftItemComponent.Subject = .starGift(gift: gift, price: "") - var variant3: GiftItemComponent.Subject = .starGift(gift: gift, price: "") + var upgradeAttributes: [StarGift.UniqueGift.Attribute]? + + if case let .generic(gift) = component.subject.arguments?.gift { + variant1 = .starGift(gift: gift, price: "") + variant2 = .starGift(gift: gift, price: "") + variant3 = .starGift(gift: gift, price: "") + } + + if let upgradePreview = state.upgradePreview { + upgradeAttributes = upgradePreview.attributes + } else if case let .upgradePreview(_, attributes, _) = component.subject { + upgradeAttributes = attributes + } + if let upgradeAttributes { var i = 0 - for attribute in upgradePreview.attributes { + for attribute in upgradeAttributes { if case .model = attribute { switch i { case 0: @@ -2907,7 +2917,9 @@ private final class GiftViewSheetContent: CombinedComponent { i += 1 } } - + } + + if let variant1, let variant2, let variant3 { var buttonColor: UIColor = UIColor.white.withAlphaComponent(0.16) if let backgroundColor = giftCompositionExternalState.backgroundColor { buttonColor = backgroundColor.mixedWith(.white, alpha: 0.2) @@ -2923,7 +2935,21 @@ private final class GiftViewSheetContent: CombinedComponent { ) let variantsButtonSize = CGSize(width: variantsMeasureDescription.size.width + 87.0, height: 24.0) - + + let upgradeTitle = upgradeTitle.update( + component: MultilineTextComponent( + text: .plain(NSAttributedString( + string: title, + font: Font.bold(20.0), + textColor: .white, + paragraphAlignment: .center + )), + horizontalAlignment: .center, + maximumNumberOfLines: 1 + ), + availableSize: CGSize(width: context.availableSize.width - sideInset * 2.0 - 60.0, height: CGFloat.greatestFiniteMagnitude), + transition: .immediate + ) let upgradeDescription = upgradeDescription.update( component: GlassBarButtonComponent( size: variantsButtonSize, @@ -5415,7 +5441,7 @@ public class GiftViewScreen: ViewControllerComponentContainer { case uniqueGift(StarGift.UniqueGift, EnginePeer.Id?) case profileGift(EnginePeer.Id, ProfileGiftsContext.State.StarGift) case soldOutGift(StarGift.Gift) - case upgradePreview([StarGift.UniqueGift.Attribute], String) + case upgradePreview(StarGift.Gift, [StarGift.UniqueGift.Attribute], String) case wearPreview(StarGift, [StarGift.UniqueGift.Attribute]?) var arguments: ( diff --git a/submodules/TelegramUI/Sources/SharedAccountContext.swift b/submodules/TelegramUI/Sources/SharedAccountContext.swift index 0ffb96cc38..7af47de9ab 100644 --- a/submodules/TelegramUI/Sources/SharedAccountContext.swift +++ b/submodules/TelegramUI/Sources/SharedAccountContext.swift @@ -3867,8 +3867,8 @@ public final class SharedAccountContextImpl: SharedAccountContext { return GiftViewScreen(context: context, subject: .wearPreview(gift, attributes)) } - public func makeGiftUpgradePreviewScreen(context: AccountContext, attributes: [StarGift.UniqueGift.Attribute], peerName: String) -> ViewController { - return GiftViewScreen(context: context, subject: .upgradePreview(attributes, peerName)) + public func makeGiftUpgradePreviewScreen(context: AccountContext, gift: StarGift.Gift, attributes: [StarGift.UniqueGift.Attribute], peerName: String) -> ViewController { + return GiftViewScreen(context: context, subject: .upgradePreview(gift, attributes, peerName)) } public func makeGiftAuctionInfoScreen(context: AccountContext, auctionContext: GiftAuctionContext, completion: (() -> Void)?) -> ViewController { @@ -3891,8 +3891,8 @@ public final class SharedAccountContextImpl: SharedAccountContext { return giftOfferAlertController(context: context, updatedPresentationData: updatedPresentationData, gift: gift, peer: peer, amount: amount, commit: commit) } - public func makeGiftUpgradeVariantsScreen(context: AccountContext, gift: StarGift, onlyCrafted: Bool, attributes: [StarGift.UniqueGift.Attribute], selectedAttributes: [StarGift.UniqueGift.Attribute]?, focusedAttribute: StarGift.UniqueGift.Attribute?) -> ViewController { - return GiftUpgradeVariantsScreen(context: context, gift: gift, onlyCrafted: onlyCrafted, attributes: attributes, selectedAttributes: selectedAttributes, focusedAttribute: focusedAttribute) + public func makeGiftUpgradeVariantsScreen(context: AccountContext, gift: StarGift, crafted: Bool, attributes: [StarGift.UniqueGift.Attribute], selectedAttributes: [StarGift.UniqueGift.Attribute]?, focusedAttribute: StarGift.UniqueGift.Attribute?) -> ViewController { + return GiftUpgradeVariantsScreen(context: context, gift: gift, crafted: crafted, attributes: attributes, selectedAttributes: selectedAttributes, focusedAttribute: focusedAttribute) } public func makeGiftAuctionWearPreviewScreen(context: AccountContext, auctionContext: GiftAuctionContext, acquiredGifts: Signal<[GiftAuctionAcquiredGift], NoError>?, attributes: [StarGift.UniqueGift.Attribute], completion: @escaping () -> Void) -> ViewController {