From fe2cc49a55c7b44e0d618f0e570296f15834ee86 Mon Sep 17 00:00:00 2001 From: Ilya Laktyushin Date: Fri, 2 May 2025 18:31:42 +0400 Subject: [PATCH] Various fixes --- .../Telegram-iOS/en.lproj/Localizable.strings | 1 + .../GiftAttributeListContextItem.swift | 11 ++++++- .../Sources/GiftStoreScreen.swift | 29 ++++++++++++++----- .../Sources/StarsPurchaseScreen.swift | 4 ++- 4 files changed, 36 insertions(+), 9 deletions(-) diff --git a/Telegram/Telegram-iOS/en.lproj/Localizable.strings b/Telegram/Telegram-iOS/en.lproj/Localizable.strings index d578975f89..c7ef0e4901 100644 --- a/Telegram/Telegram-iOS/en.lproj/Localizable.strings +++ b/Telegram/Telegram-iOS/en.lproj/Localizable.strings @@ -14262,6 +14262,7 @@ Sorry for the inconvenience."; "PeerInfo.Gifts.Sale" = "sale"; +"Gift.Store.ForResaleNoResults" = "no results"; "Gift.Store.ForResale_1" = "%@ for resale"; "Gift.Store.ForResale_any" = "%@ for resale"; "Gift.Store.Sort.Price" = "Price"; diff --git a/submodules/TelegramUI/Components/Gifts/GiftStoreScreen/Sources/GiftAttributeListContextItem.swift b/submodules/TelegramUI/Components/Gifts/GiftStoreScreen/Sources/GiftAttributeListContextItem.swift index bbb4658b85..58f23df6bf 100644 --- a/submodules/TelegramUI/Components/Gifts/GiftStoreScreen/Sources/GiftAttributeListContextItem.swift +++ b/submodules/TelegramUI/Components/Gifts/GiftStoreScreen/Sources/GiftAttributeListContextItem.swift @@ -71,7 +71,15 @@ private func actionForAttribute(attribute: StarGift.UniqueGift.Attribute, presen var title = "# \(name)" var count = "" - if let counter = item.attributeCount[.model(file.fileId.id)] { + var attributeId: ResaleGiftsContext.Attribute? + switch attribute { + case .model: + attributeId = .model(file.fileId.id) + case .pattern: + attributeId = .pattenr(file.fileId.id) + } + + if let attributeId, let counter = item.attributeCount[attributeId] { count = " \(presentationStringsFormattedNumber(counter, presentationData.dateTimeFormat.groupingSeparator))" entities.append( MessageTextEntity( @@ -81,6 +89,7 @@ private func actionForAttribute(attribute: StarGift.UniqueGift.Attribute, presen ) title += count } + let words = title.components(separatedBy: .whitespacesAndNewlines).filter { !$0.isEmpty } var wordStartIndices: [String.Index] = [] diff --git a/submodules/TelegramUI/Components/Gifts/GiftStoreScreen/Sources/GiftStoreScreen.swift b/submodules/TelegramUI/Components/Gifts/GiftStoreScreen/Sources/GiftStoreScreen.swift index 835092e294..99f6f05b84 100644 --- a/submodules/TelegramUI/Components/Gifts/GiftStoreScreen/Sources/GiftStoreScreen.swift +++ b/submodules/TelegramUI/Components/Gifts/GiftStoreScreen/Sources/GiftStoreScreen.swift @@ -454,22 +454,31 @@ final class GiftStoreScreenComponent: Component { return generateTintedImage(image: UIImage(bundleImageName: "Peer Info/SortValue"), color: theme.contextMenu.primaryColor) }, action: { [weak self] _, f in f(.default) - - self?.state?.starGiftsContext.updateSorting(.value) + guard let self else { + return + } + self.state?.starGiftsContext.updateSorting(.value) + self.scrollToTop() }))) items.append(.action(ContextMenuActionItem(text: presentationData.strings.Gift_Store_SortByDate, icon: { theme in return generateTintedImage(image: UIImage(bundleImageName: "Peer Info/SortDate"), color: theme.contextMenu.primaryColor) }, action: { [weak self] _, f in f(.default) - - self?.state?.starGiftsContext.updateSorting(.date) + guard let self else { + return + } + self.state?.starGiftsContext.updateSorting(.date) + self.scrollToTop() }))) items.append(.action(ContextMenuActionItem(text: presentationData.strings.Gift_Store_SortByNumber, icon: { theme in return generateTintedImage(image: UIImage(bundleImageName: "Peer Info/SortNumber"), color: theme.contextMenu.primaryColor) }, action: { [weak self] _, f in f(.default) - - self?.state?.starGiftsContext.updateSorting(.number) + guard let self else { + return + } + self.state?.starGiftsContext.updateSorting(.number) + self.scrollToTop() }))) let contextController = ContextController(presentationData: presentationData, source: .reference(GiftStoreReferenceContentSource(controller: controller, sourceView: sourceView)), items: .single(ContextController.Items(content: .list(items))), gesture: nil) @@ -542,6 +551,7 @@ final class GiftStoreScreenComponent: Component { } } self.state?.starGiftsContext.updateFilterAttributes(updatedFilterAttributes) + self.scrollToTop() }, selectAll: { [weak self] in guard let self else { @@ -554,6 +564,7 @@ final class GiftStoreScreenComponent: Component { return true } self.state?.starGiftsContext.updateFilterAttributes(updatedFilterAttributes) + self.scrollToTop() } ), false)) @@ -633,6 +644,7 @@ final class GiftStoreScreenComponent: Component { } } self.state?.starGiftsContext.updateFilterAttributes(updatedFilterAttributes) + self.scrollToTop() }, selectAll: { [weak self] in guard let self else { @@ -645,6 +657,7 @@ final class GiftStoreScreenComponent: Component { return true } self.state?.starGiftsContext.updateFilterAttributes(updatedFilterAttributes) + self.scrollToTop() } ), false)) @@ -724,6 +737,7 @@ final class GiftStoreScreenComponent: Component { } } self.state?.starGiftsContext.updateFilterAttributes(updatedFilterAttributes) + self.scrollToTop() }, selectAll: { [weak self] in guard let self else { @@ -736,6 +750,7 @@ final class GiftStoreScreenComponent: Component { return true } self.state?.starGiftsContext.updateFilterAttributes(updatedFilterAttributes) + self.scrollToTop() } ), false)) @@ -900,7 +915,7 @@ final class GiftStoreScreenComponent: Component { let subtitleSize = self.subtitle.update( transition: transition, component: AnyComponent(BalancedTextComponent( - text: .plain(NSAttributedString(string: environment.strings.Gift_Store_ForResale(effectiveCount), font: Font.regular(13.0), textColor: theme.rootController.navigationBar.secondaryTextColor)), + text: .plain(NSAttributedString(string: effectiveCount == 0 ? environment.strings.Gift_Store_ForResaleNoResults : environment.strings.Gift_Store_ForResale(effectiveCount), font: Font.regular(13.0), textColor: theme.rootController.navigationBar.secondaryTextColor)), horizontalAlignment: .center, maximumNumberOfLines: 1 )), diff --git a/submodules/TelegramUI/Components/Stars/StarsPurchaseScreen/Sources/StarsPurchaseScreen.swift b/submodules/TelegramUI/Components/Stars/StarsPurchaseScreen/Sources/StarsPurchaseScreen.swift index c0aec3aef2..37da22d283 100644 --- a/submodules/TelegramUI/Components/Stars/StarsPurchaseScreen/Sources/StarsPurchaseScreen.swift +++ b/submodules/TelegramUI/Components/Stars/StarsPurchaseScreen/Sources/StarsPurchaseScreen.swift @@ -308,6 +308,7 @@ private final class StarsPurchaseScreenContentComponent: CombinedComponent { var i = 0 var items: [AnyComponentWithIdentity] = [] + var collapsedItems = 0 if let products = state.products, let balance = context.component.balance { var minimumCount: StarsAmount? if let requiredStars = context.component.purpose.requiredStars { @@ -326,6 +327,7 @@ private final class StarsPurchaseScreenContentComponent: CombinedComponent { if let _ = minimumCount, items.isEmpty { } else if !context.component.expanded && product.isExtended { + collapsedItems += 1 continue } @@ -390,7 +392,7 @@ private final class StarsPurchaseScreenContentComponent: CombinedComponent { } } - if !context.component.expanded && items.count > 1 { + if !context.component.expanded && collapsedItems > 0 { let titleComponent = AnyComponent(MultilineTextComponent( text: .plain(NSAttributedString( string: strings.Stars_Purchase_ShowMore,