KMPurchaseCompareWindowController.m 51 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098
  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 "KMPurchaseCompareDMGWindowController.h"
  11. //#import "WaitingView.h"
  12. //#import "NSButton+TitleColor.h"
  13. //#import "HyperLinkButton.h"
  14. //#import "IAPProductsManager.h"
  15. //#import "GAIManager.h"
  16. //#import "NSImage_SKExtensions.h"
  17. //
  18. //#import "KMButton.h"
  19. //#import "KMCustomButton.h"
  20. //#import "KMKdanRemoteConfig.h"
  21. //#import "VerificationManager.h"
  22. //#import "KMVerificationWindowController.h"
  23. //#import "SKInspectPublicTool.h"
  24. //#import "FMTrackEventManager.h"
  25. //#import "NSFont+Custom.h"
  26. //#if !VERSION_DMG
  27. //#import <StoreKit/StoreKit.h>
  28. //#endif
  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, assign) BOOL isPurchaseSwitch;
  194. @property (assign) IBOutlet NSLayoutConstraint *billedTopConst;
  195. @end
  196. @implementation KMPurchaseCompareWindowController
  197. #pragma mark - Init Methods
  198. - (id)init {
  199. if (self = [super initWithWindowNibName:@"KMPurchaseCompareWindowController"]) {
  200. [[NSNotificationCenter defaultCenter] addObserver:self
  201. selector:@selector(IAPProductLoadedNotification:)
  202. name:KMIAPProductLoadedNotification
  203. object:nil];
  204. [[NSNotificationCenter defaultCenter] addObserver:self
  205. selector:@selector(IAPSubscriptionLoadedNotification:)
  206. name:KMIAPSubscriptionLoadedNotification
  207. object:nil];
  208. [[NSNotificationCenter defaultCenter] addObserver:self
  209. selector:@selector(IAPProductPurchasedNotification:)
  210. name:KMIAPProductPurchasedNotification
  211. object:nil];
  212. [[NSNotificationCenter defaultCenter] addObserver:self
  213. selector:@selector(IAPProductFailedNotification:)
  214. name:KMIAPProductFailedNotification
  215. object:nil];
  216. [[NSNotificationCenter defaultCenter] addObserver:self
  217. selector:@selector(IAPProductRestoreFinishedNotification:)
  218. name:KMIAPProductRestoreFinishedNotification
  219. object:nil];
  220. [[NSNotificationCenter defaultCenter] addObserver:self
  221. selector:@selector(IAPProductRestoreFailedNotification:)
  222. name:KMIAPProductRestoreFailedNotification
  223. object:nil];
  224. [NSDistributedNotificationCenter.defaultCenter addObserver:self selector:@selector(themeChanged:) name:@"AppleInterfaceThemeChangedNotification" object: nil];
  225. self.isPurchaseSwitch = false;
  226. }
  227. return self;
  228. }
  229. - (void)themeChanged:(NSNotification *)notification {
  230. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  231. [self updateViewColor];
  232. });
  233. }
  234. - (void)dealloc {
  235. [[NSNotificationCenter defaultCenter] removeObserver:self];
  236. }
  237. + (NSWindowController *)sharedInstance {
  238. #if VERSION_DMG
  239. if (ActivityStatusNone == [VerificationManager manager].status) {
  240. static KMPurchaseFirstTrialWindowController *singleton = nil;
  241. static dispatch_once_t pred;
  242. dispatch_once(&pred, ^{
  243. singleton = [KMPurchaseCompareWindowController firstTrialWCCheck];
  244. });
  245. return singleton;
  246. } else {
  247. static KMPurchaseCompareDMGWindowController *singleton = nil;
  248. static dispatch_once_t pred;
  249. dispatch_once(&pred, ^{
  250. singleton = [[KMPurchaseCompareDMGWindowController alloc] init];
  251. });
  252. return singleton;
  253. }
  254. #else
  255. static KMPurchaseCompareWindowController *singleton = nil;
  256. static dispatch_once_t pred;
  257. dispatch_once(&pred, ^{
  258. singleton = [[KMPurchaseCompareWindowController alloc] init];
  259. });
  260. return singleton;
  261. #endif
  262. }
  263. + (NSWindowController *)DMGPurchaseInstance {
  264. static KMPurchaseCompareDMGWindowController *singleton = nil;
  265. static dispatch_once_t pred;
  266. dispatch_once(&pred, ^{
  267. singleton = [[KMPurchaseCompareDMGWindowController alloc] init];
  268. });
  269. return singleton;
  270. }
  271. #pragma mark - FirstTrial WC
  272. + (KMPurchaseFirstTrialWindowController *)firstTrialWCCheck {
  273. //弹出 试用弹窗UI优化-新用户试用路径 新UI 情况三 点到付费功能
  274. KMPurchaseFirstTrialWindowController *firstTrialWC = [KMPurchaseFirstTrialWindowController currentFirstTrialWC];
  275. firstTrialWC.buttonActionBlock = ^(KMPurchaseFirstTrialWindowController * _Nonnull ftWC, KMButton * _Nonnull btn, NSString * _Nonnull email, NSString * _Nonnull name) {
  276. if (btn.tag == 10001) {
  277. if (ActivityStatusNone == [VerificationManager manager].status ||
  278. ActivityStatusTrialExpire == [VerificationManager manager].status ) {
  279. [[FMTrackEventManager defaultManager] trackEventWithEvent:@"Tbr" withProperties:@{@"Tbr_Btn":@"Btn_Tbr_SecondTrial"}];
  280. [[VerificationManager manager] trialForDays:7
  281. email:email?:[VerificationManager manager].email
  282. name:name?:[VerificationManager manager].accountName
  283. complention:^(ActivityStatus status, NSDictionary *info, NSError *error) {
  284. if (error ||
  285. status != ActivityStatusTrial) {
  286. NSAlert *alert = [NSAlert alertWithMessageText:NSLocalizedString(@"Activation Error", nil)
  287. defaultButton:NSLocalizedString(@"Try Again", nil)
  288. alternateButton:nil
  289. otherButton:nil
  290. informativeTextWithFormat:NSLocalizedString(@"Failed to sign up for the free trial. Please make sure your internet connection is available and try again later.", nil), nil];
  291. [alert runModal];
  292. } else {
  293. KMVerificationWindowController *vc = [KMVerificationWindowController verificationWithType:KMVerificationTypeRepeatTrialSuccess];
  294. [vc showWindow:nil];
  295. }
  296. }];
  297. [ftWC close];
  298. } else {
  299. [ftWC close];
  300. KMVerificationWindowController *vc = [KMVerificationWindowController verificationWithType:KMVerificationTypeActivate];
  301. vc.callback = ^{
  302. [[KMPurchaseCompareWindowController sharedInstance] showWindow:nil];
  303. };
  304. [vc showWindow:nil];
  305. }
  306. } else if (btn.tag == 10002) {
  307. #if VERSION_DMG
  308. NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@?utm_source=app_dmg&utm_medium=dmg_puw_free_trial", Swift_oc_Tool.Store_Link_OC]];
  309. [[NSWorkspace sharedWorkspace] openURL:url];
  310. [[FMTrackEventManager defaultManager] trackEventWithEvent:@"PUW" withProperties:@{@"PUW_Btn":@"PUW_Btn_UpgradeBuyNow"}];
  311. #endif
  312. } else if (btn.tag == 10003) {
  313. #if VERSION_DMG
  314. KMVerificationWindowController *vc = [KMVerificationWindowController verificationWithType:KMVerificationTypeActivate];//KMVerificationTypeActivate
  315. [vc showWindow:nil];
  316. [ftWC close];
  317. #endif
  318. }
  319. };
  320. return firstTrialWC;
  321. }
  322. #pragma mark - Window Methods
  323. - (void)windowDidLoad {
  324. [super windowDidLoad];
  325. // Implement this method to handle any initialization after your window controller's window has been loaded from its nib file.
  326. self.window.backgroundColor = [KMAppearance KMColor_Upgrade_Vip_BG];
  327. self.window.movableByWindowBackground = YES;
  328. [self updateViewColor];
  329. self.value1InfoBox.fillColor = [NSColor colorWithRed:17/255. green:6/255. blue:143/255. alpha:1];
  330. self.freeInfoLabel.stringValue = NSLocalizedString(@"Free", nil);
  331. self.value1InfoLabel.stringValue = NSLocalizedString(@"6-Month Plan", nil);
  332. self.value2InfoLabel.stringValue = NSLocalizedString(@"Permanent Version", nil);
  333. self.value3InfoLabel.stringValue = NSLocalizedString(@"Premium Version", nil);
  334. self.freeInfoLabel.font = [NSFont UbuntuMediumFontWithSize:18];
  335. self.value1InfoLabel.font = [NSFont UbuntuMediumFontWithSize:16];
  336. self.value2InfoLabel.font = [NSFont UbuntuMediumFontWithSize:16];
  337. self.value3InfoLabel.font = [NSFont UbuntuMediumFontWithSize:16];
  338. self.value1InfoTypeBox.fillColor = [NSColor clearColor];
  339. self.value1InfoTypeBox.borderWidth = 0;
  340. self.sixMouthProLabel.stringValue = NSLocalizedString(@"6-month Plan", @"");
  341. self.sixMouthProLabel.textColor = NSColor.whiteColor;
  342. self.sixMouthProLabel.font = [NSFont UbuntuMediumFontWithSize:14];
  343. self.sixMouthProLabel.lineBreakMode = NSLineBreakByTruncatingTail;
  344. self.sixMouthProLabel.toolTip = self.sixMouthProLabel.stringValue;
  345. self.sixMouthProLabel.alignment = NSTextAlignmentCenter;
  346. // #757780
  347. self.oneYearProLabel.stringValue = NSLocalizedString(@"1-year Plan", @"");
  348. self.oneYearProLabel.textColor = NSColor.whiteColor;
  349. self.oneYearProLabel.font = [NSFont UbuntuMediumFontWithSize:14];
  350. self.oneYearProLabel.lineBreakMode = NSLineBreakByTruncatingTail;
  351. self.oneYearProLabel.toolTip = self.oneYearProLabel.stringValue;
  352. self.oneYearProLabel.alignment = NSTextAlignmentCenter;
  353. self.switchBox.fillColor = [NSColor colorWithWhite:1 alpha:0.2];
  354. self.switchBox.cornerRadius = 12;
  355. self.switchBox.borderWidth = 1;
  356. self.switchBox.borderColor = [NSColor colorWithRed:235/255.0 green:236/255.0 blue:240/255.0 alpha:1.0];
  357. self.switchCircleView.wantsLayer = true;
  358. self.switchCircleView.layer.cornerRadius = 8;
  359. self.switchCircleView.layer.backgroundColor = [NSColor whiteColor].CGColor;
  360. self.switchBtn.title = @"";
  361. self.switchBtn.target = self;
  362. self.switchBtn.action = @selector(switchAction:);
  363. // self.saleLabel.stringValue = NSLocalizedString(@"30%\nOFF", @"");
  364. // self.saleLabel.textColor = NSColor.whiteColor;
  365. // self.saleLabel.wantsLayer = true;
  366. // self.saleLabel.layer.transform = CATransform3DMakeRotation(M_PI/4, 0, 1, 0);
  367. // self.saleLabel.layer.transform.m34 = 1/500.0;
  368. // self.saleLabel.layer.affineTransform = CGAffineTransformMakeRotation(M_PI/2);
  369. // self.saleLabel.superview.wantsLayer = true;
  370. // self.saleLabel.superview.layer.transform = CATransform3DMakeRotation(M_PI/4, 0, 0, 1);
  371. self.saleLabel.hidden = true;
  372. self.saleLabel.superview.hidden = true;
  373. self.saleBox.borderWidth = 0;
  374. self.value1PurchaseButton.wantsLayer = YES;
  375. self.value1PurchaseButton.layer.backgroundColor = [NSColor colorWithRed:1 green:94/255. blue:44/255. alpha:1].CGColor;
  376. self.value1PurchaseButton.layer.cornerRadius = CGRectGetHeight(self.value1PurchaseButton.frame) / 2.;
  377. self.value1PurchaseBtnLblBtn.wantsLayer = YES;
  378. self.value1PurchaseButton.mouseMoveCallback = ^(BOOL mouseEntered) {
  379. if (self.value1PurchaseBtnLblBtn.enabled) {
  380. if (mouseEntered) {
  381. self.value1PurchaseBtnLblBtn.layer.backgroundColor = [[NSColor blackColor] colorWithAlphaComponent:0.15].CGColor;
  382. } else {
  383. self.value1PurchaseBtnLblBtn.layer.backgroundColor = [NSColor clearColor].CGColor;
  384. }
  385. }
  386. };
  387. self.value1PurchaseBtnLblBtn.layer.cornerRadius = CGRectGetHeight(self.value1PurchaseBtnLblBtn.frame)/2.;
  388. self.value1PurchaseBtnLblBtn.layer.masksToBounds = YES;
  389. self.value2PurchaseButton.wantsLayer = YES;
  390. self.value2PurchaseButton.layer.cornerRadius = CGRectGetHeight(self.value2PurchaseButton.frame) / 2.;
  391. self.value2PurchaseButton.layer.backgroundColor = [NSColor whiteColor].CGColor;
  392. self.value2PurchaseLbl.stringValue = NSLocalizedString(@"Purchase", nil);
  393. self.value2PurchaseLbl.textColor = [NSColor colorWithRed:85/255. green:40/255.0 blue:255.0/255.0 alpha:1.0];
  394. self.value3PurchaseButton.title = NSLocalizedString(@"", nil);
  395. self.value3PurchaseBtnLbl.stringValue = NSLocalizedString(@"Purchase", nil);
  396. self.value3PurchaseButton.wantsLayer = YES;
  397. [self.value3PurchaseButton setTitleColor:[NSColor colorWithRed:85/255. green:40/255.0 blue:255.0/255.0 alpha:1.0]];
  398. self.value3PurchaseBtnLbl.textColor = [NSColor colorWithRed:85/255. green:40/255.0 blue:255.0/255.0 alpha:1.0];
  399. self.value3PurchaseButton.layer.backgroundColor = [NSColor whiteColor].CGColor;
  400. self.value3PurchaseButton.layer.cornerRadius = CGRectGetHeight(self.value3PurchaseButton.frame) / 2.;
  401. self.titleLabel.stringValue = NSLocalizedString(@"Subscribe to All Access Pack to enjoy more expanded features.", nil);
  402. self.switchLabel.stringValue = NSLocalizedString(@"Choose your favorite payment and enjoy flexible upgrades.", nil);
  403. self.switchLabel.textColor = [KMAppearance KMColor_Interactive_M0];
  404. self.switchButton.title = [NSString stringWithFormat:@"%@",NSLocalizedString(@"Pricing and Plans", nil)];
  405. self.box.wantsLayer = YES;
  406. self.box.shadow = [[NSShadow alloc] init];
  407. self.box.layer.shadowOpacity = 0.3;
  408. self.box.layer.shadowColor = [NSColor colorWithRed:0 green:0 blue:0 alpha:0.3].CGColor;
  409. self.box.layer.shadowOffset = NSMakeSize(0,3);
  410. self.box.layer.shadowRadius = 8;
  411. self.box.layer.masksToBounds = NO;
  412. NSButtonCell *cell = self.switchButton.cell;
  413. NSColor *txtColor = [NSColor colorWithRed:102.0/255.0 green:102.0/255.0 blue:102.0/255.0 alpha:1.0];
  414. NSAttributedString *attrStr1 = [cell attributedTitle];
  415. NSMutableAttributedString *myAttr = [[NSMutableAttributedString alloc] initWithAttributedString:attrStr1];
  416. [myAttr addAttribute:NSForegroundColorAttributeName value:txtColor range:NSMakeRange(0, myAttr.length)];
  417. [myAttr addAttribute:NSFontAttributeName value:[NSFont boldSystemFontOfSize:13.0] range:NSMakeRange(0, myAttr.length)];
  418. [cell setAttributedTitle:myAttr];
  419. [self.switchButton updateCell:cell];
  420. self.aboutButton.title = NSLocalizedString(@"About Subscriptions", nil);
  421. self.btnRestore.title = NSLocalizedString(@"Restore", nil);
  422. self.privacyPolicyBtn.title = NSLocalizedString(@"Privacy Policy", nil);
  423. self.termOfSerBtn.title = NSLocalizedString(@"Terms of Service", nil);
  424. self.btnRestore.toolTip = NSLocalizedString(@"Restore", nil);
  425. self.privacyPolicyBtn.toolTip = NSLocalizedString(@"Privacy Policy", nil);
  426. self.termOfSerBtn.toolTip = NSLocalizedString(@"Terms of Service", nil);
  427. [self.aboutButton setTitleColor:[NSColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:0.7]];
  428. [self.btnRestore setTitleColor:[NSColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:1]];
  429. [self.privacyPolicyBtn setTitleColor:[NSColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:1]];
  430. [self.termOfSerBtn setTitleColor:[NSColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:1]];
  431. self.btnRestore.mouseMoveCallback = ^(BOOL mouseEntered) {
  432. if (mouseEntered) {
  433. [self.btnRestore setTitleColor:[NSColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:0.7]];
  434. } else {
  435. [self.btnRestore setTitleColor:[NSColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:1]];
  436. }
  437. };
  438. self.privacyPolicyBtn.mouseMoveCallback = ^(BOOL mouseEntered) {
  439. if (mouseEntered) {
  440. [self.privacyPolicyBtn setTitleColor:[NSColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:0.7]];
  441. } else {
  442. [self.privacyPolicyBtn setTitleColor:[NSColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:1]];
  443. }
  444. };
  445. self.termOfSerBtn.mouseMoveCallback = ^(BOOL mouseEntered) {
  446. if (mouseEntered) {
  447. [self.termOfSerBtn setTitleColor:[NSColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:0.7]];
  448. } else {
  449. [self.termOfSerBtn setTitleColor:[NSColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:1]];
  450. }
  451. };
  452. self.aboutButton.hidden = YES;
  453. [self reloadData];
  454. [self reloadDataContent];
  455. [[IAPProductsManager defaultManager] loadProducts];
  456. __block typeof(self) blockSelf = self;
  457. self.value2PurchaseButton.mouseMoveCallback = ^(BOOL mouseEntered) {
  458. if (blockSelf.value2PurchaseButton.enabled) {
  459. if (mouseEntered) {
  460. [blockSelf.value2PurchaseLbl setTextColor:[NSColor whiteColor]];
  461. blockSelf.value2PurchaseButton.layer.backgroundColor = [NSColor colorWithRed:1 green:94/255.0 blue:44/255.0 alpha:1.0].CGColor;
  462. } else {
  463. [blockSelf.value2PurchaseLbl setTextColor:[NSColor colorWithRed:85/255. green:40/255.0 blue:255.0/255.0 alpha:1.0]];
  464. blockSelf.value2PurchaseButton.layer.backgroundColor = [NSColor whiteColor].CGColor;
  465. }
  466. }
  467. };
  468. self.value3PurchaseButton.mouseMoveCallback = ^(BOOL mouseEntered) {
  469. if (mouseEntered) {
  470. // [blockSelf.value3PurchaseButton setTitleColor:[NSColor whiteColor]];
  471. blockSelf.value3PurchaseBtnLbl.textColor = [NSColor whiteColor];
  472. blockSelf.value3PurchaseButton.layer.backgroundColor = [NSColor colorWithRed:1 green:94/255.0 blue:44/255.0 alpha:1.0].CGColor;
  473. } else {
  474. // [blockSelf.value3PurchaseButton setTitleColor:[NSColor colorWithRed:85/255. green:40/255.0 blue:255.0/255.0 alpha:1.0]];
  475. blockSelf.value3PurchaseBtnLbl.textColor = [NSColor colorWithRed:85/255. green:40/255.0 blue:255.0/255.0 alpha:1.0];
  476. blockSelf.value3PurchaseButton.layer.backgroundColor = [NSColor whiteColor].CGColor;
  477. }
  478. };
  479. self.textView.string = NSLocalizedString(@"Subscription plans:\nSubscriptions: USD $39.99/(6 months), USD $79.99/(one-time purchase)\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", nil);
  480. }
  481. - (BOOL)windowShouldClose:(id)sender {
  482. [[FMTrackEventManager defaultManager] trackEventWithEvent:@"PUW" withProperties:@{@"PUW_Btn":@"PUW_Btn_Upgrade_Cancel"}];
  483. [self endModal:sender];
  484. return YES;
  485. }
  486. - (void)close {
  487. [super close];
  488. [self endModal:nil];
  489. }
  490. - (IBAction)startModal:(id)sender {
  491. [NSApp stopModal];
  492. NSInteger modalCode;
  493. self.modalSession = [NSApp beginModalSessionForWindow:self.window];
  494. do {
  495. modalCode = [NSApp runModalSession:self.modalSession];
  496. } while (modalCode == NSModalResponseContinue);
  497. }
  498. - (IBAction)endModal:(id)sender {
  499. if (self.modalSession) {
  500. [NSApp stopModal];
  501. [NSApp endModalSession:self.modalSession];
  502. [self.window orderOut:self];
  503. self.modalSession = nil;
  504. }
  505. }
  506. - (void)showWindowRestore:(id)sender {
  507. [self showWindow:sender];
  508. [self buttonItemClicked_Restore:nil];
  509. }
  510. - (void)showWindow:(id)sender {
  511. [super showWindow:sender];
  512. [self reloadData];
  513. }
  514. #pragma mark - Private Methods
  515. - (void)reloadData {
  516. if (self.isPurchaseSwitch) {
  517. self.sixMouthProLabel.textColor = [NSColor colorWithRed:117/255.0 green:119/255.0 blue:128/255.0 alpha:1.0];
  518. self.oneYearProLabel.textColor = NSColor.whiteColor;
  519. self.switchCircleLeftConst.constant = 22;
  520. self.value1InfoLabel.stringValue = NSLocalizedString(@"1-year Plan", nil);
  521. } else {
  522. self.sixMouthProLabel.textColor = NSColor.whiteColor;
  523. self.oneYearProLabel.textColor = [NSColor colorWithRed:117/255.0 green:119/255.0 blue:128/255.0 alpha:1.0];
  524. self.switchCircleLeftConst.constant = 4;
  525. self.value1InfoLabel.stringValue = NSLocalizedString(@"6-month Plan", nil);
  526. }
  527. self.saleBox.hidden = true;
  528. self.saleIv.hidden = true;
  529. // if ([self isShowSale]) {
  530. // KMRecommondInfo *recoveryInfo = KMRecommondManager.manager.userRecoveryRecommond.recommondInfoArrM.firstObject;
  531. // NSImage *image = recoveryInfo.saleImage;
  532. // self.saleIv.image = image;
  533. // self.saleBox.hidden = false;
  534. // self.saleIv.hidden = false;
  535. // } else {
  536. // self.saleBox.hidden = true;
  537. // }
  538. if ([IAPProductsManager defaultManager].isAvailableAllFunction) {
  539. self.value1PurchaseButton.enabled = NO;
  540. self.value2PurchaseButton.enabled = NO;
  541. self.value2PurchaseLbl.textColor = [NSColor colorWithRed:85/255. green:40/255.0 blue:255.0/255.0 alpha:0.5];
  542. } else {
  543. self.value1PurchaseButton.enabled = YES;
  544. self.value2PurchaseButton.enabled = YES;
  545. self.value2PurchaseLbl.textColor = [NSColor colorWithRed:85/255. green:40/255.0 blue:255.0/255.0 alpha:1.0];
  546. }
  547. self.value1PurchaseBtnLblBtn.enabled = self.value1PurchaseButton.enabled;
  548. self.value1PurchaseBtnLbl.stringValue = NSLocalizedString(@"Subscribe", nil);
  549. if ([IAPProductsManager defaultManager].newlyMonthProduct.isTrialPeriod) {
  550. self.value1PurchaseBtnLbl.stringValue = NSLocalizedString(@"Subscribe", nil);
  551. if ([IAPProductsManager defaultManager].newlyMonthProduct.isSubscribed) {
  552. self.value1PurchaseBtnLbl.stringValue = NSLocalizedString(@"Subscribed", nil);
  553. }
  554. } else {
  555. if ([IAPProductsManager defaultManager].newlyMonthProduct.isSubscribed) {
  556. self.value1PurchaseBtnLbl.stringValue = NSLocalizedString(@"Subscribed", nil);
  557. } else {
  558. self.value1PurchaseBtnLbl.stringValue = NSLocalizedString(@"Free Trial", nil);
  559. if (@available(macOS 10.13.2, *)) {
  560. #if !VERSION_DMG
  561. if (![IAPProductsManager defaultManager].newlyMonthProduct.product.introductoryPrice) {
  562. self.value1PurchaseBtnLbl.stringValue = NSLocalizedString(@"Subscribe", nil);
  563. }
  564. #endif
  565. }
  566. }
  567. }
  568. if (self.value1PurchaseBtnLblBtn.enabled) {
  569. [self.value1PurchaseBtnLbl setTextColor:[NSColor whiteColor]];
  570. } else {
  571. [self.value1PurchaseBtnLbl setTextColor:[[NSColor whiteColor] colorWithAlphaComponent:0.5]];
  572. }
  573. self.value2PurchaseLblBtn.enabled = self.value2PurchaseButton.enabled;
  574. NSString *averageMonthPrice = nil;
  575. NSString *monthPrice = nil;
  576. NSString *allPrice = nil;
  577. if ([IAPProductsManager defaultManager].newlyMonthProduct.isOffers) {
  578. self.specialView1.hidden = NO;
  579. averageMonthPrice = [IAPProductsManager defaultManager].newlyMonthProduct.offersAveragePrice;
  580. monthPrice = [IAPProductsManager defaultManager].newlyMonthProduct.offersPrice;
  581. self.topButtonOffset.constant = 20;
  582. } else {
  583. self.specialView1.hidden = YES;
  584. averageMonthPrice = [IAPProductsManager defaultManager].newlyMonthProduct.averagePrice;
  585. monthPrice = [IAPProductsManager defaultManager].newlyMonthProduct.price;
  586. self.topButtonOffset.constant = 10;
  587. }
  588. if ([IAPProductsManager defaultManager].allAccessProduct.isOffers) {
  589. self.topButtonOffset.constant = 20;
  590. self.specialView.hidden = NO;
  591. allPrice = [IAPProductsManager defaultManager].allAccessProduct.offersPrice;
  592. } else {
  593. self.topButtonOffset.constant = 10;
  594. self.specialView.hidden = YES;
  595. allPrice = [IAPProductsManager defaultManager].allAccessProduct.price;
  596. }
  597. CGFloat off = 1 -[IAPProductsManager defaultManager].allAccessProduct.offers;
  598. NSString *offString = [NSString stringWithFormat:@"%.f%%",off * 100];
  599. self.specialLabel.stringValue = [NSString stringWithFormat:NSLocalizedString(@"%@ off", @""),offString];
  600. off = 1 -[IAPProductsManager defaultManager].newlyMonthProduct.offers;
  601. offString = [NSString stringWithFormat:@"%.f%%",off * 100];
  602. self.specialLabel1.stringValue = [NSString stringWithFormat:NSLocalizedString(@"%@ off", @""),offString];
  603. NSImage *image = [NSImage imageNamed:@"KMImageNameCompareTagBG"];
  604. self.specialImageView.image = image;
  605. self.specialImageView1.image = image;
  606. if (KMKdanRemoteConfig.remoteConfig.showAPP_AveragePrice) {
  607. self.value1PurchaseLabel.stringValue = [NSString stringWithFormat:@"%@/%@", averageMonthPrice, NSLocalizedString(@"mon", nil)];
  608. } else {
  609. self.value1PurchaseLabel.stringValue = [NSString stringWithFormat:@"%@/%@", monthPrice, NSLocalizedString(@"6mon", nil)];
  610. }
  611. self.value1PurchaseLabel.textColor = [NSColor colorWithRed:1 green:231/255. blue:106/255. alpha:1.];
  612. NSString *tTips = [NSString stringWithFormat:NSLocalizedString(@"Billed every 6 months at %@", nil), monthPrice];
  613. if ([self.value1PurchaseBtnLbl.stringValue isEqualToString:NSLocalizedString(@"Free Trial", nil)]) {
  614. tTips = [NSString stringWithFormat:NSLocalizedString(@"Billed every 6 months at %@ after 7-day trial ends.", nil), monthPrice];
  615. #if !VERSION_DMG
  616. if ([IAPProductsManager defaultManager].newlyMonthProduct.product) {
  617. if (@available(macOS 10.13.2, *)) {
  618. tTips = [NSString stringWithFormat:NSLocalizedString(@"Billed every 6 months at %@ after %@-day trial ends.", nil), monthPrice,@([IAPProductsManager defaultManager].newlyMonthProduct.product.introductoryPrice.subscriptionPeriod.numberOfUnits)];
  619. }
  620. }
  621. #endif
  622. }
  623. if (@available(macOS 10.13.2, *)) {
  624. #if !VERSION_DMG
  625. if (![IAPProductsManager defaultManager].newlyMonthProduct.product.introductoryPrice) {
  626. tTips = [NSString stringWithFormat:NSLocalizedString(@"Billed every 6 months at %@", nil), monthPrice];
  627. }
  628. #endif
  629. }
  630. self.value1PurchaseSubLabel.stringValue = [NSString stringWithFormat:NSLocalizedString(@"%@", nil), tTips];
  631. self.value2PurchaseLabel.stringValue = allPrice?:@"";
  632. self.value2PurchaseLabel.textColor = [NSColor colorWithRed:1 green:231/255. blue:106/255. alpha:1.];
  633. self.value2PurchaseSubLabel.stringValue = NSLocalizedString(@"one-time purchase", nil);
  634. self.value3PurchaseLabel.stringValue = NSLocalizedString(@"USD $59.99", nil);
  635. self.value3PurchaseLabel.textColor = [NSColor colorWithRed:1 green:231/255. blue:106/255. alpha:1.];
  636. self.value3PurchaseSubLabel.stringValue = NSLocalizedString(@"one-time purchase", nil);
  637. self.value1PurchaseBtnLbl.font = [NSFont UbuntuBoldFontWithSize:16];
  638. self.value2PurchaseLbl.font = [NSFont UbuntuBoldFontWithSize:16];
  639. self.value3PurchaseBtnLbl.font = [NSFont UbuntuBoldFontWithSize:16];
  640. self.value1PurchaseLabel.font = [NSFont UbuntuBoldFontWithSize:22];
  641. self.value2PurchaseLabel.font = [NSFont UbuntuBoldFontWithSize:22];
  642. self.value3PurchaseLabel.font = [NSFont UbuntuBoldFontWithSize:22];
  643. }
  644. - (void)reloadDataContent {
  645. self.dataSource = @[@"PDF to Office",
  646. @[@"Convert PDFs to Word, HTML, TXT, JPEG or PNG files",@"Only first 10 pages",@"Advanced",@"Advanced",@"Standard"],
  647. @[@"Turn PDF to PPT, Excel, RTF, CSV, and more",@"Only first 10 pages",@"✓",@"✓",@"Only first 10 pages"],
  648. @[@"Convert PDF to TIFF, BMP, GIF or TGA files",@"Only first 10 pages",@"✓",@"✓",@"Only first 10 pages"],
  649. @"Edit PDF",
  650. @[@"Add and edit text in PDF",@"X",@"✓",@"✓",@"✓"],
  651. @[@"Edit, crop, replace image in PDF",@"X",@"✓",@"✓",@"✓"],
  652. @"OCR",
  653. @[@"Extract texts from image-based or scanned PDF",@"X",@"✓",@"✓",@"✓"],
  654. @"Organize Pages",
  655. @[@"Extract, rotate, rearrange, replace, add, delete pages",@"X",@"✓",@"✓",@"✓"],
  656. @[@"Split PDFs into multiple files",@"X",@"✓",@"✓",@"✓"],
  657. @"Advanced Editing Tools",
  658. @[@"Merge multiple documents into a new PDF",@"Up to 2 files or 20 MB",@"✓",@"∞",@"∞"],
  659. @[@"Add & edit watermark",@"X",@"✓",@"✓",@"✓"],
  660. @[@"Add header, footer, page numbers",@"X",@"✓",@"✓",@"✓"],
  661. @[@"Add Bates Number",@"X",@"✓",@"✓",@"✓"],
  662. @[@"Insert PDF page background by color or image",@"X",@"✓",@"✓",@"✓"],
  663. @[@"Create fattened copies",@"X",@"✓",@"✓",@"✓"],
  664. @[@"Extract Images",@"X",@"✓",@"✓",@"✓"],
  665. @[@"Extract tables",@"Only first 10 pages",@"✓",@"✓",@"Only first 10 pages"],
  666. @"Fill & Sign",
  667. @[@"Create digital signature",@"X",@"✓",@"✓",@"✓"],
  668. @[@"Create & Edit & Fill Adobe Fillable PDF Forms",@"X",@"✓",@"✓",@"✓"],
  669. @"Security",
  670. @[@"Batch encrypting PDF documents",@"X",@"✓",@"✓",@"✓"],
  671. @[@"PDF Password Remover",@"X",@"✓",@"✓",@"✓"],
  672. @[@"Redact sensitive information",@"X",@"✓",@"✓",@"✓"],
  673. @"Create PDF",
  674. @[@"Convert JPEG, JPG, PNG, TIFF, BMP or PSD files to PDFs",@"1 file",@"✓",@"✓",@"✓"],
  675. @[@"Create PDFs from a scanner and iOS devices",@"X",@"✓",@"✓",@"✓"],
  676. @"Annotations",
  677. @[@"Customize PDF stamps",@"X",@"✓",@"✓",@"✓",@"✓"],
  678. @[@"Hyperlink",@"Page Number",@"Page Number, URL, Email",@"Page Number, URL, Email",@"Page Number, URL, Email"],
  679. @[@"Signature",@"Standard",@"Advanced",@"Advanced",@"Advanced"],
  680. @[@"Table",@"X",@"✓",@"✓",@"✓",@"✓"],
  681. @"View PDF",
  682. @[@"Multi-tab viewer",@"X",@"✓",@"✓",@"✓"],
  683. @[@"Various printing types: poster, booklet, multi-page printing",@"X",@"✓",@"✓",@"✓"],
  684. @[@"Customize theme colors: Light Mode, Dark Mode, Sepia Mode and more",@"X",@"✓",@"✓",@"✓"],
  685. @[@"Split View to compare files",@"X",@"✓",@"✓",@"✓"],
  686. @"Subscription Based Solution",
  687. @[@"Access all premium features in app",@"X",@"6 months",@"∞",@"∞"],
  688. @[@"Priority customer support",@"X",@"✓",@"✓",@"✓"],
  689. @[@"Ad-free",@"X",@"✓",@"✓",@"✓"],
  690. @{}
  691. ];
  692. [self.tableView reloadData];
  693. }
  694. - (void)addWaingView:(NSView *)view {
  695. [self removeWaitingView:view];
  696. WaitingView *wView = [[WaitingView alloc] initWithFrame:view.bounds];
  697. [wView setAutoresizingMask:NSViewWidthSizable|NSViewHeightSizable];
  698. [view addSubview:wView];
  699. [wView startAnimation];
  700. }
  701. - (void)removeWaitingView:(NSView *)view {
  702. for (id v in view.subviews) {
  703. if ([[v class] isSubclassOfClass:[WaitingView class]]) {
  704. [v removeFromSuperview];
  705. break;
  706. }
  707. }
  708. }
  709. - (void)updateViewColor {
  710. self.box.fillColor = [KMAppearance KMColor_Layout_L1];
  711. self.labelbox.fillColor = [NSColor clearColor];
  712. self.tableView.backgroundColor = [KMAppearance KMColor_Layout_L0];
  713. self.textView.backgroundColor = [NSColor clearColor];
  714. self.textView.textColor = [[NSColor whiteColor] colorWithAlphaComponent:0.5];
  715. self.value1PurchaseSubLabel.textColor = self.value2PurchaseSubLabel.textColor = self.value3PurchaseSubLabel.textColor = [KMAppearance KMColor_Layout_W0];
  716. }
  717. #pragma mark - Button Actions
  718. - (IBAction)buttonItemClicked_Subscribe:(id)sender {
  719. [[IAPProductsManager defaultManager] makeProduct:[IAPProductsManager defaultManager].newlyMonthProduct];
  720. [self addWaingView:self.window.contentView];
  721. [[FMTrackEventManager defaultManager] trackEventWithEvent:@"PUW" withProperties:@{@"PUW_Btn":@"PUW_Btn_Upgrade_6Mon"}];
  722. }
  723. - (IBAction)buttonItemClicked_Restore:(id)sender {
  724. [[IAPProductsManager defaultManager] restoreSubscriptions];
  725. [self addWaingView:self.window.contentView];
  726. }
  727. - (IBAction)buttonItemClicked_Upgrade:(id)sender {
  728. [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:@"macappstore://apps.apple.com/app/id825459243?mt=12"]];
  729. [[FMTrackEventManager defaultManager] trackEventWithEvent:@"PUW" withProperties:@{@"PUW_Btn":@"PUW_Btn_Upgrade_Premium"}];
  730. }
  731. - (IBAction)privacyPolicyAction:(NSButton *)sender {
  732. [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:@"https://www.pdfreaderpro.com/privacy-policy"]];
  733. }
  734. - (IBAction)termOfSerAction:(NSButton *)sender {
  735. [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:@"https://www.pdfreaderpro.com/terms_of_service"]];
  736. }
  737. - (IBAction)buttonItemClicked_LicenseUpgrade:(id)sender {
  738. [[IAPProductsManager defaultManager] makeProduct:[IAPProductsManager defaultManager].allAccessProduct];
  739. [self addWaingView:self.window.contentView];
  740. [[FMTrackEventManager defaultManager] trackEventWithEvent:@"PUW" withProperties:@{@"PUW_Btn":@"PUW_Btn_Upgrade_Permanent"}];
  741. }
  742. - (IBAction)buttonItemClicked_AboutSubscriptions:(id)sender {
  743. NSString *tMessage = [NSString stringWithFormat:@"%@\n%@\n\n%@\n%@\n%@\n%@\n%@\n\n%@\n%@\n\n",
  744. @"Subscription plans: ",
  745. @"Subscriptions: USD $39.99/(6 months), USD $79.99/(one-time purchase) ",
  746. @"- Subscriptions will be charged through your iTunes account at the confirmation of purchase. ",
  747. @"- Your subscriptions will automatically renew unless cancelled at least 24 hours before the end of current subscription period. ",
  748. @"- 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. ",
  749. @"- You may manage your subscriptions in your iTunes Account Settings after purchase. ",
  750. @"- No cancellation of the current subscription is allowed during an active subscription period. ",
  751. @"- Terms of service: \nhttps://www.pdfreaderpro.com/terms_of_service ",
  752. @"- Privacy Policy: \nhttps://www.pdfreaderpro.com/privacy-policy "];
  753. NSAlert *alert = [[NSAlert alloc] init];
  754. [alert setAlertStyle:NSAlertStyleInformational];
  755. [alert setMessageText:NSLocalizedString(tMessage, nil)];
  756. [alert runModal];
  757. }
  758. - (IBAction)buttonItemClicked_CloseWindow:(id)sender {
  759. [self close];
  760. }
  761. - (void)switchAction:(NSButton *)sender {
  762. // NSControlStateValue state = self.switchBtn.state;
  763. BOOL isSwitch = self.isPurchaseSwitch;
  764. if (isSwitch) {
  765. // self.switchBtn.state = NSControlStateValueOff;
  766. self.isPurchaseSwitch = false;
  767. // self.switchCircleLeftConst.constant = 4;
  768. } else {
  769. // self.switchBtn.state = NSControlStateValueOn;
  770. self.isPurchaseSwitch = true;
  771. // self.switchCircleLeftConst.constant = 22;
  772. }
  773. // if (self.isPurchaseSwitch) { // 一年
  774. //
  775. // } else { // 半年
  776. //
  777. // }
  778. [self reloadDataContent];
  779. [self reloadData];
  780. }
  781. #pragma mark - NSTableViewDataSource Methods
  782. - (NSInteger)numberOfRowsInTableView:(NSTableView *)aTableView {
  783. return self.dataSource.count;
  784. }
  785. - (id)tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row {
  786. id object = [self.dataSource objectAtIndex:row];
  787. if ([object isKindOfClass:[NSString class]]) {
  788. KMPurchaseCompareHeaderCell *cellView = [tableView makeViewWithIdentifier:KMPurchaseCompareHeaderCellIdentifier owner:self];
  789. cellView.textField.stringValue = NSLocalizedString(object, nil);
  790. return cellView;
  791. } else if ([object isKindOfClass:[NSArray class]]) {
  792. KMPurchaseCompareCell *cellView = [tableView makeViewWithIdentifier:KMPurchaseCompareCellIdentifier owner:self];
  793. NSString *value = [(NSArray *)object count] > 0 ? object[0] : @"";
  794. NSString *value1 = [(NSArray *)object count] > 1 ? object[1] : @"";
  795. NSString *value2 = [(NSArray *)object count] > 2 ? object[2] : @"";
  796. NSString *value3 = [(NSArray *)object count] > 3 ? object[3] : @"";
  797. NSString *value4 = [(NSArray *)object count] > 4 ? object[4] : @"";
  798. cellView.textField.stringValue = NSLocalizedString(value, nil);
  799. cellView.lineBox.hidden = NO;
  800. if (row + 1 == (NSInteger)self.dataSource.count) {
  801. cellView.lineBox.hidden = YES;
  802. } else {
  803. id nextobject = [self.dataSource objectAtIndex:row+1];
  804. if ([nextobject isKindOfClass:[NSString class]]) {
  805. cellView.lineBox.hidden = YES;
  806. }
  807. }
  808. if (row + 2 == (NSInteger)self.dataSource.count) {
  809. cellView.boxBottomConst.constant = 0;
  810. } else {
  811. cellView.boxBottomConst.constant = -4;
  812. }
  813. if ([value1 isEqualToString:@"X"]) {
  814. cellView.value1Label.stringValue = @"";
  815. cellView.value1ImageView.image = [NSImage imageNamed:@"compare_nosupport"];
  816. } else if ([value1 isEqualToString:@"✓"]) {
  817. cellView.value1Label.stringValue = @"";
  818. cellView.value1ImageView.image = [NSImage imageNamed:@"compare_support"];
  819. } else if ([value1 isEqualToString:@"∞"]) {
  820. cellView.value1Label.stringValue = @"";
  821. cellView.value1ImageView.image = [NSImage imageNamed:@"compare_00"];
  822. } else {
  823. cellView.value1Label.stringValue = NSLocalizedString(value1, nil);
  824. cellView.value1ImageView.image = nil;
  825. }
  826. if ([value2 isEqualToString:@"X"]) {
  827. cellView.value2Label.stringValue = @"";
  828. cellView.value2ImageView.image = [NSImage imageNamed:@"compare_nosupport"];
  829. } else if ([value2 isEqualToString:@"✓"]) {
  830. cellView.value2Label.stringValue = @"";
  831. cellView.value2ImageView.image = [NSImage imageNamed:@"compare_support"];
  832. } else if ([value2 isEqualToString:@"∞"]) {
  833. cellView.value2Label.stringValue = @"";
  834. cellView.value2ImageView.image = [NSImage imageNamed:@"compare_00"];
  835. } else {
  836. cellView.value2Label.stringValue = NSLocalizedString(value2, nil);
  837. cellView.value2ImageView.image = nil;
  838. }
  839. if ([value3 isEqualToString:@"X"]) {
  840. cellView.value3Label.stringValue = @"";
  841. cellView.value3ImageView.image = [NSImage imageNamed:@"compare_nosupport"];
  842. } else if ([value3 isEqualToString:@"✓"]) {
  843. cellView.value3Label.stringValue = @"";
  844. cellView.value3ImageView.image = [NSImage imageNamed:@"compare_support"];
  845. } else if ([value3 isEqualToString:@"∞"]) {
  846. cellView.value3Label.stringValue = @"";
  847. cellView.value3ImageView.image = [NSImage imageNamed:@"compare_00"];
  848. } else {
  849. cellView.value3Label.stringValue = NSLocalizedString(value3, nil);
  850. cellView.value3ImageView.image = nil;
  851. }
  852. if ([value4 isEqualToString:@"X"]) {
  853. cellView.value4Label.stringValue = @"";
  854. cellView.value4ImageView.image = [NSImage imageNamed:@"compare_nosupport"];
  855. } else if ([value4 isEqualToString:@"✓"]) {
  856. cellView.value4Label.stringValue = @"";
  857. cellView.value4ImageView.image = [NSImage imageNamed:@"compare_support"];
  858. } else if ([value4 isEqualToString:@"∞"]) {
  859. cellView.value4Label.stringValue = @"";
  860. cellView.value4ImageView.image = [NSImage imageNamed:@"compare_00"];
  861. } else {
  862. cellView.value4Label.stringValue = NSLocalizedString(value4, nil);
  863. cellView.value4ImageView.image = nil;
  864. }
  865. return cellView;
  866. } else if ([object isKindOfClass:[NSDictionary class]]) {
  867. KMPurchaseCompareEmptyCell *cellView = [tableView makeViewWithIdentifier:KMPurchaseCompareEmptyCellIdentifier owner:self];
  868. return cellView;
  869. }
  870. return nil;
  871. }
  872. - (CGFloat)tableView:(NSTableView *)tableView heightOfRow:(NSInteger)row {
  873. NSTableCellView *cellView = nil;
  874. id object = [self.dataSource objectAtIndex:row];
  875. if ([object isKindOfClass:[NSString class]]) {
  876. cellView = [tableView makeViewWithIdentifier:KMPurchaseCompareHeaderCellIdentifier owner:self];
  877. cellView.textField.stringValue = NSLocalizedString(object, nil);
  878. } else if ([object isKindOfClass:[NSArray class]]) {
  879. cellView = [tableView makeViewWithIdentifier:KMPurchaseCompareCellIdentifier owner:self];
  880. cellView.textField.stringValue = NSLocalizedString(object[0], nil);
  881. } else if ([object isKindOfClass:[NSDictionary class]]) {
  882. return 40;
  883. }
  884. if (cellView) {
  885. [cellView layoutSubtreeIfNeeded];
  886. return cellView.frame.size.height;
  887. } else {
  888. return 0;
  889. }
  890. }
  891. #pragma mark - InAppPurchaseManager Notification
  892. - (void)IAPProductFailedNotification:(NSNotification*)notification {
  893. [self removeWaitingView:self.window.contentView];
  894. }
  895. - (void)IAPProductPurchasedNotification:(NSNotification*)notification {
  896. [self removeWaitingView:self.window.contentView];
  897. [self reloadData];
  898. }
  899. - (void)IAPProductLoadedNotification:(NSNotification*)notification {
  900. [self reloadData];
  901. }
  902. - (void)IAPProductRestoreFinishedNotification:(NSNotification *)notification {
  903. [self removeWaitingView:self.window.contentView];
  904. [self reloadData];
  905. }
  906. - (void)IAPProductRestoreFailedNotification:(NSNotification *)notification {
  907. [self removeWaitingView:self.window.contentView];
  908. }
  909. - (void)IAPSubscriptionLoadedNotification:(NSNotification *)notification {
  910. [self removeWaitingView:self.window.contentView];
  911. [self reloadData];
  912. }
  913. @end