Stars fixes

This commit is contained in:
Ilya Laktyushin 2024-05-25 18:06:37 +04:00
parent 4d6810c5c0
commit b1be15e4a1
12 changed files with 81 additions and 51 deletions

View File

@ -1031,6 +1031,8 @@ public protocol ChatController: ViewController {
func performScrollToTop() -> Bool
func transferScrollingVelocity(_ velocity: CGFloat)
func updateIsScrollingLockedAtTop(isScrollingLockedAtTop: Bool)
func playShakeAnimation()
}
public protocol ChatMessagePreviewItemNode: AnyObject {

View File

@ -147,7 +147,7 @@ private final class SheetContent: CombinedComponent {
showPeer = true
case let .withdrawal(status, amount, date, provider, _, transactionUrl):
labelColor = theme.list.itemDestructiveColor
amountString = amountAttributedString(formatBalanceText(amount, decimalSeparator: dateTimeFormat.decimalSeparator), integralFont: integralFont, fractionalFont: fractionalFont, color: labelColor).mutableCopy() as! NSMutableAttributedString
amountString = amountAttributedString(formatBalanceText(amount, decimalSeparator: dateTimeFormat.groupingSeparator), integralFont: integralFont, fractionalFont: fractionalFont, color: labelColor).mutableCopy() as! NSMutableAttributedString
dateString = stringForFullDate(timestamp: date, strings: strings, dateTimeFormat: dateTimeFormat)
switch status {

View File

@ -982,7 +982,7 @@ private func settingsItems(data: PeerInfoScreenData?, context: AccountContext, p
if let starsState = data.starsState {
let balanceText: String
if starsState.balance > 0 {
balanceText = "\(starsState.balance)"
balanceText = presentationStringsFormattedNumber(Int32(starsState.balance), presentationData.dateTimeFormat.groupingSeparator)
} else {
balanceText = ""
}

View File

@ -787,7 +787,7 @@ private final class StarsPurchaseScreenComponent: CombinedComponent {
let balanceValue = balanceValue.update(
component: MultilineTextComponent(
text: .plain(NSAttributedString(
string: presentationStringsFormattedNumber(Int32(state.starsState?.balance ?? 0), environment.dateTimeFormat.decimalSeparator),
string: presentationStringsFormattedNumber(Int32(state.starsState?.balance ?? 0), environment.dateTimeFormat.groupingSeparator),
font: Font.semibold(14.0),
textColor: environment.theme.actionSheet.primaryTextColor
)),

View File

@ -127,11 +127,12 @@ private final class StarsTransactionSheetContent: CombinedComponent {
return { context in
let environment = context.environment[ViewControllerComponentContainer.Environment.self].value
let controller = environment.controller
let component = context.component
let theme = environment.theme
let strings = environment.strings
let dateTimeFormat = environment.dateTimeFormat
let accountContext = context.component.context
let state = context.state
let subject = component.subject
@ -171,7 +172,7 @@ private final class StarsTransactionSheetContent: CombinedComponent {
let toPeer: EnginePeer?
let photo: TelegramMediaWebFile?
let gloss = false
var delayedCloseOnOpenPeer = true
switch subject {
case let .transaction(transaction):
switch transaction.peer {
@ -218,9 +219,10 @@ private final class StarsTransactionSheetContent: CombinedComponent {
toPeer = nil
}
photo = receipt.invoiceMedia.photo
delayedCloseOnOpenPeer = false
}
let formattedAmount = presentationStringsFormattedNumber(abs(Int32(count)), dateTimeFormat.decimalSeparator)
let formattedAmount = presentationStringsFormattedNumber(abs(Int32(count)), dateTimeFormat.groupingSeparator)
if count < 0 {
amountText = "- \(formattedAmount)"
} else {
@ -300,11 +302,16 @@ private final class StarsTransactionSheetContent: CombinedComponent {
)
),
action: {
if toPeer.id != accountContext.account.peerId {
if delayedCloseOnOpenPeer {
component.openPeer(toPeer)
Queue.mainQueue().after(1.0, {
component.cancel(false)
})
} else {
if let controller = controller() as? StarsTransactionScreen, let navigationController = controller.navigationController, let chatController = navigationController.viewControllers.first(where: { $0 is ChatController }) as? ChatController {
chatController.playShakeAnimation()
}
component.cancel(true)
}
}
)
@ -325,11 +332,15 @@ private final class StarsTransactionSheetContent: CombinedComponent {
id: "transaction",
title: strings.Stars_Transaction_Id,
component: AnyComponent(
TransactionCellComponent(
textColor: tableTextColor,
accentColor: tableLinkColor,
transactionId: transactionId,
copy: {
Button(
content: AnyComponent(
TransactionCellComponent(
textColor: tableTextColor,
accentColor: tableLinkColor,
transactionId: transactionId
)
),
action: {
component.copyTransactionId()
}
)
@ -393,7 +404,7 @@ private final class StarsTransactionSheetContent: CombinedComponent {
fontSize: 17.0,
height: 50.0,
cornerRadius: 10.0,
gloss: gloss,
gloss: false,
iconName: nil,
animationName: nil,
iconPosition: .left,
@ -656,7 +667,7 @@ public class StarsTransactionScreen: ViewControllerComponentContainer {
guard let peer else {
return
}
context.sharedContext.navigateToChatController(NavigateToChatControllerParams(navigationController: navigationController, chatController: nil, context: context, chatLocation: .peer(peer), subject: nil, botStart: nil, updateTextInputState: nil, keepStack: .always, useExisting: false, purposefulAction: nil, scrollToEndIfExists: false, activateMessageSearch: nil, animated: true))
context.sharedContext.navigateToChatController(NavigateToChatControllerParams(navigationController: navigationController, chatController: nil, context: context, chatLocation: .peer(peer), subject: nil, botStart: nil, updateTextInputState: nil, keepStack: .always, useExisting: true, purposefulAction: nil, scrollToEndIfExists: false, activateMessageSearch: nil, animated: true))
})
}
@ -1029,13 +1040,11 @@ private final class TransactionCellComponent: Component {
let textColor: UIColor
let accentColor: UIColor
let transactionId: String
let copy: () -> Void
init(textColor: UIColor, accentColor: UIColor, transactionId: String, copy: @escaping () -> Void) {
init(textColor: UIColor, accentColor: UIColor, transactionId: String) {
self.textColor = textColor
self.accentColor = accentColor
self.transactionId = transactionId
self.copy = copy
}
static func ==(lhs: TransactionCellComponent, rhs: TransactionCellComponent) -> Bool {
@ -1075,14 +1084,7 @@ private final class TransactionCellComponent: Component {
let buttonSize = self.button.update(
transition: .immediate,
component: AnyComponent(
Button(
content: AnyComponent(
BundleIconComponent(name: "Chat/Context Menu/Copy", tintColor: component.accentColor)
),
action: {
component.copy()
}
)
BundleIconComponent(name: "Chat/Context Menu/Copy", tintColor: component.accentColor)
),
environment: {},
containerSize: CGSize(width: availableSize.width, height: availableSize.height)

View File

@ -237,7 +237,7 @@ final class StarsTransactionsListPanelComponent: Component {
let itemLabel: NSAttributedString
let labelString: String
let formattedLabel = presentationStringsFormattedNumber(abs(Int32(item.transaction.count)), environment.dateTimeFormat.decimalSeparator)
let formattedLabel = presentationStringsFormattedNumber(abs(Int32(item.transaction.count)), environment.dateTimeFormat.groupingSeparator)
if item.transaction.count < 0 {
labelString = "- \(formattedLabel)"
} else {
@ -475,8 +475,7 @@ private final class AvatarComponent: Component {
super.init(frame: frame)
self.iconView.contentMode = .center
self.iconView.image = UIImage(bundleImageName: "Premium/Stars/Apple")
self.iconView.contentMode = .scaleAspectFit
self.addSubnode(self.avatarNode)
self.addSubview(self.backgroundView)
@ -492,8 +491,8 @@ private final class AvatarComponent: Component {
self.state = state
let size = CGSize(width: 40.0, height: 40.0)
let gradientImage = generateGradientFilledCircleImage(diameter: size.width, colors: [UIColor(rgb: 0x2a9ef1).cgColor, UIColor(rgb: 0x72d5fd).cgColor], direction: .mirroredDiagonal)
var iconInset: CGFloat = 3.0
var iconOffset: CGFloat = 0.0
switch component.peer {
case let .peer(peer):
@ -507,34 +506,73 @@ private final class AvatarComponent: Component {
self.iconView.isHidden = true
self.avatarNode.isHidden = false
case .appStore:
self.backgroundView.image = gradientImage
self.backgroundView.image = generateGradientFilledCircleImage(
diameter: size.width,
colors: [
UIColor(rgb: 0x2a9ef1).cgColor,
UIColor(rgb: 0x72d5fd).cgColor
],
direction: .mirroredDiagonal
)
self.backgroundView.isHidden = false
self.iconView.isHidden = false
self.avatarNode.isHidden = true
self.iconView.image = UIImage(bundleImageName: "Premium/Stars/Apple")
case .playMarket:
self.backgroundView.image = gradientImage
self.backgroundView.image = generateGradientFilledCircleImage(
diameter: size.width,
colors: [
UIColor(rgb: 0x54cb68).cgColor,
UIColor(rgb: 0xa0de7e).cgColor
],
direction: .mirroredDiagonal
)
self.backgroundView.isHidden = false
self.iconView.isHidden = false
self.avatarNode.isHidden = true
self.iconView.image = UIImage(bundleImageName: "Premium/Stars/Google")
case .fragment:
self.backgroundView.image = gradientImage
self.backgroundView.image = generateFilledCircleImage(diameter: size.width, color: UIColor(rgb: 0x1b1f24))
self.backgroundView.isHidden = false
self.iconView.isHidden = false
self.avatarNode.isHidden = true
self.iconView.image = UIImage(bundleImageName: "Premium/Stars/Fragment")
iconOffset = 2.0
case .premiumBot:
self.backgroundView.image = gradientImage
iconInset = 7.0
self.backgroundView.image = generateGradientFilledCircleImage(
diameter: size.width,
colors: [
UIColor(rgb: 0x6b93ff).cgColor,
UIColor(rgb: 0x6b93ff).cgColor,
UIColor(rgb: 0x8d77ff).cgColor,
UIColor(rgb: 0xb56eec).cgColor,
UIColor(rgb: 0xb56eec).cgColor
],
direction: .mirroredDiagonal
)
self.backgroundView.isHidden = false
self.iconView.isHidden = false
self.avatarNode.isHidden = true
self.iconView.image = generateTintedImage(image: UIImage(bundleImageName: "Chat/Input/Media/EntityInputPremiumIcon"), color: .white)
case .unsupported:
self.backgroundView.image = gradientImage
iconInset = 7.0
self.backgroundView.image = generateGradientFilledCircleImage(
diameter: size.width,
colors: [
UIColor(rgb: 0xb1b1b1).cgColor,
UIColor(rgb: 0xcdcdcd).cgColor
],
direction: .mirroredDiagonal
)
self.backgroundView.isHidden = false
self.iconView.isHidden = false
self.avatarNode.isHidden = true
self.iconView.image = generateTintedImage(image: UIImage(bundleImageName: "Chat/Input/Media/EntityInputPremiumIcon"), color: .white)
}
self.avatarNode.frame = CGRect(origin: .zero, size: size)
self.iconView.frame = CGRect(origin: .zero, size: size)
self.iconView.frame = CGRect(origin: .zero, size: size).insetBy(dx: iconInset, dy: iconInset).offsetBy(dx: 0.0, dy: iconOffset)
self.backgroundView.frame = CGRect(origin: .zero, size: size)
return size

View File

@ -437,7 +437,7 @@ final class StarsTransactionsScreenComponent: Component {
transition: .immediate,
component: AnyComponent(MultilineTextComponent(
text: .plain(NSAttributedString(
string: presentationStringsFormattedNumber(Int32(self.starsState?.balance ?? 0), environment.dateTimeFormat.decimalSeparator),
string: presentationStringsFormattedNumber(Int32(self.starsState?.balance ?? 0), environment.dateTimeFormat.groupingSeparator),
font: Font.semibold(14.0),
textColor: environment.theme.actionSheet.primaryTextColor
)),

View File

@ -331,7 +331,7 @@ private final class SheetContent: CombinedComponent {
let balanceValue = balanceValue.update(
component: MultilineTextComponent(
text: .plain(NSAttributedString(
string: presentationStringsFormattedNumber(Int32(state.balance ?? 0), environment.dateTimeFormat.decimalSeparator),
string: presentationStringsFormattedNumber(Int32(state.balance ?? 0), environment.dateTimeFormat.groupingSeparator),
font: Font.semibold(16.0),
textColor: textColor
)),

View File

@ -1,12 +0,0 @@
{
"images" : [
{
"filename" : "topbalance.pdf",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}