-
-
Notifications
You must be signed in to change notification settings - Fork 205
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1249 from TortugaPower/develop
Release v5.5.3
- Loading branch information
Showing
27 changed files
with
898 additions
and
232 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
// | ||
// TipJarView.swift | ||
// BookPlayer | ||
// | ||
// Created by Gianni Carlo on 2/2/25. | ||
// Copyright © 2025 BookPlayer LLC. All rights reserved. | ||
// | ||
|
||
import BookPlayerKit | ||
import SwiftUI | ||
|
||
struct TipJarView: View { | ||
@ObservedObject var viewModel: TipJarViewModel | ||
@StateObject var themeViewModel = ThemeViewModel() | ||
@State var selected: TipOption = TipOption.excellent | ||
@State var error: Error? | ||
|
||
var body: some View { | ||
NavigationView { | ||
VStack { | ||
if let disclaimer = viewModel.disclaimer { | ||
Text(disclaimer) | ||
.foregroundColor(themeViewModel.primaryColor) | ||
.font(Font(Fonts.titleRegular)) | ||
.padding() | ||
} | ||
|
||
HStack(spacing: Spacing.S1) { | ||
Spacer() | ||
ForEach(TipOption.allCases) { option in | ||
TipOptionView( | ||
title: .constant(option.title), | ||
price: .constant(option.price), | ||
isSelected: .constant(selected == option) | ||
) | ||
.onTapGesture { | ||
selected = option | ||
} | ||
} | ||
Spacer() | ||
} | ||
Button(action: { | ||
Task { @MainActor in | ||
await viewModel.donate(selected) | ||
} | ||
}) { | ||
Text("Donate") | ||
.contentShape(Rectangle()) | ||
.font(Font(Fonts.headline)) | ||
.frame(height: 45) | ||
.frame(maxWidth: .infinity) | ||
.foregroundColor(.white) | ||
.background(Color(UIColor(hex: "687AB7"))) | ||
.cornerRadius(6) | ||
.padding(.top, Spacing.S1) | ||
} | ||
Spacer() | ||
} | ||
.padding(.horizontal, Spacing.M) | ||
.background(themeViewModel.systemGroupedBackgroundColor) | ||
.toolbar { | ||
ToolbarItem(placement: .cancellationAction) { | ||
Button { | ||
viewModel.dismiss() | ||
} label: { | ||
Image(systemName: "xmark") | ||
} | ||
} | ||
|
||
ToolbarItem(placement: .confirmationAction) { | ||
Button("Restore") { | ||
Task { @MainActor in | ||
await viewModel.restorePurchases() | ||
} | ||
} | ||
} | ||
} | ||
.navigationTitle("Tip Jar") | ||
.navigationBarTitleDisplayMode(.inline) | ||
} | ||
} | ||
} |
93 changes: 93 additions & 0 deletions
93
BookPlayer/SecondOnboarding/Support/Tips/TipJarViewModel.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
// | ||
// TipJarViewModel.swift | ||
// BookPlayer | ||
// | ||
// Created by Gianni Carlo on 3/2/25. | ||
// Copyright © 2025 BookPlayer LLC. All rights reserved. | ||
// | ||
|
||
import BookPlayerKit | ||
import Foundation | ||
import RevenueCat | ||
|
||
@MainActor | ||
public final class TipJarViewModel: ObservableObject { | ||
enum Routes { | ||
case showLoader(Bool) | ||
case showAlert(BPAlertContent) | ||
case success(message: String) | ||
case dismiss | ||
} | ||
|
||
let disclaimer: String? | ||
let accountService: AccountServiceProtocol | ||
/// Callback to handle actions on this screen | ||
var onTransition: BPTransition<Routes>? | ||
|
||
init( | ||
disclaimer: String?, | ||
accountService: AccountServiceProtocol | ||
) { | ||
self.disclaimer = disclaimer | ||
self.accountService = accountService | ||
} | ||
|
||
func donate(_ tip: TipOption) async { | ||
onTransition?(.showLoader(true)) | ||
do { | ||
let product = await Purchases.shared.products([tip.rawValue]).first! | ||
let result = try await Purchases.shared.purchase(product: product) | ||
onTransition?(.showLoader(false)) | ||
if !result.userCancelled { | ||
accountService.updateAccount( | ||
id: nil, | ||
email: nil, | ||
donationMade: true, | ||
hasSubscription: nil | ||
) | ||
onTransition?(.success(message: "thanks_amazing_title".localized)) | ||
} | ||
} catch { | ||
onTransition?(.showLoader(false)) | ||
onTransition?( | ||
.showAlert( | ||
BPAlertContent.errorAlert(message: error.localizedDescription) | ||
) | ||
) | ||
} | ||
} | ||
|
||
func restorePurchases() async { | ||
onTransition?(.showLoader(true)) | ||
do { | ||
let customerInfo = try await Purchases.shared.restorePurchases() | ||
onTransition?(.showLoader(false)) | ||
if customerInfo.nonSubscriptions.isEmpty { | ||
onTransition?( | ||
.showAlert( | ||
BPAlertContent.errorAlert(message: "tip_missing_title".localized) | ||
) | ||
) | ||
} else { | ||
accountService.updateAccount( | ||
id: nil, | ||
email: nil, | ||
donationMade: true, | ||
hasSubscription: nil | ||
) | ||
onTransition?(.success(message: "purchases_restored_title".localized)) | ||
} | ||
} catch { | ||
onTransition?(.showLoader(false)) | ||
onTransition?( | ||
.showAlert( | ||
BPAlertContent.errorAlert(message: error.localizedDescription) | ||
) | ||
) | ||
} | ||
} | ||
|
||
func dismiss() { | ||
onTransition?(.dismiss) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// | ||
// TipOption.swift | ||
// BookPlayer | ||
// | ||
// Created by Gianni Carlo on 3/2/25. | ||
// Copyright © 2025 BookPlayer LLC. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
enum TipOption: String, Identifiable, CaseIterable { | ||
public var id: Self { self } | ||
case kind = "com.tortugapower.audiobookplayer.tip.kind" | ||
case excellent = "com.tortugapower.audiobookplayer.tip.excellent" | ||
case incredible = "com.tortugapower.audiobookplayer.tip.incredible" | ||
|
||
var title: String { | ||
switch self { | ||
case .kind: | ||
return "Kind\ntip of" | ||
case .excellent: | ||
return "Excellent\ntip of" | ||
case .incredible: | ||
return "Incredible\ntip of" | ||
} | ||
} | ||
|
||
var price: String { | ||
switch self { | ||
case .kind: | ||
return "$2.99" | ||
case .excellent: | ||
return "$4.99" | ||
case .incredible: | ||
return "$9.99" | ||
} | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
BookPlayer/SecondOnboarding/Support/Tips/TipOptionView.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// | ||
// TipOptionView.swift | ||
// BookPlayer | ||
// | ||
// Created by Gianni Carlo on 2/2/25. | ||
// Copyright © 2025 BookPlayer LLC. All rights reserved. | ||
// | ||
|
||
import BookPlayerKit | ||
import SwiftUI | ||
|
||
struct TipOptionView: View { | ||
@Binding var title: String | ||
@Binding var price: String | ||
@Binding var isSelected: Bool | ||
|
||
var imageLength: CGFloat = 16 | ||
var imageName: String { | ||
isSelected ? "checkmark.circle" : "circle" | ||
} | ||
var foregroundColor: Color { | ||
isSelected | ||
? Color(UIColor(hex: "3488D1")) | ||
: Color(UIColor(hex: "334046")) | ||
} | ||
|
||
var body: some View { | ||
VStack(spacing: 0) { | ||
HStack { | ||
Spacer() | ||
Image(systemName: imageName) | ||
.resizable() | ||
.frame(width: imageLength, height: imageLength) | ||
.foregroundColor(foregroundColor) | ||
.padding([.trailing, .top], Spacing.S3) | ||
} | ||
Text(title) | ||
.font(Font(Fonts.titleRegular)) | ||
.foregroundColor(foregroundColor.opacity(0.7)) | ||
.multilineTextAlignment(.center) | ||
Text(price) | ||
.font(Font(Fonts.titleLarge)) | ||
.foregroundColor(foregroundColor) | ||
} | ||
.padding([.bottom]) | ||
.background(Color(UIColor(hex: "F8F8F8"))) | ||
.clipShape(RoundedRectangle(cornerRadius: 12)) | ||
.contentShape(Rectangle()) | ||
.accessibilityElement(children: .combine) | ||
.accessibilityAddTraits(.isButton) | ||
.frame(maxWidth: 88) | ||
|
||
} | ||
} | ||
|
||
#Preview { | ||
ZStack { | ||
TipOptionView( | ||
title: .constant("Kind tip\nof"), | ||
price: .constant("1.99"), | ||
isSelected: .constant(true) | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.