Various improvements

This commit is contained in:
Ilya Laktyushin 2024-08-11 17:15:34 +02:00
parent 87cf5a59f4
commit ca6a312a74
5 changed files with 41 additions and 13 deletions

View File

@ -12702,6 +12702,7 @@ Sorry for the inconvenience.";
"Stars.Transaction.Subscription.JoinChannel" = "Join Channel"; "Stars.Transaction.Subscription.JoinChannel" = "Join Channel";
"Stars.Transaction.Subscription.JoinAgainChannel" = "Join Channel"; "Stars.Transaction.Subscription.JoinAgainChannel" = "Join Channel";
"Stars.Transaction.Subscription.LeftChannel" = "You left channel but you can still get back until %@"; "Stars.Transaction.Subscription.LeftChannel" = "You left channel but you can still get back until %@";
"Stars.Transaction.Subscription.Expired" = "Your subscription expired on %@.";
"Stars.Transaction.Subscription.PerMonth" = "%@ / month"; "Stars.Transaction.Subscription.PerMonth" = "%@ / month";
"Stars.Transaction.Subscription.PerMonthUsd" = "appx. %@ per month"; "Stars.Transaction.Subscription.PerMonthUsd" = "appx. %@ per month";
"Stars.Transaction.Subscription.Subscription" = "Subscription"; "Stars.Transaction.Subscription.Subscription" = "Subscription";
@ -12724,6 +12725,7 @@ Sorry for the inconvenience.";
"Stars.Intro.Subscriptions.Expires" = "expires on %@"; "Stars.Intro.Subscriptions.Expires" = "expires on %@";
"Stars.Intro.Subscriptions.Expired" = "expired on %@"; "Stars.Intro.Subscriptions.Expired" = "expired on %@";
"Stars.Intro.Subscriptions.Cancelled" = "cancelled"; "Stars.Intro.Subscriptions.Cancelled" = "cancelled";
"Stars.Intro.Subscriptions.ExpiredStatus" = "expired";
"Stars.Intro.Subscriptions.ShowMore" = "Show More"; "Stars.Intro.Subscriptions.ShowMore" = "Show More";
"Stars.Intro.Transaction.SubscriptionFee.Title" = "Monthly Subscription Fee"; "Stars.Intro.Transaction.SubscriptionFee.Title" = "Monthly Subscription Fee";

View File

@ -260,6 +260,7 @@ private final class StarsTransactionSheetContent: CombinedComponent {
} }
} else { } else {
if date < Int32(CFAbsoluteTimeGetCurrent() + kCFAbsoluteTimeIntervalSince1970) { if date < Int32(CFAbsoluteTimeGetCurrent() + kCFAbsoluteTimeIntervalSince1970) {
statusText = strings.Stars_Transaction_Subscription_Expired(stringForMediumDate(timestamp: subscription.untilDate, strings: strings, dateTimeFormat: dateTimeFormat, withTime: false)).string
buttonText = strings.Stars_Transaction_Subscription_Renew buttonText = strings.Stars_Transaction_Subscription_Renew
} else { } else {
statusText = strings.Stars_Transaction_Subscription_LeftChannel(stringForMediumDate(timestamp: subscription.untilDate, strings: strings, dateTimeFormat: dateTimeFormat, withTime: false)).string statusText = strings.Stars_Transaction_Subscription_LeftChannel(stringForMediumDate(timestamp: subscription.untilDate, strings: strings, dateTimeFormat: dateTimeFormat, withTime: false)).string
@ -1135,7 +1136,7 @@ public class StarsTransactionScreen: ViewControllerComponentContainer {
theme: forceDark ? .dark : .default theme: forceDark ? .dark : .default
) )
self.navigationPresentation = .standaloneModal self.navigationPresentation = .flatModal
self.automaticallyControlPresentationContextLayout = false self.automaticallyControlPresentationContextLayout = false
openPeerImpl = { [weak self] peer in openPeerImpl = { [weak self] peer in

View File

@ -323,10 +323,15 @@ final class StarsTransactionsScreenComponent: Component {
guard let self else { guard let self else {
return return
} }
self.subscriptionsState = state let isFirstTime = self.subscriptionsState == nil
if !state.subscriptions.isEmpty {
self.subscriptionsState = state
} else {
self.subscriptionsState = nil
}
if !self.isUpdating { if !self.isUpdating {
self.state?.updated() self.state?.updated(transition: isFirstTime ? .immediate : .spring(duration: 0.4))
} }
}) })
} }
@ -628,14 +633,18 @@ final class StarsTransactionsScreenComponent: Component {
) )
let dateText: String let dateText: String
let dateValue = stringForDateWithoutYear(date: Date(timeIntervalSince1970: Double(subscription.untilDate)), strings: environment.strings) let dateValue = stringForDateWithoutYear(date: Date(timeIntervalSince1970: Double(subscription.untilDate)), strings: environment.strings)
if subscription.flags.contains(.isCancelled) { var isExpired = false
if subscription.untilDate > Int32(CFAbsoluteTimeGetCurrent() + kCFAbsoluteTimeIntervalSince1970) { if subscription.untilDate > Int32(CFAbsoluteTimeGetCurrent() + kCFAbsoluteTimeIntervalSince1970) {
if subscription.flags.contains(.isCancelled) {
dateText = environment.strings.Stars_Intro_Subscriptions_Expires(dateValue).string dateText = environment.strings.Stars_Intro_Subscriptions_Expires(dateValue).string
} else { } else {
dateText = environment.strings.Stars_Intro_Subscriptions_Expired(dateValue).string dateText = environment.strings.Stars_Intro_Subscriptions_Renews(dateValue).string
} }
} else { } else {
dateText = environment.strings.Stars_Intro_Subscriptions_Renews(dateValue).string dateText = environment.strings.Stars_Intro_Subscriptions_Expired(dateValue).string
if !subscription.flags.contains(.isCancelled) {
isExpired = true
}
} }
titleComponents.append( titleComponents.append(
AnyComponentWithIdentity(id: AnyHashable(1), component: AnyComponent(MultilineTextComponent( AnyComponentWithIdentity(id: AnyHashable(1), component: AnyComponent(MultilineTextComponent(
@ -648,9 +657,9 @@ final class StarsTransactionsScreenComponent: Component {
))) )))
) )
let labelComponent: AnyComponentWithIdentity<Empty> let labelComponent: AnyComponentWithIdentity<Empty>
if subscription.flags.contains(.isCancelled) { if subscription.flags.contains(.isCancelled) || isExpired {
labelComponent = AnyComponentWithIdentity(id: "cancelledLabel", component: AnyComponent( labelComponent = AnyComponentWithIdentity(id: "cancelledLabel", component: AnyComponent(
MultilineTextComponent(text: .plain(NSAttributedString(string: environment.strings.Stars_Intro_Subscriptions_Cancelled, font: Font.regular(floor(fontBaseDisplaySize * 13.0 / 17.0)), textColor: environment.theme.list.itemDestructiveColor))) MultilineTextComponent(text: .plain(NSAttributedString(string: isExpired ? environment.strings.Stars_Intro_Subscriptions_ExpiredStatus : environment.strings.Stars_Intro_Subscriptions_Cancelled, font: Font.regular(floor(fontBaseDisplaySize * 13.0 / 17.0)), textColor: environment.theme.list.itemDestructiveColor)))
)) ))
} else { } else {
let itemLabel = NSAttributedString(string: "\(subscription.pricing.amount)", font: Font.medium(fontBaseDisplaySize), textColor: environment.theme.list.itemPrimaryTextColor) let itemLabel = NSAttributedString(string: "\(subscription.pricing.amount)", font: Font.medium(fontBaseDisplaySize), textColor: environment.theme.list.itemPrimaryTextColor)
@ -710,6 +719,7 @@ final class StarsTransactionsScreenComponent: Component {
} else { } else {
self.subscriptionsExpanded = true self.subscriptionsExpanded = true
} }
self.state?.updated(transition: .spring(duration: 0.4))
component.subscriptionsContext.loadMore() component.subscriptionsContext.loadMore()
}, },
highlighting: .default, highlighting: .default,
@ -723,7 +733,7 @@ final class StarsTransactionsScreenComponent: Component {
if !subscriptionsItems.isEmpty { if !subscriptionsItems.isEmpty {
let subscriptionsSize = self.subscriptionsView.update( let subscriptionsSize = self.subscriptionsView.update(
transition: .immediate, transition: transition,
component: AnyComponent(ListSectionComponent( component: AnyComponent(ListSectionComponent(
theme: environment.theme, theme: environment.theme,
header: AnyComponent(MultilineTextComponent( header: AnyComponent(MultilineTextComponent(
@ -956,7 +966,22 @@ public final class StarsTransactionsScreen: ViewControllerComponentContainer {
guard let self else { guard let self else {
return return
} }
self.subscriptionsContext.updateSubscription(id: subscription.id, cancel: cancel) if subscription.untilDate > Int32(CFAbsoluteTimeGetCurrent() + kCFAbsoluteTimeIntervalSince1970) {
if let channel = subscription.peer._asPeer() as? TelegramChannel, channel.participationStatus == .left {
let _ = self.context.engine.payments.fulfillStarsSubscription(peerId: context.account.peerId, subscriptionId: subscription.id).startStandalone()
if subscription.flags.contains(.isCancelled) {
self.subscriptionsContext.updateSubscription(id: subscription.id, cancel: false)
}
} else {
if !subscription.flags.contains(.isCancelled) {
self.subscriptionsContext.updateSubscription(id: subscription.id, cancel: true)
}
}
} else {
if let inviteHash = subscription.inviteHash {
self.context.sharedContext.openResolvedUrl(.join(inviteHash), context: self.context, urlContext: .generic, navigationController: self.navigationController as? NavigationController, forceExternal: false, openPeer: { _, _ in }, sendFile: nil, sendSticker: nil, sendEmoji: nil, requestMessageActionUrlAuth: nil, joinVoiceChat: nil, present: { _, _ in }, dismissInput: {}, contentContext: nil, progress: Promise(), completion: nil)
}
}
}) })
self.push(controller) self.push(controller)
} }

View File

@ -800,7 +800,7 @@ public final class StarsTransferScreen: ViewControllerComponentContainer {
theme: .default theme: .default
) )
self.navigationPresentation = .standaloneModal self.navigationPresentation = .flatModal
starsContext.load(force: false) starsContext.load(force: false)
} }

View File

@ -524,7 +524,7 @@ public final class StarsWithdrawScreen: ViewControllerComponentContainer {
theme: .default theme: .default
) )
self.navigationPresentation = .standaloneModal self.navigationPresentation = .flatModal
} }
required public init(coder aDecoder: NSCoder) { required public init(coder aDecoder: NSCoder) {