@@ -11,12 +11,6 @@ import SwiftSignalKit
1111import TGUIKit
1212import TelegramCore
1313
14- extension StarGift {
15- var id : Int64 {
16- return self . generic? . id ?? self . unique? . id ?? 0
17- }
18- }
19-
2014struct PremiumPaymentOption : Equatable {
2115 var title : String
2216 var desc : String
@@ -75,7 +69,7 @@ final class GiftOptionsRowItem : GeneralRowItem {
7569 struct Option {
7670 enum TypeValue {
7771 case price( String )
78- case stars( Int64 , Bool )
72+ case stars( Int64 )
7973 case none
8074 }
8175 struct Badge {
@@ -91,8 +85,6 @@ final class GiftOptionsRowItem : GeneralRowItem {
9185 let invisible : Bool
9286 let pinned : Bool
9387
94- let priceBadge : TextViewLayout ?
95-
9688 var starsPrice : TextViewLayout ?
9789
9890 var nativePayment : PremiumPaymentOption ?
@@ -126,14 +118,14 @@ final class GiftOptionsRowItem : GeneralRowItem {
126118 starsPrice = nil
127119 }
128120
129- return . init( file: option. media. file, text: option. text, type: . price( option. total) , badge: option. discount. flatMap { . init( text: $0, colors: colors, textColor: . white ) } , peer: nil , invisible: false , pinned: false , priceBadge : nil , starsPrice: starsPrice, nativePayment: option)
121+ return . init( file: option. media. file, text: option. text, type: . price( option. total) , badge: option. discount. flatMap { . init( text: $0, colors: colors, textColor: . white ) } , peer: nil , invisible: false , pinned: false , starsPrice: starsPrice, nativePayment: option)
130122 }
131123 static func initialize( _ option: PeerStarGift ) -> Option {
132124 let badge : Badge ?
133125
134126 var redColor : [ NSColor ] = [ ]
135127 var blueColor : [ NSColor ] = [ ]
136- var greenColor : [ NSColor ] = [ NSColor ( 0x74b036 ) , NSColor ( 0x87d151 ) ]
128+
137129 if theme. colors. isDark {
138130 redColor = [ NSColor ( 0x522124 ) , NSColor ( 0x653634 ) ]
139131 blueColor = [ NSColor ( 0x142e42 ) , NSColor ( 0x354f5b ) ]
@@ -143,10 +135,7 @@ final class GiftOptionsRowItem : GeneralRowItem {
143135 }
144136
145137 if let availability = option. native. generic? . availability {
146- if availability. minResaleStars != nil {
147- //TODOLANG
148- badge = . init( text: " resale " , colors: greenColor, textColor: . white)
149- } else if availability. remains == 0 {
138+ if availability. remains == 0 {
150139 badge = . init( text: strings ( ) . giftSoldOut, colors: redColor, textColor: . white)
151140 } else {
152141 badge = . init( text: strings ( ) . starGiftLimited, colors: blueColor, textColor: theme. colors. underSelectedColor)
@@ -156,29 +145,11 @@ final class GiftOptionsRowItem : GeneralRowItem {
156145 } else {
157146 badge = nil
158147 }
159- return . init( file: option. media, text: nil , type: . stars( option. native . generic ? . availability ? . minResaleStars ?? option . stars, false ) , badge: badge, peer: nil , invisible: false , pinned: false , priceBadge : nil , nativeStarGift: option)
148+ return . init( file: option. media, text: nil , type: . stars( option. stars) , badge: badge, peer: nil , invisible: false , pinned: false , nativeStarGift: option)
160149 }
161150
162- static func initialize( _ option: StarGift . UniqueGift , resale: Bool = false , showNumber: Bool = false ) -> Option {
163-
164- let badge : Option . Badge ?
165-
166- var blueColor : [ NSColor ] = [ ]
167-
168- if theme. colors. isDark {
169- blueColor = [ NSColor ( 0x142e42 ) , NSColor ( 0x354f5b ) ]
170- } else {
171- blueColor = [ theme. colors. accent. withMultipliedBrightnessBy ( 1.1 ) , theme. colors. accent. withMultipliedBrightnessBy ( 0.9 ) ]
172- }
173-
174-
175- if showNumber {
176- badge = . init( text: " # \( option. number) " , colors: option. backdrop ?? blueColor, textColor: theme. colors. underSelectedColor)
177- } else {
178- badge = nil
179- }
180-
181- return . init( file: option. file!, text: nil , type: option. resellStars != nil ? . stars( option. resellStars!, true ) : . none, badge: badge, peer: nil , invisible: false , pinned: false , priceBadge: nil , nativeStarUniqueGift: option)
151+ static func initialize( _ option: StarGift . UniqueGift ) -> Option {
152+ return . init( file: option. file!, text: nil , type: . none, badge: nil , peer: nil , invisible: false , pinned: false , nativeStarUniqueGift: option)
182153 }
183154
184155
@@ -192,23 +163,11 @@ final class GiftOptionsRowItem : GeneralRowItem {
192163 blueColor = [ theme. colors. accent. withMultipliedBrightnessBy ( 1.1 ) , theme. colors. accent. withMultipliedBrightnessBy ( 0.9 ) ]
193164 }
194165
195- var priceBadge : TextViewLayout ? = nil
196-
197166 let badge : Badge ?
198- if let resellStars = option. gift. unique? . resellStars {
199- //TODOLANG
200- badge = . init( text: " sale " , colors: [ NSColor ( 0x74b036 ) , NSColor ( 0x87d151 ) ] , textColor: theme. colors. underSelectedColor)
201-
202- let attr = NSMutableAttributedString ( )
203- attr. append ( . initialize( string: " \( clown_space) \( resellStars) " , color: . white, font: . normal( . text) ) )
204- attr. insertEmbedded ( . embeddedAnimated( LocalAnimatedSticker . star_currency_new. file) , for: clown)
205-
206- priceBadge = . init( attr)
207- priceBadge? . measure ( width: . greatestFiniteMagnitude)
208- } else if let availability = option. gift. generic? . availability {
167+ if let availability = option. gift. generic? . availability {
209168 badge = . init( text: strings ( ) . starTransactionAvailabilityOf ( 1 , Int ( availability. total) . prettyNumber) , colors: blueColor, textColor: theme. colors. underSelectedColor)
210169 } else if let unique = option. gift. unique {
211- badge = . init( text: " # \( unique. number) " , colors: option. gift. backdropColor ?? blueColor, textColor: theme. colors. underSelectedColor)
170+ badge = . init( text: " \( unique. number) " , colors: option. gift. backdropColor ?? blueColor, textColor: theme. colors. underSelectedColor)
212171 } else {
213172 badge = nil
214173 }
@@ -219,8 +178,8 @@ final class GiftOptionsRowItem : GeneralRowItem {
219178 file = gift. file
220179 case . unique( let uniqueGift) :
221180 file = uniqueGift. file!
222- }
223- return . init( file: file, text: nil , type: transfrarable ? . price( strings ( ) . starNftTransfer) : . none, badge: badge, peer: option. fromPeer, invisible: !option. savedToProfile, pinned: option. pinnedToTop, priceBadge : priceBadge , nativeProfileGift: option)
181+ }
182+ return . init( file: file, text: nil , type: transfrarable ? . price( strings ( ) . starNftTransfer) : . none, badge: badge, peer: option. fromPeer, invisible: !option. savedToProfile, pinned: option. pinnedToTop, nativeProfileGift: option)
224183 }
225184
226185 var height : CGFloat {
@@ -327,33 +286,6 @@ private final class GiftOptionsRowView: GeneralContainableRowView {
327286 }
328287 }
329288
330- final class PriceBadgeView : VisualEffect {
331- private let textView = InteractiveTextView ( )
332- override init ( frame frameRect: NSRect ) {
333- super. init ( frame: frameRect)
334- addSubview ( textView)
335- textView. isEventLess = true
336- textView. userInteractionEnabled = false
337- }
338-
339- required init ? ( coder: NSCoder ) {
340- fatalError ( " init(coder:) has not been implemented " )
341- }
342-
343- func update( _ layout: TextViewLayout , context: AccountContext ) {
344- self . textView. set ( text: layout, context: context)
345-
346- setFrameSize ( NSMakeSize ( layout. layoutSize. width + 10 , layout. layoutSize. height + 6 ) )
347-
348- self . layer? . cornerRadius = self . frame. height / 2
349- }
350-
351- override func layout( ) {
352- super. layout ( )
353- textView. center ( )
354- }
355- }
356-
357289 private let sticker = MediaAnimatedStickerView ( frame: NSMakeRect ( 0 , 0 , 80 , 80 ) )
358290 private var textView : TextView ?
359291 private var badgeView : ImageView ?
@@ -366,7 +298,6 @@ private final class GiftOptionsRowView: GeneralContainableRowView {
366298 private var selectionView : View ?
367299 private var starsPrice : InteractiveTextView ?
368300 private var pinnedView : ImageView ?
369- private var priceBadgeView : PriceBadgeView ?
370301
371302
372303 private class PriceView : View {
@@ -396,7 +327,7 @@ private final class GiftOptionsRowView: GeneralContainableRowView {
396327
397328 private class StarPriceView : View {
398329 private let textView = InteractiveTextView ( )
399- let effect = StarsButtonEffectLayer ( )
330+ private let effect = StarsButtonEffectLayer ( )
400331 required init ( frame frameRect: NSRect ) {
401332 super. init ( frame: frameRect)
402333 addSubview ( textView)
@@ -519,7 +450,7 @@ private final class GiftOptionsRowView: GeneralContainableRowView {
519450 current. backgroundColor = option. gift? . unique != nil ? NSColor . white. withAlphaComponent ( 0.2 ) : theme. colors. accent. withAlphaComponent ( 0.2 )
520451 current. update ( text: priceLayout)
521452
522- case let . stars( int64 , plain ) :
453+ case . stars( let int64 ) :
523454 if let view = self . priceView {
524455 performSubviewRemoval ( view, animated: false )
525456 self . priceView = nil
@@ -533,15 +464,12 @@ private final class GiftOptionsRowView: GeneralContainableRowView {
533464 self . addSubview ( current)
534465 self . starPriceView = current
535466 }
536-
537- current. effect. isHidden = plain
538-
539467 let attr = NSMutableAttributedString ( )
540- attr. append ( string: " \( clown_space) \( int64) " , color: plain ? NSColor . white : GOLD, font: . medium( . text) )
541- attr. insertEmbedded ( . embeddedAnimated( LocalAnimatedSticker . star_currency_new. file, color : nil ) , for: clown)
468+ attr. append ( string: " \( clown_space) \( int64) " , color: GOLD, font: . medium( . text) )
469+ attr. insertEmbedded ( . embeddedAnimated( LocalAnimatedSticker . star_currency_new. file) , for: clown)
542470 let priceLayout = TextViewLayout ( attr)
543471 priceLayout. measure ( width: . greatestFiniteMagnitude)
544- current. backgroundColor = plain ? NSColor . white . withAlphaComponent ( 0.2 ) : GOLD . withAlphaComponent ( 0.2 )
472+ current. backgroundColor = GOLD . withAlphaComponent ( 0.2 )
545473 current. update ( text: priceLayout, context: context)
546474 case . none:
547475 if let view = self . priceView {
@@ -605,7 +533,7 @@ private final class GiftOptionsRowView: GeneralContainableRowView {
605533
606534 for attribute in uniqueGift. attributes {
607535 switch attribute {
608- case let . backdrop( _, _ , innerColor, outerColor, _, _, _) :
536+ case let . backdrop( _, innerColor, outerColor, _, _, _) :
609537 colors = [ NSColor ( UInt32 ( innerColor) ) , NSColor ( UInt32 ( outerColor) ) ]
610538 default :
611539 break
@@ -631,7 +559,7 @@ private final class GiftOptionsRowView: GeneralContainableRowView {
631559 switch attribute {
632560 case . pattern( _, let file, _) :
633561 patternFile = file
634- case let . backdrop( _, _, _, _ , color, _, _) :
562+ case let . backdrop( _, _, _, color, _, _) :
635563 patternColor = NSColor ( UInt32 ( color) ) . withAlphaComponent ( 0.7 )
636564 default :
637565 break
@@ -687,22 +615,6 @@ private final class GiftOptionsRowView: GeneralContainableRowView {
687615 self . starsPrice = nil
688616 }
689617
690- if let priceBadge = option. priceBadge {
691- let current : PriceBadgeView
692- if let view = self . priceBadgeView {
693- current = view
694- } else {
695- current = PriceBadgeView ( frame: . zero)
696- self . priceBadgeView = current
697- addSubview ( current)
698- }
699-
700- current. update ( priceBadge, context: context)
701- } else if let view = self . priceBadgeView {
702- performSubviewRemoval ( view, animated: animated)
703- self . priceBadgeView = nil
704- }
705-
706618 if selected {
707619 let current : View
708620 if let view = selectionView {
@@ -766,10 +678,6 @@ private final class GiftOptionsRowView: GeneralContainableRowView {
766678 if let selectionView {
767679 selectionView. frame = bounds. insetBy ( dx: 3 , dy: 3 )
768680 }
769-
770- if let priceBadgeView {
771- priceBadgeView. centerX ( y: frame. height - priceBadgeView. frame. height - 10 )
772- }
773681 }
774682 }
775683
@@ -814,7 +722,7 @@ private final class GiftOptionsRowView: GeneralContainableRowView {
814722
815723 for (i, subview) in content. subviews. enumerated ( ) {
816724 let view = subview as? OptionView
817- if view? . option? . gift ? . id != item. options [ i] . gift ? . id {
725+ if view? . option? . nativeStarGift ? . native . generic ? . id != item. options [ i] . nativeStarGift ? . native . generic ? . id {
818726 if animated {
819727 view? . layer? . animateScaleSpring ( from: 0.1 , to: 1 , duration: 0.35 )
820728 }
0 commit comments