Various fixes

This commit is contained in:
Ilya Laktyushin 2024-06-16 02:46:28 +04:00
parent 8304a9c0a0
commit a232ba765f
9 changed files with 108 additions and 36 deletions

View File

@ -12247,6 +12247,8 @@ Sorry for the inconvenience.";
"Stars.Intro.Transaction.PremiumBotTopUp.Subtitle" = "via Premium Bot";
"Stars.Intro.Transaction.FragmentTopUp.Title" = "Stars Top-Up";
"Stars.Intro.Transaction.FragmentTopUp.Subtitle" = "via Fragment";
"Stars.Intro.Transaction.FragmentWithdrawal.Title" = "Withdrawal";
"Stars.Intro.Transaction.FragmentWithdrawal.Subtitle" = "via Fragment";
"Stars.Intro.Transaction.Unsupported.Title" = "Unsupported";
"Stars.Intro.Transaction.Refund" = "Refund";
@ -12287,6 +12289,8 @@ Sorry for the inconvenience.";
"Stars.Transaction.PremiumBotTopUp.Subtitle" = "Premium Bot";
"Stars.Transaction.FragmentTopUp.Title" = "Stars Top-Up";
"Stars.Transaction.FragmentTopUp.Subtitle" = "Fragment";
"Stars.Transaction.FragmentWithdrawal.Title" = "Stars Withdrawal";
"Stars.Transaction.FragmentWithdrawal.Subtitle" = "Fragment";
"Stars.Transaction.Unsupported.Title" = "Unsupported";
"Stars.Transaction.Refund" = "Refund";
@ -12336,6 +12340,7 @@ Sorry for the inconvenience.";
"Stars.BotRevenue.Withdraw.Balance" = "Available Balance";
"Stars.BotRevenue.Withdraw.Withdraw" = "Withdraw via Fragment";
"Stars.BotRevenue.Withdraw.Info" = "You can withdraw Stars using Fragment, or use Stars to advertise your bot. [Learn More >]()";
"Stars.BotRevenue.Withdraw.Info_URL" = "https://telegram.org/tos";
"Stars.BotRevenue.Transactions.Title" = "Transaction History";

View File

@ -1066,7 +1066,7 @@ public protocol SharedAccountContext: AnyObject {
func makeStarsTransactionsScreen(context: AccountContext, starsContext: StarsContext) -> ViewController
func makeStarsPurchaseScreen(context: AccountContext, starsContext: StarsContext, options: [StarsTopUpOption], peerId: EnginePeer.Id?, requiredStars: Int64?, completion: @escaping (Int64) -> Void) -> ViewController
func makeStarsTransferScreen(context: AccountContext, starsContext: StarsContext, invoice: TelegramMediaInvoice, source: BotPaymentInvoiceSource, inputData: Signal<(StarsContext.State, BotPaymentForm, EnginePeer?)?, NoError>, completion: @escaping (Bool) -> Void) -> ViewController
func makeStarsTransactionScreen(context: AccountContext, transaction: StarsContext.State.Transaction) -> ViewController
func makeStarsTransactionScreen(context: AccountContext, transaction: StarsContext.State.Transaction, isAccount: Bool) -> ViewController
func makeStarsReceiptScreen(context: AccountContext, receipt: BotPaymentReceipt) -> ViewController
func makeStarsStatisticsScreen(context: AccountContext, peerId: EnginePeer.Id, revenueContext: StarsRevenueStatsContext) -> ViewController
func makeStarsAmountScreen(context: AccountContext, completion: @escaping (Int64) -> Void) -> ViewController

View File

@ -19,6 +19,7 @@ public enum ChartType {
case twoAxisHourlyStep
case twoAxis5MinStep
case currency
case stars
}
public extension ChartTheme {
@ -87,7 +88,42 @@ public func createChartController(_ data: String, type: ChartType, rate: Double
controller = StackedBarsChartController(chartsCollection: collection)
controller.isZoomable = false
case .currency:
controller = StackedBarsChartController(chartsCollection: collection, currency: .ton, rate: rate)
var iconCache: [UInt32: UIImage] = [:]
controller = StackedBarsChartController(chartsCollection: collection, currency: .ton, drawCurrency: { context, color, point in
let icon: UIImage?
if let current = iconCache[color.rgb] {
icon = current
} else if let image = generateTintedImage(image: UIImage(bundleImageName: "Ads/Ton"), color: color) {
icon = generateImage(image.size, rotatedContext: { size, context in
context.clear(CGRect(origin: .zero, size: size))
if let cgImage = image.cgImage {
context.draw(cgImage, in: CGRect(origin: .zero, size: size), byTiling: false)
}
})
iconCache[color.rgb] = icon
} else {
icon = nil
}
if let icon, let cgImage = icon.cgImage {
context.draw(cgImage, in: CGRect(origin: point.offsetBy(dx: 0.0, dy: -2.0), size: icon.size), byTiling: false)
}
}, rate: rate)
controller.isZoomable = false
case .stars:
var icon: UIImage?
if let image = UIImage(bundleImageName: "Premium/Stars/StarSmall") {
icon = generateImage(CGSize(width: floor(image.size.width * 0.82), height: floor(image.size.width * 0.82)), rotatedContext: { size, context in
context.clear(CGRect(origin: .zero, size: size))
if let cgImage = image.cgImage {
context.draw(cgImage, in: CGRect(origin: .zero, size: size), byTiling: false)
}
})
}
controller = StackedBarsChartController(chartsCollection: collection, currency: .xtr, drawCurrency: { context, color, point in
if let icon, let cgImage = icon.cgImage {
context.draw(cgImage, in: CGRect(origin: point.offsetBy(dx: -3.0, dy: -4.0), size: icon.size), byTiling: false)
}
}, rate: rate)
controller.isZoomable = false
case .step:
controller = StepBarsChartController(chartsCollection: collection)

View File

@ -4517,19 +4517,12 @@ public final class MediaEditorScreen: ViewController, UIDropInteractionDelegate
entity.renderImage = result.image
entity.secondaryRenderImage = result.nightImage
let fraction: CGFloat = 1.0
// if let image = result.image {
// fraction = max(image.size.width, image.size.height) / 353.0
// } else {
// fraction = 1.0
// }
if let existingEntity {
self.entitiesView.remove(uuid: existingEntity.uuid, animated: true)
}
self.interaction?.insertEntity(
entity,
scale: existingEntity?.scale ?? min(6.0, fraction),
scale: existingEntity?.scale ?? 1.0,
position: existingEntity?.position
)
})

View File

@ -258,6 +258,7 @@ final class StarsStatisticsScreenComponent: Component {
let environment = environment[ViewControllerComponentContainer.Environment.self].value
let presentationData = component.context.sharedContext.currentPresentationData.with { $0 }
let strings = environment.strings
if self.stateDisposable == nil {
self.stateDisposable = (component.revenueContext.state
@ -309,7 +310,7 @@ final class StarsStatisticsScreenComponent: Component {
transition: .immediate,
component: AnyComponent(
MultilineTextComponent(
text: .plain(NSAttributedString(string: environment.strings.Stars_BotRevenue_Title, font: Font.semibold(17.0), textColor: environment.theme.list.itemPrimaryTextColor)),
text: .plain(NSAttributedString(string: strings.Stars_BotRevenue_Title, font: Font.semibold(17.0), textColor: environment.theme.list.itemPrimaryTextColor)),
horizontalAlignment: .center,
truncationType: .end,
maximumNumberOfLines: 1
@ -334,7 +335,7 @@ final class StarsStatisticsScreenComponent: Component {
theme: environment.theme,
header: AnyComponent(MultilineTextComponent(
text: .plain(NSAttributedString(
string: environment.strings.Stars_BotRevenue_Revenue_Title.uppercased(),
string: strings.Stars_BotRevenue_Revenue_Title.uppercased(),
font: Font.regular(presentationData.listsFontSize.itemListBaseHeaderFontSize),
textColor: environment.theme.list.freeTextColor
)),
@ -343,7 +344,7 @@ final class StarsStatisticsScreenComponent: Component {
footer: nil,
items: [
AnyComponentWithIdentity(id: 0, component: AnyComponent(ListItemComponentAdaptor(
itemGenerator: StatsGraphItem(presentationData: ItemListPresentationData(presentationData), graph: revenueGraph, type: .currency, conversionRate: starsState?.usdRate ?? 0.0, sectionId: 0, style: .blocks),
itemGenerator: StatsGraphItem(presentationData: ItemListPresentationData(presentationData), graph: revenueGraph, type: .stars, conversionRate: starsState?.usdRate ?? 0.0, sectionId: 0, style: .blocks),
params: ListViewItemLayoutParams(width: availableSize.width - sideInsets, leftInset: 0.0, rightInset: 0.0, availableHeight: 10000.0, isStandalone: true)
))),
],
@ -369,7 +370,7 @@ final class StarsStatisticsScreenComponent: Component {
theme: environment.theme,
header: AnyComponent(MultilineTextComponent(
text: .plain(NSAttributedString(
string: environment.strings.Stars_BotRevenue_Proceeds_Title.uppercased(),
string: strings.Stars_BotRevenue_Proceeds_Title.uppercased(),
font: Font.regular(presentationData.listsFontSize.itemListBaseHeaderFontSize),
textColor: environment.theme.list.freeTextColor
)),
@ -380,14 +381,14 @@ final class StarsStatisticsScreenComponent: Component {
AnyComponentWithIdentity(id: 0, component: AnyComponent(StarsOverviewItemComponent(
theme: environment.theme,
dateTimeFormat: environment.dateTimeFormat,
title: environment.strings.Stars_BotRevenue_Proceeds_Available,
title: strings.Stars_BotRevenue_Proceeds_Available,
value: starsState?.balances.availableBalance ?? 0,
rate: starsState?.usdRate ?? 0.0
))),
AnyComponentWithIdentity(id: 1, component: AnyComponent(StarsOverviewItemComponent(
theme: environment.theme,
dateTimeFormat: environment.dateTimeFormat,
title: environment.strings.Stars_BotRevenue_Proceeds_Total,
title: strings.Stars_BotRevenue_Proceeds_Total,
value: starsState?.balances.overallRevenue ?? 0,
rate: starsState?.usdRate ?? 0.0
)))
@ -413,7 +414,7 @@ final class StarsStatisticsScreenComponent: Component {
return (TelegramTextAttributes.URL, contents)
})
let balanceInfoString = NSMutableAttributedString(attributedString: parseMarkdownIntoAttributedString(environment.strings.Stars_BotRevenue_Withdraw_Info, attributes: termsMarkdownAttributes, textAlignment: .natural
let balanceInfoString = NSMutableAttributedString(attributedString: parseMarkdownIntoAttributedString(strings.Stars_BotRevenue_Withdraw_Info, attributes: termsMarkdownAttributes, textAlignment: .natural
))
if self.cachedChevronImage == nil || self.cachedChevronImage?.1 !== environment.theme {
self.cachedChevronImage = (generateTintedImage(image: UIImage(bundleImageName: "Contact List/SubtitleArrow"), color: environment.theme.list.itemAccentColor)!, environment.theme)
@ -428,7 +429,7 @@ final class StarsStatisticsScreenComponent: Component {
theme: environment.theme,
header: AnyComponent(MultilineTextComponent(
text: .plain(NSAttributedString(
string: environment.strings.Stars_BotRevenue_Withdraw_Balance.uppercased(),
string: strings.Stars_BotRevenue_Withdraw_Balance.uppercased(),
font: Font.regular(presentationData.listsFontSize.itemListBaseHeaderFontSize),
textColor: environment.theme.list.freeTextColor
)),
@ -436,16 +437,27 @@ final class StarsStatisticsScreenComponent: Component {
)),
footer: AnyComponent(MultilineTextComponent(
text: .plain(balanceInfoString),
maximumNumberOfLines: 0
maximumNumberOfLines: 0,
highlightColor: environment.theme.list.itemAccentColor.withAlphaComponent(0.2),
highlightAction: { attributes in
if let _ = attributes[NSAttributedString.Key(rawValue: TelegramTextAttributes.URL)] {
return NSAttributedString.Key(rawValue: TelegramTextAttributes.URL)
} else {
return nil
}
},
tapAction: { attributes, _ in
component.context.sharedContext.openExternalUrl(context: component.context, urlContext: .generic, url: strings.Stars_BotRevenue_Withdraw_Info_URL, forceExternal: true, presentationData: presentationData, navigationController: nil, dismissInput: {})
}
)),
items: [AnyComponentWithIdentity(id: 0, component: AnyComponent(
StarsBalanceComponent(
theme: environment.theme,
strings: environment.strings,
strings: strings,
dateTimeFormat: environment.dateTimeFormat,
count: self.starsState?.balances.availableBalance ?? 0,
rate: 0.2,
actionTitle: environment.strings.Stars_BotRevenue_Withdraw_Withdraw,
actionTitle: strings.Stars_BotRevenue_Withdraw_Withdraw,
actionAvailable: true,
buy: { [weak self] in
guard let self, let component = self.component else {
@ -482,7 +494,7 @@ final class StarsStatisticsScreenComponent: Component {
transition: transition,
component: AnyComponent(MultilineTextComponent(
text: .plain(NSAttributedString(
string: environment.strings.Stars_BotRevenue_Transactions_Title.uppercased(),
string: strings.Stars_BotRevenue_Transactions_Title.uppercased(),
font: Font.regular(presentationData.listsFontSize.itemListBaseHeaderFontSize),
textColor: environment.theme.list.freeTextColor
)),
@ -512,6 +524,7 @@ final class StarsStatisticsScreenComponent: Component {
component: AnyComponent(StarsTransactionsListPanelComponent(
context: component.context,
transactionsContext: allTransactionsContext,
isAccount: false,
action: { transaction in
component.openTransaction(transaction)
}
@ -519,15 +532,16 @@ final class StarsStatisticsScreenComponent: Component {
environment: {
StarsTransactionsPanelEnvironment(
theme: environment.theme,
strings: environment.strings,
strings: strings,
dateTimeFormat: environment.dateTimeFormat,
containerInsets: UIEdgeInsets(top: 0.0, left: environment.safeInsets.left, bottom: environment.safeInsets.bottom, right: environment.safeInsets.right),
containerInsets: UIEdgeInsets(top: 0.0, left: environment.safeInsets.left, bottom: 0.0, right: environment.safeInsets.right),
isScrollable: wasLockedAtPanels,
isCurrent: true
)
},
containerSize: CGSize(width: availableSize.width - sideInsets, height: availableSize.height)
)
self.transactionsView.parentState = state
let transactionsFrame = CGRect(origin: CGPoint(x: floorToScreenPixels((availableSize.width - transactionsSize.width) / 2.0), y: contentHeight), size: transactionsSize)
if let panelContainerView = self.transactionsView.view {
if panelContainerView.superview == nil {
@ -609,7 +623,7 @@ public final class StarsStatisticsScreen: ViewControllerComponentContainer {
guard let self else {
return
}
let controller = context.sharedContext.makeStarsTransactionScreen(context: context, transaction: transaction)
let controller = context.sharedContext.makeStarsTransactionScreen(context: context, transaction: transaction, isAccount: false)
self.push(controller)
}

View File

@ -75,7 +75,7 @@ private final class StarsTransactionSheetContent: CombinedComponent {
var peerIds: [EnginePeer.Id] = []
switch subject {
case let .transaction(transaction):
case let .transaction(transaction, _):
if case let .peer(peer) = transaction.peer {
peerIds.append(peer.id)
}
@ -179,7 +179,7 @@ private final class StarsTransactionSheetContent: CombinedComponent {
var delayedCloseOnOpenPeer = true
switch subject {
case let .transaction(transaction):
case let .transaction(transaction, isAccount):
switch transaction.peer {
case let .peer(peer):
titleText = transaction.title ?? peer.compactDisplayTitle
@ -194,8 +194,13 @@ private final class StarsTransactionSheetContent: CombinedComponent {
titleText = strings.Stars_Transaction_PremiumBotTopUp_Title
via = strings.Stars_Transaction_PremiumBotTopUp_Subtitle
case .fragment:
titleText = strings.Stars_Transaction_FragmentTopUp_Title
via = strings.Stars_Transaction_FragmentTopUp_Subtitle
if isAccount {
titleText = strings.Stars_Transaction_FragmentTopUp_Title
via = strings.Stars_Transaction_FragmentTopUp_Subtitle
} else {
titleText = strings.Stars_Transaction_FragmentWithdrawal_Title
via = strings.Stars_Transaction_FragmentWithdrawal_Subtitle
}
case .unsupported:
titleText = strings.Stars_Transaction_Unsupported_Title
via = nil
@ -662,7 +667,7 @@ private final class StarsTransactionSheetComponent: CombinedComponent {
public class StarsTransactionScreen: ViewControllerComponentContainer {
public enum Subject: Equatable {
case transaction(StarsContext.State.Transaction)
case transaction(StarsContext.State.Transaction, Bool)
case receipt(BotPaymentReceipt)
}

View File

@ -31,15 +31,18 @@ final class StarsTransactionsListPanelComponent: Component {
let context: AccountContext
let transactionsContext: StarsTransactionsContext
let isAccount: Bool
let action: (StarsContext.State.Transaction) -> Void
init(
context: AccountContext,
transactionsContext: StarsTransactionsContext,
isAccount: Bool,
action: @escaping (StarsContext.State.Transaction) -> Void
) {
self.context = context
self.transactionsContext = transactionsContext
self.isAccount = isAccount
self.action = action
}
@ -47,6 +50,9 @@ final class StarsTransactionsListPanelComponent: Component {
if lhs.context !== rhs.context {
return false
}
if lhs.isAccount != rhs.isAccount {
return false
}
return true
}
@ -191,6 +197,7 @@ final class StarsTransactionsListPanelComponent: Component {
}
separatorView.backgroundColor = environment.theme.list.itemBlocksSeparatorColor
separatorView.isHidden = index == self.items.count - 1
let fontBaseDisplaySize = 17.0
@ -213,8 +220,13 @@ final class StarsTransactionsListPanelComponent: Component {
itemTitle = environment.strings.Stars_Intro_Transaction_GoogleTopUp_Title
itemSubtitle = environment.strings.Stars_Intro_Transaction_GoogleTopUp_Subtitle
case .fragment:
itemTitle = environment.strings.Stars_Intro_Transaction_FragmentTopUp_Title
itemSubtitle = environment.strings.Stars_Intro_Transaction_FragmentTopUp_Subtitle
if component.isAccount {
itemTitle = environment.strings.Stars_Intro_Transaction_FragmentTopUp_Title
itemSubtitle = environment.strings.Stars_Intro_Transaction_FragmentTopUp_Subtitle
} else {
itemTitle = environment.strings.Stars_Intro_Transaction_FragmentWithdrawal_Title
itemSubtitle = environment.strings.Stars_Intro_Transaction_FragmentWithdrawal_Subtitle
}
case .premiumBot:
itemTitle = environment.strings.Stars_Intro_Transaction_PremiumBotTopUp_Title
itemSubtitle = environment.strings.Stars_Intro_Transaction_PremiumBotTopUp_Subtitle
@ -444,7 +456,11 @@ final class StarsTransactionsListPanelComponent: Component {
self.ignoreScrolling = false
self.updateScrolling(transition: transition)
return availableSize
if component.isAccount {
return availableSize
} else {
return CGSize(width: availableSize.width, height: min(availableSize.height, contentSize.height))
}
}
}

View File

@ -580,6 +580,7 @@ final class StarsTransactionsScreenComponent: Component {
panel: AnyComponent(StarsTransactionsListPanelComponent(
context: component.context,
transactionsContext: allTransactionsContext,
isAccount: true,
action: { transaction in
component.openTransaction(transaction)
}
@ -592,6 +593,7 @@ final class StarsTransactionsScreenComponent: Component {
panel: AnyComponent(StarsTransactionsListPanelComponent(
context: component.context,
transactionsContext: incomingTransactionsContext,
isAccount: true,
action: { transaction in
component.openTransaction(transaction)
}
@ -604,6 +606,7 @@ final class StarsTransactionsScreenComponent: Component {
panel: AnyComponent(StarsTransactionsListPanelComponent(
context: component.context,
transactionsContext: outgoingTransactionsContext,
isAccount: true,
action: { transaction in
component.openTransaction(transaction)
}
@ -719,7 +722,7 @@ public final class StarsTransactionsScreen: ViewControllerComponentContainer {
guard let self else {
return
}
let controller = context.sharedContext.makeStarsTransactionScreen(context: context, transaction: transaction)
let controller = context.sharedContext.makeStarsTransactionScreen(context: context, transaction: transaction, isAccount: true)
self.push(controller)
}

View File

@ -2632,8 +2632,8 @@ public final class SharedAccountContextImpl: SharedAccountContext {
return StarsTransferScreen(context: context, starsContext: starsContext, invoice: invoice, source: source, inputData: inputData, completion: completion)
}
public func makeStarsTransactionScreen(context: AccountContext, transaction: StarsContext.State.Transaction) -> ViewController {
return StarsTransactionScreen(context: context, subject: .transaction(transaction), action: {})
public func makeStarsTransactionScreen(context: AccountContext, transaction: StarsContext.State.Transaction, isAccount: Bool) -> ViewController {
return StarsTransactionScreen(context: context, subject: .transaction(transaction, isAccount), action: {})
}
public func makeStarsReceiptScreen(context: AccountContext, receipt: BotPaymentReceipt) -> ViewController {