KMPurchaseCompareWindowController.m 45 KB

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