Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
phillipthelen committed Oct 29, 2024
1 parent 43d3aa2 commit 2688081
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 10 deletions.
2 changes: 1 addition & 1 deletion HabitRPG/UI/General/FaintViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ private class ViewModel: ObservableObject {
let defaults = UserDefaults.standard
defaults.set(Date(), forKey: "lastFaintSubBenefit")
DispatchQueue.main.asyncAfter(deadline: .now() + 2) {
ToastManager.show(text: L10n.Faint.perkSuccess, color: .subscriberPerk)
ToastManager.show(text: L10n.Faint.perkSuccess, color: .subscriberPerk, duration: 4.0)
}
onCompleted()
}
Expand Down
2 changes: 1 addition & 1 deletion HabitRPG/UI/Purchases/GiftSubscriptionViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ class GiftSubscriptionViewController: UIHostingController<GiftSubscriptionPage>

func displayConfirmationDialog() {
var body = L10n.giftConfirmationBody(viewModel.giftedUser?.profile?.name ?? "", selectedDurationString())
if activePromo?.identifier == "g1g1" {
if activePromo?.identifier == "g1g1" && viewModel.giftedUser?.id != userRepository.currentUserId {
body = L10n.giftConfirmationBodyG1g1(viewModel.giftedUser?.profile?.name ?? "", selectedDurationString())
}
let alertController = HabiticaAlertController(title: L10n.giftConfirmationTitle, message: body)
Expand Down
28 changes: 20 additions & 8 deletions HabitRPG/UI/Purchases/SubscriptionPage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class SubscriptionViewModel: BaseSubscriptionViewModel {
let inventoryRepository = InventoryRepository()
let configRepository = ConfigRepository.shared

var onSubscriptionSuccessful: (() -> Void)?
var dimissVC: (() -> Void)?
var onGiftButtonTapped: (() -> Void)?

@Published var presentationPoint: PresentationPoint?
Expand Down Expand Up @@ -155,6 +155,7 @@ class SubscriptionViewModel: BaseSubscriptionViewModel {

func subscribeTapped() {
if !PurchaseHandler.shared.isAllowedToMakePurchases() {
dismiss()
return
}
withAnimation {
Expand Down Expand Up @@ -200,7 +201,7 @@ class SubscriptionViewModel: BaseSubscriptionViewModel {
}

private func dismiss() {
if let action = self.onSubscriptionSuccessful {
if let action = self.dimissVC {
action()
}
}
Expand Down Expand Up @@ -418,7 +419,7 @@ struct SubscriptionPage: View {
.padding(.top, 8)
.padding(.horizontal, 41)
}
}.padding(.bottom, 24)
}.padding(.bottom, 12)
}
SubscriptionBenefitListView(presentationPoint: viewModel.presentationPoint, mysteryGear: viewModel.mysteryGear, mysteryGearSet: viewModel.mysteryGearSet)
.padding(.horizontal, 24)
Expand Down Expand Up @@ -471,6 +472,9 @@ struct SubscriptionPage: View {
.padding(.vertical, 30)
}
Image(Asset.subscriptionBackground.name)
.resizable()
.aspectRatio(contentMode: .fit)
.frame(maxWidth: .infinity)
SubscriptionDisclaimer()
} else {
Image(uiImage: HabiticaIcons.imageOfHeartLarge)
Expand Down Expand Up @@ -503,6 +507,9 @@ struct SubscriptionPage: View {
.padding(.horizontal, 32)

Image(Asset.subscriptionBackground.name)
.resizable()
.aspectRatio(contentMode: .fit)
.frame(maxWidth: .infinity)
}
Group {
if viewModel.presentationPoint == nil {
Expand Down Expand Up @@ -540,6 +547,7 @@ struct SubscriptionPage: View {
.foregroundColor(textColor)
.padding(.top, 16)
.background(backgroundColor.ignoresSafeArea(.all, edges: .top).padding(.bottom, 4))
.ignoresSafeArea()
.cornerRadius([.topLeading, .topTrailing], 12)
}
}
Expand Down Expand Up @@ -584,8 +592,10 @@ class SubscriptionModalViewController: HostingPanModal<SubscriptionPage> {
init(presentationPoint: PresentationPoint?) {
viewModel = SubscriptionViewModel(presentationPoint: presentationPoint)
super.init(nibName: nil, bundle: nil)
viewModel.onSubscriptionSuccessful = {
self.dismiss()
viewModel.dimissVC = {
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5, execute: {
self.dismiss()
})
}

switch presentationPoint {
Expand All @@ -605,6 +615,11 @@ class SubscriptionModalViewController: HostingPanModal<SubscriptionPage> {
required init?(coder aDecoder: NSCoder) {
viewModel = SubscriptionViewModel(presentationPoint: nil)
super.init(coder: aDecoder)
viewModel.dimissVC = {
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5, execute: {
self.dismiss()
})
}
}

override func viewDidLoad() {
Expand Down Expand Up @@ -646,9 +661,6 @@ class SubscriptionPageController: UIHostingController<ScrollableSubscriptionPage
init(presentationPoint: PresentationPoint?) {
viewModel = SubscriptionViewModel(presentationPoint: presentationPoint)
super.init(rootView: ScrollableSubscriptionPage(viewModel: viewModel))
viewModel.onSubscriptionSuccessful = {
self.dismiss()
}

switch presentationPoint {
case .faint:
Expand Down
4 changes: 4 additions & 0 deletions HabitRPG/Utilities/PurchaseHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -258,11 +258,15 @@ class PurchaseHandler: NSObject, SKPaymentTransactionObserver {
}

func isAllowedToMakePurchases() -> Bool {
#if DEBUG || targetEnvironment(simulator)
return false
#else
let testinglevel = ConfigRepository.shared.testingLevel
if HabiticaAppDelegate.isRunningLive() || testinglevel.isTrustworthy {
return true
}
return false
#endif
}

func isNoRenewSubscription(_ identifier: String) -> Bool {
Expand Down

0 comments on commit 2688081

Please sign in to comment.