KMPurchaseCompareWindowController.m 64 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318
  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. #import "KMDiscountToSaveWindowController.h"
  30. static NSString *const KMPurchaseCompareEmptyCellIdentifier = @"KMPurchaseCompareEmptyCellIdentifier";
  31. static NSString *const KMPurchaseCompareHeaderCellIdentifier = @"KMPurchaseCompareHeaderCell";
  32. static NSString *const KMPurchaseCompareCellIdentifier = @"KMPurchaseCompareCell";
  33. #pragma mark - KMPurchaseCompareEmptyCell
  34. @interface KMPurchaseCompareEmptyCell : NSTableCellView
  35. @end
  36. @implementation KMPurchaseCompareEmptyCell
  37. - (void)dealloc {
  38. [NSDistributedNotificationCenter.defaultCenter removeObserver:self];
  39. }
  40. - (void)awakeFromNib {
  41. [super awakeFromNib];
  42. self.wantsLayer = YES;
  43. [self updateViewColor];
  44. [NSDistributedNotificationCenter.defaultCenter addObserver:self selector:@selector(themeChanged:) name:@"AppleInterfaceThemeChangedNotification" object: nil];
  45. }
  46. - (void)themeChanged:(NSNotification *)notification {
  47. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  48. [self updateViewColor];
  49. });
  50. }
  51. - (void)updateViewColor {
  52. if ([KMAppearance isDarkMode]) {
  53. self.layer.backgroundColor = [NSColor colorWithRed:24/255.0 green:22/255.0 blue:31/255. alpha:1.].CGColor;
  54. } else {
  55. self.layer.backgroundColor = [NSColor colorWithRed:247/255.0 green:245/255.0 blue:1 alpha:1.].CGColor;
  56. }
  57. }
  58. @end
  59. @interface KMPurchaseCompareHeaderCell : NSTableCellView
  60. @property (nonatomic,assign) IBOutlet NSView *contentView;
  61. @end
  62. @implementation KMPurchaseCompareHeaderCell
  63. - (void)dealloc
  64. {
  65. [NSDistributedNotificationCenter.defaultCenter removeObserver:self];
  66. }
  67. - (void)awakeFromNib
  68. {
  69. [super awakeFromNib];
  70. self.contentView.wantsLayer = YES;
  71. [self updateViewColor];
  72. [NSDistributedNotificationCenter.defaultCenter addObserver:self selector:@selector(themeChanged:) name:@"AppleInterfaceThemeChangedNotification" object: nil];
  73. }
  74. - (void)themeChanged:(NSNotification *)notification {
  75. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  76. [self updateViewColor];
  77. });
  78. }
  79. - (void)updateViewColor {
  80. if ([KMAppearance isDarkMode]) {
  81. self.contentView.layer.backgroundColor = [NSColor colorWithRed:40/255. green:38/255. blue:47/255. alpha:1].CGColor;
  82. } else {
  83. self.contentView.layer.backgroundColor = [NSColor colorWithRed:237/255. green:231/255. blue:255/255. alpha:1].CGColor;
  84. }
  85. self.textField.textColor = [KMAppearance KMColor_Layout_H0];
  86. self.textField.font = [NSFont boldSystemFontOfSize:14.0];
  87. }
  88. @end
  89. #pragma mark - KMPurchaseCompareCell
  90. @interface KMPurchaseCompareCell : NSTableCellView
  91. @property (nonatomic,assign) IBOutlet NSView *bgColorView;
  92. @property (nonatomic,assign) IBOutlet NSTextField *value1Label;
  93. @property (nonatomic,assign) IBOutlet NSTextField *value2Label;
  94. @property (nonatomic,assign) IBOutlet NSTextField *value3Label;
  95. @property (nonatomic,assign) IBOutlet NSTextField *value4Label;
  96. @property (nonatomic,assign) IBOutlet NSImageView *value1ImageView;
  97. @property (nonatomic,assign) IBOutlet NSImageView *value2ImageView;
  98. @property (nonatomic,assign) IBOutlet NSImageView *value3ImageView;
  99. @property (nonatomic,assign) IBOutlet NSImageView *value4ImageView;
  100. @property (nonatomic,assign) IBOutlet NSBox *lineBox;
  101. @property (assign) IBOutlet NSLayoutConstraint *boxBottomConst;
  102. @end
  103. @implementation KMPurchaseCompareCell
  104. - (void)dealloc
  105. {
  106. [NSDistributedNotificationCenter.defaultCenter removeObserver:self];
  107. }
  108. - (void)awakeFromNib
  109. {
  110. [super awakeFromNib];
  111. self.bgColorView.wantsLayer = YES;
  112. [self updateViewColor];
  113. [NSDistributedNotificationCenter.defaultCenter addObserver:self selector:@selector(themeChanged:) name:@"AppleInterfaceThemeChangedNotification" object: nil];
  114. }
  115. - (void)themeChanged:(NSNotification *)notification {
  116. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  117. [self updateViewColor];
  118. });
  119. }
  120. - (void)updateViewColor {
  121. self.bgColorView.layer.backgroundColor = [NSColor colorWithRed:247/255.0 green:245/255.0 blue:1 alpha:1.].CGColor;
  122. NSColor *textColor = [NSColor colorWithRed:68.0/255.0 green:68.0/255.0 blue:68.0/255.0 alpha:1.0];
  123. NSColor *subtextColor = [NSColor colorWithRed:141.0/255.0 green:141.0/255.0 blue:141.0/255.0 alpha:1.0];
  124. NSColor *lineColor = [NSColor colorWithRed:204.0/255.0 green:204.0/255.0 blue:204.0/255.0 alpha:0.4];
  125. if ([KMAppearance isDarkMode]) {
  126. self.bgColorView.layer.backgroundColor = [NSColor colorWithRed:24/255.0 green:22/255.0 blue:31/255. alpha:1.].CGColor;
  127. textColor = [NSColor colorWithRed:255.0/255.0 green:255.0/255.0 blue:255.0/255.0 alpha:0.8];
  128. subtextColor = [NSColor colorWithRed:255.0/255.0 green:255.0/255.0 blue:255.0/255.0 alpha:0.6];
  129. lineColor = [NSColor colorWithRed:0.0/255.0 green:0.0/255.0 blue:0.0/255.0 alpha:0.15];
  130. }
  131. self.value1Label.textColor = subtextColor;
  132. self.value2Label.textColor = self.value3Label.textColor = self.value4Label.textColor = subtextColor;
  133. self.lineBox.fillColor = lineColor;
  134. self.textField.textColor = textColor;
  135. }
  136. @end
  137. #pragma mark - KMPurchaseCompareWindowController
  138. @interface KMPurchaseCompareWindowController ()<NSTableViewDelegate, NSTableViewDataSource>
  139. @property (nonatomic,assign) NSModalSession modalSession;
  140. @property (nonatomic,retain) NSArray *dataSource;
  141. @property (nonatomic,assign) IBOutlet NSTableView *tableView;
  142. @property (nonatomic,assign) IBOutlet NSTextField *titleLabel;
  143. @property (nonatomic,assign) IBOutlet NSTextField *switchLabel;
  144. @property (nonatomic,assign) IBOutlet NSButton *switchButton;
  145. @property (assign) IBOutlet NSView *freeInfoView;
  146. @property (assign) IBOutlet NSTextField *freeInfoLabel;
  147. @property (assign) IBOutlet NSView *value1InfoView;
  148. @property (assign) IBOutlet NSBox *value1InfoBox;
  149. @property (assign) IBOutlet NSBox *value1InfoTypeBox;
  150. @property (assign) IBOutlet NSTextField *sixMouthProLabel;
  151. @property (assign) IBOutlet NSTextField *oneYearProLabel;
  152. @property (assign) IBOutlet NSBox *switchBox;
  153. @property (assign) IBOutlet NSButton *switchBtn;
  154. @property (assign) IBOutlet NSView *switchCircleView;
  155. @property (assign) IBOutlet NSLayoutConstraint *switchCircleLeftConst;
  156. @property (assign) IBOutlet NSBox *saleBox;
  157. @property (assign) IBOutlet NSImageView *saleIv;
  158. @property (assign) IBOutlet NSTextField *saleLabel;
  159. @property (assign) IBOutlet NSTextField *value1InfoLabel;
  160. @property (nonatomic,assign) IBOutlet NSTextField *value1PurchaseLabel;
  161. @property (nonatomic,assign) IBOutlet NSTextField *value1PurchaseSubLabel;
  162. @property (nonatomic,assign) IBOutlet KMCustomButton *value1PurchaseButton;
  163. @property (assign) IBOutlet NSTextField *value1PurchaseBtnLbl;
  164. @property (assign) IBOutlet NSTextField *value1PurchaseOriPriceLbl;
  165. @property (assign) IBOutlet NSButton *value1PurchaseBtnLblBtn;
  166. @property (assign) IBOutlet NSView *value2InfoView;
  167. @property (assign) IBOutlet NSTextField *value2InfoLabel;
  168. @property (nonatomic,assign) IBOutlet NSTextField *value2PurchaseLabel;
  169. @property (nonatomic,assign) IBOutlet NSTextField *value2PurchaseSubLabel;
  170. @property (nonatomic,assign) IBOutlet KMButton *value2PurchaseButton;
  171. @property (assign) IBOutlet NSTextField *value2PurchaseLbl;
  172. @property (assign) IBOutlet KMButton *value2PurchaseLblBtn;
  173. @property (assign) IBOutlet NSView *value3InfoView;
  174. @property (assign) IBOutlet NSTextField *value3InfoLabel;
  175. @property (nonatomic,assign) IBOutlet NSTextField *value3PurchaseLabel;
  176. @property (nonatomic,assign) IBOutlet NSTextField *value3PurchaseSubLabel;
  177. @property (nonatomic,assign) IBOutlet KMButton *value3PurchaseButton;
  178. @property (strong) IBOutlet NSTextField *value3PurchaseBtnLbl;
  179. @property (nonatomic,assign) IBOutlet NSButton *aboutButton;
  180. @property (nonatomic,assign) IBOutlet HyperLinkButton *btnRestore;
  181. @property (assign) IBOutlet HyperLinkButton *privacyPolicyBtn;
  182. @property (assign) IBOutlet HyperLinkButton *termOfSerBtn;
  183. @property (nonatomic,assign) IBOutlet NSTextView *textView;
  184. @property (nonatomic,assign) IBOutlet NSView *specialView;
  185. @property (nonatomic,assign) IBOutlet NSImageView *specialImageView;
  186. @property (nonatomic,assign) IBOutlet NSTextField *specialLabel;
  187. @property (nonatomic,assign) IBOutlet NSView *specialView1;
  188. @property (nonatomic,assign) IBOutlet NSImageView *specialImageView1;
  189. @property (nonatomic,assign) IBOutlet NSTextField *specialLabel1;
  190. @property (nonatomic,assign) IBOutlet NSBox *box;
  191. @property (nonatomic,assign) IBOutlet NSBox *labelbox;
  192. @property (assign) IBOutlet NSLayoutConstraint *topButtonOffset;
  193. @property (nonatomic, retain) CALayer *value1Layer;
  194. @property (nonatomic, retain) KMDiscountToSaveWindowController *discountToSaveWinC;
  195. @property (nonatomic, assign) BOOL isPurchaseSwitch;
  196. @property (assign) IBOutlet NSLayoutConstraint *billedTopConst;
  197. @end
  198. @implementation KMPurchaseCompareWindowController
  199. #pragma mark - Init Methods
  200. - (id)init {
  201. if (self = [super initWithWindowNibName:@"KMPurchaseCompareWindowController"]) {
  202. [[NSNotificationCenter defaultCenter] addObserver:self
  203. selector:@selector(IAPProductLoadedNotification:)
  204. name:KMIAPProductLoadedNotification
  205. object:nil];
  206. [[NSNotificationCenter defaultCenter] addObserver:self
  207. selector:@selector(IAPSubscriptionLoadedNotification:)
  208. name:KMIAPSubscriptionLoadedNotification
  209. object:nil];
  210. [[NSNotificationCenter defaultCenter] addObserver:self
  211. selector:@selector(IAPProductPurchasedNotification:)
  212. name:KMIAPProductPurchasedNotification
  213. object:nil];
  214. [[NSNotificationCenter defaultCenter] addObserver:self
  215. selector:@selector(IAPProductFailedNotification:)
  216. name:KMIAPProductFailedNotification
  217. object:nil];
  218. [[NSNotificationCenter defaultCenter] addObserver:self
  219. selector:@selector(IAPProductRestoreFinishedNotification:)
  220. name:KMIAPProductRestoreFinishedNotification
  221. object:nil];
  222. [[NSNotificationCenter defaultCenter] addObserver:self
  223. selector:@selector(IAPProductRestoreFailedNotification:)
  224. name:KMIAPProductRestoreFailedNotification
  225. object:nil];
  226. [NSDistributedNotificationCenter.defaultCenter addObserver:self selector:@selector(themeChanged:) name:@"AppleInterfaceThemeChangedNotification" object: nil];
  227. self.isPurchaseSwitch = false;
  228. }
  229. return self;
  230. }
  231. - (void)themeChanged:(NSNotification *)notification {
  232. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  233. [self updateViewColor];
  234. });
  235. }
  236. - (void)dealloc {
  237. [[NSNotificationCenter defaultCenter] removeObserver:self];
  238. }
  239. + (NSWindowController *)sharedInstance {
  240. #if VERSION_DMG
  241. if (ActivityStatusNone == [VerificationManager manager].status) {
  242. static KMPurchaseFirstTrialWindowController *singleton = nil;
  243. static dispatch_once_t pred;
  244. dispatch_once(&pred, ^{
  245. singleton = [KMPurchaseCompareWindowController firstTrialWCCheck];
  246. });
  247. return singleton;
  248. } else {
  249. static KMPurchaseCompareDMGWindowController *singleton = nil;
  250. static dispatch_once_t pred;
  251. dispatch_once(&pred, ^{
  252. singleton = [[KMPurchaseCompareDMGWindowController alloc] init];
  253. });
  254. return singleton;
  255. }
  256. #else
  257. static KMPurchaseCompareWindowController *singleton = nil;
  258. static dispatch_once_t pred;
  259. dispatch_once(&pred, ^{
  260. singleton = [[KMPurchaseCompareWindowController alloc] init];
  261. });
  262. return singleton;
  263. #endif
  264. }
  265. + (NSWindowController *)DMGPurchaseInstance {
  266. static KMPurchaseCompareDMGWindowController *singleton = nil;
  267. static dispatch_once_t pred;
  268. dispatch_once(&pred, ^{
  269. singleton = [[KMPurchaseCompareDMGWindowController alloc] init];
  270. });
  271. return singleton;
  272. }
  273. #pragma mark - FirstTrial WC
  274. + (KMPurchaseFirstTrialWindowController *)firstTrialWCCheck {
  275. //弹出 试用弹窗UI优化-新用户试用路径 新UI 情况三 点到付费功能
  276. KMPurchaseFirstTrialWindowController *firstTrialWC = [KMPurchaseFirstTrialWindowController currentFirstTrialWC];
  277. firstTrialWC.buttonActionBlock = ^(KMPurchaseFirstTrialWindowController * _Nonnull ftWC, KMButton * _Nonnull btn, NSString * _Nonnull email, NSString * _Nonnull name) {
  278. if (btn.tag == 10001) {
  279. if (ActivityStatusNone == [VerificationManager manager].status ||
  280. ActivityStatusTrialExpire == [VerificationManager manager].status ) {
  281. [[FMTrackEventManager defaultManager] trackEventWithEvent:@"Tbr" withProperties:@{@"Tbr_Btn":@"Btn_Tbr_SecondTrial"}];
  282. [[VerificationManager manager] trialForDays:7
  283. email:email?:[VerificationManager manager].email
  284. name:name?:[VerificationManager manager].accountName
  285. complention:^(ActivityStatus status, NSDictionary *info, NSError *error) {
  286. if (error ||
  287. status != ActivityStatusTrial) {
  288. NSAlert *alert = [NSAlert alertWithMessageText:NSLocalizedString(@"Activation Error", nil)
  289. defaultButton:NSLocalizedString(@"Try Again", nil)
  290. alternateButton:nil
  291. otherButton:nil
  292. informativeTextWithFormat:NSLocalizedString(@"Failed to sign up for the free trial. Please make sure your internet connection is available and try again later.", nil), nil];
  293. [alert runModal];
  294. } else {
  295. KMVerificationWindowController *vc = [KMVerificationWindowController verificationWithType:KMVerificationTypeRepeatTrialSuccess];
  296. [vc showWindow:nil];
  297. }
  298. }];
  299. [ftWC close];
  300. } else {
  301. [ftWC close];
  302. KMVerificationWindowController *vc = [KMVerificationWindowController verificationWithType:KMVerificationTypeActivate];
  303. vc.callback = ^{
  304. [[KMPurchaseCompareWindowController sharedInstance] showWindow:nil];
  305. };
  306. [vc showWindow:nil];
  307. }
  308. } else if (btn.tag == 10002) {
  309. #if VERSION_DMG
  310. NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@?utm_source=app_dmg&utm_medium=dmg_puw_free_trial", Swift_oc_Tool.Store_Link_OC]];
  311. [[NSWorkspace sharedWorkspace] openURL:url];
  312. [[FMTrackEventManager defaultManager] trackEventWithEvent:@"PUW" withProperties:@{@"PUW_Btn":@"PUW_Btn_UpgradeBuyNow"}];
  313. #endif
  314. } else if (btn.tag == 10003) {
  315. #if VERSION_DMG
  316. KMVerificationWindowController *vc = [KMVerificationWindowController verificationWithType:KMVerificationTypeActivate];//KMVerificationTypeActivate
  317. [vc showWindow:nil];
  318. [ftWC close];
  319. #endif
  320. }
  321. };
  322. return firstTrialWC;
  323. }
  324. #pragma mark - Window Methods
  325. - (void)windowDidLoad {
  326. [super windowDidLoad];
  327. // Implement this method to handle any initialization after your window controller's window has been loaded from its nib file.
  328. self.window.backgroundColor = [KMAppearance KMColor_Upgrade_Vip_BG];
  329. self.window.movableByWindowBackground = YES;
  330. [self updateViewColor];
  331. self.value1InfoBox.fillColor = [NSColor colorWithRed:17/255. green:6/255. blue:143/255. alpha:1];
  332. self.freeInfoLabel.stringValue = NSLocalizedString(@"Free", nil);
  333. self.value1InfoLabel.stringValue = NSLocalizedString(@"6-Month Plan", nil);
  334. self.value2InfoLabel.stringValue = NSLocalizedString(@"Permanent Version", nil);
  335. self.value3InfoLabel.stringValue = NSLocalizedString(@"Premium Version", nil);
  336. self.freeInfoLabel.font = [NSFont UbuntuMediumFontWithSize:18];
  337. self.value1InfoLabel.font = [NSFont UbuntuMediumFontWithSize:16];
  338. self.value2InfoLabel.font = [NSFont UbuntuMediumFontWithSize:16];
  339. self.value3InfoLabel.font = [NSFont UbuntuMediumFontWithSize:16];
  340. self.value1InfoTypeBox.fillColor = [NSColor clearColor];
  341. self.value1InfoTypeBox.borderWidth = 0;
  342. self.sixMouthProLabel.stringValue = NSLocalizedString(@"6-Month Plan", @"");
  343. self.sixMouthProLabel.textColor = NSColor.whiteColor;
  344. self.sixMouthProLabel.font = [NSFont UbuntuMediumFontWithSize:14];
  345. self.sixMouthProLabel.lineBreakMode = NSLineBreakByTruncatingTail;
  346. self.sixMouthProLabel.toolTip = self.sixMouthProLabel.stringValue;
  347. self.sixMouthProLabel.alignment = NSTextAlignmentCenter;
  348. // #757780
  349. self.oneYearProLabel.stringValue = NSLocalizedString(@"1-year Plan", @"");
  350. self.oneYearProLabel.textColor = NSColor.whiteColor;
  351. self.oneYearProLabel.font = [NSFont UbuntuMediumFontWithSize:14];
  352. self.oneYearProLabel.lineBreakMode = NSLineBreakByTruncatingTail;
  353. self.oneYearProLabel.toolTip = self.oneYearProLabel.stringValue;
  354. self.oneYearProLabel.alignment = NSTextAlignmentCenter;
  355. self.switchBox.fillColor = [NSColor colorWithWhite:1 alpha:0.2];
  356. self.switchBox.cornerRadius = 12;
  357. self.switchBox.borderWidth = 1;
  358. self.switchBox.borderColor = [NSColor colorWithRed:235/255.0 green:236/255.0 blue:240/255.0 alpha:1.0];
  359. self.switchCircleView.wantsLayer = true;
  360. self.switchCircleView.layer.cornerRadius = 8;
  361. self.switchCircleView.layer.backgroundColor = [NSColor whiteColor].CGColor;
  362. self.switchBtn.title = @"";
  363. self.switchBtn.target = self;
  364. self.switchBtn.action = @selector(switchAction:);
  365. // self.saleLabel.stringValue = NSLocalizedString(@"30%\nOFF", @"");
  366. // self.saleLabel.textColor = NSColor.whiteColor;
  367. // self.saleLabel.wantsLayer = true;
  368. // self.saleLabel.layer.transform = CATransform3DMakeRotation(M_PI/4, 0, 1, 0);
  369. // self.saleLabel.layer.transform.m34 = 1/500.0;
  370. // self.saleLabel.layer.affineTransform = CGAffineTransformMakeRotation(M_PI/2);
  371. // self.saleLabel.superview.wantsLayer = true;
  372. // self.saleLabel.superview.layer.transform = CATransform3DMakeRotation(M_PI/4, 0, 0, 1);
  373. self.saleLabel.hidden = true;
  374. self.saleLabel.superview.hidden = true;
  375. self.saleBox.borderWidth = 0;
  376. self.value1PurchaseButton.wantsLayer = YES;
  377. self.value1PurchaseButton.layer.backgroundColor = [NSColor colorWithRed:1 green:94/255. blue:44/255. alpha:1].CGColor;
  378. self.value1PurchaseButton.layer.cornerRadius = CGRectGetHeight(self.value1PurchaseButton.frame) / 2.;
  379. self.value1PurchaseBtnLblBtn.wantsLayer = YES;
  380. self.value1PurchaseButton.mouseMoveCallback = ^(BOOL mouseEntered) {
  381. if (self.value1PurchaseBtnLblBtn.enabled) {
  382. if (mouseEntered) {
  383. self.value1PurchaseBtnLblBtn.layer.backgroundColor = [[NSColor blackColor] colorWithAlphaComponent:0.15].CGColor;
  384. } else {
  385. self.value1PurchaseBtnLblBtn.layer.backgroundColor = [NSColor clearColor].CGColor;
  386. }
  387. }
  388. };
  389. self.value1PurchaseBtnLblBtn.layer.cornerRadius = CGRectGetHeight(self.value1PurchaseBtnLblBtn.frame)/2.;
  390. self.value1PurchaseBtnLblBtn.layer.masksToBounds = YES;
  391. self.value2PurchaseButton.wantsLayer = YES;
  392. self.value2PurchaseButton.layer.cornerRadius = CGRectGetHeight(self.value2PurchaseButton.frame) / 2.;
  393. self.value2PurchaseButton.layer.backgroundColor = [NSColor whiteColor].CGColor;
  394. self.value2PurchaseLbl.stringValue = NSLocalizedString(@"Purchase", nil);
  395. self.value2PurchaseLbl.textColor = [NSColor colorWithRed:85/255. green:40/255.0 blue:255.0/255.0 alpha:1.0];
  396. self.value3PurchaseButton.title = NSLocalizedString(@"Purchase", nil);
  397. self.value3PurchaseBtnLbl.stringValue = NSLocalizedString(@"Purchase", nil);
  398. self.value3PurchaseButton.wantsLayer = YES;
  399. [self.value3PurchaseButton setTitleColor:[NSColor colorWithRed:85/255. green:40/255.0 blue:255.0/255.0 alpha:1.0]];
  400. self.value3PurchaseBtnLbl.textColor = [NSColor colorWithRed:85/255. green:40/255.0 blue:255.0/255.0 alpha:1.0];
  401. self.value3PurchaseButton.layer.backgroundColor = [NSColor whiteColor].CGColor;
  402. self.value3PurchaseButton.layer.cornerRadius = CGRectGetHeight(self.value3PurchaseButton.frame) / 2.;
  403. self.titleLabel.stringValue = NSLocalizedString(@"Subscribe to All Access Pack to enjoy more expanded features.", nil);
  404. self.switchLabel.stringValue = NSLocalizedString(@"Choose your favorite payment and enjoy flexible upgrades.", nil);
  405. self.switchLabel.textColor = [KMAppearance KMColor_Interactive_M0];
  406. self.switchButton.title = [NSString stringWithFormat:@"%@",NSLocalizedString(@"Pricing and Plans", nil)];
  407. self.box.wantsLayer = YES;
  408. self.box.shadow = [[NSShadow alloc] init];
  409. self.box.layer.shadowOpacity = 0.3;
  410. self.box.layer.shadowColor = [NSColor colorWithRed:0 green:0 blue:0 alpha:0.3].CGColor;
  411. self.box.layer.shadowOffset = NSMakeSize(0,3);
  412. self.box.layer.shadowRadius = 8;
  413. self.box.layer.masksToBounds = NO;
  414. NSButtonCell *cell = self.switchButton.cell;
  415. NSColor *txtColor = [NSColor colorWithRed:102.0/255.0 green:102.0/255.0 blue:102.0/255.0 alpha:1.0];
  416. NSAttributedString *attrStr1 = [cell attributedTitle];
  417. NSMutableAttributedString *myAttr = [[NSMutableAttributedString alloc] initWithAttributedString:attrStr1];
  418. [myAttr addAttribute:NSForegroundColorAttributeName value:txtColor range:NSMakeRange(0, myAttr.length)];
  419. [myAttr addAttribute:NSFontAttributeName value:[NSFont boldSystemFontOfSize:13.0] range:NSMakeRange(0, myAttr.length)];
  420. [cell setAttributedTitle:myAttr];
  421. [self.switchButton updateCell:cell];
  422. self.aboutButton.title = NSLocalizedString(@"About Subscriptions", nil);
  423. self.btnRestore.title = NSLocalizedString(@"Restore", nil);
  424. self.privacyPolicyBtn.title = NSLocalizedString(@"Privacy Policy", nil);
  425. self.termOfSerBtn.title = NSLocalizedString(@"Terms of Service", nil);
  426. self.btnRestore.toolTip = NSLocalizedString(@"Restore", nil);
  427. self.privacyPolicyBtn.toolTip = NSLocalizedString(@"Privacy Policy", nil);
  428. self.termOfSerBtn.toolTip = NSLocalizedString(@"Terms of Service", nil);
  429. [self.aboutButton setTitleColor:[NSColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:0.7]];
  430. [self.btnRestore setTitleColor:[NSColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:1]];
  431. [self.privacyPolicyBtn setTitleColor:[NSColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:1]];
  432. [self.termOfSerBtn setTitleColor:[NSColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:1]];
  433. self.btnRestore.mouseMoveCallback = ^(BOOL mouseEntered) {
  434. if (mouseEntered) {
  435. [self.btnRestore setTitleColor:[NSColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:0.7]];
  436. } else {
  437. [self.btnRestore setTitleColor:[NSColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:1]];
  438. }
  439. };
  440. self.privacyPolicyBtn.mouseMoveCallback = ^(BOOL mouseEntered) {
  441. if (mouseEntered) {
  442. [self.privacyPolicyBtn setTitleColor:[NSColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:0.7]];
  443. } else {
  444. [self.privacyPolicyBtn setTitleColor:[NSColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:1]];
  445. }
  446. };
  447. self.termOfSerBtn.mouseMoveCallback = ^(BOOL mouseEntered) {
  448. if (mouseEntered) {
  449. [self.termOfSerBtn setTitleColor:[NSColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:0.7]];
  450. } else {
  451. [self.termOfSerBtn setTitleColor:[NSColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:1]];
  452. }
  453. };
  454. self.aboutButton.hidden = YES;
  455. [self reloadData];
  456. [self reloadDataContent];
  457. [[IAPProductsManager defaultManager] loadProducts];
  458. __block typeof(self) blockSelf = self;
  459. self.value2PurchaseButton.mouseMoveCallback = ^(BOOL mouseEntered) {
  460. if (blockSelf.value2PurchaseButton.enabled) {
  461. if (mouseEntered) {
  462. [blockSelf.value2PurchaseLbl setTextColor:[NSColor whiteColor]];
  463. blockSelf.value2PurchaseButton.layer.backgroundColor = [NSColor colorWithRed:1 green:94/255.0 blue:44/255.0 alpha:1.0].CGColor;
  464. } else {
  465. [blockSelf.value2PurchaseLbl setTextColor:[NSColor colorWithRed:85/255. green:40/255.0 blue:255.0/255.0 alpha:1.0]];
  466. blockSelf.value2PurchaseButton.layer.backgroundColor = [NSColor whiteColor].CGColor;
  467. }
  468. }
  469. };
  470. self.value3PurchaseButton.mouseMoveCallback = ^(BOOL mouseEntered) {
  471. if (mouseEntered) {
  472. // [blockSelf.value3PurchaseButton setTitleColor:[NSColor whiteColor]];
  473. blockSelf.value3PurchaseBtnLbl.textColor = [NSColor whiteColor];
  474. blockSelf.value3PurchaseButton.layer.backgroundColor = [NSColor colorWithRed:1 green:94/255.0 blue:44/255.0 alpha:1.0].CGColor;
  475. } else {
  476. // [blockSelf.value3PurchaseButton setTitleColor:[NSColor colorWithRed:85/255. green:40/255.0 blue:255.0/255.0 alpha:1.0]];
  477. blockSelf.value3PurchaseBtnLbl.textColor = [NSColor colorWithRed:85/255. green:40/255.0 blue:255.0/255.0 alpha:1.0];
  478. blockSelf.value3PurchaseButton.layer.backgroundColor = [NSColor whiteColor].CGColor;
  479. }
  480. };
  481. self.textView.string = [NSString stringWithFormat:NSLocalizedString(@"Subscription plans:\nSubscriptions: %@\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", @""), NSLocalizedString(@"USD $39.99/(6 months), USD$59.99/(12 months), USD $59.99/(one-time purchase)", @"")];
  482. }
  483. - (BOOL)windowShouldClose:(id)sender {
  484. [[FMTrackEventManager defaultManager] trackEventWithEvent:@"PUW" withProperties:@{@"PUW_Btn":@"PUW_Btn_Upgrade_Cancel"}];
  485. [self endModal:sender];
  486. return YES;
  487. }
  488. - (void)close {
  489. [super close];
  490. [self endModal:nil];
  491. }
  492. - (IBAction)startModal:(id)sender {
  493. [NSApp stopModal];
  494. NSInteger modalCode;
  495. self.modalSession = [NSApp beginModalSessionForWindow:self.window];
  496. do {
  497. modalCode = [NSApp runModalSession:self.modalSession];
  498. } while (modalCode == NSModalResponseContinue);
  499. }
  500. - (IBAction)endModal:(id)sender {
  501. if (self.modalSession) {
  502. [NSApp stopModal];
  503. [NSApp endModalSession:self.modalSession];
  504. [self.window orderOut:self];
  505. self.modalSession = nil;
  506. }
  507. }
  508. - (void)showWindowRestore:(id)sender {
  509. [self showWindow:sender];
  510. [self buttonItemClicked_Restore:nil];
  511. }
  512. - (void)showWindow:(id)sender {
  513. [super showWindow:sender];
  514. [self reloadData];
  515. if ([self isShowSale]) {
  516. [self showDiscountToSaveWindow];
  517. }
  518. }
  519. #pragma mark - Private Methods
  520. - (void)reloadData {
  521. if (self.isPurchaseSwitch) {
  522. self.sixMouthProLabel.textColor = [NSColor colorWithRed:117/255.0 green:119/255.0 blue:128/255.0 alpha:1.0];
  523. self.oneYearProLabel.textColor = NSColor.whiteColor;
  524. self.switchCircleLeftConst.constant = 22;
  525. self.value1InfoLabel.stringValue = NSLocalizedString(@"1-year Plan", nil);
  526. } else {
  527. self.sixMouthProLabel.textColor = NSColor.whiteColor;
  528. self.oneYearProLabel.textColor = [NSColor colorWithRed:117/255.0 green:119/255.0 blue:128/255.0 alpha:1.0];
  529. self.switchCircleLeftConst.constant = 4;
  530. self.value1InfoLabel.stringValue = NSLocalizedString(@"6-Month Plan", nil);
  531. }
  532. self.saleBox.hidden = true;
  533. self.saleIv.hidden = true;
  534. if ([self isShowSale]) {
  535. KMAdvertisementItemInfo *info = KMAdvertisementManager.manager.info.StoreUserRecovery.content.firstObject;
  536. NSURL *url = [NSURL URLWithString:[KMAdvertisementModelTransition transitionImagePathWithImage:info.saleImage highlight:true]];
  537. [KMAdvertisementImage imageWithURLWithUrl:url completion:^(NSImage * _Nonnull image) {
  538. if (image != nil) {
  539. self.saleIv.image = image;
  540. self.saleBox.hidden = false;
  541. self.saleIv.hidden = false;
  542. }
  543. }];
  544. } else {
  545. self.saleBox.hidden = true;
  546. }
  547. if ([IAPProductsManager defaultManager].isAvailableAllFunction) {
  548. self.value1PurchaseButton.enabled = NO;
  549. self.value2PurchaseButton.enabled = NO;
  550. self.value2PurchaseLbl.textColor = [NSColor colorWithRed:85/255. green:40/255.0 blue:255.0/255.0 alpha:0.5];
  551. } else {
  552. self.value1PurchaseButton.enabled = YES;
  553. self.value2PurchaseButton.enabled = YES;
  554. self.value2PurchaseLbl.textColor = [NSColor colorWithRed:85/255. green:40/255.0 blue:255.0/255.0 alpha:1.0];
  555. }
  556. self.value1PurchaseBtnLblBtn.enabled = self.value1PurchaseButton.enabled;
  557. self.value1PurchaseBtnLbl.stringValue = NSLocalizedString(@"Subscribe", nil);
  558. if ([IAPProductsManager defaultManager].newlyMonthProduct.isTrialPeriod) {
  559. self.value1PurchaseBtnLbl.stringValue = NSLocalizedString(@"Subscribe", nil);
  560. if ([IAPProductsManager defaultManager].newlyMonthProduct.isSubscribed) {
  561. self.value1PurchaseBtnLbl.stringValue = NSLocalizedString(@"Subscribed", nil);
  562. }
  563. } else if ([IAPProductsManager defaultManager].yearProduct.isTrialPeriod) {
  564. self.value1PurchaseBtnLbl.stringValue = NSLocalizedString(@"Subscribe", nil);
  565. if ([IAPProductsManager defaultManager].yearProduct.isSubscribed) {
  566. self.value1PurchaseBtnLbl.stringValue = NSLocalizedString(@"Subscribed", nil);
  567. }
  568. } else {
  569. if ([IAPProductsManager defaultManager].newlyMonthProduct.isSubscribed) {
  570. self.value1PurchaseBtnLbl.stringValue = NSLocalizedString(@"Subscribed", nil);
  571. } else if ([IAPProductsManager defaultManager].yearProduct.isSubscribed) {
  572. self.value1PurchaseBtnLbl.stringValue = NSLocalizedString(@"Subscribed", nil);
  573. } else {
  574. self.value1PurchaseBtnLbl.stringValue = NSLocalizedString(@"Free Trial", nil);
  575. if (@available(macOS 10.13.2, *)) {
  576. #if !VERSION_DMG
  577. if (![IAPProductsManager defaultManager].newlyMonthProduct.product.introductoryPrice) {
  578. self.value1PurchaseBtnLbl.stringValue = NSLocalizedString(@"Subscribe", nil);
  579. } else if (![IAPProductsManager defaultManager].yearProduct.product.introductoryPrice) {
  580. self.value1PurchaseBtnLbl.stringValue = NSLocalizedString(@"Subscribe", nil);
  581. }
  582. #endif
  583. }
  584. }
  585. }
  586. if (self.value1PurchaseBtnLblBtn.enabled) {
  587. [self.value1PurchaseBtnLbl setTextColor:[NSColor whiteColor]];
  588. } else {
  589. [self.value1PurchaseBtnLbl setTextColor:[[NSColor whiteColor] colorWithAlphaComponent:0.5]];
  590. }
  591. self.value2PurchaseLblBtn.enabled = self.value2PurchaseButton.enabled;
  592. NSString *averageMonthPrice = nil;
  593. NSString *monthPrice = nil;
  594. NSString *averageMonthPrice_discount = nil;
  595. NSString *monthPrice_discount = nil;
  596. NSString *allPrice = nil;
  597. if ([IAPProductsManager defaultManager].newlyMonthProduct.isOffers) {
  598. self.specialView1.hidden = NO;
  599. averageMonthPrice = [IAPProductsManager defaultManager].newlyMonthProduct.offersAveragePrice;
  600. monthPrice = [IAPProductsManager defaultManager].newlyMonthProduct.offersPrice;
  601. averageMonthPrice_discount = [IAPProductsManager defaultManager].newlyMonthProduct.discountAveragePrice;
  602. monthPrice_discount = [IAPProductsManager defaultManager].newlyMonthProduct.discountPrice;
  603. self.topButtonOffset.constant = 20;
  604. } else if ([IAPProductsManager defaultManager].yearProduct.isOffers) {
  605. averageMonthPrice = [IAPProductsManager defaultManager].yearProduct.offersAveragePrice;
  606. monthPrice = [IAPProductsManager defaultManager].yearProduct.offersPrice;
  607. averageMonthPrice_discount = [IAPProductsManager defaultManager].yearProduct.discountAveragePrice;
  608. monthPrice_discount = [IAPProductsManager defaultManager].yearProduct.discountPrice;
  609. self.topButtonOffset.constant = 20;
  610. } else {
  611. self.specialView1.hidden = YES;
  612. if (self.isPurchaseSwitch == false) {
  613. averageMonthPrice = [IAPProductsManager defaultManager].newlyMonthProduct.averagePrice;
  614. monthPrice = [IAPProductsManager defaultManager].newlyMonthProduct.price;
  615. averageMonthPrice_discount = [IAPProductsManager defaultManager].newlyMonthProduct.discountAveragePrice;
  616. monthPrice_discount = [IAPProductsManager defaultManager].newlyMonthProduct.discountPrice;
  617. } else {
  618. averageMonthPrice = [IAPProductsManager defaultManager].yearProduct.averagePrice;
  619. monthPrice = [IAPProductsManager defaultManager].yearProduct.price;
  620. averageMonthPrice_discount = [IAPProductsManager defaultManager].yearProduct.discountAveragePrice;
  621. monthPrice_discount = [IAPProductsManager defaultManager].yearProduct.discountPrice;
  622. }
  623. self.topButtonOffset.constant = 10;
  624. }
  625. if ([IAPProductsManager defaultManager].allAccessProduct.isOffers) {
  626. self.topButtonOffset.constant = 20;
  627. self.specialView.hidden = NO;
  628. allPrice = [IAPProductsManager defaultManager].allAccessProduct.offersPrice;
  629. } else {
  630. self.topButtonOffset.constant = 10;
  631. self.specialView.hidden = YES;
  632. allPrice = [IAPProductsManager defaultManager].allAccessProduct.price;
  633. }
  634. CGFloat off = 1 -[IAPProductsManager defaultManager].allAccessProduct.offers;
  635. NSString *offString = [NSString stringWithFormat:@"%.f%%",off * 100];
  636. self.specialLabel.stringValue = [NSString stringWithFormat:NSLocalizedString(@"%@ off", @""),offString];
  637. if (self.isPurchaseSwitch) {
  638. off = 1 -[IAPProductsManager defaultManager].yearProduct.offers;
  639. } else {
  640. off = 1 -[IAPProductsManager defaultManager].newlyMonthProduct.offers;
  641. }
  642. offString = [NSString stringWithFormat:@"%.f%%",off * 100];
  643. self.specialLabel1.stringValue = [NSString stringWithFormat:NSLocalizedString(@"%@ off", @""),offString];
  644. NSImage *image = [NSImage imageNamed:@"KMImageNameCompareTagBG"];
  645. self.specialImageView.image = image;
  646. self.specialImageView1.image = image;
  647. BOOL isShowSale = [self isShowSale];
  648. if (KMKdanRemoteConfig.remoteConfig.showAPP_AveragePrice) {
  649. if (isShowSale) {
  650. self.value1PurchaseLabel.stringValue = [NSString stringWithFormat:@"%@/%@", averageMonthPrice_discount, NSLocalizedString(@"mon", nil)];
  651. self.value1PurchaseOriPriceLbl.stringValue = [NSString stringWithFormat:@"%@/%@", averageMonthPrice, NSLocalizedString(@"mon", nil)];
  652. self.value1PurchaseOriPriceLbl.hidden = false;
  653. self.billedTopConst.constant = 16;
  654. } else {
  655. self.value1PurchaseLabel.stringValue = [NSString stringWithFormat:@"%@/%@", averageMonthPrice, NSLocalizedString(@"mon", nil)];
  656. self.value1PurchaseOriPriceLbl.hidden = true;
  657. self.billedTopConst.constant = 0;
  658. }
  659. } else {
  660. if (self.isPurchaseSwitch) {
  661. if (isShowSale) {
  662. self.value1PurchaseLabel.stringValue = [NSString stringWithFormat:@"%@/%@", monthPrice_discount, NSLocalizedString(@"12 months", nil)];
  663. self.value1PurchaseOriPriceLbl.stringValue = [NSString stringWithFormat:@"%@/%@", monthPrice, NSLocalizedString(@"12 months", nil)];
  664. self.value1PurchaseOriPriceLbl.hidden = false;
  665. self.billedTopConst.constant = 16;
  666. } else {
  667. self.value1PurchaseLabel.stringValue = [NSString stringWithFormat:@"%@/%@", monthPrice, NSLocalizedString(@"12 months", nil)];
  668. self.value1PurchaseOriPriceLbl.hidden = true;
  669. self.billedTopConst.constant = 0;
  670. }
  671. } else {
  672. if (isShowSale) {
  673. self.value1PurchaseLabel.stringValue = [NSString stringWithFormat:@"%@/%@", monthPrice_discount, NSLocalizedString(@"6mon", nil)];
  674. self.value1PurchaseOriPriceLbl.stringValue = [NSString stringWithFormat:@"%@/%@", monthPrice, NSLocalizedString(@"6mon", nil)];
  675. self.value1PurchaseOriPriceLbl.hidden = false;
  676. self.billedTopConst.constant = 16;
  677. } else {
  678. self.value1PurchaseLabel.stringValue = [NSString stringWithFormat:@"%@/%@", monthPrice, NSLocalizedString(@"6mon", nil)];
  679. self.value1PurchaseOriPriceLbl.hidden = true;
  680. self.billedTopConst.constant = 0;
  681. }
  682. }
  683. }
  684. self.value1PurchaseLabel.textColor = [NSColor colorWithRed:1 green:231/255. blue:106/255. alpha:1.];
  685. self.value1PurchaseOriPriceLbl.textColor = [NSColor colorWithWhite:1 alpha:0.7];
  686. self.value1PurchaseOriPriceLbl.attributedStringValue = [[NSAttributedString alloc] initWithString:self.value1PurchaseOriPriceLbl.stringValue attributes:@{
  687. NSFontAttributeName : [NSFont SFProTextRegularFont:12],
  688. NSForegroundColorAttributeName: [NSColor colorWithWhite:1 alpha:0.7],
  689. NSStrikethroughStyleAttributeName : @(1)
  690. }];
  691. NSString *tTips = @"";
  692. if (isShowSale) {
  693. tTips = [NSString stringWithFormat:NSLocalizedString(@"%@ for the first 6-month subscription", nil), monthPrice_discount];
  694. } else {
  695. tTips = [NSString stringWithFormat:NSLocalizedString(@"Billed every 6 months at %@", nil), monthPrice];
  696. }
  697. if ([self.value1PurchaseBtnLbl.stringValue isEqualToString:NSLocalizedString(@"Free Trial", nil)]) {
  698. tTips = [NSString stringWithFormat:NSLocalizedString(@"Billed every 6 months at %@ after 7-day trial ends.", nil), monthPrice];
  699. #if !VERSION_DMG
  700. if (self.isPurchaseSwitch) {
  701. if ([IAPProductsManager defaultManager].yearProduct.product) {
  702. if (@available(macOS 10.13.2, *)) {
  703. tTips = [NSString stringWithFormat:NSLocalizedString(@"Billed every 12 months at %@ after %@-day trial ends.", nil), monthPrice,@([IAPProductsManager defaultManager].yearProduct.product.introductoryPrice.subscriptionPeriod.numberOfUnits)];
  704. }
  705. }
  706. } else {
  707. if ([IAPProductsManager defaultManager].newlyMonthProduct.product) {
  708. if (@available(macOS 10.13.2, *)) {
  709. tTips = [NSString stringWithFormat:NSLocalizedString(@"Billed every 6 months at %@ after %@-day trial ends.", nil), monthPrice,@([IAPProductsManager defaultManager].newlyMonthProduct.product.introductoryPrice.subscriptionPeriod.numberOfUnits)];
  710. }
  711. }
  712. }
  713. #endif
  714. }
  715. if (@available(macOS 10.13.2, *)) {
  716. #if !VERSION_DMG
  717. if (self.isPurchaseSwitch) {
  718. if (![IAPProductsManager defaultManager].yearProduct.product.introductoryPrice) {
  719. if (isShowSale) {
  720. tTips = [NSString stringWithFormat:NSLocalizedString(@"%@ for the first year's subscription", nil), monthPrice_discount];
  721. } else {
  722. tTips = [NSString stringWithFormat:NSLocalizedString(@"Billed every 12 months at %@", nil), monthPrice];
  723. }
  724. }
  725. } else {
  726. if (![IAPProductsManager defaultManager].newlyMonthProduct.product.introductoryPrice) {
  727. if (isShowSale) {
  728. tTips = [NSString stringWithFormat:NSLocalizedString(@"%@ for the first 6-month subscription", nil), monthPrice_discount];
  729. } else {
  730. tTips = [NSString stringWithFormat:NSLocalizedString(@"Billed every 6 months at %@", nil), monthPrice];
  731. }
  732. }
  733. }
  734. #endif
  735. }
  736. self.value1PurchaseSubLabel.stringValue = [NSString stringWithFormat:NSLocalizedString(@"%@", nil), tTips];
  737. self.value2PurchaseLabel.stringValue = allPrice?:@"";
  738. self.value2PurchaseLabel.textColor = [NSColor colorWithRed:1 green:231/255. blue:106/255. alpha:1.];
  739. self.value2PurchaseSubLabel.stringValue = NSLocalizedString(@"one-time purchase", nil);
  740. self.value3PurchaseLabel.stringValue = NSLocalizedString(@"USD $59.99", nil);
  741. self.value3PurchaseLabel.textColor = [NSColor colorWithRed:1 green:231/255. blue:106/255. alpha:1.];
  742. self.value3PurchaseSubLabel.stringValue = NSLocalizedString(@"one-time purchase", nil);
  743. self.value1PurchaseBtnLbl.font = [NSFont UbuntuBoldFontWithSize:16];
  744. self.value2PurchaseLbl.font = [NSFont UbuntuBoldFontWithSize:16];
  745. self.value3PurchaseBtnLbl.font = [NSFont UbuntuBoldFontWithSize:16];
  746. self.value1PurchaseLabel.font = [NSFont UbuntuBoldFontWithSize:22];
  747. self.value2PurchaseLabel.font = [NSFont UbuntuBoldFontWithSize:22];
  748. self.value3PurchaseLabel.font = [NSFont UbuntuBoldFontWithSize:22];
  749. self.value1PurchaseOriPriceLbl.font = [NSFont SFProTextRegularFont:12];
  750. }
  751. - (void)reloadDataContent {
  752. if (self.isPurchaseSwitch) {
  753. self.dataSource = @[@"PDF to Office",
  754. @[@"Convert PDFs to Word, HTML, TXT, JPEG or PNG files",@"Only first 10 pages",@"Advanced",@"Advanced",@"Standard"],
  755. @[@"Turn PDF to PPT, Excel, RTF, CSV, and more",@"Only first 10 pages",@"✓",@"✓",@"Only first 10 pages"],
  756. @[@"Convert PDF to TIFF, BMP, GIF or TGA files",@"Only first 10 pages",@"✓",@"✓",@"Only first 10 pages"],
  757. @"Edit PDF",
  758. @[@"Add and edit text in PDF",@"X",@"✓",@"✓",@"✓"],
  759. @[@"Edit, crop, replace image in PDF",@"X",@"✓",@"✓",@"✓"],
  760. @"OCR",
  761. @[@"Extract texts from image-based or scanned PDF",@"X",@"✓",@"✓",@"✓"],
  762. @"Organize Pages",
  763. @[@"Extract, rotate, rearrange, replace, add, delete pages",@"X",@"✓",@"✓",@"✓"],
  764. @[@"Split PDFs into multiple files",@"X",@"✓",@"✓",@"✓"],
  765. @"Advanced Editing Tools",
  766. @[@"Merge multiple documents into a new PDF",@"Up to 2 files or 20 MB",@"✓",@"∞",@"∞"],
  767. @[@"Add & edit watermark",@"X",@"✓",@"✓",@"✓"],
  768. @[@"Add header, footer, page numbers",@"X",@"✓",@"✓",@"✓"],
  769. @[@"Add Bates Number",@"X",@"✓",@"✓",@"✓"],
  770. @[@"Insert PDF page background by color or image",@"X",@"✓",@"✓",@"✓"],
  771. @[@"Create fattened copies",@"X",@"✓",@"✓",@"✓"],
  772. @[@"Extract Images",@"X",@"✓",@"✓",@"✓"],
  773. @[@"Extract tables",@"Only first 10 pages",@"✓",@"✓",@"Only first 10 pages"],
  774. @"Fill & Sign",
  775. @[@"Create digital signature",@"X",@"✓",@"✓",@"✓"],
  776. @[@"Create & Edit & Fill Adobe Fillable PDF Forms",@"X",@"✓",@"✓",@"✓"],
  777. @"Security",
  778. @[@"Batch encrypting PDF documents",@"X",@"✓",@"✓",@"✓"],
  779. @[@"PDF Password Remover",@"X",@"✓",@"✓",@"✓"],
  780. @[@"Redact sensitive information",@"X",@"✓",@"✓",@"✓"],
  781. @"Create PDF",
  782. @[@"Convert JPEG, JPG, PNG, TIFF, BMP or PSD files to PDFs",@"1 file",@"✓",@"✓",@"✓"],
  783. @[@"Create PDFs from a scanner and iOS devices",@"X",@"✓",@"✓",@"✓"],
  784. @"Annotations",
  785. @[@"Customize PDF stamps",@"X",@"✓",@"✓",@"✓",@"✓"],
  786. @[@"Hyperlink",@"Page Number",@"Page Number, URL, Email",@"Page Number, URL, Email",@"Page Number, URL, Email"],
  787. @[@"Signature",@"Standard",@"Advanced",@"Advanced",@"Advanced"],
  788. @[@"Table",@"X",@"✓",@"✓",@"✓",@"✓"],
  789. @"View PDF",
  790. @[@"Multi-tab viewer",@"X",@"✓",@"✓",@"✓"],
  791. @[@"Various printing types: poster, booklet, multi-page printing",@"X",@"✓",@"✓",@"✓"],
  792. @[@"Customize theme colors: Light Mode, Dark Mode, Sepia Mode and more",@"X",@"✓",@"✓",@"✓"],
  793. @[@"Split View to compare files",@"X",@"✓",@"✓",@"✓"],
  794. @"Subscription Based Solution",
  795. @[@"Access all premium features in app",@"X",@"12 months",@"∞",@"∞"],
  796. @[@"Priority customer support",@"X",@"✓",@"✓",@"✓"],
  797. @[@"Ad-free",@"X",@"✓",@"✓",@"✓"],
  798. @{}
  799. ];
  800. } else {
  801. self.dataSource = @[@"PDF to Office",
  802. @[@"Convert PDFs to Word, HTML, TXT, JPEG or PNG files",@"Only first 10 pages",@"Advanced",@"Advanced",@"Standard"],
  803. @[@"Turn PDF to PPT, Excel, RTF, CSV, and more",@"Only first 10 pages",@"✓",@"✓",@"Only first 10 pages"],
  804. @[@"Convert PDF to TIFF, BMP, GIF or TGA files",@"Only first 10 pages",@"✓",@"✓",@"Only first 10 pages"],
  805. @"Edit PDF",
  806. @[@"Add and edit text in PDF",@"X",@"✓",@"✓",@"✓"],
  807. @[@"Edit, crop, replace image in PDF",@"X",@"✓",@"✓",@"✓"],
  808. @"OCR",
  809. @[@"Extract texts from image-based or scanned PDF",@"X",@"✓",@"✓",@"✓"],
  810. @"Organize Pages",
  811. @[@"Extract, rotate, rearrange, replace, add, delete pages",@"X",@"✓",@"✓",@"✓"],
  812. @[@"Split PDFs into multiple files",@"X",@"✓",@"✓",@"✓"],
  813. @"Advanced Editing Tools",
  814. @[@"Merge multiple documents into a new PDF",@"Up to 2 files or 20 MB",@"✓",@"∞",@"∞"],
  815. @[@"Add & edit watermark",@"X",@"✓",@"✓",@"✓"],
  816. @[@"Add header, footer, page numbers",@"X",@"✓",@"✓",@"✓"],
  817. @[@"Add Bates Number",@"X",@"✓",@"✓",@"✓"],
  818. @[@"Insert PDF page background by color or image",@"X",@"✓",@"✓",@"✓"],
  819. @[@"Create fattened copies",@"X",@"✓",@"✓",@"✓"],
  820. @[@"Extract Images",@"X",@"✓",@"✓",@"✓"],
  821. @[@"Extract tables",@"Only first 10 pages",@"✓",@"✓",@"Only first 10 pages"],
  822. @"Fill & Sign",
  823. @[@"Create digital signature",@"X",@"✓",@"✓",@"✓"],
  824. @[@"Create & Edit & Fill Adobe Fillable PDF Forms",@"X",@"✓",@"✓",@"✓"],
  825. @"Security",
  826. @[@"Batch encrypting PDF documents",@"X",@"✓",@"✓",@"✓"],
  827. @[@"PDF Password Remover",@"X",@"✓",@"✓",@"✓"],
  828. @[@"Redact sensitive information",@"X",@"✓",@"✓",@"✓"],
  829. @"Create PDF",
  830. @[@"Convert JPEG, JPG, PNG, TIFF, BMP or PSD files to PDFs",@"1 file",@"✓",@"✓",@"✓"],
  831. @[@"Create PDFs from a scanner and iOS devices",@"X",@"✓",@"✓",@"✓"],
  832. @"Annotations",
  833. @[@"Customize PDF stamps",@"X",@"✓",@"✓",@"✓",@"✓"],
  834. @[@"Hyperlink",@"Page Number",@"Page Number, URL, Email",@"Page Number, URL, Email",@"Page Number, URL, Email"],
  835. @[@"Signature",@"Standard",@"Advanced",@"Advanced",@"Advanced"],
  836. @[@"Table",@"X",@"✓",@"✓",@"✓",@"✓"],
  837. @"View PDF",
  838. @[@"Multi-tab viewer",@"X",@"✓",@"✓",@"✓"],
  839. @[@"Various printing types: poster, booklet, multi-page printing",@"X",@"✓",@"✓",@"✓"],
  840. @[@"Customize theme colors: Light Mode, Dark Mode, Sepia Mode and more",@"X",@"✓",@"✓",@"✓"],
  841. @[@"Split View to compare files",@"X",@"✓",@"✓",@"✓"],
  842. @"Subscription Based Solution",
  843. @[@"Access all premium features in app",@"X",@"6 months",@"∞",@"∞"],
  844. @[@"Priority customer support",@"X",@"✓",@"✓",@"✓"],
  845. @[@"Ad-free",@"X",@"✓",@"✓",@"✓"],
  846. @{}
  847. ];
  848. }
  849. [self.tableView reloadData];
  850. }
  851. - (void)addWaingView:(NSView *)view {
  852. [self removeWaitingView:view];
  853. WaitingView *wView = [[WaitingView alloc] initWithFrame:view.bounds];
  854. [wView setAutoresizingMask:NSViewWidthSizable|NSViewHeightSizable];
  855. [view addSubview:wView];
  856. [wView startAnimation];
  857. }
  858. - (void)removeWaitingView:(NSView *)view {
  859. for (id v in view.subviews) {
  860. if ([[v class] isSubclassOfClass:[WaitingView class]]) {
  861. [v removeFromSuperview];
  862. break;
  863. }
  864. }
  865. }
  866. - (void)updateViewColor {
  867. self.box.fillColor = [KMAppearance KMColor_Layout_L1];
  868. self.labelbox.fillColor = [NSColor clearColor];
  869. self.tableView.backgroundColor = [KMAppearance KMColor_Layout_L0];
  870. self.textView.backgroundColor = [NSColor clearColor];
  871. self.textView.textColor = [[NSColor whiteColor] colorWithAlphaComponent:0.5];
  872. self.value1PurchaseSubLabel.textColor = self.value2PurchaseSubLabel.textColor = self.value3PurchaseSubLabel.textColor = [KMAppearance KMColor_Layout_W0];
  873. }
  874. - (BOOL)isCancelAutoRenew {
  875. return [[IAPProductsManager defaultManager] isCancelAutoRenew];
  876. }
  877. - (BOOL)isShowSale {
  878. if (@available(macOS 10.14.4, *)) {
  879. if ([self isCancelAutoRenew]) {
  880. BOOL isSubscribed = [IAPProductsManager defaultManager].newlyMonthProduct.isSubscribed;
  881. if (isSubscribed) {
  882. return false;
  883. }
  884. isSubscribed = [IAPProductsManager defaultManager].yearProduct.isSubscribed;
  885. if (isSubscribed) {
  886. return false;
  887. }
  888. KMAdvertisementItemInfo *info = KMAdvertisementManager.manager.info.StoreUserRecovery.content.firstObject;
  889. if ([info.show boolValue] == false) { // 活动结束
  890. return false;
  891. }
  892. return true;
  893. }
  894. }
  895. return false;
  896. }
  897. #pragma mark - Button Actions
  898. - (IBAction)buttonItemClicked_Subscribe:(id)sender {
  899. if (self.isPurchaseSwitch) {
  900. [[IAPProductsManager defaultManager] makeSubProduct:[IAPProductsManager defaultManager].yearProduct discount:[self isCancelAutoRenew]];
  901. } else {
  902. [[IAPProductsManager defaultManager] makeSubProduct:[IAPProductsManager defaultManager].newlyMonthProduct discount:[self isCancelAutoRenew]];
  903. }
  904. [self addWaingView:self.window.contentView];
  905. [[FMTrackEventManager defaultManager] trackEventWithEvent:@"PUW" withProperties:@{@"PUW_Btn":@"PUW_Btn_Upgrade_6Mon"}];
  906. }
  907. - (void)showDiscountToSaveWindow {
  908. if ([KMDiscountToSaveWindowController needShow] == false) {
  909. return;
  910. }
  911. KMAdvertisementItemInfo *info = KMAdvertisementManager.manager.info.StoreUserRecovery.content.firstObject;
  912. NSURL *url = [NSURL URLWithString: [KMAdvertisementModelTransition transitionImagePathWithImage:info.image highlight: YES]];
  913. __weak typeof(self) weakSelf = self;
  914. [self addWaingView:self.window.contentView];
  915. [KMAdvertisementImage imageWithURLWithUrl:url completion:^(NSImage *image) {
  916. [weakSelf removeWaitingView:weakSelf.window.contentView];
  917. if (image == nil) {
  918. return;
  919. }
  920. KMDiscountToSaveWindowController *winC = [[KMDiscountToSaveWindowController alloc] initWithWindowNibName:@"KMDiscountToSaveWindowController"];
  921. weakSelf.discountToSaveWinC = winC;
  922. [weakSelf.window beginSheet:winC.window completionHandler:^(NSModalResponse returnCode) { }];
  923. winC.imgIv.image = image;
  924. winC.itemClick = ^(NSInteger idx) {
  925. [weakSelf.window endSheet:weakSelf.discountToSaveWinC.window];
  926. weakSelf.discountToSaveWinC = nil;
  927. if (idx == 2) { // 订阅
  928. //// NSLog(@"buttonItemClicked_Subscribe");
  929. }
  930. };
  931. }];
  932. }
  933. - (IBAction)buttonItemClicked_Restore:(id)sender {
  934. [[IAPProductsManager defaultManager] restoreSubscriptions];
  935. [self addWaingView:self.window.contentView];
  936. }
  937. - (IBAction)buttonItemClicked_Upgrade:(id)sender {
  938. [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:@"macappstore://apps.apple.com/app/id825459243?mt=12"]];
  939. [[FMTrackEventManager defaultManager] trackEventWithEvent:@"PUW" withProperties:@{@"PUW_Btn":@"PUW_Btn_Upgrade_Premium"}];
  940. }
  941. - (IBAction)privacyPolicyAction:(NSButton *)sender {
  942. [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:@"https://www.pdfreaderpro.com/privacy-policy"]];
  943. }
  944. - (IBAction)termOfSerAction:(NSButton *)sender {
  945. [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:@"https://www.pdfreaderpro.com/terms_of_service"]];
  946. }
  947. - (IBAction)buttonItemClicked_LicenseUpgrade:(id)sender {
  948. [[IAPProductsManager defaultManager] makeProduct:[IAPProductsManager defaultManager].allAccessProduct];
  949. [self addWaingView:self.window.contentView];
  950. [[FMTrackEventManager defaultManager] trackEventWithEvent:@"PUW" withProperties:@{@"PUW_Btn":@"PUW_Btn_Upgrade_Permanent"}];
  951. }
  952. - (IBAction)buttonItemClicked_AboutSubscriptions:(id)sender {
  953. NSString *tMessage = [NSString stringWithFormat:@"%@\n%@\n\n%@\n%@\n%@\n%@\n%@\n\n%@\n%@\n\n",
  954. @"Subscription plans: ",
  955. @"Subscriptions: USD $39.99/(6 months), USD $79.99/(one-time purchase) ",
  956. @"- Subscriptions will be charged through your iTunes account at the confirmation of purchase. ",
  957. @"- Your subscriptions will automatically renew unless cancelled at least 24 hours before the end of current subscription period. ",
  958. @"- 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. ",
  959. @"- You may manage your subscriptions in your iTunes Account Settings after purchase. ",
  960. @"- No cancellation of the current subscription is allowed during an active subscription period. ",
  961. @"- Terms of service: \nhttps://www.pdfreaderpro.com/terms_of_service ",
  962. @"- Privacy Policy: \nhttps://www.pdfreaderpro.com/privacy-policy "];
  963. NSAlert *alert = [[NSAlert alloc] init];
  964. [alert setAlertStyle:NSAlertStyleInformational];
  965. [alert setMessageText:NSLocalizedString(tMessage, nil)];
  966. [alert runModal];
  967. }
  968. - (IBAction)buttonItemClicked_CloseWindow:(id)sender {
  969. [self close];
  970. }
  971. - (void)switchAction:(NSButton *)sender {
  972. // NSControlStateValue state = self.switchBtn.state;
  973. BOOL isSwitch = self.isPurchaseSwitch;
  974. if (isSwitch) {
  975. // self.switchBtn.state = NSControlStateValueOff;
  976. self.isPurchaseSwitch = false;
  977. // self.switchCircleLeftConst.constant = 4;
  978. } else {
  979. // self.switchBtn.state = NSControlStateValueOn;
  980. self.isPurchaseSwitch = true;
  981. // self.switchCircleLeftConst.constant = 22;
  982. }
  983. // if (self.isPurchaseSwitch) { // 一年
  984. //
  985. // } else { // 半年
  986. //
  987. // }
  988. [self reloadDataContent];
  989. [self reloadData];
  990. }
  991. #pragma mark - NSTableViewDataSource Methods
  992. - (NSInteger)numberOfRowsInTableView:(NSTableView *)aTableView {
  993. return self.dataSource.count;
  994. }
  995. - (id)tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row {
  996. id object = [self.dataSource objectAtIndex:row];
  997. if ([object isKindOfClass:[NSString class]]) {
  998. KMPurchaseCompareHeaderCell *cellView = [tableView makeViewWithIdentifier:KMPurchaseCompareHeaderCellIdentifier owner:self];
  999. cellView.textField.stringValue = NSLocalizedString(object, nil);
  1000. return cellView;
  1001. } else if ([object isKindOfClass:[NSArray class]]) {
  1002. KMPurchaseCompareCell *cellView = [tableView makeViewWithIdentifier:KMPurchaseCompareCellIdentifier owner:self];
  1003. NSString *value = [(NSArray *)object count] > 0 ? object[0] : @"";
  1004. NSString *value1 = [(NSArray *)object count] > 1 ? object[1] : @"";
  1005. NSString *value2 = [(NSArray *)object count] > 2 ? object[2] : @"";
  1006. NSString *value3 = [(NSArray *)object count] > 3 ? object[3] : @"";
  1007. NSString *value4 = [(NSArray *)object count] > 4 ? object[4] : @"";
  1008. cellView.textField.stringValue = NSLocalizedString(value, nil);
  1009. cellView.lineBox.hidden = NO;
  1010. if (row + 1 == (NSInteger)self.dataSource.count) {
  1011. cellView.lineBox.hidden = YES;
  1012. } else {
  1013. id nextobject = [self.dataSource objectAtIndex:row+1];
  1014. if ([nextobject isKindOfClass:[NSString class]]) {
  1015. cellView.lineBox.hidden = YES;
  1016. }
  1017. }
  1018. if (row + 2 == (NSInteger)self.dataSource.count) {
  1019. cellView.boxBottomConst.constant = 0;
  1020. } else {
  1021. cellView.boxBottomConst.constant = -4;
  1022. }
  1023. if ([value1 isEqualToString:@"X"]) {
  1024. cellView.value1Label.stringValue = @"";
  1025. cellView.value1ImageView.image = [NSImage imageNamed:@"compare_nosupport"];
  1026. } else if ([value1 isEqualToString:@"✓"]) {
  1027. cellView.value1Label.stringValue = @"";
  1028. cellView.value1ImageView.image = [NSImage imageNamed:@"compare_support"];
  1029. } else if ([value1 isEqualToString:@"∞"]) {
  1030. cellView.value1Label.stringValue = @"";
  1031. cellView.value1ImageView.image = [NSImage imageNamed:@"compare_00"];
  1032. } else {
  1033. cellView.value1Label.stringValue = NSLocalizedString(value1, nil);
  1034. cellView.value1ImageView.image = nil;
  1035. }
  1036. if ([value2 isEqualToString:@"X"]) {
  1037. cellView.value2Label.stringValue = @"";
  1038. cellView.value2ImageView.image = [NSImage imageNamed:@"compare_nosupport"];
  1039. } else if ([value2 isEqualToString:@"✓"]) {
  1040. cellView.value2Label.stringValue = @"";
  1041. cellView.value2ImageView.image = [NSImage imageNamed:@"compare_support"];
  1042. } else if ([value2 isEqualToString:@"∞"]) {
  1043. cellView.value2Label.stringValue = @"";
  1044. cellView.value2ImageView.image = [NSImage imageNamed:@"compare_00"];
  1045. } else {
  1046. cellView.value2Label.stringValue = NSLocalizedString(value2, nil);
  1047. cellView.value2ImageView.image = nil;
  1048. }
  1049. if ([value3 isEqualToString:@"X"]) {
  1050. cellView.value3Label.stringValue = @"";
  1051. cellView.value3ImageView.image = [NSImage imageNamed:@"compare_nosupport"];
  1052. } else if ([value3 isEqualToString:@"✓"]) {
  1053. cellView.value3Label.stringValue = @"";
  1054. cellView.value3ImageView.image = [NSImage imageNamed:@"compare_support"];
  1055. } else if ([value3 isEqualToString:@"∞"]) {
  1056. cellView.value3Label.stringValue = @"";
  1057. cellView.value3ImageView.image = [NSImage imageNamed:@"compare_00"];
  1058. } else {
  1059. cellView.value3Label.stringValue = NSLocalizedString(value3, nil);
  1060. cellView.value3ImageView.image = nil;
  1061. }
  1062. if ([value4 isEqualToString:@"X"]) {
  1063. cellView.value4Label.stringValue = @"";
  1064. cellView.value4ImageView.image = [NSImage imageNamed:@"compare_nosupport"];
  1065. } else if ([value4 isEqualToString:@"✓"]) {
  1066. cellView.value4Label.stringValue = @"";
  1067. cellView.value4ImageView.image = [NSImage imageNamed:@"compare_support"];
  1068. } else if ([value4 isEqualToString:@"∞"]) {
  1069. cellView.value4Label.stringValue = @"";
  1070. cellView.value4ImageView.image = [NSImage imageNamed:@"compare_00"];
  1071. } else {
  1072. cellView.value4Label.stringValue = NSLocalizedString(value4, nil);
  1073. cellView.value4ImageView.image = nil;
  1074. }
  1075. return cellView;
  1076. } else if ([object isKindOfClass:[NSDictionary class]]) {
  1077. KMPurchaseCompareEmptyCell *cellView = [tableView makeViewWithIdentifier:KMPurchaseCompareEmptyCellIdentifier owner:self];
  1078. return cellView;
  1079. }
  1080. return nil;
  1081. }
  1082. - (CGFloat)tableView:(NSTableView *)tableView heightOfRow:(NSInteger)row {
  1083. NSTableCellView *cellView = nil;
  1084. id object = [self.dataSource objectAtIndex:row];
  1085. if ([object isKindOfClass:[NSString class]]) {
  1086. cellView = [tableView makeViewWithIdentifier:KMPurchaseCompareHeaderCellIdentifier owner:self];
  1087. cellView.textField.stringValue = NSLocalizedString(object, nil);
  1088. } else if ([object isKindOfClass:[NSArray class]]) {
  1089. cellView = [tableView makeViewWithIdentifier:KMPurchaseCompareCellIdentifier owner:self];
  1090. cellView.textField.stringValue = NSLocalizedString(object[0], nil);
  1091. } else if ([object isKindOfClass:[NSDictionary class]]) {
  1092. return 40;
  1093. }
  1094. if (cellView) {
  1095. [cellView layoutSubtreeIfNeeded];
  1096. return cellView.frame.size.height;
  1097. } else {
  1098. return 0;
  1099. }
  1100. }
  1101. #pragma mark - InAppPurchaseManager Notification
  1102. - (void)IAPProductFailedNotification:(NSNotification*)notification {
  1103. [self removeWaitingView:self.window.contentView];
  1104. }
  1105. - (void)IAPProductPurchasedNotification:(NSNotification*)notification {
  1106. [self removeWaitingView:self.window.contentView];
  1107. [self reloadData];
  1108. }
  1109. - (void)IAPProductLoadedNotification:(NSNotification*)notification {
  1110. [self reloadData];
  1111. }
  1112. - (void)IAPProductRestoreFinishedNotification:(NSNotification *)notification {
  1113. [self removeWaitingView:self.window.contentView];
  1114. [self reloadData];
  1115. }
  1116. - (void)IAPProductRestoreFailedNotification:(NSNotification *)notification {
  1117. [self removeWaitingView:self.window.contentView];
  1118. }
  1119. - (void)IAPSubscriptionLoadedNotification:(NSNotification *)notification {
  1120. [self removeWaitingView:self.window.contentView];
  1121. [self reloadData];
  1122. }
  1123. @end