|
@@ -8,6 +8,9 @@
|
|
|
import Combine
|
|
|
import SwiftUI
|
|
|
import SwiftUIX
|
|
|
+import APNGKit
|
|
|
+import Delegate
|
|
|
+
|
|
|
class PurchaseViewModel : ObservableObject{
|
|
|
|
|
|
@Published var selectedType: PremiumPeriod = .year
|
|
@@ -35,7 +38,7 @@ class TSPurchaseVC: TSBaseVC {
|
|
|
return purchaseManager
|
|
|
}()
|
|
|
|
|
|
- private var isHandlePurchaseStateChanged = true //是否处理购买状态变化
|
|
|
+ var isHandlePurchaseStateChanged = true //是否处理购买状态变化
|
|
|
|
|
|
func createImageScroll(imageName:String,direction:ImagesAnimateScrollView.`Direction`)->ImagesAnimateScrollView{
|
|
|
let imageScroll1: ImagesAnimateScrollView = ImagesAnimateScrollView()
|
|
@@ -80,13 +83,25 @@ class TSPurchaseVC: TSBaseVC {
|
|
|
// }
|
|
|
|
|
|
if PurchaseManager.default.vipType == .none {
|
|
|
- viewModel.selectedType = .week
|
|
|
+ viewModel.selectedType = .week(.week)
|
|
|
}
|
|
|
let vc = UIHostingController(rootView: PurchaseView(viewModel: viewModel))
|
|
|
vc.view.backgroundColor = .clear
|
|
|
return vc
|
|
|
}()
|
|
|
|
|
|
+ lazy var apngImageView: APNGImageView = creatApngImageView()
|
|
|
+ lazy var promotionalVC: TSPurchasePromotionalVC = creatPromotionalVC()
|
|
|
+ let animationView:UIView = UIView()
|
|
|
+ lazy var animationLab: UILabel = {
|
|
|
+ let animationLab = UILabel.createLabel(text: "LUCKY GIFT\nFOR YOU!".localized,font:.font(name: .PoppinsBold, size: 38),textAlignment: .center)
|
|
|
+ animationLab.alpha = 0.0
|
|
|
+ kMainAsync {
|
|
|
+ animationLab.applyGradient(colors: ["#FA794F".uiColor,"#F8C32A".uiColor,"#FEFBF4".uiColor])
|
|
|
+ }
|
|
|
+ return animationLab
|
|
|
+ }()
|
|
|
+
|
|
|
override func createView() {
|
|
|
addNormalNavBarView()
|
|
|
_ = setNavigationItem("", imageName: "close_gray", direction: .left, action: #selector(closePage))
|
|
@@ -104,16 +119,33 @@ class TSPurchaseVC: TSBaseVC {
|
|
|
hostVc.view.snp.makeConstraints { make in
|
|
|
make.leading.trailing.bottom.top.equalToSuperview()
|
|
|
}
|
|
|
+
|
|
|
+ if kPurchaseCountDownTime.isCountDown {
|
|
|
+ addPromotionalVC()
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @objc func closePage(){
|
|
|
+ TSToastShared.hideLoading()
|
|
|
+
|
|
|
+ if showGift {
|
|
|
+// if promotionalVC.view.superview == nil {
|
|
|
+ addApngImageView()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ closePageBlock?()
|
|
|
+ self.dismiss(animated: true)
|
|
|
}
|
|
|
|
|
|
override func dealThings() {
|
|
|
|
|
|
//周会员和月会员不自动处理变化,必须点击购买后才处理
|
|
|
let vipType = purchaseManager.vipType
|
|
|
- if vipType == .week || vipType == .month {
|
|
|
+ if vipType.isWeekType || vipType == .month {
|
|
|
isHandlePurchaseStateChanged = false
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
addNotifaction()
|
|
|
onPurchaseStateChanged()
|
|
|
NotificationCenter.default.addObserver(forName: .kPurchasePrepared, object: nil, queue: OperationQueue.main) { [weak self] _ in
|
|
@@ -157,11 +189,14 @@ class TSPurchaseVC: TSBaseVC {
|
|
|
|
|
|
viewModel.restorePublisher.receive(on: DispatchQueue.main).sink { [weak self] _ in
|
|
|
guard let self = self else { return }
|
|
|
- isHandlePurchaseStateChanged = true
|
|
|
- PurchaseManager.default.restorePremium()
|
|
|
+ restorePremium()
|
|
|
}.store(in: &cancellabel)
|
|
|
}
|
|
|
|
|
|
+ func restorePremium(){
|
|
|
+ isHandlePurchaseStateChanged = true
|
|
|
+ PurchaseManager.default.restorePremium()
|
|
|
+ }
|
|
|
|
|
|
func onPurchaseStateChanged(){
|
|
|
purchaseManager.onPurchaseStateChanged = { [weak self] manager,state,object in
|
|
@@ -246,13 +281,7 @@ class TSPurchaseVC: TSBaseVC {
|
|
|
debugPrint("PurchaseManager onPurchaseStateChanged=\(String(describing: state))")
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- @objc func closePage(){
|
|
|
- closePageBlock?()
|
|
|
- TSToastShared.hideLoading()
|
|
|
- self.dismiss(animated: true)
|
|
|
- }
|
|
|
-
|
|
|
+
|
|
|
override func viewWillAppear(_ animated: Bool) {
|
|
|
super.viewWillAppear(animated)
|
|
|
// 禁用右滑返回手势
|
|
@@ -310,225 +339,3 @@ extension TSPurchaseVC{
|
|
|
}
|
|
|
|
|
|
|
|
|
-struct PurchaseView :View {
|
|
|
-
|
|
|
- @ObservedObject var viewModel: PurchaseViewModel
|
|
|
-
|
|
|
-
|
|
|
- var body: some View {
|
|
|
-
|
|
|
-
|
|
|
- let vipType = PurchaseManager.default.vipType
|
|
|
-
|
|
|
- VStack {
|
|
|
- Spacer()
|
|
|
-
|
|
|
- VStack {
|
|
|
- let text = vipType == .none ? "Get PRO Access".localized : "Super Offer for Yearly Pro".localized
|
|
|
- Text(text)
|
|
|
- .multilineTextAlignment(.center)
|
|
|
- .font(.font(name: .PoppinsBoldItalic,size: 26))
|
|
|
- .foregroundColor(UIColor.white.color)
|
|
|
- .frame(width: k_ScreenWidth - 32, alignment: .center)
|
|
|
-
|
|
|
- if vipType == .none {
|
|
|
- Spacer().frame(height: 12)
|
|
|
- HStack {
|
|
|
- Text("Unlimited")
|
|
|
- .foregroundColor("#FECB34".uiColor.color)
|
|
|
-
|
|
|
- Text("Generation")
|
|
|
- .foregroundColor(UIColor.white.color)
|
|
|
-
|
|
|
- }
|
|
|
- .multilineTextAlignment(.center)
|
|
|
- .font(.font(name: .PoppinsBoldItalic,size: 26))
|
|
|
- .frame(height: 26*kDesignScale)
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- Spacer().frame(height: 32)
|
|
|
-
|
|
|
- VStack(spacing: 12) {
|
|
|
-
|
|
|
- if vipType == .none {
|
|
|
- ZStack(alignment: .topTrailing) {
|
|
|
-// //增加月付费
|
|
|
-// PurchaseItemView(title: "One Month".localized, type: .month, selectedType: $viewModel.selectedType).onTapGesture {
|
|
|
-// viewModel.selectedType = .month
|
|
|
- PurchaseItemView(title: "One Year".localized, type: .year, selectedType: $viewModel.selectedType).onTapGesture {
|
|
|
- viewModel.selectedType = .year
|
|
|
-
|
|
|
- viewModel.buyPublisher.send(true)
|
|
|
- }
|
|
|
- TSVipRecView(save: vipType.saveString)
|
|
|
- .offset(x:-30,y:-14)
|
|
|
- }
|
|
|
-
|
|
|
- PurchaseItemView(title: "One Week".localized, type: .week, selectedType: $viewModel.selectedType).onTapGesture {
|
|
|
- viewModel.selectedType = .week
|
|
|
- viewModel.buyPublisher.send(true)
|
|
|
- }
|
|
|
- }else{
|
|
|
- PurchaseItemTypeOneView(title: "One Year".localized, type: .year, selectedType: $viewModel.selectedType).onTapGesture {
|
|
|
- viewModel.selectedType = .year
|
|
|
- viewModel.buyPublisher.send(true)
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- Spacer().frame(height: 4)
|
|
|
-
|
|
|
- Button {
|
|
|
- viewModel.buyPublisher.send(true)
|
|
|
- } label: {
|
|
|
- ZStack {
|
|
|
- UIColor.themeColor.color
|
|
|
- Text("Continue")
|
|
|
- .font(.font(size: 16,weight: .medium))
|
|
|
- .foregroundColor(.hex("#111111"))
|
|
|
-
|
|
|
- }.frame(maxWidth: .infinity ,minHeight: 48.0,maxHeight: 48.0)
|
|
|
- .cornerRadius(24.0)
|
|
|
- }
|
|
|
-
|
|
|
- HStack {
|
|
|
- Text("Recurring billing, cancel anytime".localized)
|
|
|
- .foregroundColor(Color.hex("#FFBD59")) +
|
|
|
- Text(",Payment will be charged to your iTunes account at confirmation of purchase. Subscriptions automatically renew for the same applicable term and price, unless auto-renew is turned off at least 24 hours before the end of the current period.".localized)
|
|
|
- .foregroundColor(UIColor.lesserText.color)
|
|
|
- }
|
|
|
- .multilineTextAlignment(.center).font(.font(size: 8))
|
|
|
- .onTapGesture {
|
|
|
- viewModel.privacyPublisher.send(true)
|
|
|
- }
|
|
|
-
|
|
|
- Spacer().frame(height: 6.0)
|
|
|
-
|
|
|
- HStack(spacing: 8) {
|
|
|
- Text("Terms of us".localized)
|
|
|
- .onTapGesture {
|
|
|
- viewModel.termPublisher.send(true)
|
|
|
- }
|
|
|
- Text("|")
|
|
|
- Text("Privacy Policy".localized)
|
|
|
- .onTapGesture {
|
|
|
- viewModel.privacyPublisher.send(true)
|
|
|
- }
|
|
|
- Text("|")
|
|
|
- Text("Restore".localized)
|
|
|
- .onTapGesture {
|
|
|
- viewModel.restorePublisher.send(true)
|
|
|
- }
|
|
|
- }.font(.system(size: 12)).foregroundColor(.hex("#999999"))
|
|
|
- }.padding(.horizontal)
|
|
|
-
|
|
|
- Spacer().frame(height:9+k_Height_safeAreaInsetsBottom())
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // 定义一个返回 View 的方法
|
|
|
- func customText(text:String,fontName:FontName,color:Color) -> some View {
|
|
|
- let gorgeousColor = color //UIColor.themeColor.color
|
|
|
- return Text(text)
|
|
|
- .font(.font(name: fontName,size: 48))
|
|
|
-
|
|
|
- .gradientForeground(
|
|
|
- colors: [.hex("#FA794F"),.hex("#F8C32A"),.hex("#FEFBF4")],
|
|
|
- startPoint: UnitPoint.leading,
|
|
|
- endPoint: UnitPoint.trailing
|
|
|
- )
|
|
|
-
|
|
|
- .foregroundColor(gorgeousColor)
|
|
|
- .frame(height: 20)
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-struct PurchaseItemView: View {
|
|
|
- var title: String
|
|
|
- var type: PremiumPeriod
|
|
|
- @Binding var selectedType: PremiumPeriod
|
|
|
-
|
|
|
- var body: some View {
|
|
|
- ZStack {
|
|
|
- Color.white.opacity(0.1)
|
|
|
- HStack {
|
|
|
- //左边加个
|
|
|
- VStack(alignment: .leading, spacing: 14) {
|
|
|
- Text(title).font(.font(size: 14)).foregroundColor(UIColor.white.color)
|
|
|
-
|
|
|
- HStack {
|
|
|
- Text(PurchaseManager.default.price(for: type) ?? "--").font(.font(size: 18,weight: .medium)).foregroundColor(UIColor.mainText.color)
|
|
|
- if type == .year { //.month {//增加月付费
|
|
|
- Text(" (≈\(PurchaseManager.default.averageWeekly(for:type) ?? "--")/\("Per week".localized))").font(.font(size: 12,weight: .medium)).foregroundColor(UIColor.mainText.withAlphaComponent(0.6).color)
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- Spacer()
|
|
|
-//
|
|
|
-// //右边每周的💰
|
|
|
-// VStack(alignment: .trailing, spacing: 2) {
|
|
|
-// Text("\(PurchaseManager.default.averageWeekly(for:type) ?? "--")")
|
|
|
-// Text("Per week".localized)
|
|
|
-//
|
|
|
-// }.font(.font(size: 16,weight: .regular)).foregroundColor(Color.white.opacity(0.6))
|
|
|
-
|
|
|
- }.padding(.horizontal)
|
|
|
- }
|
|
|
- .frame(height: 74) // 设置高度
|
|
|
- .cornerRadius(16.0) // 圆角
|
|
|
- .overlay(
|
|
|
- RoundedRectangle(cornerRadius: 16)
|
|
|
- .stroke(Color.hex("#FECB34"), lineWidth: type == selectedType ? 1 : 0) // 边框
|
|
|
- )
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-struct PurchaseItemTypeOneView: View {
|
|
|
- var title: String
|
|
|
- var type: PremiumPeriod
|
|
|
- @Binding var selectedType: PremiumPeriod
|
|
|
-
|
|
|
- var body: some View {
|
|
|
- ZStack {
|
|
|
- Color.white.opacity(0.1)
|
|
|
- HStack {
|
|
|
- //左边加个
|
|
|
- VStack(alignment: .leading, spacing: 8) {
|
|
|
- Text(title).font(.font(size: 14,weight: .medium)).foregroundColor(UIColor.white.color)
|
|
|
- Text(String(format:"Only %@ per day".localized,"\(PurchaseManager.default.averageDay(for:type) ?? "--")"))
|
|
|
- .font(.font(size: 12,weight: .medium))
|
|
|
- . foregroundColor(UIColor.white.color).opacity(0.7)
|
|
|
- }
|
|
|
-
|
|
|
- Spacer()
|
|
|
-
|
|
|
- Text(PurchaseManager.default.price(for: type) ?? "--").font(.font(size: 18,weight: .medium)).foregroundColor(UIColor.mainText.color)
|
|
|
-
|
|
|
- }.padding(.horizontal)
|
|
|
- }
|
|
|
- .frame(height: 74) // 设置高度
|
|
|
- .cornerRadius(16.0) // 圆角
|
|
|
- .overlay(
|
|
|
- RoundedRectangle(cornerRadius: 16)
|
|
|
- .stroke(Color.hex("#FECB34"), lineWidth: type == selectedType ? 1 : 0) // 边框
|
|
|
- )
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-//推荐选择view
|
|
|
-struct TSVipRecView: View {
|
|
|
- var save:String //年 80%,月 30%
|
|
|
- var body: some View {
|
|
|
-
|
|
|
- HStack(spacing: 4) {
|
|
|
- Image("upvote_black").resizable().frame(width: 16, height: 16)
|
|
|
- Text("Save-Vip".localized + " " + save).font(.font(size: 12,weight: .medium)).foregroundColor(.hex("#111111"))
|
|
|
- }
|
|
|
- .padding(EdgeInsets(top: 6, leading: 6, bottom: 6, trailing: 6))
|
|
|
- .background(Color.hex("#FECB34"))
|
|
|
- .frame(height: 28) // 设置高度
|
|
|
- .cornerRadius([.topLeading, .topTrailing, .bottomLeading, .bottomTrailing], 16.0)
|
|
|
- }
|
|
|
-}
|