Skip to content

Commit 2f70f72

Browse files
committed
bump
1 parent 257f5dd commit 2f70f72

File tree

3 files changed

+117
-19
lines changed

3 files changed

+117
-19
lines changed

Telegram-Mac/GiftOptionsRowItem.swift

Lines changed: 110 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ import SwiftSignalKit
1111
import TGUIKit
1212
import TelegramCore
1313

14+
extension StarGift {
15+
var id: Int64 {
16+
return self.generic?.id ?? self.unique?.id ?? 0
17+
}
18+
}
19+
1420
struct PremiumPaymentOption : Equatable {
1521
var title: String
1622
var desc: String
@@ -69,7 +75,7 @@ final class GiftOptionsRowItem : GeneralRowItem {
6975
struct Option {
7076
enum TypeValue {
7177
case price(String)
72-
case stars(Int64)
78+
case stars(Int64, Bool)
7379
case none
7480
}
7581
struct Badge {
@@ -85,6 +91,8 @@ final class GiftOptionsRowItem : GeneralRowItem {
8591
let invisible: Bool
8692
let pinned: Bool
8793

94+
let priceBadge: TextViewLayout?
95+
8896
var starsPrice: TextViewLayout?
8997

9098
var nativePayment: PremiumPaymentOption?
@@ -118,14 +126,14 @@ final class GiftOptionsRowItem : GeneralRowItem {
118126
starsPrice = nil
119127
}
120128

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)
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)
122130
}
123131
static func initialize(_ option: PeerStarGift) -> Option {
124132
let badge: Badge?
125133

126134
var redColor: [NSColor] = []
127135
var blueColor: [NSColor] = []
128-
136+
var greenColor: [NSColor] = [NSColor(0x74b036), NSColor(0x87d151)]
129137
if theme.colors.isDark {
130138
redColor = [NSColor(0x522124), NSColor(0x653634)]
131139
blueColor = [NSColor(0x142e42), NSColor(0x354f5b)]
@@ -135,7 +143,10 @@ final class GiftOptionsRowItem : GeneralRowItem {
135143
}
136144

137145
if let availability = option.native.generic?.availability {
138-
if availability.remains == 0 {
146+
if availability.minResaleStars != nil {
147+
//TODOLANG
148+
badge = .init(text: "resale", colors: greenColor, textColor: .white)
149+
} else if availability.remains == 0 {
139150
badge = .init(text: strings().giftSoldOut, colors: redColor, textColor: .white)
140151
} else {
141152
badge = .init(text: strings().starGiftLimited, colors: blueColor, textColor: theme.colors.underSelectedColor)
@@ -145,11 +156,29 @@ final class GiftOptionsRowItem : GeneralRowItem {
145156
} else {
146157
badge = nil
147158
}
148-
return .init(file: option.media, text: nil, type: .stars(option.stars), badge: badge, peer: nil, invisible: false, pinned: false, nativeStarGift: option)
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)
149160
}
150161

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)
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)
153182
}
154183

155184

@@ -163,11 +192,23 @@ final class GiftOptionsRowItem : GeneralRowItem {
163192
blueColor = [theme.colors.accent.withMultipliedBrightnessBy(1.1), theme.colors.accent.withMultipliedBrightnessBy(0.9)]
164193
}
165194

195+
var priceBadge: TextViewLayout? = nil
196+
166197
let badge: Badge?
167-
if let availability = option.gift.generic?.availability {
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 {
168209
badge = .init(text: strings().starTransactionAvailabilityOf(1, Int(availability.total).prettyNumber), colors: blueColor, textColor: theme.colors.underSelectedColor)
169210
} else if let unique = option.gift.unique {
170-
badge = .init(text: "\(unique.number)", colors: option.gift.backdropColor ?? blueColor, textColor: theme.colors.underSelectedColor)
211+
badge = .init(text: "#\(unique.number)", colors: option.gift.backdropColor ?? blueColor, textColor: theme.colors.underSelectedColor)
171212
} else {
172213
badge = nil
173214
}
@@ -179,7 +220,7 @@ final class GiftOptionsRowItem : GeneralRowItem {
179220
case .unique(let uniqueGift):
180221
file = uniqueGift.file!
181222
}
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)
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)
183224
}
184225

185226
var height: CGFloat {
@@ -286,6 +327,33 @@ private final class GiftOptionsRowView: GeneralContainableRowView {
286327
}
287328
}
288329

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+
289357
private let sticker = MediaAnimatedStickerView(frame: NSMakeRect(0, 0, 80, 80))
290358
private var textView: TextView?
291359
private var badgeView: ImageView?
@@ -298,6 +366,7 @@ private final class GiftOptionsRowView: GeneralContainableRowView {
298366
private var selectionView: View?
299367
private var starsPrice: InteractiveTextView?
300368
private var pinnedView: ImageView?
369+
private var priceBadgeView: PriceBadgeView?
301370

302371

303372
private class PriceView: View {
@@ -327,7 +396,7 @@ private final class GiftOptionsRowView: GeneralContainableRowView {
327396

328397
private class StarPriceView: View {
329398
private let textView = InteractiveTextView()
330-
private let effect = StarsButtonEffectLayer()
399+
let effect = StarsButtonEffectLayer()
331400
required init(frame frameRect: NSRect) {
332401
super.init(frame: frameRect)
333402
addSubview(textView)
@@ -450,7 +519,7 @@ private final class GiftOptionsRowView: GeneralContainableRowView {
450519
current.backgroundColor = option.gift?.unique != nil ? NSColor.white.withAlphaComponent(0.2) : theme.colors.accent.withAlphaComponent(0.2)
451520
current.update(text: priceLayout)
452521

453-
case .stars(let int64):
522+
case let .stars(int64, plain):
454523
if let view = self.priceView {
455524
performSubviewRemoval(view, animated: false)
456525
self.priceView = nil
@@ -464,12 +533,15 @@ private final class GiftOptionsRowView: GeneralContainableRowView {
464533
self.addSubview(current)
465534
self.starPriceView = current
466535
}
536+
537+
current.effect.isHidden = plain
538+
467539
let attr = NSMutableAttributedString()
468-
attr.append(string: "\(clown_space)\(int64)", color: GOLD, font: .medium(.text))
469-
attr.insertEmbedded(.embeddedAnimated(LocalAnimatedSticker.star_currency_new.file), for: clown)
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)
470542
let priceLayout = TextViewLayout(attr)
471543
priceLayout.measure(width: .greatestFiniteMagnitude)
472-
current.backgroundColor = GOLD.withAlphaComponent(0.2)
544+
current.backgroundColor = plain ? NSColor.white.withAlphaComponent(0.2) : GOLD.withAlphaComponent(0.2)
473545
current.update(text: priceLayout, context: context)
474546
case .none:
475547
if let view = self.priceView {
@@ -533,7 +605,7 @@ private final class GiftOptionsRowView: GeneralContainableRowView {
533605

534606
for attribute in uniqueGift.attributes {
535607
switch attribute {
536-
case let .backdrop(_, innerColor, outerColor, _, _, _):
608+
case let .backdrop(_, _, innerColor, outerColor, _, _, _):
537609
colors = [NSColor(UInt32(innerColor)), NSColor(UInt32(outerColor))]
538610
default:
539611
break
@@ -559,7 +631,7 @@ private final class GiftOptionsRowView: GeneralContainableRowView {
559631
switch attribute {
560632
case .pattern(_, let file, _):
561633
patternFile = file
562-
case let .backdrop(_, _, _, color, _, _):
634+
case let .backdrop(_, _, _, _, color, _, _):
563635
patternColor = NSColor(UInt32(color)).withAlphaComponent(0.7)
564636
default:
565637
break
@@ -615,6 +687,22 @@ private final class GiftOptionsRowView: GeneralContainableRowView {
615687
self.starsPrice = nil
616688
}
617689

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+
618706
if selected {
619707
let current: View
620708
if let view = selectionView {
@@ -678,6 +766,10 @@ private final class GiftOptionsRowView: GeneralContainableRowView {
678766
if let selectionView {
679767
selectionView.frame = bounds.insetBy(dx: 3, dy: 3)
680768
}
769+
770+
if let priceBadgeView {
771+
priceBadgeView.centerX(y: frame.height - priceBadgeView.frame.height - 10)
772+
}
681773
}
682774
}
683775

@@ -722,7 +814,7 @@ private final class GiftOptionsRowView: GeneralContainableRowView {
722814

723815
for (i, subview) in content.subviews.enumerated() {
724816
let view = subview as? OptionView
725-
if view?.option?.nativeStarGift?.native.generic?.id != item.options[i].nativeStarGift?.native.generic?.id {
817+
if view?.option?.gift?.id != item.options[i].gift?.id {
726818
if animated {
727819
view?.layer?.animateScaleSpring(from: 0.1, to: 1, duration: 0.35)
728820
}

Telegram-Mac/GroupCallView.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,10 @@ final class GroupCallView : View {
179179
addSubview(peersTableContainer)
180180
addSubview(peersTable)
181181

182+
peersTable.layer?.cornerRadius = 10
183+
peersTable.clipView.layer?.cornerRadius = 10
184+
peersTableContainer.layer?.cornerRadius = 10
185+
182186
addSubview(content)
183187

184188
addSubview(controlsContainer)
@@ -538,6 +542,7 @@ final class GroupCallView : View {
538542

539543
if let state = state, state.isConference, isFullScreen || state.videoActive(.main).isEmpty {
540544
rect.origin.y += 40
545+
rect.size.height -= 40
541546
}
542547

543548
return rect
@@ -608,6 +613,7 @@ final class GroupCallView : View {
608613
}
609614
if let state, state.isConference {
610615
rect.origin.y += 40
616+
rect.size.height -= 40
611617
}
612618
return rect
613619
}

Telegram-Mac/JoinGroupCallController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ private final class HeaderItemView: GeneralRowView {
244244
usersInfoView.centerX(y: frame.height - 20 - usersInfoView.frame.height)
245245

246246

247-
var avatarRect = self.focus(avatarsContainer.subviewsWidthSize)
247+
var avatarRect = self.focus(NSMakeSize(avatarsContainer.subviews.max(by: { $0.frame.maxX < $1.frame.maxX })?.frame.maxX ?? 0, avatarsContainer.subviewsWidthSize.height))
248248
avatarRect.origin.y = usersInfoView.frame.minY - avatarRect.height - 20
249249
self.avatarsContainer.frame = avatarRect
250250

0 commit comments

Comments
 (0)