KMPurchaseCompareWindowController.m 69 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407
  1. //
  2. // KMPurchaseCompareWindowController.m
  3. // PDF Reader
  4. //
  5. // Created by wangshuai on 2017/5/8.
  6. // Copyright © 2017年 zhangjie. All rights reserved.
  7. //
  8. #import "KMPurchaseCompareWindowController.h"
  9. #import <PDF_Reader_Pro-Swift.h>
  10. //#import "WaitingView.h"
  11. //#import "NSButton+TitleColor.h"
  12. //#import "HyperLinkButton.h"
  13. //#import "IAPProductsManager.h"
  14. //#import "GAIManager.h"
  15. //#import "NSImage_SKExtensions.h"
  16. //
  17. //#import "KMButton.h"
  18. //#import "KMCustomButton.h"
  19. //#import "KMKdanRemoteConfig.h"
  20. //#import "VerificationManager.h"
  21. //#import "KMVerificationWindowController.h"
  22. //#import "SKInspectPublicTool.h"
  23. //#import "FMTrackEventManager.h"
  24. //#import "NSFont+Custom.h"
  25. //#if !VERSION_DMG
  26. //#import <StoreKit/StoreKit.h>
  27. //#endif
  28. #import "KMDiscountToSaveWindowController.h"
  29. static NSString *const KMPurchaseCompareEmptyCellIdentifier = @"KMPurchaseCompareEmptyCellIdentifier";
  30. static NSString *const KMPurchaseCompareHeaderCellIdentifier = @"KMPurchaseCompareHeaderCell";
  31. static NSString *const KMPurchaseCompareCellIdentifier = @"KMPurchaseCompareCell";
  32. #pragma mark - KMPurchaseCompareEmptyCell
  33. @interface KMPurchaseCompareEmptyCell : NSTableCellView
  34. @end
  35. @implementation KMPurchaseCompareEmptyCell
  36. - (void)dealloc {
  37. [NSDistributedNotificationCenter.defaultCenter removeObserver:self];
  38. }
  39. - (void)awakeFromNib {
  40. [super awakeFromNib];
  41. self.wantsLayer = YES;
  42. [self updateViewColor];
  43. [NSDistributedNotificationCenter.defaultCenter addObserver:self selector:@selector(themeChanged:) name:@"AppleInterfaceThemeChangedNotification" object: nil];
  44. }
  45. - (void)themeChanged:(NSNotification *)notification {
  46. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  47. [self updateViewColor];
  48. });
  49. }
  50. - (void)updateViewColor {
  51. if ([KMAppearance isDarkMode]) {
  52. self.layer.backgroundColor = [NSColor colorWithRed:24/255.0 green:22/255.0 blue:31/255. alpha:1.].CGColor;
  53. } else {
  54. self.layer.backgroundColor = [NSColor colorWithRed:247/255.0 green:245/255.0 blue:1 alpha:1.].CGColor;
  55. }
  56. }
  57. @end
  58. @interface KMPurchaseCompareHeaderCell : NSTableCellView
  59. @property (nonatomic,assign) IBOutlet NSView *contentView;
  60. @end
  61. @implementation KMPurchaseCompareHeaderCell
  62. - (void)dealloc
  63. {
  64. [NSDistributedNotificationCenter.defaultCenter removeObserver:self];
  65. }
  66. - (void)awakeFromNib
  67. {
  68. [super awakeFromNib];
  69. self.contentView.wantsLayer = YES;
  70. [self updateViewColor];
  71. [NSDistributedNotificationCenter.defaultCenter addObserver:self selector:@selector(themeChanged:) name:@"AppleInterfaceThemeChangedNotification" object: nil];
  72. }
  73. - (void)themeChanged:(NSNotification *)notification {
  74. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  75. [self updateViewColor];
  76. });
  77. }
  78. - (void)updateViewColor {
  79. if ([KMAppearance isDarkMode]) {
  80. self.contentView.layer.backgroundColor = [NSColor colorWithRed:40/255. green:38/255. blue:47/255. alpha:1].CGColor;
  81. } else {
  82. self.contentView.layer.backgroundColor = [NSColor colorWithRed:237/255. green:231/255. blue:255/255. alpha:1].CGColor;
  83. }
  84. self.textField.textColor = [KMAppearance KMColor_Layout_H0];
  85. self.textField.font = [NSFont boldSystemFontOfSize:14.0];
  86. }
  87. @end
  88. #pragma mark - KMPurchaseCompareCell
  89. @interface KMPurchaseCompareCell : NSTableCellView
  90. @property (nonatomic,assign) IBOutlet NSView *bgColorView;
  91. @property (nonatomic,assign) IBOutlet NSTextField *value1Label;
  92. @property (nonatomic,assign) IBOutlet NSTextField *value2Label;
  93. @property (nonatomic,assign) IBOutlet NSTextField *value3Label;
  94. @property (nonatomic,assign) IBOutlet NSTextField *value4Label;
  95. @property (nonatomic,assign) IBOutlet NSImageView *value1ImageView;
  96. @property (nonatomic,assign) IBOutlet NSImageView *value2ImageView;
  97. @property (nonatomic,assign) IBOutlet NSImageView *value3ImageView;
  98. @property (nonatomic,assign) IBOutlet NSImageView *value4ImageView;
  99. @property (nonatomic,assign) IBOutlet NSBox *lineBox;
  100. @property (assign) IBOutlet NSLayoutConstraint *boxBottomConst;
  101. @end
  102. @implementation KMPurchaseCompareCell
  103. - (void)dealloc
  104. {
  105. [NSDistributedNotificationCenter.defaultCenter removeObserver:self];
  106. }
  107. - (void)awakeFromNib
  108. {
  109. [super awakeFromNib];
  110. self.bgColorView.wantsLayer = YES;
  111. [self updateViewColor];
  112. [NSDistributedNotificationCenter.defaultCenter addObserver:self selector:@selector(themeChanged:) name:@"AppleInterfaceThemeChangedNotification" object: nil];
  113. }
  114. - (void)themeChanged:(NSNotification *)notification {
  115. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  116. [self updateViewColor];
  117. });
  118. }
  119. - (void)updateViewColor {
  120. self.bgColorView.layer.backgroundColor = [NSColor colorWithRed:247/255.0 green:245/255.0 blue:1 alpha:1.].CGColor;
  121. NSColor *textColor = [NSColor colorWithRed:68.0/255.0 green:68.0/255.0 blue:68.0/255.0 alpha:1.0];
  122. NSColor *subtextColor = [NSColor colorWithRed:141.0/255.0 green:141.0/255.0 blue:141.0/255.0 alpha:1.0];
  123. NSColor *lineColor = [NSColor colorWithRed:204.0/255.0 green:204.0/255.0 blue:204.0/255.0 alpha:0.4];
  124. if ([KMAppearance isDarkMode]) {
  125. self.bgColorView.layer.backgroundColor = [NSColor colorWithRed:24/255.0 green:22/255.0 blue:31/255. alpha:1.].CGColor;
  126. textColor = [NSColor colorWithRed:255.0/255.0 green:255.0/255.0 blue:255.0/255.0 alpha:0.8];
  127. subtextColor = [NSColor colorWithRed:255.0/255.0 green:255.0/255.0 blue:255.0/255.0 alpha:0.6];
  128. lineColor = [NSColor colorWithRed:0.0/255.0 green:0.0/255.0 blue:0.0/255.0 alpha:0.15];
  129. }
  130. self.value1Label.textColor = subtextColor;
  131. self.value2Label.textColor = self.value3Label.textColor = self.value4Label.textColor = subtextColor;
  132. self.lineBox.fillColor = lineColor;
  133. self.textField.textColor = textColor;
  134. }
  135. @end
  136. #pragma mark - KMPurchaseCompareWindowController
  137. @interface KMPurchaseCompareWindowController ()<NSTableViewDelegate, NSTableViewDataSource>
  138. @property (nonatomic,assign) NSModalSession modalSession;
  139. @property (nonatomic,retain) NSArray *dataSource;
  140. @property (nonatomic,assign) IBOutlet NSTableView *tableView;
  141. @property (nonatomic,assign) IBOutlet NSTextField *titleLabel;
  142. @property (nonatomic,assign) IBOutlet NSTextField *switchLabel;
  143. @property (nonatomic,assign) IBOutlet NSButton *switchButton;
  144. @property (assign) IBOutlet NSView *freeInfoView;
  145. @property (assign) IBOutlet NSTextField *freeInfoLabel;
  146. @property (assign) IBOutlet NSView *value1InfoView;
  147. @property (assign) IBOutlet NSBox *value1InfoBox;
  148. @property (assign) IBOutlet NSBox *value1InfoTypeBox;
  149. @property (assign) IBOutlet NSTextField *sixMouthProLabel;
  150. @property (assign) IBOutlet NSTextField *oneYearProLabel;
  151. @property (assign) IBOutlet NSBox *switchBox;
  152. @property (assign) IBOutlet NSButton *switchBtn;
  153. @property (assign) IBOutlet NSView *switchCircleView;
  154. @property (assign) IBOutlet NSLayoutConstraint *switchCircleLeftConst;
  155. @property (assign) IBOutlet NSBox *saleBox;
  156. @property (assign) IBOutlet NSImageView *saleIv;
  157. @property (assign) IBOutlet NSTextField *saleLabel;
  158. @property (assign) IBOutlet NSTextField *value1InfoLabel;
  159. @property (nonatomic,assign) IBOutlet NSTextField *value1PurchaseLabel;
  160. @property (nonatomic,assign) IBOutlet NSTextField *value1PurchaseSubLabel;
  161. @property (nonatomic,assign) IBOutlet KMCustomButton *value1PurchaseButton;
  162. @property (assign) IBOutlet NSTextField *value1PurchaseBtnLbl;
  163. @property (assign) IBOutlet NSTextField *value1PurchaseOriPriceLbl;
  164. @property (assign) IBOutlet NSButton *value1PurchaseBtnLblBtn;
  165. @property (assign) IBOutlet NSView *value2InfoView;
  166. @property (assign) IBOutlet NSTextField *value2InfoLabel;
  167. @property (nonatomic,assign) IBOutlet NSTextField *value2PurchaseLabel;
  168. @property (nonatomic,assign) IBOutlet NSTextField *value2PurchaseSubLabel;
  169. @property (nonatomic,assign) IBOutlet KMButton *value2PurchaseButton;
  170. @property (assign) IBOutlet NSTextField *value2PurchaseLbl;
  171. @property (assign) IBOutlet KMButton *value2PurchaseLblBtn;
  172. @property (assign) IBOutlet NSView *value3InfoView;
  173. @property (assign) IBOutlet NSTextField *value3InfoLabel;
  174. @property (nonatomic,assign) IBOutlet NSTextField *value3PurchaseLabel;
  175. @property (nonatomic,assign) IBOutlet NSTextField *value3PurchaseSubLabel;
  176. @property (nonatomic,assign) IBOutlet KMButton *value3PurchaseButton;
  177. @property (strong) IBOutlet NSTextField *value3PurchaseBtnLbl;
  178. @property (nonatomic,assign) IBOutlet NSButton *aboutButton;
  179. @property (nonatomic,assign) IBOutlet HyperLinkButton *btnRestore;
  180. @property (assign) IBOutlet HyperLinkButton *privacyPolicyBtn;
  181. @property (assign) IBOutlet HyperLinkButton *termOfSerBtn;
  182. @property (nonatomic,assign) IBOutlet NSTextView *textView;
  183. @property (nonatomic,assign) IBOutlet NSView *specialView;
  184. @property (nonatomic,assign) IBOutlet NSImageView *specialImageView;
  185. @property (nonatomic,assign) IBOutlet NSTextField *specialLabel;
  186. @property (nonatomic,assign) IBOutlet NSView *specialView1;
  187. @property (nonatomic,assign) IBOutlet NSImageView *specialImageView1;
  188. @property (nonatomic,assign) IBOutlet NSTextField *specialLabel1;
  189. @property (nonatomic,assign) IBOutlet NSBox *box;
  190. @property (nonatomic,assign) IBOutlet NSBox *labelbox;
  191. @property (assign) IBOutlet NSLayoutConstraint *topButtonOffset;
  192. @property (nonatomic, retain) CALayer *value1Layer;
  193. @property (nonatomic, retain) KMDiscountToSaveWindowController *discountToSaveWinC;
  194. @property (nonatomic, assign) BOOL isPurchaseSwitch;
  195. @property (assign) IBOutlet NSLayoutConstraint *billedTopConst;
  196. @property (weak) IBOutlet NSImageView *discountYearly;
  197. @property (weak) IBOutlet NSImageView *discountPermanent;
  198. @property (weak) IBOutlet NSImageView *discountPremium;
  199. @end
  200. @implementation KMPurchaseCompareWindowController
  201. #pragma mark - Init Methods
  202. - (id)init {
  203. if (self = [super initWithWindowNibName:@"KMPurchaseCompareWindowController"]) {
  204. [[NSNotificationCenter defaultCenter] addObserver:self
  205. selector:@selector(IAPProductLoadedNotification:)
  206. name:KMIAPProductLoadedNotification
  207. object:nil];
  208. [[NSNotificationCenter defaultCenter] addObserver:self
  209. selector:@selector(IAPSubscriptionLoadedNotification:)
  210. name:KMIAPSubscriptionLoadedNotification
  211. object:nil];
  212. [[NSNotificationCenter defaultCenter] addObserver:self
  213. selector:@selector(IAPProductPurchasedNotification:)
  214. name:KMIAPProductPurchasedNotification
  215. object:nil];
  216. [[NSNotificationCenter defaultCenter] addObserver:self
  217. selector:@selector(IAPProductFailedNotification:)
  218. name:KMIAPProductFailedNotification
  219. object:nil];
  220. [[NSNotificationCenter defaultCenter] addObserver:self
  221. selector:@selector(IAPProductRestoreFinishedNotification:)
  222. name:KMIAPProductRestoreFinishedNotification
  223. object:nil];
  224. [[NSNotificationCenter defaultCenter] addObserver:self
  225. selector:@selector(IAPProductRestoreFailedNotification:)
  226. name:KMIAPProductRestoreFailedNotification
  227. object:nil];
  228. [NSDistributedNotificationCenter.defaultCenter addObserver:self selector:@selector(themeChanged:) name:@"AppleInterfaceThemeChangedNotification" object: nil];
  229. self.isPurchaseSwitch = false;
  230. }
  231. return self;
  232. }
  233. - (void)themeChanged:(NSNotification *)notification {
  234. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  235. [self updateViewColor];
  236. });
  237. }
  238. - (void)dealloc {
  239. [[NSNotificationCenter defaultCenter] removeObserver:self];
  240. }
  241. + (NSWindowController *)sharedInstance {
  242. #if VERSION_DMG
  243. if (ActivityStatusNone == [VerificationManager manager].status) {
  244. static KMPurchaseFirstTrialWindowController *singleton = nil;
  245. static dispatch_once_t pred;
  246. dispatch_once(&pred, ^{
  247. singleton = [KMPurchaseCompareWindowController firstTrialWCCheck];
  248. });
  249. return singleton;
  250. } else {
  251. static KMPurchaseCompareDMGWindowController *singleton = nil;
  252. static dispatch_once_t pred;
  253. dispatch_once(&pred, ^{
  254. singleton = [[KMPurchaseCompareDMGWindowController alloc] init];
  255. });
  256. return singleton;
  257. }
  258. #else
  259. static KMPurchaseCompareWindowController *singleton = nil;
  260. static dispatch_once_t pred;
  261. dispatch_once(&pred, ^{
  262. singleton = [[KMPurchaseCompareWindowController alloc] init];
  263. });
  264. return singleton;
  265. #endif
  266. }
  267. + (NSWindowController *)DMGPurchaseInstance {
  268. static KMPurchaseCompareDMGWindowController *singleton = nil;
  269. static dispatch_once_t pred;
  270. dispatch_once(&pred, ^{
  271. singleton = [[KMPurchaseCompareDMGWindowController alloc] init];
  272. });
  273. return singleton;
  274. }
  275. #pragma mark - FirstTrial WC
  276. + (KMPurchaseFirstTrialWindowController *)firstTrialWCCheck {
  277. //弹出 试用弹窗UI优化-新用户试用路径 新UI 情况三 点到付费功能
  278. KMPurchaseFirstTrialWindowController *firstTrialWC = [KMPurchaseFirstTrialWindowController currentFirstTrialWC];
  279. firstTrialWC.buttonActionBlock = ^(KMPurchaseFirstTrialWindowController * _Nonnull ftWC, KMButton * _Nonnull btn, NSString * _Nonnull email, NSString * _Nonnull name) {
  280. if (btn.tag == 10001) {
  281. if (ActivityStatusNone == [VerificationManager manager].status ||
  282. ActivityStatusTrialExpire == [VerificationManager manager].status ) {
  283. [[FMTrackEventManager defaultManager] trackEventWithEvent:@"Tbr" withProperties:@{@"Tbr_Btn":@"Btn_Tbr_SecondTrial"}];
  284. [[VerificationManager manager] trialForDays:7
  285. email:email?:[VerificationManager manager].email
  286. name:name?:[VerificationManager manager].accountName
  287. complention:^(ActivityStatus status, NSDictionary *info, NSError *error) {
  288. if (error ||
  289. status != ActivityStatusTrial) {
  290. NSAlert *alert = [NSAlert alertWithMessageText:NSLocalizedString(@"Activation Error", nil)
  291. defaultButton:NSLocalizedString(@"Try Again", nil)
  292. alternateButton:nil
  293. otherButton:nil
  294. informativeTextWithFormat:NSLocalizedString(@"Failed to sign up for the free trial. Please make sure your internet connection is available and try again later.", nil), nil];
  295. [alert runModal];
  296. } else {
  297. KMVerificationWindowController *vc = [KMVerificationWindowController verificationWithType:KMVerificationTypeRepeatTrialSuccess];
  298. [vc showWindow:nil];
  299. }
  300. }];
  301. [ftWC close];
  302. } else {
  303. [ftWC close];
  304. KMVerificationWindowController *vc = [KMVerificationWindowController verificationWithType:KMVerificationTypeActivate];
  305. vc.callback = ^{
  306. [[KMPurchaseCompareWindowController sharedInstance] showWindow:nil];
  307. };
  308. [vc showWindow:nil];
  309. }
  310. } else if (btn.tag == 10002) {
  311. #if VERSION_DMG
  312. NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@?utm_source=app_dmg&utm_medium=dmg_puw_free_trial", Swift_oc_Tool.Store_Link_OC]];
  313. [[NSWorkspace sharedWorkspace] openURL:url];
  314. [[FMTrackEventManager defaultManager] trackEventWithEvent:@"PUW" withProperties:@{@"PUW_Btn":@"PUW_Btn_UpgradeBuyNow"}];
  315. #endif
  316. } else if (btn.tag == 10003) {
  317. #if VERSION_DMG
  318. KMVerificationWindowController *vc = [KMVerificationWindowController verificationWithType:KMVerificationTypeActivate];//KMVerificationTypeActivate
  319. [vc showWindow:nil];
  320. [ftWC close];
  321. #endif
  322. }
  323. };
  324. return firstTrialWC;
  325. }
  326. #pragma mark - Window Methods
  327. - (void)windowDidLoad {
  328. [super windowDidLoad];
  329. // Implement this method to handle any initialization after your window controller's window has been loaded from its nib file.
  330. self.window.backgroundColor = [KMAppearance KMColor_Upgrade_Vip_BG];
  331. self.window.movableByWindowBackground = YES;
  332. [self updateViewColor];
  333. self.value1InfoBox.fillColor = [NSColor colorWithRed:17/255. green:6/255. blue:143/255. alpha:1];
  334. self.freeInfoLabel.stringValue = NSLocalizedString(@"Free", nil);
  335. self.value1InfoLabel.stringValue = NSLocalizedString(@"6-Month Plan", nil);
  336. self.value2InfoLabel.stringValue = NSLocalizedString(@"Permanent Version", nil);
  337. self.value3InfoLabel.stringValue = NSLocalizedString(@"Premium Version", nil);
  338. self.freeInfoLabel.font = [NSFont UbuntuMediumFontWithSize:18];
  339. self.value1InfoLabel.font = [NSFont UbuntuMediumFontWithSize:16];
  340. self.value2InfoLabel.font = [NSFont UbuntuMediumFontWithSize:16];
  341. self.value3InfoLabel.font = [NSFont UbuntuMediumFontWithSize:16];
  342. self.value1InfoTypeBox.fillColor = [NSColor clearColor];
  343. self.value1InfoTypeBox.borderWidth = 0;
  344. self.sixMouthProLabel.stringValue = NSLocalizedString(@"6-Month Plan", @"");
  345. self.sixMouthProLabel.textColor = NSColor.whiteColor;
  346. self.sixMouthProLabel.font = [NSFont UbuntuMediumFontWithSize:14];
  347. self.sixMouthProLabel.lineBreakMode = NSLineBreakByTruncatingTail;
  348. self.sixMouthProLabel.toolTip = self.sixMouthProLabel.stringValue;
  349. self.sixMouthProLabel.alignment = NSTextAlignmentCenter;
  350. // #757780
  351. self.oneYearProLabel.stringValue = NSLocalizedString(@"1-year Plan", @"");
  352. self.oneYearProLabel.textColor = NSColor.whiteColor;
  353. self.oneYearProLabel.font = [NSFont UbuntuMediumFontWithSize:14];
  354. self.oneYearProLabel.lineBreakMode = NSLineBreakByTruncatingTail;
  355. self.oneYearProLabel.toolTip = self.oneYearProLabel.stringValue;
  356. self.oneYearProLabel.alignment = NSTextAlignmentCenter;
  357. self.switchBox.fillColor = [NSColor colorWithWhite:1 alpha:0.2];
  358. self.switchBox.cornerRadius = 12;
  359. self.switchBox.borderWidth = 1;
  360. self.switchBox.borderColor = [NSColor colorWithRed:235/255.0 green:236/255.0 blue:240/255.0 alpha:1.0];
  361. self.switchCircleView.wantsLayer = true;
  362. self.switchCircleView.layer.cornerRadius = 8;
  363. self.switchCircleView.layer.backgroundColor = [NSColor whiteColor].CGColor;
  364. self.switchBtn.title = @"";
  365. self.switchBtn.target = self;
  366. self.switchBtn.action = @selector(switchAction:);
  367. // self.saleLabel.stringValue = NSLocalizedString(@"30%\nOFF", @"");
  368. // self.saleLabel.textColor = NSColor.whiteColor;
  369. // self.saleLabel.wantsLayer = true;
  370. // self.saleLabel.layer.transform = CATransform3DMakeRotation(M_PI/4, 0, 1, 0);
  371. // self.saleLabel.layer.transform.m34 = 1/500.0;
  372. // self.saleLabel.layer.affineTransform = CGAffineTransformMakeRotation(M_PI/2);
  373. // self.saleLabel.superview.wantsLayer = true;
  374. // self.saleLabel.superview.layer.transform = CATransform3DMakeRotation(M_PI/4, 0, 0, 1);
  375. self.saleLabel.hidden = true;
  376. self.saleLabel.superview.hidden = true;
  377. self.saleBox.borderWidth = 0;
  378. self.value1PurchaseButton.wantsLayer = YES;
  379. self.value1PurchaseButton.layer.backgroundColor = [NSColor colorWithRed:1 green:94/255. blue:44/255. alpha:1].CGColor;
  380. self.value1PurchaseButton.layer.cornerRadius = CGRectGetHeight(self.value1PurchaseButton.frame) / 2.;
  381. self.value1PurchaseBtnLblBtn.wantsLayer = YES;
  382. self.value1PurchaseButton.mouseMoveCallback = ^(BOOL mouseEntered) {
  383. if (self.value1PurchaseBtnLblBtn.enabled) {
  384. if (mouseEntered) {
  385. self.value1PurchaseBtnLblBtn.layer.backgroundColor = [[NSColor blackColor] colorWithAlphaComponent:0.15].CGColor;
  386. } else {
  387. self.value1PurchaseBtnLblBtn.layer.backgroundColor = [NSColor clearColor].CGColor;
  388. }
  389. }
  390. };
  391. self.value1PurchaseBtnLblBtn.layer.cornerRadius = CGRectGetHeight(self.value1PurchaseBtnLblBtn.frame)/2.;
  392. self.value1PurchaseBtnLblBtn.layer.masksToBounds = YES;
  393. self.value2PurchaseButton.wantsLayer = YES;
  394. self.value2PurchaseButton.layer.cornerRadius = CGRectGetHeight(self.value2PurchaseButton.frame) / 2.;
  395. self.value2PurchaseButton.layer.backgroundColor = [NSColor whiteColor].CGColor;
  396. self.value2PurchaseLbl.stringValue = NSLocalizedString(@"Purchase", nil);
  397. self.value2PurchaseLbl.textColor = [NSColor colorWithRed:85/255. green:40/255.0 blue:255.0/255.0 alpha:1.0];
  398. self.value3PurchaseButton.title = NSLocalizedString(@"Purchase", nil);
  399. self.value3PurchaseBtnLbl.stringValue = NSLocalizedString(@"Purchase", nil);
  400. self.value3PurchaseButton.wantsLayer = YES;
  401. [self.value3PurchaseButton setTitleColor:[NSColor colorWithRed:85/255. green:40/255.0 blue:255.0/255.0 alpha:1.0]];
  402. self.value3PurchaseBtnLbl.textColor = [NSColor colorWithRed:85/255. green:40/255.0 blue:255.0/255.0 alpha:1.0];
  403. self.value3PurchaseButton.layer.backgroundColor = [NSColor whiteColor].CGColor;
  404. self.value3PurchaseButton.layer.cornerRadius = CGRectGetHeight(self.value3PurchaseButton.frame) / 2.;
  405. self.titleLabel.stringValue = NSLocalizedString(@"Subscribe to All Access Pack to enjoy more expanded features.", nil);
  406. self.switchLabel.stringValue = NSLocalizedString(@"Choose your favorite payment and enjoy flexible upgrades.", nil);
  407. self.switchLabel.textColor = [KMAppearance KMColor_Interactive_M0];
  408. self.switchButton.title = [NSString stringWithFormat:@"%@",NSLocalizedString(@"Pricing and Plans", nil)];
  409. self.box.wantsLayer = YES;
  410. self.box.shadow = [[NSShadow alloc] init];
  411. self.box.layer.shadowOpacity = 0.3;
  412. self.box.layer.shadowColor = [NSColor colorWithRed:0 green:0 blue:0 alpha:0.3].CGColor;
  413. self.box.layer.shadowOffset = NSMakeSize(0,3);
  414. self.box.layer.shadowRadius = 8;
  415. self.box.layer.masksToBounds = NO;
  416. NSButtonCell *cell = self.switchButton.cell;
  417. NSColor *txtColor = [NSColor colorWithRed:102.0/255.0 green:102.0/255.0 blue:102.0/255.0 alpha:1.0];
  418. NSAttributedString *attrStr1 = [cell attributedTitle];
  419. NSMutableAttributedString *myAttr = [[NSMutableAttributedString alloc] initWithAttributedString:attrStr1];
  420. [myAttr addAttribute:NSForegroundColorAttributeName value:txtColor range:NSMakeRange(0, myAttr.length)];
  421. [myAttr addAttribute:NSFontAttributeName value:[NSFont boldSystemFontOfSize:13.0] range:NSMakeRange(0, myAttr.length)];
  422. [cell setAttributedTitle:myAttr];
  423. [self.switchButton updateCell:cell];
  424. self.aboutButton.title = NSLocalizedString(@"About Subscriptions", nil);
  425. self.btnRestore.title = NSLocalizedString(@"Restore", nil);
  426. self.privacyPolicyBtn.title = NSLocalizedString(@"Privacy Policy", nil);
  427. self.termOfSerBtn.title = NSLocalizedString(@"Terms of Service", nil);
  428. self.btnRestore.toolTip = NSLocalizedString(@"Restore", nil);
  429. self.privacyPolicyBtn.toolTip = NSLocalizedString(@"Privacy Policy", nil);
  430. self.termOfSerBtn.toolTip = NSLocalizedString(@"Terms of Service", nil);
  431. [self.aboutButton setTitleColor:[NSColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:0.7]];
  432. [self.btnRestore setTitleColor:[NSColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:1]];
  433. [self.privacyPolicyBtn setTitleColor:[NSColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:1]];
  434. [self.termOfSerBtn setTitleColor:[NSColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:1]];
  435. self.btnRestore.mouseMoveCallback = ^(BOOL mouseEntered) {
  436. if (mouseEntered) {
  437. [self.btnRestore setTitleColor:[NSColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:0.7]];
  438. } else {
  439. [self.btnRestore setTitleColor:[NSColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:1]];
  440. }
  441. };
  442. self.privacyPolicyBtn.mouseMoveCallback = ^(BOOL mouseEntered) {
  443. if (mouseEntered) {
  444. [self.privacyPolicyBtn setTitleColor:[NSColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:0.7]];
  445. } else {
  446. [self.privacyPolicyBtn setTitleColor:[NSColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:1]];
  447. }
  448. };
  449. self.termOfSerBtn.mouseMoveCallback = ^(BOOL mouseEntered) {
  450. if (mouseEntered) {
  451. [self.termOfSerBtn setTitleColor:[NSColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:0.7]];
  452. } else {
  453. [self.termOfSerBtn setTitleColor:[NSColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:1]];
  454. }
  455. };
  456. self.aboutButton.hidden = YES;
  457. [self reloadData];
  458. [self reloadDataContent];
  459. [[IAPProductsManager defaultManager] loadProducts];
  460. __block typeof(self) blockSelf = self;
  461. self.value2PurchaseButton.mouseMoveCallback = ^(BOOL mouseEntered) {
  462. if (blockSelf.value2PurchaseButton.enabled) {
  463. if (mouseEntered) {
  464. [blockSelf.value2PurchaseLbl setTextColor:[NSColor whiteColor]];
  465. blockSelf.value2PurchaseButton.layer.backgroundColor = [NSColor colorWithRed:1 green:94/255.0 blue:44/255.0 alpha:1.0].CGColor;
  466. } else {
  467. [blockSelf.value2PurchaseLbl setTextColor:[NSColor colorWithRed:85/255. green:40/255.0 blue:255.0/255.0 alpha:1.0]];
  468. blockSelf.value2PurchaseButton.layer.backgroundColor = [NSColor whiteColor].CGColor;
  469. }
  470. }
  471. };
  472. self.value3PurchaseButton.mouseMoveCallback = ^(BOOL mouseEntered) {
  473. if (mouseEntered) {
  474. // [blockSelf.value3PurchaseButton setTitleColor:[NSColor whiteColor]];
  475. blockSelf.value3PurchaseBtnLbl.textColor = [NSColor whiteColor];
  476. blockSelf.value3PurchaseButton.layer.backgroundColor = [NSColor colorWithRed:1 green:94/255.0 blue:44/255.0 alpha:1.0].CGColor;
  477. } else {
  478. // [blockSelf.value3PurchaseButton setTitleColor:[NSColor colorWithRed:85/255. green:40/255.0 blue:255.0/255.0 alpha:1.0]];
  479. blockSelf.value3PurchaseBtnLbl.textColor = [NSColor colorWithRed:85/255. green:40/255.0 blue:255.0/255.0 alpha:1.0];
  480. blockSelf.value3PurchaseButton.layer.backgroundColor = [NSColor whiteColor].CGColor;
  481. }
  482. };
  483. self.textView.string = [NSString stringWithFormat:NSLocalizedString(@"Subscription plans:\nSubscriptions: %@\n\n- Subscriptions will be charged through your iTunes account at the confirmation of purchase.\n- Your subscriptions will automatically renew unless cancelled at least 24 hours before the end of current subscription period.\n- Your iTunes account will be charged for renewal within 24-hours prior to the end of the current period, for the same duration and at the current subscription price.\n- You may manage your subscriptions in your iTunes Account Settings after purchase.\n- No cancellation of the current subscription is allowed during an active subscription period.\n\n- Terms of service:\nhttps://www.pdfreaderpro.com/terms_of_service\n- Privacy Policy:\nhttps://www.pdfreaderpro.com/privacy-policy", @""), NSLocalizedString(@"USD $39.99/(6 months), USD$59.99/(12 months), USD $59.99/(one-time purchase)", @"")];
  484. [self showDiscount];
  485. }
  486. - (BOOL)windowShouldClose:(id)sender {
  487. [[FMTrackEventManager defaultManager] trackEventWithEvent:@"PUW" withProperties:@{@"PUW_Btn":@"PUW_Btn_Upgrade_Cancel"}];
  488. if ([self isShowSale]) {
  489. [self trackEvent_freeWithEventName:@"PromotionalOffer" params:@{@"PUW_Btn" : @"PUW_7OffUpgrade_Cancel"} platform:KMAnalyticsPlatformAppCenter];
  490. }
  491. [self endModal:sender];
  492. return YES;
  493. }
  494. - (void)close {
  495. [super close];
  496. [self endModal:nil];
  497. }
  498. - (IBAction)startModal:(id)sender {
  499. [NSApp stopModal];
  500. NSInteger modalCode;
  501. self.modalSession = [NSApp beginModalSessionForWindow:self.window];
  502. do {
  503. modalCode = [NSApp runModalSession:self.modalSession];
  504. } while (modalCode == NSModalResponseContinue);
  505. }
  506. - (IBAction)endModal:(id)sender {
  507. if (self.modalSession) {
  508. [NSApp stopModal];
  509. [NSApp endModalSession:self.modalSession];
  510. [self.window orderOut:self];
  511. self.modalSession = nil;
  512. }
  513. }
  514. - (void)showWindowRestore:(id)sender {
  515. [self showWindow:sender];
  516. [self buttonItemClicked_Restore:nil];
  517. }
  518. - (void)showWindow:(id)sender {
  519. [super showWindow:sender];
  520. [self reloadData];
  521. if ([self isShowSale]) {
  522. [self showDiscountToSaveWindow];
  523. }
  524. }
  525. #pragma mark - Private Methods
  526. - (void)reloadData {
  527. if (self.isPurchaseSwitch) {
  528. self.sixMouthProLabel.textColor = [NSColor colorWithRed:117/255.0 green:119/255.0 blue:128/255.0 alpha:1.0];
  529. self.oneYearProLabel.textColor = NSColor.whiteColor;
  530. self.switchCircleLeftConst.constant = 22;
  531. self.value1InfoLabel.stringValue = NSLocalizedString(@"1-year Plan", nil);
  532. } else {
  533. self.sixMouthProLabel.textColor = NSColor.whiteColor;
  534. self.oneYearProLabel.textColor = [NSColor colorWithRed:117/255.0 green:119/255.0 blue:128/255.0 alpha:1.0];
  535. self.switchCircleLeftConst.constant = 4;
  536. self.value1InfoLabel.stringValue = NSLocalizedString(@"6-Month Plan", nil);
  537. }
  538. self.saleBox.hidden = true;
  539. self.saleIv.hidden = true;
  540. if ([self isShowSale]) {
  541. KMAdvertisementItemInfo *info = KMAdvertisementManager.manager.info.StoreUserRecovery.content.firstObject;
  542. NSURL *url = [NSURL URLWithString:[KMAdvertisementModelTransition transitionImagePathWithImage:info.saleImage highlight:true]];
  543. [KMAdvertisementImage imageWithURLWithUrl:url completion:^(NSImage * _Nonnull image) {
  544. if (image != nil) {
  545. self.saleIv.image = image;
  546. self.saleBox.hidden = false;
  547. self.saleIv.hidden = false;
  548. [self trackEvent_freeWithEventName:@"PromotionalOffer" params:@{@"PUW_Exposure" : @"PUW_7OffUpgrade"} platform:KMAnalyticsPlatformAppCenter];
  549. }
  550. }];
  551. } else {
  552. self.saleBox.hidden = true;
  553. }
  554. if ([IAPProductsManager defaultManager].isAvailableAllFunction) {
  555. self.value1PurchaseButton.enabled = NO;
  556. self.value2PurchaseButton.enabled = NO;
  557. self.value2PurchaseLbl.textColor = [NSColor colorWithRed:85/255. green:40/255.0 blue:255.0/255.0 alpha:0.5];
  558. } else {
  559. self.value1PurchaseButton.enabled = YES;
  560. self.value2PurchaseButton.enabled = YES;
  561. self.value2PurchaseLbl.textColor = [NSColor colorWithRed:85/255. green:40/255.0 blue:255.0/255.0 alpha:1.0];
  562. }
  563. self.value1PurchaseBtnLblBtn.enabled = self.value1PurchaseButton.enabled;
  564. self.value1PurchaseBtnLbl.stringValue = NSLocalizedString(@"Subscribe", nil);
  565. if ([IAPProductsManager defaultManager].allAccessPackNew6months_lite.isTrialPeriod) {
  566. self.value1PurchaseBtnLbl.stringValue = NSLocalizedString(@"Subscribe", nil);
  567. if ([IAPProductsManager defaultManager].allAccessPackNew6months_lite.isSubscribed) {
  568. self.value1PurchaseBtnLbl.stringValue = NSLocalizedString(@"Subscribed", nil);
  569. }
  570. } else if ([IAPProductsManager defaultManager].allAccessPack12months_lite.isTrialPeriod) {
  571. self.value1PurchaseBtnLbl.stringValue = NSLocalizedString(@"Subscribe", nil);
  572. if ([IAPProductsManager defaultManager].allAccessPack12months_lite.isSubscribed) {
  573. self.value1PurchaseBtnLbl.stringValue = NSLocalizedString(@"Subscribed", nil);
  574. }
  575. } else {
  576. if ([IAPProductsManager defaultManager].allAccessPackNew6months_lite.isSubscribed) {
  577. self.value1PurchaseBtnLbl.stringValue = NSLocalizedString(@"Subscribed", nil);
  578. } else if ([IAPProductsManager defaultManager].allAccessPack12months_lite.isSubscribed) {
  579. self.value1PurchaseBtnLbl.stringValue = NSLocalizedString(@"Subscribed", nil);
  580. } else {
  581. self.value1PurchaseBtnLbl.stringValue = NSLocalizedString(@"Free Trial", nil);
  582. if (@available(macOS 10.13.2, *)) {
  583. #if !VERSION_DMG
  584. if (![IAPProductsManager defaultManager].allAccessPackNew6months_lite.product.introductoryPrice) {
  585. self.value1PurchaseBtnLbl.stringValue = NSLocalizedString(@"Subscribe", nil);
  586. } else if (![IAPProductsManager defaultManager].allAccessPack12months_lite.product.introductoryPrice) {
  587. self.value1PurchaseBtnLbl.stringValue = NSLocalizedString(@"Subscribe", nil);
  588. }
  589. #endif
  590. }
  591. }
  592. }
  593. if (self.value1PurchaseBtnLblBtn.enabled) {
  594. [self.value1PurchaseBtnLbl setTextColor:[NSColor whiteColor]];
  595. } else {
  596. [self.value1PurchaseBtnLbl setTextColor:[[NSColor whiteColor] colorWithAlphaComponent:0.5]];
  597. }
  598. self.value2PurchaseLblBtn.enabled = self.value2PurchaseButton.enabled;
  599. NSString *averageMonthPrice = nil;
  600. NSString *monthPrice = nil;
  601. NSString *averageMonthPrice_discount = nil;
  602. NSString *monthPrice_discount = nil;
  603. NSString *allPrice = nil;
  604. if ([IAPProductsManager defaultManager].allAccessPackNew6months_lite.isOffers) {
  605. self.specialView1.hidden = NO;
  606. averageMonthPrice = [IAPProductsManager defaultManager].allAccessPackNew6months_lite.offersAveragePrice;
  607. monthPrice = [IAPProductsManager defaultManager].allAccessPackNew6months_lite.offersPrice;
  608. averageMonthPrice_discount = [IAPProductsManager defaultManager].allAccessPackNew6months_lite.discountAveragePrice;
  609. monthPrice_discount = [IAPProductsManager defaultManager].allAccessPackNew6months_lite.discountPrice;
  610. self.topButtonOffset.constant = 20;
  611. } else if ([IAPProductsManager defaultManager].allAccessPack12months_lite.isOffers) {
  612. averageMonthPrice = [IAPProductsManager defaultManager].allAccessPack12months_lite.offersAveragePrice;
  613. monthPrice = [IAPProductsManager defaultManager].allAccessPack12months_lite.offersPrice;
  614. averageMonthPrice_discount = [IAPProductsManager defaultManager].allAccessPack12months_lite.discountAveragePrice;
  615. monthPrice_discount = [IAPProductsManager defaultManager].allAccessPack12months_lite.discountPrice;
  616. self.topButtonOffset.constant = 20;
  617. } else {
  618. self.specialView1.hidden = YES;
  619. if (self.isPurchaseSwitch == false) {
  620. averageMonthPrice = [IAPProductsManager defaultManager].allAccessPackNew6months_lite.averagePrice;
  621. monthPrice = [IAPProductsManager defaultManager].allAccessPackNew6months_lite.price;
  622. averageMonthPrice_discount = [IAPProductsManager defaultManager].allAccessPackNew6months_lite.discountAveragePrice;
  623. monthPrice_discount = [IAPProductsManager defaultManager].allAccessPackNew6months_lite.discountPrice;
  624. } else {
  625. averageMonthPrice = [IAPProductsManager defaultManager].allAccessPack12months_lite.averagePrice;
  626. monthPrice = [IAPProductsManager defaultManager].allAccessPack12months_lite.price;
  627. averageMonthPrice_discount = [IAPProductsManager defaultManager].allAccessPack12months_lite.discountAveragePrice;
  628. monthPrice_discount = [IAPProductsManager defaultManager].allAccessPack12months_lite.discountPrice;
  629. }
  630. self.topButtonOffset.constant = 10;
  631. }
  632. if ([IAPProductsManager defaultManager].allAccessPackPermanent_lite.isOffers) {
  633. self.topButtonOffset.constant = 20;
  634. self.specialView.hidden = NO;
  635. allPrice = [IAPProductsManager defaultManager].allAccessPackPermanent_lite.offersPrice;
  636. } else {
  637. self.topButtonOffset.constant = 10;
  638. self.specialView.hidden = YES;
  639. allPrice = [IAPProductsManager defaultManager].allAccessPackPermanent_lite.price;
  640. }
  641. CGFloat off = 1 -[IAPProductsManager defaultManager].allAccessPackPermanent_lite.offers;
  642. NSString *offString = [NSString stringWithFormat:@"%.f%%",off * 100];
  643. self.specialLabel.stringValue = [NSString stringWithFormat:NSLocalizedString(@"%@ off", @""),offString];
  644. if (self.isPurchaseSwitch) {
  645. off = 1 -[IAPProductsManager defaultManager].allAccessPack12months_lite.offers;
  646. } else {
  647. off = 1 -[IAPProductsManager defaultManager].allAccessPackNew6months_lite.offers;
  648. }
  649. offString = [NSString stringWithFormat:@"%.f%%",off * 100];
  650. self.specialLabel1.stringValue = [NSString stringWithFormat:NSLocalizedString(@"%@ off", @""),offString];
  651. NSImage *image = [NSImage imageNamed:@"KMImageNameCompareTagBG"];
  652. self.specialImageView.image = image;
  653. self.specialImageView1.image = image;
  654. BOOL isShowSale = [self isShowSale];
  655. if (KMKdanRemoteConfig.remoteConfig.showAPP_AveragePrice) {
  656. if (isShowSale) {
  657. self.value1PurchaseLabel.stringValue = [NSString stringWithFormat:@"%@/%@", averageMonthPrice_discount, NSLocalizedString(@"mon", nil)];
  658. self.value1PurchaseOriPriceLbl.stringValue = [NSString stringWithFormat:@"%@/%@", averageMonthPrice, NSLocalizedString(@"mon", nil)];
  659. self.value1PurchaseOriPriceLbl.hidden = false;
  660. self.billedTopConst.constant = 16;
  661. } else {
  662. self.value1PurchaseLabel.stringValue = [NSString stringWithFormat:@"%@/%@", averageMonthPrice, NSLocalizedString(@"mon", nil)];
  663. self.value1PurchaseOriPriceLbl.hidden = true;
  664. self.billedTopConst.constant = 0;
  665. }
  666. } else {
  667. if (self.isPurchaseSwitch) {
  668. if (isShowSale) {
  669. self.value1PurchaseLabel.stringValue = [NSString stringWithFormat:@"%@/%@", monthPrice_discount, NSLocalizedString(@"12 months", nil)];
  670. self.value1PurchaseOriPriceLbl.stringValue = [NSString stringWithFormat:@"%@/%@", monthPrice, NSLocalizedString(@"12 months", nil)];
  671. self.value1PurchaseOriPriceLbl.hidden = false;
  672. self.billedTopConst.constant = 16;
  673. } else {
  674. self.value1PurchaseLabel.stringValue = [NSString stringWithFormat:@"%@/%@", monthPrice, NSLocalizedString(@"12 months", nil)];
  675. self.value1PurchaseOriPriceLbl.hidden = true;
  676. self.billedTopConst.constant = 0;
  677. }
  678. } else {
  679. if (isShowSale) {
  680. self.value1PurchaseLabel.stringValue = [NSString stringWithFormat:@"%@/%@", monthPrice_discount, NSLocalizedString(@"6mon", nil)];
  681. self.value1PurchaseOriPriceLbl.stringValue = [NSString stringWithFormat:@"%@/%@", monthPrice, NSLocalizedString(@"6mon", nil)];
  682. self.value1PurchaseOriPriceLbl.hidden = false;
  683. self.billedTopConst.constant = 16;
  684. } else {
  685. self.value1PurchaseLabel.stringValue = [NSString stringWithFormat:@"%@/%@", monthPrice, NSLocalizedString(@"6mon", nil)];
  686. self.value1PurchaseOriPriceLbl.hidden = true;
  687. self.billedTopConst.constant = 0;
  688. }
  689. }
  690. }
  691. self.value1PurchaseLabel.textColor = [NSColor colorWithRed:1 green:231/255. blue:106/255. alpha:1.];
  692. self.value1PurchaseOriPriceLbl.textColor = [NSColor colorWithWhite:1 alpha:0.7];
  693. self.value1PurchaseOriPriceLbl.attributedStringValue = [[NSAttributedString alloc] initWithString:self.value1PurchaseOriPriceLbl.stringValue attributes:@{
  694. NSFontAttributeName : [NSFont SFProTextRegularFont:12],
  695. NSForegroundColorAttributeName: [NSColor colorWithWhite:1 alpha:0.7],
  696. NSStrikethroughStyleAttributeName : @(1)
  697. }];
  698. NSString *tTips = @"";
  699. if (isShowSale) {
  700. tTips = [NSString stringWithFormat:NSLocalizedString(@"%@ for the first 6-month subscription", nil), monthPrice_discount];
  701. } else {
  702. tTips = [NSString stringWithFormat:NSLocalizedString(@"Billed every 6 months at %@", nil), monthPrice];
  703. }
  704. if ([self.value1PurchaseBtnLbl.stringValue isEqualToString:NSLocalizedString(@"Free Trial", nil)]) {
  705. tTips = [NSString stringWithFormat:NSLocalizedString(@"Billed every 6 months at %@ after 7-day trial ends.", nil), monthPrice];
  706. #if !VERSION_DMG
  707. if (self.isPurchaseSwitch) {
  708. if ([IAPProductsManager defaultManager].allAccessPack12months_lite.product) {
  709. if (@available(macOS 10.13.2, *)) {
  710. tTips = [NSString stringWithFormat:NSLocalizedString(@"Billed every 12 months at %@ after %@-day trial ends.", nil), monthPrice,@([IAPProductsManager defaultManager].allAccessPack12months_lite.product.introductoryPrice.subscriptionPeriod.numberOfUnits)];
  711. }
  712. }
  713. } else {
  714. if ([IAPProductsManager defaultManager].allAccessPackNew6months_lite.product) {
  715. if (@available(macOS 10.13.2, *)) {
  716. tTips = [NSString stringWithFormat:NSLocalizedString(@"Billed every 6 months at %@ after %@-day trial ends.", nil), monthPrice,@([IAPProductsManager defaultManager].allAccessPackNew6months_lite.product.introductoryPrice.subscriptionPeriod.numberOfUnits)];
  717. }
  718. }
  719. }
  720. #endif
  721. }
  722. if (@available(macOS 10.13.2, *)) {
  723. #if !VERSION_DMG
  724. if (self.isPurchaseSwitch) {
  725. if (![IAPProductsManager defaultManager].allAccessPack12months_lite.product.introductoryPrice) {
  726. if (isShowSale) {
  727. tTips = [NSString stringWithFormat:NSLocalizedString(@"%@ for the first year's subscription", nil), monthPrice_discount];
  728. } else {
  729. tTips = [NSString stringWithFormat:NSLocalizedString(@"Billed every 12 months at %@", nil), monthPrice];
  730. }
  731. }
  732. } else {
  733. if (![IAPProductsManager defaultManager].allAccessPackNew6months_lite.product.introductoryPrice) {
  734. if (isShowSale) {
  735. tTips = [NSString stringWithFormat:NSLocalizedString(@"%@ for the first 6-month subscription", nil), monthPrice_discount];
  736. } else {
  737. tTips = [NSString stringWithFormat:NSLocalizedString(@"Billed every 6 months at %@", nil), monthPrice];
  738. }
  739. }
  740. }
  741. #endif
  742. }
  743. self.value1PurchaseSubLabel.stringValue = [NSString stringWithFormat:NSLocalizedString(@"%@", nil), tTips];
  744. self.value2PurchaseLabel.stringValue = allPrice?:@"";
  745. self.value2PurchaseLabel.textColor = [NSColor colorWithRed:1 green:231/255. blue:106/255. alpha:1.];
  746. self.value2PurchaseSubLabel.stringValue = NSLocalizedString(@"one-time purchase", nil);
  747. self.value3PurchaseLabel.stringValue = NSLocalizedString(@"USD $59.99", nil);
  748. self.value3PurchaseLabel.textColor = [NSColor colorWithRed:1 green:231/255. blue:106/255. alpha:1.];
  749. self.value3PurchaseSubLabel.stringValue = NSLocalizedString(@"one-time purchase", nil);
  750. self.value1PurchaseBtnLbl.font = [NSFont UbuntuBoldFontWithSize:16];
  751. self.value2PurchaseLbl.font = [NSFont UbuntuBoldFontWithSize:16];
  752. self.value3PurchaseBtnLbl.font = [NSFont UbuntuBoldFontWithSize:16];
  753. self.value1PurchaseLabel.font = [NSFont UbuntuBoldFontWithSize:22];
  754. self.value2PurchaseLabel.font = [NSFont UbuntuBoldFontWithSize:22];
  755. self.value3PurchaseLabel.font = [NSFont UbuntuBoldFontWithSize:22];
  756. self.value1PurchaseOriPriceLbl.font = [NSFont SFProTextRegularFont:12];
  757. }
  758. - (void)reloadDataContent {
  759. if (self.isPurchaseSwitch) {
  760. self.dataSource = @[@"PDF to Office",
  761. @[@"Convert PDFs to Word, HTML, TXT, JPEG or PNG files",@"Only first 10 pages",@"Advanced",@"Advanced",@"Standard"],
  762. @[@"Turn PDF to PPT, Excel, RTF, CSV, and more",@"Only first 10 pages",@"✓",@"✓",@"Only first 10 pages"],
  763. @[@"Convert PDF to TIFF, BMP, GIF or TGA files",@"Only first 10 pages",@"✓",@"✓",@"Only first 10 pages"],
  764. @"Edit PDF",
  765. @[@"Add and edit text in PDF",@"X",@"✓",@"✓",@"✓"],
  766. @[@"Edit, crop, replace image in PDF",@"X",@"✓",@"✓",@"✓"],
  767. @"OCR",
  768. @[@"Extract texts from image-based or scanned PDF",@"X",@"✓",@"✓",@"✓"],
  769. @"Organize Pages",
  770. @[@"Extract, rotate, rearrange, replace, add, delete pages",@"X",@"✓",@"✓",@"✓"],
  771. @[@"Split PDFs into multiple files",@"X",@"✓",@"✓",@"✓"],
  772. @"Advanced Editing Tools",
  773. @[@"Merge multiple documents into a new PDF",@"Up to 2 files or 20 MB",@"✓",@"∞",@"∞"],
  774. @[@"Add & edit watermark",@"X",@"✓",@"✓",@"✓"],
  775. @[@"Add header, footer, page numbers",@"X",@"✓",@"✓",@"✓"],
  776. @[@"Add Bates Number",@"X",@"✓",@"✓",@"✓"],
  777. @[@"Insert PDF page background by color or image",@"X",@"✓",@"✓",@"✓"],
  778. @[@"Create fattened copies",@"X",@"✓",@"✓",@"✓"],
  779. @[@"Extract Images",@"X",@"✓",@"✓",@"✓"],
  780. @[@"Extract tables",@"Only first 10 pages",@"✓",@"✓",@"Only first 10 pages"],
  781. @[@"Measuring Tools",@"X",@"✓",@"✓",@"✓"],
  782. @"Fill & Sign",
  783. @[@"Create digital signature",@"X",@"✓",@"✓",@"✓"],
  784. @[@"Create & Edit & Fill Adobe Fillable PDF Forms",@"X",@"✓",@"✓",@"✓"],
  785. @"Security",
  786. @[@"Batch encrypting PDF documents",@"X",@"✓",@"✓",@"✓"],
  787. @[@"PDF Password Remover",@"X",@"✓",@"✓",@"✓"],
  788. @[@"Redact sensitive information",@"X",@"✓",@"✓",@"✓"],
  789. @"Create PDF",
  790. @[@"Convert JPEG, JPG, PNG, TIFF, BMP or PSD files to PDFs",@"1 file",@"✓",@"✓",@"✓"],
  791. @[@"Create PDFs from a scanner and iOS devices",@"X",@"✓",@"✓",@"✓"],
  792. @"Annotations",
  793. @[@"Customize PDF stamps",@"X",@"✓",@"✓",@"✓",@"✓"],
  794. @[@"Hyperlink",@"Page Number",@"Page Number, URL, Email",@"Page Number, URL, Email",@"Page Number, URL, Email"],
  795. @[@"Signature",@"Standard",@"Advanced",@"Advanced",@"Advanced"],
  796. @[@"Table",@"X",@"✓",@"✓",@"✓",@"✓"],
  797. @"View PDF",
  798. @[@"Multi-tab viewer",@"X",@"✓",@"✓",@"✓"],
  799. @[@"Various printing types: poster, booklet, multi-page printing",@"X",@"✓",@"✓",@"✓"],
  800. @[@"Customize theme colors: Light Mode, Dark Mode, Sepia Mode and more",@"X",@"✓",@"✓",@"✓"],
  801. @[@"Split View to compare files",@"X",@"✓",@"✓",@"✓"],
  802. @"Subscription Based Solution",
  803. @[@"Access all premium features in app",@"X",@"12 months",@"∞",@"∞"],
  804. @[@"Priority customer support",@"X",@"✓",@"✓",@"✓"],
  805. @[@"Ad-free",@"X",@"✓",@"✓",@"✓"],
  806. @{}
  807. ];
  808. } else {
  809. self.dataSource = @[@"PDF to Office",
  810. @[@"Convert PDFs to Word, HTML, TXT, JPEG or PNG files",@"Only first 10 pages",@"Advanced",@"Advanced",@"Standard"],
  811. @[@"Turn PDF to PPT, Excel, RTF, CSV, and more",@"Only first 10 pages",@"✓",@"✓",@"Only first 10 pages"],
  812. @[@"Convert PDF to TIFF, BMP, GIF or TGA files",@"Only first 10 pages",@"✓",@"✓",@"Only first 10 pages"],
  813. @"Edit PDF",
  814. @[@"Add and edit text in PDF",@"X",@"✓",@"✓",@"✓"],
  815. @[@"Edit, crop, replace image in PDF",@"X",@"✓",@"✓",@"✓"],
  816. @"OCR",
  817. @[@"Extract texts from image-based or scanned PDF",@"X",@"✓",@"✓",@"✓"],
  818. @"Organize Pages",
  819. @[@"Extract, rotate, rearrange, replace, add, delete pages",@"X",@"✓",@"✓",@"✓"],
  820. @[@"Split PDFs into multiple files",@"X",@"✓",@"✓",@"✓"],
  821. @"Advanced Editing Tools",
  822. @[@"Merge multiple documents into a new PDF",@"Up to 2 files or 20 MB",@"✓",@"∞",@"∞"],
  823. @[@"Add & edit watermark",@"X",@"✓",@"✓",@"✓"],
  824. @[@"Add header, footer, page numbers",@"X",@"✓",@"✓",@"✓"],
  825. @[@"Add Bates Number",@"X",@"✓",@"✓",@"✓"],
  826. @[@"Insert PDF page background by color or image",@"X",@"✓",@"✓",@"✓"],
  827. @[@"Create fattened copies",@"X",@"✓",@"✓",@"✓"],
  828. @[@"Extract Images",@"X",@"✓",@"✓",@"✓"],
  829. @[@"Extract tables",@"Only first 10 pages",@"✓",@"✓",@"Only first 10 pages"],
  830. @[@"Measuring Tools",@"X",@"✓",@"✓",@"✓"],
  831. @"Fill & Sign",
  832. @[@"Create digital signature",@"X",@"✓",@"✓",@"✓"],
  833. @[@"Create & Edit & Fill Adobe Fillable PDF Forms",@"X",@"✓",@"✓",@"✓"],
  834. @"Security",
  835. @[@"Batch encrypting PDF documents",@"X",@"✓",@"✓",@"✓"],
  836. @[@"PDF Password Remover",@"X",@"✓",@"✓",@"✓"],
  837. @[@"Redact sensitive information",@"X",@"✓",@"✓",@"✓"],
  838. @"Create PDF",
  839. @[@"Convert JPEG, JPG, PNG, TIFF, BMP or PSD files to PDFs",@"1 file",@"✓",@"✓",@"✓"],
  840. @[@"Create PDFs from a scanner and iOS devices",@"X",@"✓",@"✓",@"✓"],
  841. @"Annotations",
  842. @[@"Customize PDF stamps",@"X",@"✓",@"✓",@"✓",@"✓"],
  843. @[@"Hyperlink",@"Page Number",@"Page Number, URL, Email",@"Page Number, URL, Email",@"Page Number, URL, Email"],
  844. @[@"Signature",@"Standard",@"Advanced",@"Advanced",@"Advanced"],
  845. @[@"Table",@"X",@"✓",@"✓",@"✓",@"✓"],
  846. @"View PDF",
  847. @[@"Multi-tab viewer",@"X",@"✓",@"✓",@"✓"],
  848. @[@"Various printing types: poster, booklet, multi-page printing",@"X",@"✓",@"✓",@"✓"],
  849. @[@"Customize theme colors: Light Mode, Dark Mode, Sepia Mode and more",@"X",@"✓",@"✓",@"✓"],
  850. @[@"Split View to compare files",@"X",@"✓",@"✓",@"✓"],
  851. @"Subscription Based Solution",
  852. @[@"Access all premium features in app",@"X",@"6 months",@"∞",@"∞"],
  853. @[@"Priority customer support",@"X",@"✓",@"✓",@"✓"],
  854. @[@"Ad-free",@"X",@"✓",@"✓",@"✓"],
  855. @{}
  856. ];
  857. }
  858. [self.tableView reloadData];
  859. }
  860. - (void)addWaingView:(NSView *)view {
  861. [self removeWaitingView:view];
  862. WaitingView *wView = [[WaitingView alloc] initWithFrame:view.bounds];
  863. [wView setAutoresizingMask:NSViewWidthSizable|NSViewHeightSizable];
  864. [view addSubview:wView];
  865. [wView startAnimation];
  866. }
  867. - (void)removeWaitingView:(NSView *)view {
  868. for (id v in view.subviews) {
  869. if ([[v class] isSubclassOfClass:[WaitingView class]]) {
  870. [v removeFromSuperview];
  871. break;
  872. }
  873. }
  874. }
  875. - (void)updateViewColor {
  876. self.box.fillColor = [KMAppearance KMColor_Layout_L1];
  877. self.labelbox.fillColor = [NSColor clearColor];
  878. self.tableView.backgroundColor = [KMAppearance KMColor_Layout_L0];
  879. self.textView.backgroundColor = [NSColor clearColor];
  880. self.textView.textColor = [[NSColor whiteColor] colorWithAlphaComponent:0.5];
  881. self.value1PurchaseSubLabel.textColor = self.value2PurchaseSubLabel.textColor = self.value3PurchaseSubLabel.textColor = [KMAppearance KMColor_Layout_W0];
  882. }
  883. - (BOOL)isCancelAutoRenew {
  884. return [[IAPProductsManager defaultManager] isCancelAutoRenew];
  885. }
  886. - (BOOL)isShowSale {
  887. if (@available(macOS 10.14.4, *)) {
  888. if ([self isCancelAutoRenew]) {
  889. BOOL isSubscribed = [IAPProductsManager defaultManager].allAccessPackNew6months_lite.isSubscribed;
  890. if (isSubscribed) {
  891. return false;
  892. }
  893. isSubscribed = [IAPProductsManager defaultManager].allAccessPack12months_lite.isSubscribed;
  894. if (isSubscribed) {
  895. return false;
  896. }
  897. KMAdvertisementItemInfo *info = KMAdvertisementManager.manager.info.StoreUserRecovery.content.firstObject;
  898. if ([info.show boolValue] == false) { // 活动结束
  899. return false;
  900. }
  901. return true;
  902. }
  903. }
  904. return false;
  905. }
  906. - (void)showDiscount {
  907. [self.discountYearly setHidden:YES];
  908. [self.discountPermanent setHidden:YES];
  909. [self.discountPremium setHidden:YES];
  910. if (KMAdvertisementManager.manager.info.StoreUserRecovery.content.count > 0) {
  911. for (int i = 0; i < KMAdvertisementManager.manager.info.StoreUserRecovery.content.count; i++) {
  912. if (i == 1) {
  913. KMAdvertisementItemInfo *info = KMAdvertisementManager.manager.info.StoreUserRecovery.content[1];
  914. if ([KMAdvertisementManager checkAdvertisementValid:info]) {
  915. [self.discountYearly setHidden:NO];
  916. NSURL *url = [NSURL URLWithString:[KMAdvertisementModelTransition transitionImagePathWithImage:info.image highlight:NO]];
  917. self.discountYearly.image = [KMAdvertisementImage imageWithURLWithUrl:url completion:^(NSImage * _Nonnull image) {
  918. self.discountYearly.image = image;
  919. }];
  920. } else {
  921. [self.discountYearly setHidden:YES];
  922. }
  923. } else if (i == 2) {
  924. KMAdvertisementItemInfo *info = KMAdvertisementManager.manager.info.StoreUserRecovery.content[2];
  925. if ([KMAdvertisementManager checkAdvertisementValid:info]) {
  926. [self.discountPermanent setHidden:NO];
  927. NSURL *url = [NSURL URLWithString:[KMAdvertisementModelTransition transitionImagePathWithImage:info.image highlight:NO]];
  928. self.discountPermanent.image = [KMAdvertisementImage imageWithURLWithUrl:url completion:^(NSImage * _Nonnull image) {
  929. self.discountPermanent.image = image;
  930. }];
  931. } else {
  932. [self.discountPermanent setHidden:YES];
  933. }
  934. } else if (i == 3) {
  935. KMAdvertisementItemInfo *info = KMAdvertisementManager.manager.info.StoreUserRecovery.content[3];
  936. if ([KMAdvertisementManager checkAdvertisementValid:info]) {
  937. [self.discountPremium setHidden:NO];
  938. NSURL *url = [NSURL URLWithString:[KMAdvertisementModelTransition transitionImagePathWithImage:info.image highlight:NO]];
  939. self.discountPremium.image = [KMAdvertisementImage imageWithURLWithUrl:url completion:^(NSImage * _Nonnull image) {
  940. self.discountPremium.image = image;
  941. }];
  942. } else {
  943. [self.discountPremium setHidden:YES];
  944. }
  945. }
  946. }
  947. }
  948. }
  949. #pragma mark - Button Actions
  950. - (IBAction)buttonItemClicked_Subscribe:(id)sender {
  951. if KMMemberInfo.shared.isLogin && KMMemberInfo.shared.validFlag == "5" {
  952. KMMemberPromptWC.shared.showWindow(nil)
  953. KMMemberPromptWC.shared.tipType = .signouting
  954. } else {
  955. if (self.isPurchaseSwitch) {
  956. [[IAPProductsManager defaultManager] makeSubProduct:[IAPProductsManager defaultManager].allAccessPack12months_lite discount:[self isCancelAutoRenew]];
  957. } else {
  958. [[IAPProductsManager defaultManager] makeSubProduct:[IAPProductsManager defaultManager].allAccessPackNew6months_lite discount:[self isCancelAutoRenew]];
  959. }
  960. [self addWaingView:self.window.contentView];
  961. [[FMTrackEventManager defaultManager] trackEventWithEvent:@"PUW" withProperties:@{@"PUW_Btn":@"PUW_Btn_Upgrade_6Mon"}];
  962. if ([self isShowSale]) {
  963. self.kEventTag = 1;
  964. if (self.isPurchaseSwitch) {
  965. [self trackEvent_freeWithEventName:@"PromotionalOffer" params:@{@"PUW_Btn" : @"PUW_7OffUpgrade_12Mon"} platform:KMAnalyticsPlatformAppCenter];
  966. } else {
  967. [self trackEvent_freeWithEventName:@"PromotionalOffer" params:@{@"PUW_Btn" : @"PUW_7OffUpgrade_6Mon"} platform:KMAnalyticsPlatformAppCenter];
  968. }
  969. }
  970. }
  971. }
  972. - (void)showDiscountToSaveWindow {
  973. if ([KMDiscountToSaveWindowController needShow] == false) {
  974. return;
  975. }
  976. KMAdvertisementItemInfo *info = KMAdvertisementManager.manager.info.StoreUserRecovery.content.firstObject;
  977. NSURL *url = [NSURL URLWithString: [KMAdvertisementModelTransition transitionImagePathWithImage:info.image highlight: YES]];
  978. __weak typeof(self) weakSelf = self;
  979. [self addWaingView:self.window.contentView];
  980. [KMAdvertisementImage imageWithURLWithUrl:url completion:^(NSImage *image) {
  981. [weakSelf removeWaitingView:weakSelf.window.contentView];
  982. if (image == nil) {
  983. return;
  984. }
  985. [self trackEvent_freeWithEventName:@"PromotionalOffer" params:@{@"PUW_Exposure" : @"PUW_PromotionalOffer"} platform:KMAnalyticsPlatformAppCenter];
  986. KMDiscountToSaveWindowController *winC = [[KMDiscountToSaveWindowController alloc] initWithWindowNibName:@"KMDiscountToSaveWindowController"];
  987. weakSelf.discountToSaveWinC = winC;
  988. [weakSelf.window beginSheet:winC.window completionHandler:^(NSModalResponse returnCode) { }];
  989. winC.imgIv.image = image;
  990. winC.itemClick = ^(NSInteger idx) {
  991. [weakSelf.window endSheet:weakSelf.discountToSaveWinC.window];
  992. weakSelf.discountToSaveWinC = nil;
  993. if (idx == 2) { // 订阅
  994. //// NSLog(@"buttonItemClicked_Subscribe");
  995. [weakSelf trackEvent_freeWithEventName:@"PromotionalOffer" params:@{@"PUW_Btn" : @"PUW_PromotionalOffer_Subscribe"} platform:KMAnalyticsPlatformAppCenter];
  996. } else if (idx == 1) {
  997. [weakSelf trackEvent_freeWithEventName:@"PromotionalOffer" params:@{@"PUW_Btn" : @"PUW_PromotionalOffer_Cancel"} platform:KMAnalyticsPlatformAppCenter];
  998. }
  999. };
  1000. }];
  1001. }
  1002. - (IBAction)buttonItemClicked_Restore:(id)sender {
  1003. [[IAPProductsManager defaultManager] restoreSubscriptions];
  1004. [self addWaingView:self.window.contentView];
  1005. }
  1006. - (IBAction)buttonItemClicked_Upgrade:(id)sender {
  1007. [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:@"macappstore://apps.apple.com/app/id825459243?mt=12"]];
  1008. [[FMTrackEventManager defaultManager] trackEventWithEvent:@"PUW" withProperties:@{@"PUW_Btn":@"PUW_Btn_Upgrade_Premium"}];
  1009. }
  1010. - (IBAction)privacyPolicyAction:(NSButton *)sender {
  1011. [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:@"https://www.pdfreaderpro.com/privacy-policy"]];
  1012. }
  1013. - (IBAction)termOfSerAction:(NSButton *)sender {
  1014. [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:@"https://www.pdfreaderpro.com/terms_of_service"]];
  1015. }
  1016. - (IBAction)buttonItemClicked_LicenseUpgrade:(id)sender {
  1017. [[IAPProductsManager defaultManager] makeProduct:[IAPProductsManager defaultManager].allAccessPackPermanent_lite];
  1018. [self addWaingView:self.window.contentView];
  1019. [[FMTrackEventManager defaultManager] trackEventWithEvent:@"PUW" withProperties:@{@"PUW_Btn":@"PUW_Btn_Upgrade_Permanent"}];
  1020. }
  1021. - (IBAction)buttonItemClicked_AboutSubscriptions:(id)sender {
  1022. NSString *tMessage = [NSString stringWithFormat:@"%@\n%@\n\n%@\n%@\n%@\n%@\n%@\n\n%@\n%@\n\n",
  1023. @"Subscription plans: ",
  1024. @"Subscriptions: USD $39.99/(6 months), USD $79.99/(one-time purchase) ",
  1025. @"- Subscriptions will be charged through your iTunes account at the confirmation of purchase. ",
  1026. @"- Your subscriptions will automatically renew unless cancelled at least 24 hours before the end of current subscription period. ",
  1027. @"- Your iTunes account will be charged for renewal within 24-hours prior to the end of the current period, for the same duration and at the current subscription price. ",
  1028. @"- You may manage your subscriptions in your iTunes Account Settings after purchase. ",
  1029. @"- No cancellation of the current subscription is allowed during an active subscription period. ",
  1030. @"- Terms of service: \nhttps://www.pdfreaderpro.com/terms_of_service ",
  1031. @"- Privacy Policy: \nhttps://www.pdfreaderpro.com/privacy-policy "];
  1032. NSAlert *alert = [[NSAlert alloc] init];
  1033. [alert setAlertStyle:NSAlertStyleInformational];
  1034. [alert setMessageText:NSLocalizedString(tMessage, nil)];
  1035. [alert runModal];
  1036. }
  1037. - (IBAction)buttonItemClicked_CloseWindow:(id)sender {
  1038. [self close];
  1039. }
  1040. - (void)switchAction:(NSButton *)sender {
  1041. // NSControlStateValue state = self.switchBtn.state;
  1042. BOOL isSwitch = self.isPurchaseSwitch;
  1043. if (isSwitch) {
  1044. // self.switchBtn.state = NSControlStateValueOff;
  1045. self.isPurchaseSwitch = false;
  1046. // self.switchCircleLeftConst.constant = 4;
  1047. } else {
  1048. // self.switchBtn.state = NSControlStateValueOn;
  1049. self.isPurchaseSwitch = true;
  1050. // self.switchCircleLeftConst.constant = 22;
  1051. }
  1052. // if (self.isPurchaseSwitch) { // 一年
  1053. //
  1054. // } else { // 半年
  1055. //
  1056. // }
  1057. [self reloadDataContent];
  1058. [self reloadData];
  1059. }
  1060. #pragma mark - NSTableViewDataSource Methods
  1061. - (NSInteger)numberOfRowsInTableView:(NSTableView *)aTableView {
  1062. return self.dataSource.count;
  1063. }
  1064. - (id)tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row {
  1065. id object = [self.dataSource objectAtIndex:row];
  1066. if ([object isKindOfClass:[NSString class]]) {
  1067. KMPurchaseCompareHeaderCell *cellView = [tableView makeViewWithIdentifier:KMPurchaseCompareHeaderCellIdentifier owner:self];
  1068. cellView.textField.stringValue = NSLocalizedString(object, nil);
  1069. return cellView;
  1070. } else if ([object isKindOfClass:[NSArray class]]) {
  1071. KMPurchaseCompareCell *cellView = [tableView makeViewWithIdentifier:KMPurchaseCompareCellIdentifier owner:self];
  1072. NSString *value = [(NSArray *)object count] > 0 ? object[0] : @"";
  1073. NSString *value1 = [(NSArray *)object count] > 1 ? object[1] : @"";
  1074. NSString *value2 = [(NSArray *)object count] > 2 ? object[2] : @"";
  1075. NSString *value3 = [(NSArray *)object count] > 3 ? object[3] : @"";
  1076. NSString *value4 = [(NSArray *)object count] > 4 ? object[4] : @"";
  1077. cellView.textField.stringValue = NSLocalizedString(value, nil);
  1078. cellView.lineBox.hidden = NO;
  1079. if (row + 1 == (NSInteger)self.dataSource.count) {
  1080. cellView.lineBox.hidden = YES;
  1081. } else {
  1082. id nextobject = [self.dataSource objectAtIndex:row+1];
  1083. if ([nextobject isKindOfClass:[NSString class]]) {
  1084. cellView.lineBox.hidden = YES;
  1085. }
  1086. }
  1087. if (row + 2 == (NSInteger)self.dataSource.count) {
  1088. cellView.boxBottomConst.constant = 0;
  1089. } else {
  1090. cellView.boxBottomConst.constant = -4;
  1091. }
  1092. if ([value1 isEqualToString:@"X"]) {
  1093. cellView.value1Label.stringValue = @"";
  1094. cellView.value1ImageView.image = [NSImage imageNamed:@"compare_nosupport"];
  1095. } else if ([value1 isEqualToString:@"✓"]) {
  1096. cellView.value1Label.stringValue = @"";
  1097. cellView.value1ImageView.image = [NSImage imageNamed:@"compare_support"];
  1098. } else if ([value1 isEqualToString:@"∞"]) {
  1099. cellView.value1Label.stringValue = @"";
  1100. cellView.value1ImageView.image = [NSImage imageNamed:@"compare_00"];
  1101. } else {
  1102. cellView.value1Label.stringValue = NSLocalizedString(value1, nil);
  1103. cellView.value1ImageView.image = nil;
  1104. }
  1105. if ([value2 isEqualToString:@"X"]) {
  1106. cellView.value2Label.stringValue = @"";
  1107. cellView.value2ImageView.image = [NSImage imageNamed:@"compare_nosupport"];
  1108. } else if ([value2 isEqualToString:@"✓"]) {
  1109. cellView.value2Label.stringValue = @"";
  1110. cellView.value2ImageView.image = [NSImage imageNamed:@"compare_support"];
  1111. } else if ([value2 isEqualToString:@"∞"]) {
  1112. cellView.value2Label.stringValue = @"";
  1113. cellView.value2ImageView.image = [NSImage imageNamed:@"compare_00"];
  1114. } else {
  1115. cellView.value2Label.stringValue = NSLocalizedString(value2, nil);
  1116. cellView.value2ImageView.image = nil;
  1117. }
  1118. if ([value3 isEqualToString:@"X"]) {
  1119. cellView.value3Label.stringValue = @"";
  1120. cellView.value3ImageView.image = [NSImage imageNamed:@"compare_nosupport"];
  1121. } else if ([value3 isEqualToString:@"✓"]) {
  1122. cellView.value3Label.stringValue = @"";
  1123. cellView.value3ImageView.image = [NSImage imageNamed:@"compare_support"];
  1124. } else if ([value3 isEqualToString:@"∞"]) {
  1125. cellView.value3Label.stringValue = @"";
  1126. cellView.value3ImageView.image = [NSImage imageNamed:@"compare_00"];
  1127. } else {
  1128. cellView.value3Label.stringValue = NSLocalizedString(value3, nil);
  1129. cellView.value3ImageView.image = nil;
  1130. }
  1131. if ([value4 isEqualToString:@"X"]) {
  1132. cellView.value4Label.stringValue = @"";
  1133. cellView.value4ImageView.image = [NSImage imageNamed:@"compare_nosupport"];
  1134. } else if ([value4 isEqualToString:@"✓"]) {
  1135. cellView.value4Label.stringValue = @"";
  1136. cellView.value4ImageView.image = [NSImage imageNamed:@"compare_support"];
  1137. } else if ([value4 isEqualToString:@"∞"]) {
  1138. cellView.value4Label.stringValue = @"";
  1139. cellView.value4ImageView.image = [NSImage imageNamed:@"compare_00"];
  1140. } else {
  1141. cellView.value4Label.stringValue = NSLocalizedString(value4, nil);
  1142. cellView.value4ImageView.image = nil;
  1143. }
  1144. return cellView;
  1145. } else if ([object isKindOfClass:[NSDictionary class]]) {
  1146. KMPurchaseCompareEmptyCell *cellView = [tableView makeViewWithIdentifier:KMPurchaseCompareEmptyCellIdentifier owner:self];
  1147. return cellView;
  1148. }
  1149. return nil;
  1150. }
  1151. - (CGFloat)tableView:(NSTableView *)tableView heightOfRow:(NSInteger)row {
  1152. NSTableCellView *cellView = nil;
  1153. id object = [self.dataSource objectAtIndex:row];
  1154. if ([object isKindOfClass:[NSString class]]) {
  1155. cellView = [tableView makeViewWithIdentifier:KMPurchaseCompareHeaderCellIdentifier owner:self];
  1156. cellView.textField.stringValue = NSLocalizedString(object, nil);
  1157. } else if ([object isKindOfClass:[NSArray class]]) {
  1158. cellView = [tableView makeViewWithIdentifier:KMPurchaseCompareCellIdentifier owner:self];
  1159. cellView.textField.stringValue = NSLocalizedString(object[0], nil);
  1160. } else if ([object isKindOfClass:[NSDictionary class]]) {
  1161. return 40;
  1162. }
  1163. if (cellView) {
  1164. [cellView layoutSubtreeIfNeeded];
  1165. return cellView.frame.size.height;
  1166. } else {
  1167. return 0;
  1168. }
  1169. }
  1170. #pragma mark - InAppPurchaseManager Notification
  1171. - (void)IAPProductFailedNotification:(NSNotification*)notification {
  1172. [self removeWaitingView:self.window.contentView];
  1173. }
  1174. - (void)IAPProductPurchasedNotification:(NSNotification*)notification {
  1175. [self removeWaitingView:self.window.contentView];
  1176. [self reloadData];
  1177. if (IAPProductsManager.defaultManager.allAccessPackNew6months_lite.isSubscribed) {
  1178. if (self.kEventTag == 1) {
  1179. [self trackEvent_freeWithEventName:@"PromotionalOffer" params:@{@"PUW_Btn" : @"PUW_7OffUpgrade_6MonthPaid"} platform:KMAnalyticsPlatformAppCenter];
  1180. }
  1181. } else if (IAPProductsManager.defaultManager.allAccessPack12months_lite.isSubscribed) {
  1182. if (self.kEventTag == 1) {
  1183. [self trackEvent_freeWithEventName:@"PromotionalOffer" params:@{@"PUW_Btn" : @"PUW_7OffUpgrade_12MonthPaid"} platform:KMAnalyticsPlatformAppCenter];
  1184. }
  1185. }
  1186. }
  1187. - (void)IAPProductLoadedNotification:(NSNotification*)notification {
  1188. [self reloadData];
  1189. }
  1190. - (void)IAPProductRestoreFinishedNotification:(NSNotification *)notification {
  1191. [self removeWaitingView:self.window.contentView];
  1192. [self reloadData];
  1193. }
  1194. - (void)IAPProductRestoreFailedNotification:(NSNotification *)notification {
  1195. [self removeWaitingView:self.window.contentView];
  1196. }
  1197. - (void)IAPSubscriptionLoadedNotification:(NSNotification *)notification {
  1198. [self removeWaitingView:self.window.contentView];
  1199. [self reloadData];
  1200. }
  1201. @end