KMPurchaseCompareWindowController.m 46 KB

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