KMPurchaseCompareWindowController.m 46 KB

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