KMPurchaseCompareWindowController.m 45 KB

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