mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-11-07 01:10:09 +00:00
Merge commit 'cf3bc1edbdbab6fecc24a4446a78cee8777ac2f6'
This commit is contained in:
commit
633b44843a
@ -28,7 +28,7 @@ public func formatTonUsdValue(_ value: Int64, divide: Bool = true, rate: Double
|
||||
return "$\(formattedValue)"
|
||||
}
|
||||
|
||||
public func formatTonAmountText(_ value: Int64, dateTimeFormat: PresentationDateTimeFormat, showPlus: Bool = false, maxDecimalPositions: Int = 2) -> String {
|
||||
public func formatTonAmountText(_ value: Int64, dateTimeFormat: PresentationDateTimeFormat, showPlus: Bool = false, maxDecimalPositions: Int? = 2) -> String {
|
||||
var balanceText = "\(abs(value))"
|
||||
while balanceText.count < 10 {
|
||||
balanceText.insert("0", at: balanceText.startIndex)
|
||||
@ -49,11 +49,13 @@ public func formatTonAmountText(_ value: Int64, dateTimeFormat: PresentationDate
|
||||
}
|
||||
|
||||
if let dotIndex = balanceText.range(of: dateTimeFormat.decimalSeparator) {
|
||||
if let maxDecimalPositions {
|
||||
if let endIndex = balanceText.index(dotIndex.upperBound, offsetBy: maxDecimalPositions, limitedBy: balanceText.endIndex) {
|
||||
balanceText = String(balanceText[balanceText.startIndex..<endIndex])
|
||||
} else {
|
||||
balanceText = String(balanceText[balanceText.startIndex..<balanceText.endIndex])
|
||||
}
|
||||
}
|
||||
|
||||
let integerPartString = balanceText[..<dotIndex.lowerBound]
|
||||
if let integerPart = Int32(integerPartString) {
|
||||
|
||||
@ -421,7 +421,6 @@ private final class GiftViewSheetContent: CombinedComponent {
|
||||
UndoOverlayController(
|
||||
presentationData: presentationData,
|
||||
content: .copy(text: presentationData.strings.Gift_View_CopiedAddress),
|
||||
elevatedLayout: false,
|
||||
position: .bottom,
|
||||
action: { _ in return true }
|
||||
),
|
||||
@ -484,7 +483,7 @@ private final class GiftViewSheetContent: CombinedComponent {
|
||||
undoText: presentationData.strings.Gift_Displayed_View,
|
||||
customAction: nil
|
||||
),
|
||||
elevatedLayout: lastController is ChatController,
|
||||
elevatedLayout: !(lastController is ChatController),
|
||||
action: { [weak navigationController] action in
|
||||
if case .undo = action, let navigationController, let giftsPeerId {
|
||||
let _ = (self.context.engine.data.get(TelegramEngine.EngineData.Item.Peer.Peer(id: giftsPeerId))
|
||||
@ -508,7 +507,7 @@ private final class GiftViewSheetContent: CombinedComponent {
|
||||
return true
|
||||
}
|
||||
)
|
||||
lastController.present(resultController, in: .window(.root))
|
||||
lastController.present(resultController, in: .current)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -608,10 +607,10 @@ private final class GiftViewSheetContent: CombinedComponent {
|
||||
customUndoText: nil,
|
||||
timeout: nil
|
||||
),
|
||||
elevatedLayout: lastController is ChatController,
|
||||
elevatedLayout: !(lastController is ChatController),
|
||||
action: { _ in return true }
|
||||
)
|
||||
lastController.present(resultController, in: .window(.root))
|
||||
lastController.present(resultController, in: .current)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -799,6 +798,8 @@ private final class GiftViewSheetContent: CombinedComponent {
|
||||
return
|
||||
}
|
||||
|
||||
let isTablet = controller.validLayout?.metrics.isTablet ?? false
|
||||
|
||||
controller.dismissAllTooltips()
|
||||
|
||||
let presentationData = self.context.sharedContext.currentPresentationData.with { $0 }
|
||||
@ -862,12 +863,12 @@ private final class GiftViewSheetContent: CombinedComponent {
|
||||
),
|
||||
position: .bottom,
|
||||
animateInAsReplacement: false,
|
||||
appearance: UndoOverlayController.Appearance(sideInset: 16.0, bottomInset: 62.0),
|
||||
appearance: isTablet ? nil : UndoOverlayController.Appearance(sideInset: 16.0, bottomInset: 62.0),
|
||||
action: { action in
|
||||
return false
|
||||
}
|
||||
)
|
||||
controller.present(tooltipController, in: .window(.root))
|
||||
controller.present(tooltipController, in: isTablet ? .current : .window(.root))
|
||||
})
|
||||
}),
|
||||
TextAlertAction(type: .genericAction, title: presentationData.strings.Common_Cancel, action: {
|
||||
@ -932,7 +933,7 @@ private final class GiftViewSheetContent: CombinedComponent {
|
||||
case .stars:
|
||||
priceString = presentationData.strings.Gift_View_Resale_Relist_Success_Stars(Int32(price.amount.value))
|
||||
case .ton:
|
||||
priceString = formatTonAmountText(price.amount.value, dateTimeFormat: presentationData.dateTimeFormat) + " TON"
|
||||
priceString = formatTonAmountText(price.amount.value, dateTimeFormat: presentationData.dateTimeFormat, maxDecimalPositions: nil) + " TON"
|
||||
}
|
||||
text = presentationData.strings.Gift_View_Resale_Relist_Success(giftTitle, priceString).string
|
||||
}
|
||||
@ -949,12 +950,12 @@ private final class GiftViewSheetContent: CombinedComponent {
|
||||
),
|
||||
position: .bottom,
|
||||
animateInAsReplacement: false,
|
||||
appearance: UndoOverlayController.Appearance(sideInset: 16.0, bottomInset: 62.0),
|
||||
appearance: isTablet ? nil : UndoOverlayController.Appearance(sideInset: 16.0, bottomInset: 62.0),
|
||||
action: { action in
|
||||
return false
|
||||
}
|
||||
)
|
||||
controller.present(tooltipController, in: .window(.root))
|
||||
controller.present(tooltipController, in: isTablet ? .current : .window(.root))
|
||||
})
|
||||
})
|
||||
controller.push(resellController)
|
||||
@ -1257,7 +1258,7 @@ private final class GiftViewSheetContent: CombinedComponent {
|
||||
case .stars:
|
||||
originalPriceString = presentationData.strings.Gift_Buy_ErrorPriceChanged_Text_Stars(Int32(resellAmount.amount.value))
|
||||
case .ton:
|
||||
originalPriceString = formatTonAmountText(resellAmount.amount.value, dateTimeFormat: presentationData.dateTimeFormat) + " TON"
|
||||
originalPriceString = formatTonAmountText(resellAmount.amount.value, dateTimeFormat: presentationData.dateTimeFormat, maxDecimalPositions: nil) + " TON"
|
||||
}
|
||||
|
||||
let newPriceString: String
|
||||
@ -1267,7 +1268,7 @@ private final class GiftViewSheetContent: CombinedComponent {
|
||||
newPriceString = presentationData.strings.Gift_Buy_ErrorPriceChanged_Text_Stars(Int32(newPrice.amount.value))
|
||||
buttonText = presentationData.strings.Gift_Buy_Confirm_BuyFor(Int32(newPrice.amount.value))
|
||||
case .ton:
|
||||
let tonValueString = formatTonAmountText(newPrice.amount.value, dateTimeFormat: presentationData.dateTimeFormat)
|
||||
let tonValueString = formatTonAmountText(newPrice.amount.value, dateTimeFormat: presentationData.dateTimeFormat, maxDecimalPositions: nil)
|
||||
newPriceString = tonValueString + " TON"
|
||||
buttonText = presentationData.strings.Gift_Buy_Confirm_BuyForTon(tonValueString).string
|
||||
}
|
||||
@ -1323,12 +1324,12 @@ private final class GiftViewSheetContent: CombinedComponent {
|
||||
let resultController = UndoOverlayController(
|
||||
presentationData: presentationData,
|
||||
content: .sticker(context: context, file: animationFile, loop: false, title: presentationData.strings.Gift_View_Resale_SuccessYou_Title, text: presentationData.strings.Gift_View_Resale_SuccessYou_Text(giftTitle).string, undoText: nil, customAction: nil),
|
||||
elevatedLayout: lastController is ChatController,
|
||||
elevatedLayout: !(lastController is ChatController),
|
||||
action: { _ in
|
||||
return true
|
||||
}
|
||||
)
|
||||
lastController.present(resultController, in: .window(.root))
|
||||
lastController.present(resultController, in: .current)
|
||||
}
|
||||
})
|
||||
} else {
|
||||
@ -1345,12 +1346,12 @@ private final class GiftViewSheetContent: CombinedComponent {
|
||||
let resultController = UndoOverlayController(
|
||||
presentationData: presentationData,
|
||||
content: .sticker(context: context, file: animationFile, loop: false, title: presentationData.strings.Gift_View_Resale_Success_Title, text: presentationData.strings.Gift_View_Resale_Success_Text(peer.compactDisplayTitle).string, undoText: nil, customAction: nil),
|
||||
elevatedLayout: lastController is ChatController,
|
||||
elevatedLayout: !(lastController is ChatController),
|
||||
action: { _ in
|
||||
return true
|
||||
}
|
||||
)
|
||||
lastController.present(resultController, in: .window(.root))
|
||||
lastController.present(resultController, in: .current)
|
||||
}
|
||||
})
|
||||
})
|
||||
@ -3383,6 +3384,8 @@ private final class GiftViewSheetContent: CombinedComponent {
|
||||
HapticFeedback().impact(.light)
|
||||
}))
|
||||
} else {
|
||||
let isTablet = environment.metrics.isTablet
|
||||
|
||||
let presentationData = context.sharedContext.currentPresentationData.with { $0 }
|
||||
let text = strings.Gift_View_TooltipPremiumWearing
|
||||
let tooltipController = UndoOverlayController(
|
||||
@ -3390,7 +3393,7 @@ private final class GiftViewSheetContent: CombinedComponent {
|
||||
content: .premiumPaywall(title: nil, text: text, customUndoText: nil, timeout: nil, linkAction: nil),
|
||||
position: .bottom,
|
||||
animateInAsReplacement: false,
|
||||
appearance: UndoOverlayController.Appearance(sideInset: 16.0, bottomInset: 62.0),
|
||||
appearance: isTablet ? nil : UndoOverlayController.Appearance(sideInset: 16.0, bottomInset: 62.0),
|
||||
action: { [weak controller, weak state] action in
|
||||
if case .info = action {
|
||||
controller?.dismissAllTooltips()
|
||||
@ -3404,7 +3407,7 @@ private final class GiftViewSheetContent: CombinedComponent {
|
||||
return false
|
||||
}
|
||||
)
|
||||
controller.present(tooltipController, in: .window(.root))
|
||||
controller.present(tooltipController, in: isTablet ? .current : .window(.root))
|
||||
}
|
||||
} else {
|
||||
state.commitWear(uniqueGift)
|
||||
@ -3540,7 +3543,7 @@ private final class GiftViewSheetContent: CombinedComponent {
|
||||
currencyAmount = formatStarsAmountText(resellAmount.amount, dateTimeFormat: environment.dateTimeFormat)
|
||||
case .ton:
|
||||
currencySymbol = "$"
|
||||
currencyAmount = formatTonAmountText(resellAmount.amount.value, dateTimeFormat: environment.dateTimeFormat)
|
||||
currencyAmount = formatTonAmountText(resellAmount.amount.value, dateTimeFormat: environment.dateTimeFormat, maxDecimalPositions: nil)
|
||||
|
||||
if let starsAmount = uniqueGift?.resellAmounts?.first(where: { $0.currency == .stars }) {
|
||||
//TODO:localize
|
||||
@ -3723,12 +3726,19 @@ final class GiftViewSheetComponent: CombinedComponent {
|
||||
)
|
||||
|
||||
if let controller = controller(), !controller.automaticallyControlPresentationContextLayout {
|
||||
var sideInset: CGFloat = 0.0
|
||||
var bottomInset: CGFloat = max(environment.safeInsets.bottom, sheetExternalState.contentHeight)
|
||||
if case .regular = environment.metrics.widthClass {
|
||||
sideInset = floor((context.availableSize.width - 430.0) / 2.0) - 12.0
|
||||
bottomInset = (context.availableSize.height - sheetExternalState.contentHeight) / 2.0 + sheetExternalState.contentHeight
|
||||
}
|
||||
|
||||
let layout = ContainerViewLayout(
|
||||
size: context.availableSize,
|
||||
metrics: environment.metrics,
|
||||
deviceMetrics: environment.deviceMetrics,
|
||||
intrinsicInsets: UIEdgeInsets(top: 0.0, left: 0.0, bottom: max(environment.safeInsets.bottom, sheetExternalState.contentHeight), right: 0.0),
|
||||
safeInsets: UIEdgeInsets(top: 0.0, left: environment.safeInsets.left, bottom: 0.0, right: environment.safeInsets.right),
|
||||
intrinsicInsets: UIEdgeInsets(top: 0.0, left: 0.0, bottom: bottomInset, right: 0.0),
|
||||
safeInsets: UIEdgeInsets(top: 0.0, left: max(sideInset, environment.safeInsets.left), bottom: 0.0, right: max(sideInset, environment.safeInsets.right)),
|
||||
additionalInsets: .zero,
|
||||
statusBarHeight: environment.statusBarHeight,
|
||||
inputHeight: nil,
|
||||
|
||||
@ -45,7 +45,7 @@ public final class StarsBalanceOverlayComponent: Component {
|
||||
|
||||
public final class View: UIView {
|
||||
private let backgroundView = BlurredBackgroundView(color: nil)
|
||||
private let text = ComponentView<Empty>()
|
||||
private var text = ComponentView<Empty>()
|
||||
private let action = ComponentView<Empty>()
|
||||
|
||||
private var component: StarsBalanceOverlayComponent?
|
||||
@ -89,6 +89,7 @@ public final class StarsBalanceOverlayComponent: Component {
|
||||
defer {
|
||||
self.isUpdating = false
|
||||
}
|
||||
let previousComponent = self.component
|
||||
self.component = component
|
||||
self.state = state
|
||||
|
||||
@ -169,6 +170,13 @@ public final class StarsBalanceOverlayComponent: Component {
|
||||
attributedText.addAttribute(.baselineOffset, value: 1.0, range: tonRange)
|
||||
}
|
||||
|
||||
if previousComponent?.currency != component.currency {
|
||||
if let textView = self.text.view {
|
||||
textView.removeFromSuperview()
|
||||
}
|
||||
self.text = ComponentView()
|
||||
}
|
||||
|
||||
let textSize = self.text.update(
|
||||
transition: .immediate,
|
||||
component: AnyComponent(
|
||||
@ -223,7 +231,6 @@ public final class StarsBalanceOverlayComponent: Component {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if let textView = self.text.view {
|
||||
if textView.superview == nil {
|
||||
self.backgroundView.addSubview(textView)
|
||||
|
||||
@ -660,7 +660,7 @@ private final class StarsTransactionSheetContent: CombinedComponent {
|
||||
case .stars:
|
||||
formattedAmount = formatStarsAmountText(absCount, dateTimeFormat: dateTimeFormat)
|
||||
case .ton:
|
||||
formattedAmount = formatTonAmountText(absCount.value, dateTimeFormat: dateTimeFormat)
|
||||
formattedAmount = formatTonAmountText(absCount.value, dateTimeFormat: dateTimeFormat, maxDecimalPositions: nil)
|
||||
}
|
||||
let countColor: UIColor
|
||||
var countFont: UIFont = isSubscription || isSubscriber ? Font.regular(17.0) : Font.semibold(17.0)
|
||||
@ -1207,14 +1207,25 @@ private final class StarsTransactionSheetContent: CombinedComponent {
|
||||
if transaction.flags.contains(.isPaidMessage) || transaction.flags.contains(.isStarGiftResale) {
|
||||
var totalStars = transaction.count
|
||||
if let starrefCount = transaction.starrefAmount {
|
||||
totalStars = CurrencyAmount(amount: totalStars.amount + starrefCount, currency: .stars)
|
||||
totalStars = CurrencyAmount(amount: totalStars.amount + starrefCount, currency: totalStars.currency)
|
||||
}
|
||||
var valueString = formatCurrencyAmountText(totalStars, dateTimeFormat: dateTimeFormat)
|
||||
switch totalStars.currency {
|
||||
case .stars:
|
||||
valueString = "\(valueString)⭐️"
|
||||
case .ton:
|
||||
valueString = "💎\(valueString)"
|
||||
}
|
||||
let valueString = "\(presentationStringsFormattedNumber(abs(Int32(totalStars.amount.value)), dateTimeFormat.groupingSeparator))⭐️"
|
||||
let valueAttributedString = NSMutableAttributedString(string: valueString, font: tableBoldFont, textColor: theme.list.itemDisclosureActions.constructive.fillColor)
|
||||
let range = (valueAttributedString.string as NSString).range(of: "⭐️")
|
||||
if range.location != NSNotFound {
|
||||
valueAttributedString.addAttribute(ChatTextInputAttributes.customEmoji, value: ChatTextInputTextCustomEmojiAttribute(interactivelySelectedFromPackId: nil, fileId: 0, file: nil, custom: .stars(tinted: false)), range: range)
|
||||
valueAttributedString.addAttribute(.baselineOffset, value: 1.0, range: range)
|
||||
let starRange = (valueAttributedString.string as NSString).range(of: "⭐️")
|
||||
if starRange.location != NSNotFound {
|
||||
valueAttributedString.addAttribute(ChatTextInputAttributes.customEmoji, value: ChatTextInputTextCustomEmojiAttribute(interactivelySelectedFromPackId: nil, fileId: 0, file: nil, custom: .stars(tinted: false)), range: starRange)
|
||||
valueAttributedString.addAttribute(.baselineOffset, value: 1.0, range: starRange)
|
||||
}
|
||||
let tonRange = (valueAttributedString.string as NSString).range(of: "💎")
|
||||
if tonRange.location != NSNotFound {
|
||||
valueAttributedString.addAttribute(ChatTextInputAttributes.customEmoji, value: ChatTextInputTextCustomEmojiAttribute(interactivelySelectedFromPackId: nil, fileId: 0, file: nil, custom: .ton(tinted: true)), range: tonRange)
|
||||
valueAttributedString.addAttribute(.baselineOffset, value: 1.0, range: tonRange)
|
||||
}
|
||||
tableItems.append(.init(
|
||||
id: "paid",
|
||||
|
||||
@ -467,7 +467,7 @@ private final class SheetContent: CombinedComponent {
|
||||
case .ton:
|
||||
if let value = state.amount?.value, value > 0 {
|
||||
let tonValue = Int64(Float(value) * Float(resaleConfiguration.starGiftCommissionTonPermille) / 1000.0)
|
||||
let tonString = formatTonAmountText(tonValue, dateTimeFormat: environment.dateTimeFormat) + " TON"
|
||||
let tonString = formatTonAmountText(tonValue, dateTimeFormat: environment.dateTimeFormat, maxDecimalPositions: nil) + " TON"
|
||||
amountInfoString = NSAttributedString(attributedString: parseMarkdownIntoAttributedString(environment.strings.Stars_SellGift_AmountInfo(tonString).string, attributes: amountMarkdownAttributes, textAlignment: .natural))
|
||||
|
||||
if let tonUsdRate = withdrawConfiguration.tonUsdRate {
|
||||
@ -778,7 +778,7 @@ private final class SheetContent: CombinedComponent {
|
||||
currencyAmount = presentationStringsFormattedNumber(amount, environment.dateTimeFormat.groupingSeparator)
|
||||
case .ton:
|
||||
currencySymbol = "$"
|
||||
currencyAmount = formatTonAmountText(amount.value, dateTimeFormat: environment.dateTimeFormat)
|
||||
currencyAmount = formatTonAmountText(amount.value, dateTimeFormat: environment.dateTimeFormat, maxDecimalPositions: nil)
|
||||
}
|
||||
buttonString = "\(environment.strings.Stars_SellGift_SellFor) \(currencySymbol) \(currencyAmount)"
|
||||
} else {
|
||||
@ -798,7 +798,7 @@ private final class SheetContent: CombinedComponent {
|
||||
currencyAmount = presentationStringsFormattedNumber(amount, environment.dateTimeFormat.groupingSeparator)
|
||||
case .ton:
|
||||
currencySymbol = "$"
|
||||
currencyAmount = formatTonAmountText(amount.value, dateTimeFormat: environment.dateTimeFormat)
|
||||
currencyAmount = formatTonAmountText(amount.value, dateTimeFormat: environment.dateTimeFormat, maxDecimalPositions: nil)
|
||||
}
|
||||
buttonString = environment.strings.Chat_PostSuggestion_Suggest_OfferButtonPrice("\(currencySymbol) \(currencyAmount)").string
|
||||
} else {
|
||||
@ -1423,7 +1423,7 @@ private final class AmountFieldStarsFormatter: NSObject, UITextFieldDelegate {
|
||||
case .stars:
|
||||
textField.text = "\(self.maxValue)"
|
||||
case .ton:
|
||||
textField.text = "\(formatTonAmountText(self.maxValue, dateTimeFormat: PresentationDateTimeFormat(timeFormat: self.dateTimeFormat.timeFormat, dateFormat: self.dateTimeFormat.dateFormat, dateSeparator: "", dateSuffix: "", requiresFullYear: false, decimalSeparator: ".", groupingSeparator: "")))"
|
||||
textField.text = "\(formatTonAmountText(self.maxValue, dateTimeFormat: PresentationDateTimeFormat(timeFormat: self.dateTimeFormat.timeFormat, dateFormat: self.dateTimeFormat.dateFormat, dateSeparator: "", dateSuffix: "", requiresFullYear: false, decimalSeparator: ".", groupingSeparator: ""), maxDecimalPositions: nil))"
|
||||
}
|
||||
self.onTextChanged(text: self.textField.text ?? "")
|
||||
self.animateError()
|
||||
@ -1592,7 +1592,7 @@ private final class AmountFieldComponent: Component {
|
||||
case .stars:
|
||||
text = "\(value)"
|
||||
case .ton:
|
||||
text = "\(formatTonAmountText(value, dateTimeFormat: PresentationDateTimeFormat(timeFormat: component.dateTimeFormat.timeFormat, dateFormat: component.dateTimeFormat.dateFormat, dateSeparator: "", dateSuffix: "", requiresFullYear: false, decimalSeparator: ".", groupingSeparator: "")))"
|
||||
text = "\(formatTonAmountText(value, dateTimeFormat: PresentationDateTimeFormat(timeFormat: component.dateTimeFormat.timeFormat, dateFormat: component.dateTimeFormat.dateFormat, dateSeparator: "", dateSuffix: "", requiresFullYear: false, decimalSeparator: ".", groupingSeparator: ""), maxDecimalPositions: nil))"
|
||||
}
|
||||
self.textField.text = text
|
||||
self.didSetValueOnce = true
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user