KMPurchaseCompareWindowController.m 45 KB

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