From a9812010164783f324e94966ed13f99ae3ace0ec Mon Sep 17 00:00:00 2001 From: Riley Testut Date: Thu, 30 Nov 2023 18:54:03 -0600 Subject: [PATCH] Designates Patreon apps with label + displays price (if provided) --- AltStore/Components/AppBannerView.swift | 52 ++++++++++++++++++++++--- AltStore/Components/AppBannerView.xib | 49 +++++++++++------------ 2 files changed, 70 insertions(+), 31 deletions(-) diff --git a/AltStore/Components/AppBannerView.swift b/AltStore/Components/AppBannerView.swift index ed316768..6ddeb72a 100644 --- a/AltStore/Components/AppBannerView.swift +++ b/AltStore/Components/AppBannerView.swift @@ -159,7 +159,16 @@ extension AppBannerView self.accessibilityLabel = values.name } - self.buttonLabel.isHidden = true + if let storeApp = app.storeApp, storeApp.isPledgeRequired + { + // Always show button label for Patreon apps. + self.buttonLabel.isHidden = false + self.buttonLabel.text = storeApp.isPledged ? NSLocalizedString("Pledged", comment: "") : NSLocalizedString("Join Patreon", comment: "") + } + else + { + self.buttonLabel.isHidden = true + } let buttonAction: AppAction @@ -220,10 +229,43 @@ extension AppBannerView self.button.countdownDate = nil case .install: - let buttonTitle = NSLocalizedString("Free", comment: "") - self.button.setTitle(buttonTitle.uppercased(), for: .normal) - self.button.accessibilityLabel = String(format: NSLocalizedString("Download %@", comment: ""), app.name) - self.button.accessibilityValue = buttonTitle + if let storeApp = app.storeApp, storeApp.isPledgeRequired + { + // Pledge required + + if storeApp.isPledged + { + let buttonTitle = NSLocalizedString("Install", comment: "") + self.button.setTitle(buttonTitle.uppercased(), for: .normal) + self.button.accessibilityLabel = String(format: NSLocalizedString("Install %@", comment: ""), app.name) + self.button.accessibilityValue = buttonTitle + } + else if let amount = storeApp.pledgeAmount, let currencyCode = storeApp.pledgeCurrency, #available(iOS 15, *) + { + let price = amount.formatted(.currency(code: currencyCode).presentation(.narrow).precision(.fractionLength(0...2))) + + let buttonTitle = String(format: NSLocalizedString("%@/mo", comment: ""), price) + self.button.setTitle(buttonTitle, for: .normal) + self.button.accessibilityLabel = String(format: NSLocalizedString("Pledge %@ a month", comment: ""), price) + self.button.accessibilityValue = String(format: NSLocalizedString("%@ a month", comment: ""), price) + } + else + { + let buttonTitle = NSLocalizedString("Pledge", comment: "") + self.button.setTitle(buttonTitle.uppercased(), for: .normal) + self.button.accessibilityLabel = buttonTitle + self.button.accessibilityValue = buttonTitle + } + } + else + { + // Free app + + let buttonTitle = NSLocalizedString("Free", comment: "") + self.button.setTitle(buttonTitle.uppercased(), for: .normal) + self.button.accessibilityLabel = String(format: NSLocalizedString("Download %@", comment: ""), app.name) + self.button.accessibilityValue = buttonTitle + } if let versionDate = app.storeApp?.latestSupportedVersion?.date, versionDate > Date() { diff --git a/AltStore/Components/AppBannerView.xib b/AltStore/Components/AppBannerView.xib index e4d18eee..d140f5ae 100644 --- a/AltStore/Components/AppBannerView.xib +++ b/AltStore/Components/AppBannerView.xib @@ -1,9 +1,9 @@ - + - + @@ -78,13 +78,13 @@ - + - + - - + - - + + + + + + + + + + +