Skip to content

Commit e574e2d

Browse files
author
Isaac
committed
Improvements
1 parent b625243 commit e574e2d

File tree

3 files changed

+115
-27
lines changed

3 files changed

+115
-27
lines changed

submodules/TelegramUI/Components/PeerInfo/PeerInfoRatingComponent/Sources/PeerInfoRatingComponent.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,8 +219,9 @@ public final class PeerInfoRatingComponent: Component {
219219

220220
var textFrame = CGRect(origin: CGPoint(x: floorToScreenPixels((size.width - textLayout.size.width) * 0.5), y: floorToScreenPixels((size.height - textLayout.size.height) * 0.5)), size: textLayout.size)
221221
if level == 1 {
222-
} else {
223222
textFrame.origin.x += UIScreenPixel
223+
} else {
224+
textFrame.origin.x += 0.0
224225
}
225226

226227
context.saveGState()

submodules/TelegramUI/Components/PeerInfo/PeerInfoScreen/Sources/PeerInfoHeaderNode.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1959,7 +1959,7 @@ final class PeerInfoHeaderNode: ASDisplayNode {
19591959
self.currentPendingStarRating = cachedData.pendingStarRating
19601960

19611961
#if DEBUG
1962-
self.currentPendingStarRating = TelegramStarPendingRating(rating: TelegramStarRating(level: starRating.level, currentLevelStars: starRating.currentLevelStars, stars: starRating.stars + 123, nextLevelStars: starRating.nextLevelStars), timestamp: 0)
1962+
self.currentPendingStarRating = TelegramStarPendingRating(rating: TelegramStarRating(level: starRating.level, currentLevelStars: starRating.currentLevelStars, stars: starRating.stars + 123, nextLevelStars: starRating.nextLevelStars), timestamp: Int32(Date().timeIntervalSince1970) + 60 * 60 * 24 * 3)
19631963
#endif
19641964
} else {
19651965
self.currentStarRating = nil

submodules/TelegramUI/Components/PeerInfo/ProfileLevelInfoScreen/Sources/ProfileLevelInfoScreen.swift

Lines changed: 112 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,14 @@ private final class ProfileLevelInfoScreenComponent: Component {
4242
return true
4343
}
4444

45+
private final class TransitionHint {
46+
let isChangingPreview: Bool
47+
48+
init(isChangingPreview: Bool) {
49+
self.isChangingPreview = isChangingPreview
50+
}
51+
}
52+
4553
private final class ScrollView: UIScrollView {
4654
override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? {
4755
return super.hitTest(point, with: event)
@@ -98,10 +106,12 @@ private final class ProfileLevelInfoScreenComponent: Component {
98106
private weak var state: EmptyComponentState?
99107
private var environment: ViewControllerComponentContainer.Environment?
100108
private var isUpdating: Bool = false
109+
private var isPreviewingPendingRating: Bool = false
101110

102111
private var itemLayout: ItemLayout?
103112
private var topOffsetDistance: CGFloat?
104113

114+
private var cachedChevronImage: UIImage?
105115
private var cachedCloseImage: UIImage?
106116

107117
override init(frame: CGRect) {
@@ -219,7 +229,7 @@ private final class ProfileLevelInfoScreenComponent: Component {
219229

220230
transition.setPosition(view: self.navigationBarContainer, position: CGPoint(x: 0.0, y: topOffset + itemLayout.containerInset))
221231

222-
let topOffsetDistance: CGFloat = min(200.0, floor(itemLayout.containerSize.height * 0.25))
232+
let topOffsetDistance: CGFloat = 80.0
223233
self.topOffsetDistance = topOffsetDistance
224234
var topOffsetFraction = topOffset / topOffsetDistance
225235
topOffsetFraction = max(0.0, min(1.0, topOffsetFraction))
@@ -273,6 +283,8 @@ private final class ProfileLevelInfoScreenComponent: Component {
273283
self.isUpdating = false
274284
}
275285

286+
let alphaTransition: ComponentTransition = transition.animation.isImmediate ? .immediate : .easeInOut(duration: 0.16)
287+
276288
let environment = environment[ViewControllerComponentContainer.Environment.self].value
277289
let themeUpdated = self.environment?.theme !== environment.theme
278290

@@ -337,10 +349,21 @@ private final class ProfileLevelInfoScreenComponent: Component {
337349
if component.peer.id == component.context.account.peerId {
338350
descriptionTextString = "The rating reflects your activity on Telegram. What affects it:"
339351

340-
if let pendingStarRating = component.pendingStarRating {
352+
let timestamp = Int32(Date().timeIntervalSince1970)
353+
if let pendingStarRating = component.pendingStarRating, pendingStarRating.timestamp > timestamp {
341354
if pendingStarRating.rating.stars > component.starRating.stars {
342355
let pendingPoints = pendingStarRating.rating.stars - component.starRating.stars
343-
secondaryDescriptionTextString = "The rating updates in 21 days after purchases.\n\(pendingPoints) points are pending."
356+
357+
if self.isPreviewingPendingRating {
358+
secondaryDescriptionTextString = "This will be your rating in 21 days,\n after \(pendingPoints) points are added. [Back >]()"
359+
} else {
360+
let dayCount = (pendingStarRating.timestamp - timestamp) / (24 * 60 * 60)
361+
if dayCount == 0 {
362+
secondaryDescriptionTextString = "The rating updates today.\n\(pendingPoints) points are pending."
363+
} else {
364+
secondaryDescriptionTextString = "The rating updates in \(dayCount) days after purchases.\n\(pendingPoints) points are pending."
365+
}
366+
}
344367
}
345368
}
346369
} else {
@@ -378,16 +401,36 @@ private final class ProfileLevelInfoScreenComponent: Component {
378401
]
379402

380403
let levelFraction: CGFloat
381-
if let nextLevelStars = component.starRating.nextLevelStars {
382-
levelFraction = Double(component.starRating.stars) / Double(nextLevelStars)
383-
} else {
384-
levelFraction = 1.0
385-
}
386404

387-
let badgeText = starCountString(Int64(component.starRating.stars), decimalSeparator: ".")
405+
let badgeText: String
388406
var badgeTextSuffix: String?
389-
if let nextLevelStars = component.starRating.nextLevelStars {
390-
badgeTextSuffix = " / \(starCountString(Int64(nextLevelStars), decimalSeparator: "."))"
407+
let currentLevel: Int32
408+
let nextLevel: Int32?
409+
410+
if let pendingStarRating = component.pendingStarRating, pendingStarRating.rating.stars > component.starRating.stars, self.isPreviewingPendingRating {
411+
badgeText = starCountString(Int64(pendingStarRating.rating.stars), decimalSeparator: ".")
412+
currentLevel = pendingStarRating.rating.level
413+
nextLevel = pendingStarRating.rating.nextLevelStars == nil ? nil : currentLevel + 1
414+
if let nextLevelStars = pendingStarRating.rating.nextLevelStars {
415+
badgeTextSuffix = " / \(starCountString(Int64(nextLevelStars), decimalSeparator: "."))"
416+
}
417+
if let nextLevelStars = pendingStarRating.rating.nextLevelStars {
418+
levelFraction = Double(pendingStarRating.rating.stars) / Double(nextLevelStars)
419+
} else {
420+
levelFraction = 1.0
421+
}
422+
} else {
423+
badgeText = starCountString(Int64(component.starRating.stars), decimalSeparator: ".")
424+
currentLevel = component.starRating.level
425+
nextLevel = component.starRating.nextLevelStars == nil ? nil : currentLevel + 1
426+
if let nextLevelStars = component.starRating.nextLevelStars {
427+
badgeTextSuffix = " / \(starCountString(Int64(nextLevelStars), decimalSeparator: "."))"
428+
}
429+
if let nextLevelStars = component.starRating.nextLevelStars {
430+
levelFraction = Double(component.starRating.stars) / Double(nextLevelStars)
431+
} else {
432+
levelFraction = 1.0
433+
}
391434
}
392435

393436
let levelInfoSize = self.levelInfo.update(
@@ -399,7 +442,7 @@ private final class ProfileLevelInfoScreenComponent: Component {
399442
inactiveValue: "",
400443
inactiveTitleColor: environment.theme.list.itemPrimaryTextColor,
401444
activeTitle: "",
402-
activeValue: component.starRating.nextLevelStars == nil ? "" : "Level \(component.starRating.level + 1)",
445+
activeValue: nextLevel.flatMap { "Level \($0)" } ?? "",
403446
activeTitleColor: .white,
404447
badgeIconName: "Peer Info/ProfileLevelProgressIcon",
405448
badgeText: badgeText,
@@ -421,32 +464,72 @@ private final class ProfileLevelInfoScreenComponent: Component {
421464

422465
contentHeight += 129.0
423466

467+
let isChangingPreview = transition.userData(TransitionHint.self)?.isChangingPreview ?? false
468+
424469
if let secondaryDescriptionTextString {
470+
if isChangingPreview, let secondaryDescriptionTextView = self.secondaryDescriptionText?.view {
471+
self.secondaryDescriptionText = nil
472+
transition.setTransform(view: secondaryDescriptionTextView, transform: CATransform3DMakeScale(0.9, 0.9, 1.0))
473+
alphaTransition.setAlpha(view: secondaryDescriptionTextView, alpha: 0.0, completion: { [weak secondaryDescriptionTextView] _ in
474+
secondaryDescriptionTextView?.removeFromSuperview()
475+
})
476+
}
477+
425478
contentHeight -= 8.0
426479
let secondaryDescriptionText: ComponentView<Empty>
480+
var secondaryDescriptionTextTransition = transition
427481
if let current = self.secondaryDescriptionText {
428482
secondaryDescriptionText = current
429483
} else {
484+
secondaryDescriptionTextTransition = .immediate
430485
secondaryDescriptionText = ComponentView()
431486
self.secondaryDescriptionText = secondaryDescriptionText
432487
}
488+
489+
let secondaryDescriptionAttributedString = NSMutableAttributedString(attributedString: parseMarkdownIntoAttributedString(secondaryDescriptionTextString, attributes: MarkdownAttributes(
490+
body: MarkdownAttributeSet(font: Font.regular(13.0), textColor: environment.theme.list.itemSecondaryTextColor),
491+
bold: MarkdownAttributeSet(font: Font.semibold(13.0), textColor: environment.theme.list.itemSecondaryTextColor),
492+
link: MarkdownAttributeSet(font: Font.regular(13.0), textColor: environment.theme.list.itemAccentColor),
493+
linkAttribute: { url in
494+
return ("URL", url)
495+
}
496+
)))
497+
498+
let chevronImage: UIImage?
499+
if let current = self.cachedChevronImage {
500+
chevronImage = current
501+
} else {
502+
chevronImage = generateTintedImage(image: UIImage(bundleImageName: "Item List/InlineTextRightArrow"), color: .white)
503+
self.cachedChevronImage = chevronImage
504+
}
505+
if let range = secondaryDescriptionAttributedString.string.range(of: ">"), let chevronImage {
506+
secondaryDescriptionAttributedString.addAttribute(.attachment, value: chevronImage, range: NSRange(range, in: secondaryDescriptionAttributedString.string))
507+
}
508+
433509
let secondaryDescriptionTextSize = secondaryDescriptionText.update(
434510
transition: .immediate,
435511
component: AnyComponent(BalancedTextComponent(
436-
text: .markdown(
437-
text: secondaryDescriptionTextString,
438-
attributes: MarkdownAttributes(
439-
body: MarkdownAttributeSet(font: Font.regular(13.0), textColor: environment.theme.list.itemSecondaryTextColor),
440-
bold: MarkdownAttributeSet(font: Font.semibold(13.0), textColor: environment.theme.list.itemSecondaryTextColor),
441-
link: MarkdownAttributeSet(font: Font.regular(13.0), textColor: environment.theme.list.itemAccentColor),
442-
linkAttribute: { url in
443-
return ("URL", url)
444-
}
445-
)
446-
),
512+
text: .plain(secondaryDescriptionAttributedString),
447513
horizontalAlignment: .center,
448514
maximumNumberOfLines: 0,
449-
lineSpacing: 0.2
515+
lineSpacing: 0.2,
516+
highlightColor: environment.theme.list.itemAccentColor.withMultipliedAlpha(0.1),
517+
highlightAction: { attributes in
518+
if let _ = attributes[NSAttributedString.Key(rawValue: "URL")] {
519+
return NSAttributedString.Key(rawValue: "URL")
520+
} else {
521+
return nil
522+
}
523+
},
524+
tapAction: { [weak self] attributes, _ in
525+
guard let self else {
526+
return
527+
}
528+
self.isPreviewingPendingRating = !self.isPreviewingPendingRating
529+
var transition: ComponentTransition = .spring(duration: 0.4)
530+
transition = transition.withUserData(TransitionHint(isChangingPreview: true))
531+
self.state?.updated(transition: transition)
532+
}
450533
)),
451534
environment: {},
452535
containerSize: CGSize(width: availableSize.width - sideInset * 2.0, height: 10000.0)
@@ -455,8 +538,12 @@ private final class ProfileLevelInfoScreenComponent: Component {
455538
if let secondaryDescriptionTextView = secondaryDescriptionText.view {
456539
if secondaryDescriptionTextView.superview == nil {
457540
self.scrollContentView.addSubview(secondaryDescriptionTextView)
541+
if isChangingPreview {
542+
transition.animateScale(view: secondaryDescriptionTextView, from: 0.9, to: 1.0)
543+
alphaTransition.animateAlpha(view: secondaryDescriptionTextView, from: 0.0, to: 1.0)
544+
}
458545
}
459-
transition.setPosition(view: secondaryDescriptionTextView, position: secondaryDescriptionTextFrame.center)
546+
secondaryDescriptionTextTransition.setPosition(view: secondaryDescriptionTextView, position: secondaryDescriptionTextFrame.center)
460547
secondaryDescriptionTextView.bounds = CGRect(origin: CGPoint(), size: secondaryDescriptionTextFrame.size)
461548
}
462549
contentHeight += secondaryDescriptionTextSize.height

0 commit comments

Comments
 (0)