KMPurchaseCompareWindowController.m 66 KB

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