Skip to content

Commit 9895601

Browse files
committed
gift folders
1 parent 78ae252 commit 9895601

File tree

19 files changed

+471
-99
lines changed

19 files changed

+471
-99
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"images" : [
3+
{
4+
"filename" : "gift_add_30.png",
5+
"idiom" : "universal",
6+
"scale" : "1x"
7+
},
8+
{
9+
"filename" : "gift_add_30@2x.png",
10+
"idiom" : "universal",
11+
"scale" : "2x"
12+
},
13+
{
14+
"idiom" : "universal",
15+
"scale" : "3x"
16+
}
17+
],
18+
"info" : {
19+
"author" : "xcode",
20+
"version" : 1
21+
}
22+
}
462 Bytes
Loading
784 Bytes
Loading
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"images" : [
3+
{
4+
"filename" : "menu_folder_add.png",
5+
"idiom" : "universal",
6+
"scale" : "1x"
7+
},
8+
{
9+
"filename" : "menu_folder_add@2x.png",
10+
"idiom" : "universal",
11+
"scale" : "2x"
12+
},
13+
{
14+
"idiom" : "universal",
15+
"scale" : "3x"
16+
}
17+
],
18+
"info" : {
19+
"author" : "xcode",
20+
"version" : 1
21+
}
22+
}
317 Bytes
Loading
469 Bytes
Loading

‎Telegram-Mac/GiftOptionsRowItem.swift‎

Lines changed: 75 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import Foundation
1010
import SwiftSignalKit
1111
import TGUIKit
1212
import TelegramCore
13+
import TelegramMedia
1314

1415
extension StarGift {
1516
var id: Int64 {
@@ -81,7 +82,27 @@ struct PeerStarGift : Equatable {
8182

8283
final class GiftOptionsRowItem : GeneralRowItem {
8384

84-
struct Option {
85+
struct Option : Equatable {
86+
87+
static func ==(lhs: Option, rhs: Option) -> Bool {
88+
if lhs.nativePayment != rhs.nativePayment {
89+
return false
90+
}
91+
if lhs.nativeProfileGift != rhs.nativeProfileGift {
92+
return false
93+
}
94+
if lhs.nativeStarGift != rhs.nativeStarGift {
95+
return false
96+
}
97+
if lhs.nativeStarUniqueGift != rhs.nativeStarUniqueGift {
98+
return false
99+
}
100+
if lhs.file != rhs.file {
101+
return false
102+
}
103+
return true
104+
}
105+
85106
enum TypeValue {
86107
case price(String)
87108
case stars(Int64, Bool, Bool)
@@ -93,7 +114,9 @@ final class GiftOptionsRowItem : GeneralRowItem {
93114
let textColor: NSColor
94115
let outline: Bool
95116
}
96-
let file: TelegramMediaFile
117+
let file: TelegramMediaFile?
118+
let image: CGImage?
119+
let colors: [LottieColor]
97120
let text: NSAttributedString?
98121
let type: TypeValue
99122
let badge: Badge?
@@ -137,8 +160,15 @@ final class GiftOptionsRowItem : GeneralRowItem {
137160
starsPrice = nil
138161
}
139162

140-
return .init(file: option.media.file, text: option.text, type: .price(option.total), badge: option.discount.flatMap { .init(text: $0, colors: colors, textColor: .white, outline: false )}, peer: nil, invisible: false, pinned: false, toggleSelect: nil, priceBadge: nil, starsPrice: starsPrice, nativePayment: option)
163+
return .init(file: option.media.file, image: nil, colors: [], text: option.text, type: .price(option.total), badge: option.discount.flatMap { .init(text: $0, colors: colors, textColor: .white, outline: false )}, peer: nil, invisible: false, pinned: false, toggleSelect: nil, priceBadge: nil, starsPrice: starsPrice, nativePayment: option)
141164
}
165+
166+
167+
static func initialize(_ image: CGImage, text: NSAttributedString) -> Option {
168+
return .init(file: nil, image: image, colors: [], text: text, type: .none, badge: nil, peer: nil, invisible: false, pinned: false, toggleSelect: nil, priceBadge: nil, starsPrice: nil, nativePayment: nil)
169+
}
170+
171+
142172
static func initialize(_ option: PeerStarGift) -> Option {
143173
let badge: Badge?
144174

@@ -183,7 +213,7 @@ final class GiftOptionsRowItem : GeneralRowItem {
183213
resale = false
184214
}
185215

186-
return .init(file: option.media, text: nil, type: .stars(price, false, resale), badge: badge, peer: nil, invisible: false, pinned: false, toggleSelect: nil, priceBadge: nil, nativeStarGift: option)
216+
return .init(file: option.media, image: nil, colors: [], text: nil, type: .stars(price, false, resale), badge: badge, peer: nil, invisible: false, pinned: false, toggleSelect: nil, priceBadge: nil, nativeStarGift: option)
187217
}
188218

189219
static func initialize(_ option: StarGift.UniqueGift, resale: Bool = false, showNumber: Bool = false) -> Option {
@@ -205,7 +235,7 @@ final class GiftOptionsRowItem : GeneralRowItem {
205235
badge = nil
206236
}
207237

208-
return .init(file: option.file!, text: nil, type: option.resellStars != nil ? .stars(option.resellStars!, true, resale) : .none, badge: badge, peer: nil, invisible: false, pinned: false, toggleSelect: nil, priceBadge: nil, nativeStarUniqueGift: option)
238+
return .init(file: option.file!, image: nil, colors: [], text: nil, type: option.resellStars != nil ? .stars(option.resellStars!, true, resale) : .none, badge: badge, peer: nil, invisible: false, pinned: false, toggleSelect: nil, priceBadge: nil, nativeStarUniqueGift: option)
209239
}
210240

211241

@@ -246,7 +276,7 @@ final class GiftOptionsRowItem : GeneralRowItem {
246276
case .unique(let uniqueGift):
247277
file = uniqueGift.file!
248278
}
249-
return .init(file: file, text: nil, type: transfrarable ? .price(strings().starNftTransfer) : .none, badge: badge, peer: selected != nil ? nil : option.fromPeer, invisible: selected != nil ? false : !option.savedToProfile, pinned: selected != nil ? false : option.pinnedToTop, toggleSelect: selected, priceBadge: selected != nil ? nil : priceBadge, nativeProfileGift: option)
279+
return .init(file: file, image: nil, colors: [], text: nil, type: transfrarable ? .price(strings().starNftTransfer) : .none, badge: badge, peer: selected != nil ? nil : option.fromPeer, invisible: selected != nil ? false : !option.savedToProfile, pinned: selected != nil ? false : option.pinnedToTop, toggleSelect: selected, priceBadge: selected != nil ? nil : priceBadge, nativeProfileGift: option)
250280
}
251281

252282
var height: CGFloat {
@@ -293,7 +323,7 @@ final class GiftOptionsRowItem : GeneralRowItem {
293323
itemSize = NSMakeSize(width - self.inset.right - self.inset.left, self.height)
294324
} else {
295325
let insets = self.inset
296-
let count = self.fitToSize ? CGFloat(self.options.count) : 3
326+
let count = self.fitToSize ? CGFloat(self.options.count) : CGFloat(self.perRowCount)
297327
let space = self.width - insets.left - insets.right - (10 * CGFloat(count - 1))
298328
itemSize = NSMakeSize(floorToScreenPixels(space / count), self.height)
299329
}
@@ -381,6 +411,7 @@ private final class GiftOptionsRowView: GeneralContainableRowView {
381411
}
382412

383413
private let sticker = MediaAnimatedStickerView(frame: NSMakeRect(0, 0, 80, 80))
414+
private var imageView: ImageView?
384415
private var textView: TextView?
385416
private var badgeView: ImageView?
386417
private var badgeOutlineView: ImageView?
@@ -488,8 +519,29 @@ private final class GiftOptionsRowView: GeneralContainableRowView {
488519
callback(option)
489520
}, for: .Click)
490521

491-
let parameters = ChatAnimatedStickerMediaLayoutParameters(playPolicy: .framesCount(1), alwaysAccept: true, cache: .temporaryLZ4(.thumb), hidePlayer: false, media: option.file, shimmer: false, thumbAtFrame: 1)
492-
self.sticker.update(with: option.file, size: self.sticker.frame.size, context: context, table: nil, parameters: parameters, animated: false)
522+
if let file = option.file {
523+
let parameters = ChatAnimatedStickerMediaLayoutParameters(playPolicy: .framesCount(2), alwaysAccept: true, cache: .temporaryLZ4(.thumb), hidePlayer: false, media: file, colors: option.colors, shimmer: false, thumbAtFrame: 1)
524+
self.sticker.update(with: file, size: self.sticker.frame.size, context: context, table: nil, parameters: parameters, animated: false)
525+
}
526+
527+
self.sticker.isHidden = option.file == nil
528+
529+
if let image = option.image {
530+
let current: ImageView
531+
if let view = self.imageView {
532+
current = view
533+
} else {
534+
current = ImageView()
535+
self.addSubview(current)
536+
self.imageView = current
537+
current.isEventLess = true
538+
}
539+
current.image = image
540+
current.sizeToFit()
541+
} else if let view = self.imageView {
542+
performSubviewRemoval(view, animated: false)
543+
self.imageView = nil
544+
}
493545

494546
if let text = option.text {
495547
let current: TextView
@@ -756,7 +808,7 @@ private final class GiftOptionsRowView: GeneralContainableRowView {
756808
self.selectionView = nil
757809
}
758810

759-
if option.gift?.generic?.flags.contains(.requiresPremium) == true, let badge = option.badge {
811+
if option.gift?.generic?.flags.contains(.requiresPremium) == true, option.nativeStarGift != nil, let badge = option.badge {
760812
let current: View
761813
if let view = premiumSelectView {
762814
current = view
@@ -769,8 +821,8 @@ private final class GiftOptionsRowView: GeneralContainableRowView {
769821
current.layer?.borderColor = badge.colors[0].cgColor
770822
current.layer?.borderWidth = 1
771823

772-
} else if let selectionView {
773-
performSubviewRemoval(selectionView, animated: animated)
824+
} else if let premiumSelectView {
825+
performSubviewRemoval(premiumSelectView, animated: animated)
774826
self.premiumSelectView = nil
775827
}
776828

@@ -854,7 +906,7 @@ private final class GiftOptionsRowView: GeneralContainableRowView {
854906
backgroundView.frame = NSMakeRect(1, 1, bounds.width - 2, bounds.height - 1)
855907
}
856908
if let emoji {
857-
emoji.frame = bounds.insetBy(dx: 1, dy: 1).offsetBy(dx: 0, dy: 25)
909+
emoji.frame = bounds.insetBy(dx: 1, dy: 1).offsetBy(dx: 0, dy: 33)
858910
}
859911

860912
surfaceView.frame = bounds.insetBy(dx: 1, dy: 1)
@@ -872,6 +924,15 @@ private final class GiftOptionsRowView: GeneralContainableRowView {
872924
premiumSelectView.frame = bounds.insetBy(dx: 1, dy: 1)
873925
}
874926

927+
if let imageView {
928+
imageView.centerX(y: 20)
929+
if let textView {
930+
textView.centerX(y: frame.height - textView.frame.height - 20)
931+
}
932+
} else {
933+
textView?.centerX(y: sticker.frame.maxY + 5)
934+
}
935+
875936

876937
if let priceBadgeView {
877938
priceBadgeView.centerX(y: frame.height - priceBadgeView.frame.height - 10)
@@ -952,7 +1013,7 @@ private final class GiftOptionsRowView: GeneralContainableRowView {
9521013
itemSize = NSMakeSize(content.frame.width - item.inset.right - item.inset.left, content.frame.height)
9531014
} else {
9541015
let insets = item.inset
955-
let count = item.fitToSize ? CGFloat(item.options.count) : 3
1016+
let count = item.fitToSize ? CGFloat(item.options.count) : CGFloat(item.perRowCount)
9561017
let space = content.frame.width - insets.left - insets.right - (10 * CGFloat(count - 1))
9571018
itemSize = NSMakeSize(floor(space / count), content.frame.height)
9581019
}

‎Telegram-Mac/Info.plist‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
</dict>
3434
</array>
3535
<key>CFBundleVersion</key>
36-
<string>274004</string>
36+
<string>274056</string>
3737
<key>ITSAppUsesNonExemptEncryption</key>
3838
<false/>
3939
<key>LSApplicationCategoryType</key>

‎Telegram-Mac/LottieLocalAnimations.swift‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ enum LocalAnimatedSticker : String {
217217
case menu_expand
218218
case menu_replace
219219
case menu_folder
220+
case menu_folder_add
220221
case menu_calendar
221222
case menu_reactions
222223
case menu_music

‎Telegram-Mac/MediaAnimatedStickerView.swift‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ class MediaAnimatedStickerView: ChatMediaContentView {
357357
}
358358
let effective = size
359359

360-
self.sticker = LottieAnimation(compressed: data, key: LottieAnimationEntryKey(key: .media(file.id), size: effective, fitzModifier: fitzModifier, mirror: mirror), type: type, cachePurpose: cache, playPolicy: playPolicy, maximumFps: maximumFps, colors: parameters?.colors ?? [], soundEffect: soundEffect, postbox: self.context?.account.postbox, metalSupport: false)
360+
self.sticker = LottieAnimation(compressed: data, key: LottieAnimationEntryKey(key: .media(file.id), size: effective, fitzModifier: fitzModifier, colors: parameters?.colors ?? [], mirror: mirror), type: type, cachePurpose: cache, playPolicy: playPolicy, maximumFps: maximumFps, colors: parameters?.colors ?? [], soundEffect: soundEffect, postbox: self.context?.account.postbox, metalSupport: false)
361361

362362
self.fetchStatus = .Local
363363
} else {

0 commit comments

Comments
 (0)