KMPurchaseCompareWindowController.m 66 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350
  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. if ([self isShowSale]) {
  486. [self trackEvent_freeWithEventName:@"PromotionalOffer" params:@{@"PUW_Btn" : @"PUW_7OffUpgrade_Cancel"} platform:KMAnalyticsPlatformAppCenter];
  487. }
  488. [self endModal:sender];
  489. return YES;
  490. }
  491. - (void)close {
  492. [super close];
  493. [self endModal:nil];
  494. }
  495. - (IBAction)startModal:(id)sender {
  496. [NSApp stopModal];
  497. NSInteger modalCode;
  498. self.modalSession = [NSApp beginModalSessionForWindow:self.window];
  499. do {
  500. modalCode = [NSApp runModalSession:self.modalSession];
  501. } while (modalCode == NSModalResponseContinue);
  502. }
  503. - (IBAction)endModal:(id)sender {
  504. if (self.modalSession) {
  505. [NSApp stopModal];
  506. [NSApp endModalSession:self.modalSession];
  507. [self.window orderOut:self];
  508. self.modalSession = nil;
  509. }
  510. }
  511. - (void)showWindowRestore:(id)sender {
  512. [self showWindow:sender];
  513. [self buttonItemClicked_Restore:nil];
  514. }
  515. - (void)showWindow:(id)sender {
  516. [super showWindow:sender];
  517. [self reloadData];
  518. if ([self isShowSale]) {
  519. [self showDiscountToSaveWindow];
  520. }
  521. }
  522. #pragma mark - Private Methods
  523. - (void)reloadData {
  524. if (self.isPurchaseSwitch) {
  525. self.sixMouthProLabel.textColor = [NSColor colorWithRed:117/255.0 green:119/255.0 blue:128/255.0 alpha:1.0];
  526. self.oneYearProLabel.textColor = NSColor.whiteColor;
  527. self.switchCircleLeftConst.constant = 22;
  528. self.value1InfoLabel.stringValue = NSLocalizedString(@"1-year Plan", nil);
  529. } else {
  530. self.sixMouthProLabel.textColor = NSColor.whiteColor;
  531. self.oneYearProLabel.textColor = [NSColor colorWithRed:117/255.0 green:119/255.0 blue:128/255.0 alpha:1.0];
  532. self.switchCircleLeftConst.constant = 4;
  533. self.value1InfoLabel.stringValue = NSLocalizedString(@"6-Month Plan", nil);
  534. }
  535. self.saleBox.hidden = true;
  536. self.saleIv.hidden = true;
  537. if ([self isShowSale]) {
  538. KMAdvertisementItemInfo *info = KMAdvertisementManager.manager.info.StoreUserRecovery.content.firstObject;
  539. NSURL *url = [NSURL URLWithString:[KMAdvertisementModelTransition transitionImagePathWithImage:info.saleImage highlight:true]];
  540. [KMAdvertisementImage imageWithURLWithUrl:url completion:^(NSImage * _Nonnull image) {
  541. if (image != nil) {
  542. self.saleIv.image = image;
  543. self.saleBox.hidden = false;
  544. self.saleIv.hidden = false;
  545. [self trackEvent_freeWithEventName:@"PromotionalOffer" params:@{@"PUW_Exposure" : @"PUW_7OffUpgrade"} platform:KMAnalyticsPlatformAppCenter];
  546. }
  547. }];
  548. } else {
  549. self.saleBox.hidden = true;
  550. }
  551. if ([IAPProductsManager defaultManager].isAvailableAllFunction) {
  552. self.value1PurchaseButton.enabled = NO;
  553. self.value2PurchaseButton.enabled = NO;
  554. self.value2PurchaseLbl.textColor = [NSColor colorWithRed:85/255. green:40/255.0 blue:255.0/255.0 alpha:0.5];
  555. } else {
  556. self.value1PurchaseButton.enabled = YES;
  557. self.value2PurchaseButton.enabled = YES;
  558. self.value2PurchaseLbl.textColor = [NSColor colorWithRed:85/255. green:40/255.0 blue:255.0/255.0 alpha:1.0];
  559. }
  560. self.value1PurchaseBtnLblBtn.enabled = self.value1PurchaseButton.enabled;
  561. self.value1PurchaseBtnLbl.stringValue = NSLocalizedString(@"Subscribe", nil);
  562. if ([IAPProductsManager defaultManager].newlyMonthProduct.isTrialPeriod) {
  563. self.value1PurchaseBtnLbl.stringValue = NSLocalizedString(@"Subscribe", nil);
  564. if ([IAPProductsManager defaultManager].newlyMonthProduct.isSubscribed) {
  565. self.value1PurchaseBtnLbl.stringValue = NSLocalizedString(@"Subscribed", nil);
  566. }
  567. } else if ([IAPProductsManager defaultManager].yearProduct.isTrialPeriod) {
  568. self.value1PurchaseBtnLbl.stringValue = NSLocalizedString(@"Subscribe", nil);
  569. if ([IAPProductsManager defaultManager].yearProduct.isSubscribed) {
  570. self.value1PurchaseBtnLbl.stringValue = NSLocalizedString(@"Subscribed", nil);
  571. }
  572. } else {
  573. if ([IAPProductsManager defaultManager].newlyMonthProduct.isSubscribed) {
  574. self.value1PurchaseBtnLbl.stringValue = NSLocalizedString(@"Subscribed", nil);
  575. } else if ([IAPProductsManager defaultManager].yearProduct.isSubscribed) {
  576. self.value1PurchaseBtnLbl.stringValue = NSLocalizedString(@"Subscribed", nil);
  577. } else {
  578. self.value1PurchaseBtnLbl.stringValue = NSLocalizedString(@"Free Trial", nil);
  579. if (@available(macOS 10.13.2, *)) {
  580. #if !VERSION_DMG
  581. if (![IAPProductsManager defaultManager].newlyMonthProduct.product.introductoryPrice) {
  582. self.value1PurchaseBtnLbl.stringValue = NSLocalizedString(@"Subscribe", nil);
  583. } else if (![IAPProductsManager defaultManager].yearProduct.product.introductoryPrice) {
  584. self.value1PurchaseBtnLbl.stringValue = NSLocalizedString(@"Subscribe", nil);
  585. }
  586. #endif
  587. }
  588. }
  589. }
  590. if (self.value1PurchaseBtnLblBtn.enabled) {
  591. [self.value1PurchaseBtnLbl setTextColor:[NSColor whiteColor]];
  592. } else {
  593. [self.value1PurchaseBtnLbl setTextColor:[[NSColor whiteColor] colorWithAlphaComponent:0.5]];
  594. }
  595. self.value2PurchaseLblBtn.enabled = self.value2PurchaseButton.enabled;
  596. NSString *averageMonthPrice = nil;
  597. NSString *monthPrice = nil;
  598. NSString *averageMonthPrice_discount = nil;
  599. NSString *monthPrice_discount = nil;
  600. NSString *allPrice = nil;
  601. if ([IAPProductsManager defaultManager].newlyMonthProduct.isOffers) {
  602. self.specialView1.hidden = NO;
  603. averageMonthPrice = [IAPProductsManager defaultManager].newlyMonthProduct.offersAveragePrice;
  604. monthPrice = [IAPProductsManager defaultManager].newlyMonthProduct.offersPrice;
  605. averageMonthPrice_discount = [IAPProductsManager defaultManager].newlyMonthProduct.discountAveragePrice;
  606. monthPrice_discount = [IAPProductsManager defaultManager].newlyMonthProduct.discountPrice;
  607. self.topButtonOffset.constant = 20;
  608. } else if ([IAPProductsManager defaultManager].yearProduct.isOffers) {
  609. averageMonthPrice = [IAPProductsManager defaultManager].yearProduct.offersAveragePrice;
  610. monthPrice = [IAPProductsManager defaultManager].yearProduct.offersPrice;
  611. averageMonthPrice_discount = [IAPProductsManager defaultManager].yearProduct.discountAveragePrice;
  612. monthPrice_discount = [IAPProductsManager defaultManager].yearProduct.discountPrice;
  613. self.topButtonOffset.constant = 20;
  614. } else {
  615. self.specialView1.hidden = YES;
  616. if (self.isPurchaseSwitch == false) {
  617. averageMonthPrice = [IAPProductsManager defaultManager].newlyMonthProduct.averagePrice;
  618. monthPrice = [IAPProductsManager defaultManager].newlyMonthProduct.price;
  619. averageMonthPrice_discount = [IAPProductsManager defaultManager].newlyMonthProduct.discountAveragePrice;
  620. monthPrice_discount = [IAPProductsManager defaultManager].newlyMonthProduct.discountPrice;
  621. } else {
  622. averageMonthPrice = [IAPProductsManager defaultManager].yearProduct.averagePrice;
  623. monthPrice = [IAPProductsManager defaultManager].yearProduct.price;
  624. averageMonthPrice_discount = [IAPProductsManager defaultManager].yearProduct.discountAveragePrice;
  625. monthPrice_discount = [IAPProductsManager defaultManager].yearProduct.discountPrice;
  626. }
  627. self.topButtonOffset.constant = 10;
  628. }
  629. if ([IAPProductsManager defaultManager].allAccessProduct.isOffers) {
  630. self.topButtonOffset.constant = 20;
  631. self.specialView.hidden = NO;
  632. allPrice = [IAPProductsManager defaultManager].allAccessProduct.offersPrice;
  633. } else {
  634. self.topButtonOffset.constant = 10;
  635. self.specialView.hidden = YES;
  636. allPrice = [IAPProductsManager defaultManager].allAccessProduct.price;
  637. }
  638. CGFloat off = 1 -[IAPProductsManager defaultManager].allAccessProduct.offers;
  639. NSString *offString = [NSString stringWithFormat:@"%.f%%",off * 100];
  640. self.specialLabel.stringValue = [NSString stringWithFormat:NSLocalizedString(@"%@ off", @""),offString];
  641. if (self.isPurchaseSwitch) {
  642. off = 1 -[IAPProductsManager defaultManager].yearProduct.offers;
  643. } else {
  644. off = 1 -[IAPProductsManager defaultManager].newlyMonthProduct.offers;
  645. }
  646. offString = [NSString stringWithFormat:@"%.f%%",off * 100];
  647. self.specialLabel1.stringValue = [NSString stringWithFormat:NSLocalizedString(@"%@ off", @""),offString];
  648. NSImage *image = [NSImage imageNamed:@"KMImageNameCompareTagBG"];
  649. self.specialImageView.image = image;
  650. self.specialImageView1.image = image;
  651. BOOL isShowSale = [self isShowSale];
  652. if (KMKdanRemoteConfig.remoteConfig.showAPP_AveragePrice) {
  653. if (isShowSale) {
  654. self.value1PurchaseLabel.stringValue = [NSString stringWithFormat:@"%@/%@", averageMonthPrice_discount, NSLocalizedString(@"mon", nil)];
  655. self.value1PurchaseOriPriceLbl.stringValue = [NSString stringWithFormat:@"%@/%@", averageMonthPrice, NSLocalizedString(@"mon", nil)];
  656. self.value1PurchaseOriPriceLbl.hidden = false;
  657. self.billedTopConst.constant = 16;
  658. } else {
  659. self.value1PurchaseLabel.stringValue = [NSString stringWithFormat:@"%@/%@", averageMonthPrice, NSLocalizedString(@"mon", nil)];
  660. self.value1PurchaseOriPriceLbl.hidden = true;
  661. self.billedTopConst.constant = 0;
  662. }
  663. } else {
  664. if (self.isPurchaseSwitch) {
  665. if (isShowSale) {
  666. self.value1PurchaseLabel.stringValue = [NSString stringWithFormat:@"%@/%@", monthPrice_discount, NSLocalizedString(@"12 months", nil)];
  667. self.value1PurchaseOriPriceLbl.stringValue = [NSString stringWithFormat:@"%@/%@", monthPrice, NSLocalizedString(@"12 months", nil)];
  668. self.value1PurchaseOriPriceLbl.hidden = false;
  669. self.billedTopConst.constant = 16;
  670. } else {
  671. self.value1PurchaseLabel.stringValue = [NSString stringWithFormat:@"%@/%@", monthPrice, NSLocalizedString(@"12 months", nil)];
  672. self.value1PurchaseOriPriceLbl.hidden = true;
  673. self.billedTopConst.constant = 0;
  674. }
  675. } else {
  676. if (isShowSale) {
  677. self.value1PurchaseLabel.stringValue = [NSString stringWithFormat:@"%@/%@", monthPrice_discount, NSLocalizedString(@"6mon", nil)];
  678. self.value1PurchaseOriPriceLbl.stringValue = [NSString stringWithFormat:@"%@/%@", monthPrice, NSLocalizedString(@"6mon", nil)];
  679. self.value1PurchaseOriPriceLbl.hidden = false;
  680. self.billedTopConst.constant = 16;
  681. } else {
  682. self.value1PurchaseLabel.stringValue = [NSString stringWithFormat:@"%@/%@", monthPrice, NSLocalizedString(@"6mon", nil)];
  683. self.value1PurchaseOriPriceLbl.hidden = true;
  684. self.billedTopConst.constant = 0;
  685. }
  686. }
  687. }
  688. self.value1PurchaseLabel.textColor = [NSColor colorWithRed:1 green:231/255. blue:106/255. alpha:1.];
  689. self.value1PurchaseOriPriceLbl.textColor = [NSColor colorWithWhite:1 alpha:0.7];
  690. self.value1PurchaseOriPriceLbl.attributedStringValue = [[NSAttributedString alloc] initWithString:self.value1PurchaseOriPriceLbl.stringValue attributes:@{
  691. NSFontAttributeName : [NSFont SFProTextRegularFont:12],
  692. NSForegroundColorAttributeName: [NSColor colorWithWhite:1 alpha:0.7],
  693. NSStrikethroughStyleAttributeName : @(1)
  694. }];
  695. NSString *tTips = @"";
  696. if (isShowSale) {
  697. tTips = [NSString stringWithFormat:NSLocalizedString(@"%@ for the first 6-month subscription", nil), monthPrice_discount];
  698. } else {
  699. tTips = [NSString stringWithFormat:NSLocalizedString(@"Billed every 6 months at %@", nil), monthPrice];
  700. }
  701. if ([self.value1PurchaseBtnLbl.stringValue isEqualToString:NSLocalizedString(@"Free Trial", nil)]) {
  702. tTips = [NSString stringWithFormat:NSLocalizedString(@"Billed every 6 months at %@ after 7-day trial ends.", nil), monthPrice];
  703. #if !VERSION_DMG
  704. if (self.isPurchaseSwitch) {
  705. if ([IAPProductsManager defaultManager].yearProduct.product) {
  706. if (@available(macOS 10.13.2, *)) {
  707. tTips = [NSString stringWithFormat:NSLocalizedString(@"Billed every 12 months at %@ after %@-day trial ends.", nil), monthPrice,@([IAPProductsManager defaultManager].yearProduct.product.introductoryPrice.subscriptionPeriod.numberOfUnits)];
  708. }
  709. }
  710. } else {
  711. if ([IAPProductsManager defaultManager].newlyMonthProduct.product) {
  712. if (@available(macOS 10.13.2, *)) {
  713. tTips = [NSString stringWithFormat:NSLocalizedString(@"Billed every 6 months at %@ after %@-day trial ends.", nil), monthPrice,@([IAPProductsManager defaultManager].newlyMonthProduct.product.introductoryPrice.subscriptionPeriod.numberOfUnits)];
  714. }
  715. }
  716. }
  717. #endif
  718. }
  719. if (@available(macOS 10.13.2, *)) {
  720. #if !VERSION_DMG
  721. if (self.isPurchaseSwitch) {
  722. if (![IAPProductsManager defaultManager].yearProduct.product.introductoryPrice) {
  723. if (isShowSale) {
  724. tTips = [NSString stringWithFormat:NSLocalizedString(@"%@ for the first year's subscription", nil), monthPrice_discount];
  725. } else {
  726. tTips = [NSString stringWithFormat:NSLocalizedString(@"Billed every 12 months at %@", nil), monthPrice];
  727. }
  728. }
  729. } else {
  730. if (![IAPProductsManager defaultManager].newlyMonthProduct.product.introductoryPrice) {
  731. if (isShowSale) {
  732. tTips = [NSString stringWithFormat:NSLocalizedString(@"%@ for the first 6-month subscription", nil), monthPrice_discount];
  733. } else {
  734. tTips = [NSString stringWithFormat:NSLocalizedString(@"Billed every 6 months at %@", nil), monthPrice];
  735. }
  736. }
  737. }
  738. #endif
  739. }
  740. self.value1PurchaseSubLabel.stringValue = [NSString stringWithFormat:NSLocalizedString(@"%@", nil), tTips];
  741. self.value2PurchaseLabel.stringValue = allPrice?:@"";
  742. self.value2PurchaseLabel.textColor = [NSColor colorWithRed:1 green:231/255. blue:106/255. alpha:1.];
  743. self.value2PurchaseSubLabel.stringValue = NSLocalizedString(@"one-time purchase", nil);
  744. self.value3PurchaseLabel.stringValue = NSLocalizedString(@"USD $59.99", nil);
  745. self.value3PurchaseLabel.textColor = [NSColor colorWithRed:1 green:231/255. blue:106/255. alpha:1.];
  746. self.value3PurchaseSubLabel.stringValue = NSLocalizedString(@"one-time purchase", nil);
  747. self.value1PurchaseBtnLbl.font = [NSFont UbuntuBoldFontWithSize:16];
  748. self.value2PurchaseLbl.font = [NSFont UbuntuBoldFontWithSize:16];
  749. self.value3PurchaseBtnLbl.font = [NSFont UbuntuBoldFontWithSize:16];
  750. self.value1PurchaseLabel.font = [NSFont UbuntuBoldFontWithSize:22];
  751. self.value2PurchaseLabel.font = [NSFont UbuntuBoldFontWithSize:22];
  752. self.value3PurchaseLabel.font = [NSFont UbuntuBoldFontWithSize:22];
  753. self.value1PurchaseOriPriceLbl.font = [NSFont SFProTextRegularFont:12];
  754. }
  755. - (void)reloadDataContent {
  756. if (self.isPurchaseSwitch) {
  757. self.dataSource = @[@"PDF to Office",
  758. @[@"Convert PDFs to Word, HTML, TXT, JPEG or PNG files",@"Only first 10 pages",@"Advanced",@"Advanced",@"Standard"],
  759. @[@"Turn PDF to PPT, Excel, RTF, CSV, and more",@"Only first 10 pages",@"✓",@"✓",@"Only first 10 pages"],
  760. @[@"Convert PDF to TIFF, BMP, GIF or TGA files",@"Only first 10 pages",@"✓",@"✓",@"Only first 10 pages"],
  761. @"Edit PDF",
  762. @[@"Add and edit text in PDF",@"X",@"✓",@"✓",@"✓"],
  763. @[@"Edit, crop, replace image in PDF",@"X",@"✓",@"✓",@"✓"],
  764. @"OCR",
  765. @[@"Extract texts from image-based or scanned PDF",@"X",@"✓",@"✓",@"✓"],
  766. @"Organize Pages",
  767. @[@"Extract, rotate, rearrange, replace, add, delete pages",@"X",@"✓",@"✓",@"✓"],
  768. @[@"Split PDFs into multiple files",@"X",@"✓",@"✓",@"✓"],
  769. @"Advanced Editing Tools",
  770. @[@"Merge multiple documents into a new PDF",@"Up to 2 files or 20 MB",@"✓",@"∞",@"∞"],
  771. @[@"Add & edit watermark",@"X",@"✓",@"✓",@"✓"],
  772. @[@"Add header, footer, page numbers",@"X",@"✓",@"✓",@"✓"],
  773. @[@"Add Bates Number",@"X",@"✓",@"✓",@"✓"],
  774. @[@"Insert PDF page background by color or image",@"X",@"✓",@"✓",@"✓"],
  775. @[@"Create fattened copies",@"X",@"✓",@"✓",@"✓"],
  776. @[@"Extract Images",@"X",@"✓",@"✓",@"✓"],
  777. @[@"Extract tables",@"Only first 10 pages",@"✓",@"✓",@"Only first 10 pages"],
  778. @[@"Measuring Tools",@"X",@"✓",@"✓",@"✓"],
  779. @"Fill & Sign",
  780. @[@"Create digital signature",@"X",@"✓",@"✓",@"✓"],
  781. @[@"Create & Edit & Fill Adobe Fillable PDF Forms",@"X",@"✓",@"✓",@"✓"],
  782. @"Security",
  783. @[@"Batch encrypting PDF documents",@"X",@"✓",@"✓",@"✓"],
  784. @[@"PDF Password Remover",@"X",@"✓",@"✓",@"✓"],
  785. @[@"Redact sensitive information",@"X",@"✓",@"✓",@"✓"],
  786. @"Create PDF",
  787. @[@"Convert JPEG, JPG, PNG, TIFF, BMP or PSD files to PDFs",@"1 file",@"✓",@"✓",@"✓"],
  788. @[@"Create PDFs from a scanner and iOS devices",@"X",@"✓",@"✓",@"✓"],
  789. @"Annotations",
  790. @[@"Customize PDF stamps",@"X",@"✓",@"✓",@"✓",@"✓"],
  791. @[@"Hyperlink",@"Page Number",@"Page Number, URL, Email",@"Page Number, URL, Email",@"Page Number, URL, Email"],
  792. @[@"Signature",@"Standard",@"Advanced",@"Advanced",@"Advanced"],
  793. @[@"Table",@"X",@"✓",@"✓",@"✓",@"✓"],
  794. @"View PDF",
  795. @[@"Multi-tab viewer",@"X",@"✓",@"✓",@"✓"],
  796. @[@"Various printing types: poster, booklet, multi-page printing",@"X",@"✓",@"✓",@"✓"],
  797. @[@"Customize theme colors: Light Mode, Dark Mode, Sepia Mode and more",@"X",@"✓",@"✓",@"✓"],
  798. @[@"Split View to compare files",@"X",@"✓",@"✓",@"✓"],
  799. @"Subscription Based Solution",
  800. @[@"Access all premium features in app",@"X",@"12 months",@"∞",@"∞"],
  801. @[@"Priority customer support",@"X",@"✓",@"✓",@"✓"],
  802. @[@"Ad-free",@"X",@"✓",@"✓",@"✓"],
  803. @{}
  804. ];
  805. } else {
  806. self.dataSource = @[@"PDF to Office",
  807. @[@"Convert PDFs to Word, HTML, TXT, JPEG or PNG files",@"Only first 10 pages",@"Advanced",@"Advanced",@"Standard"],
  808. @[@"Turn PDF to PPT, Excel, RTF, CSV, and more",@"Only first 10 pages",@"✓",@"✓",@"Only first 10 pages"],
  809. @[@"Convert PDF to TIFF, BMP, GIF or TGA files",@"Only first 10 pages",@"✓",@"✓",@"Only first 10 pages"],
  810. @"Edit PDF",
  811. @[@"Add and edit text in PDF",@"X",@"✓",@"✓",@"✓"],
  812. @[@"Edit, crop, replace image in PDF",@"X",@"✓",@"✓",@"✓"],
  813. @"OCR",
  814. @[@"Extract texts from image-based or scanned PDF",@"X",@"✓",@"✓",@"✓"],
  815. @"Organize Pages",
  816. @[@"Extract, rotate, rearrange, replace, add, delete pages",@"X",@"✓",@"✓",@"✓"],
  817. @[@"Split PDFs into multiple files",@"X",@"✓",@"✓",@"✓"],
  818. @"Advanced Editing Tools",
  819. @[@"Merge multiple documents into a new PDF",@"Up to 2 files or 20 MB",@"✓",@"∞",@"∞"],
  820. @[@"Add & edit watermark",@"X",@"✓",@"✓",@"✓"],
  821. @[@"Add header, footer, page numbers",@"X",@"✓",@"✓",@"✓"],
  822. @[@"Add Bates Number",@"X",@"✓",@"✓",@"✓"],
  823. @[@"Insert PDF page background by color or image",@"X",@"✓",@"✓",@"✓"],
  824. @[@"Create fattened copies",@"X",@"✓",@"✓",@"✓"],
  825. @[@"Extract Images",@"X",@"✓",@"✓",@"✓"],
  826. @[@"Extract tables",@"Only first 10 pages",@"✓",@"✓",@"Only first 10 pages"],
  827. @[@"Measuring Tools",@"X",@"✓",@"✓",@"✓"],
  828. @"Fill & Sign",
  829. @[@"Create digital signature",@"X",@"✓",@"✓",@"✓"],
  830. @[@"Create & Edit & Fill Adobe Fillable PDF Forms",@"X",@"✓",@"✓",@"✓"],
  831. @"Security",
  832. @[@"Batch encrypting PDF documents",@"X",@"✓",@"✓",@"✓"],
  833. @[@"PDF Password Remover",@"X",@"✓",@"✓",@"✓"],
  834. @[@"Redact sensitive information",@"X",@"✓",@"✓",@"✓"],
  835. @"Create PDF",
  836. @[@"Convert JPEG, JPG, PNG, TIFF, BMP or PSD files to PDFs",@"1 file",@"✓",@"✓",@"✓"],
  837. @[@"Create PDFs from a scanner and iOS devices",@"X",@"✓",@"✓",@"✓"],
  838. @"Annotations",
  839. @[@"Customize PDF stamps",@"X",@"✓",@"✓",@"✓",@"✓"],
  840. @[@"Hyperlink",@"Page Number",@"Page Number, URL, Email",@"Page Number, URL, Email",@"Page Number, URL, Email"],
  841. @[@"Signature",@"Standard",@"Advanced",@"Advanced",@"Advanced"],
  842. @[@"Table",@"X",@"✓",@"✓",@"✓",@"✓"],
  843. @"View PDF",
  844. @[@"Multi-tab viewer",@"X",@"✓",@"✓",@"✓"],
  845. @[@"Various printing types: poster, booklet, multi-page printing",@"X",@"✓",@"✓",@"✓"],
  846. @[@"Customize theme colors: Light Mode, Dark Mode, Sepia Mode and more",@"X",@"✓",@"✓",@"✓"],
  847. @[@"Split View to compare files",@"X",@"✓",@"✓",@"✓"],
  848. @"Subscription Based Solution",
  849. @[@"Access all premium features in app",@"X",@"6 months",@"∞",@"∞"],
  850. @[@"Priority customer support",@"X",@"✓",@"✓",@"✓"],
  851. @[@"Ad-free",@"X",@"✓",@"✓",@"✓"],
  852. @{}
  853. ];
  854. }
  855. [self.tableView reloadData];
  856. }
  857. - (void)addWaingView:(NSView *)view {
  858. [self removeWaitingView:view];
  859. WaitingView *wView = [[WaitingView alloc] initWithFrame:view.bounds];
  860. [wView setAutoresizingMask:NSViewWidthSizable|NSViewHeightSizable];
  861. [view addSubview:wView];
  862. [wView startAnimation];
  863. }
  864. - (void)removeWaitingView:(NSView *)view {
  865. for (id v in view.subviews) {
  866. if ([[v class] isSubclassOfClass:[WaitingView class]]) {
  867. [v removeFromSuperview];
  868. break;
  869. }
  870. }
  871. }
  872. - (void)updateViewColor {
  873. self.box.fillColor = [KMAppearance KMColor_Layout_L1];
  874. self.labelbox.fillColor = [NSColor clearColor];
  875. self.tableView.backgroundColor = [KMAppearance KMColor_Layout_L0];
  876. self.textView.backgroundColor = [NSColor clearColor];
  877. self.textView.textColor = [[NSColor whiteColor] colorWithAlphaComponent:0.5];
  878. self.value1PurchaseSubLabel.textColor = self.value2PurchaseSubLabel.textColor = self.value3PurchaseSubLabel.textColor = [KMAppearance KMColor_Layout_W0];
  879. }
  880. - (BOOL)isCancelAutoRenew {
  881. return [[IAPProductsManager defaultManager] isCancelAutoRenew];
  882. }
  883. - (BOOL)isShowSale {
  884. if (@available(macOS 10.14.4, *)) {
  885. if ([self isCancelAutoRenew]) {
  886. BOOL isSubscribed = [IAPProductsManager defaultManager].newlyMonthProduct.isSubscribed;
  887. if (isSubscribed) {
  888. return false;
  889. }
  890. isSubscribed = [IAPProductsManager defaultManager].yearProduct.isSubscribed;
  891. if (isSubscribed) {
  892. return false;
  893. }
  894. KMAdvertisementItemInfo *info = KMAdvertisementManager.manager.info.StoreUserRecovery.content.firstObject;
  895. if ([info.show boolValue] == false) { // 活动结束
  896. return false;
  897. }
  898. return true;
  899. }
  900. }
  901. return false;
  902. }
  903. #pragma mark - Button Actions
  904. - (IBAction)buttonItemClicked_Subscribe:(id)sender {
  905. if (self.isPurchaseSwitch) {
  906. [[IAPProductsManager defaultManager] makeSubProduct:[IAPProductsManager defaultManager].yearProduct discount:[self isCancelAutoRenew]];
  907. } else {
  908. [[IAPProductsManager defaultManager] makeSubProduct:[IAPProductsManager defaultManager].newlyMonthProduct discount:[self isCancelAutoRenew]];
  909. }
  910. [self addWaingView:self.window.contentView];
  911. [[FMTrackEventManager defaultManager] trackEventWithEvent:@"PUW" withProperties:@{@"PUW_Btn":@"PUW_Btn_Upgrade_6Mon"}];
  912. if ([self isShowSale]) {
  913. self.kEventTag = 1;
  914. if (self.isPurchaseSwitch) {
  915. [self trackEvent_freeWithEventName:@"PromotionalOffer" params:@{@"PUW_Btn" : @"PUW_7OffUpgrade_12Mon"} platform:KMAnalyticsPlatformAppCenter];
  916. } else {
  917. [self trackEvent_freeWithEventName:@"PromotionalOffer" params:@{@"PUW_Btn" : @"PUW_7OffUpgrade_6Mon"} platform:KMAnalyticsPlatformAppCenter];
  918. }
  919. }
  920. }
  921. - (void)showDiscountToSaveWindow {
  922. if ([KMDiscountToSaveWindowController needShow] == false) {
  923. return;
  924. }
  925. KMAdvertisementItemInfo *info = KMAdvertisementManager.manager.info.StoreUserRecovery.content.firstObject;
  926. NSURL *url = [NSURL URLWithString: [KMAdvertisementModelTransition transitionImagePathWithImage:info.image highlight: YES]];
  927. __weak typeof(self) weakSelf = self;
  928. [self addWaingView:self.window.contentView];
  929. [KMAdvertisementImage imageWithURLWithUrl:url completion:^(NSImage *image) {
  930. [weakSelf removeWaitingView:weakSelf.window.contentView];
  931. if (image == nil) {
  932. return;
  933. }
  934. [self trackEvent_freeWithEventName:@"PromotionalOffer" params:@{@"PUW_Exposure" : @"PUW_PromotionalOffer"} platform:KMAnalyticsPlatformAppCenter];
  935. KMDiscountToSaveWindowController *winC = [[KMDiscountToSaveWindowController alloc] initWithWindowNibName:@"KMDiscountToSaveWindowController"];
  936. weakSelf.discountToSaveWinC = winC;
  937. [weakSelf.window beginSheet:winC.window completionHandler:^(NSModalResponse returnCode) { }];
  938. winC.imgIv.image = image;
  939. winC.itemClick = ^(NSInteger idx) {
  940. [weakSelf.window endSheet:weakSelf.discountToSaveWinC.window];
  941. weakSelf.discountToSaveWinC = nil;
  942. if (idx == 2) { // 订阅
  943. //// NSLog(@"buttonItemClicked_Subscribe");
  944. [weakSelf trackEvent_freeWithEventName:@"PromotionalOffer" params:@{@"PUW_Btn" : @"PUW_PromotionalOffer_Subscribe"} platform:KMAnalyticsPlatformAppCenter];
  945. } else if (idx == 1) {
  946. [weakSelf trackEvent_freeWithEventName:@"PromotionalOffer" params:@{@"PUW_Btn" : @"PUW_PromotionalOffer_Cancel"} platform:KMAnalyticsPlatformAppCenter];
  947. }
  948. };
  949. }];
  950. }
  951. - (IBAction)buttonItemClicked_Restore:(id)sender {
  952. [[IAPProductsManager defaultManager] restoreSubscriptions];
  953. [self addWaingView:self.window.contentView];
  954. }
  955. - (IBAction)buttonItemClicked_Upgrade:(id)sender {
  956. [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:@"macappstore://apps.apple.com/app/id825459243?mt=12"]];
  957. [[FMTrackEventManager defaultManager] trackEventWithEvent:@"PUW" withProperties:@{@"PUW_Btn":@"PUW_Btn_Upgrade_Premium"}];
  958. }
  959. - (IBAction)privacyPolicyAction:(NSButton *)sender {
  960. [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:@"https://www.pdfreaderpro.com/privacy-policy"]];
  961. }
  962. - (IBAction)termOfSerAction:(NSButton *)sender {
  963. [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:@"https://www.pdfreaderpro.com/terms_of_service"]];
  964. }
  965. - (IBAction)buttonItemClicked_LicenseUpgrade:(id)sender {
  966. [[IAPProductsManager defaultManager] makeProduct:[IAPProductsManager defaultManager].allAccessProduct];
  967. [self addWaingView:self.window.contentView];
  968. [[FMTrackEventManager defaultManager] trackEventWithEvent:@"PUW" withProperties:@{@"PUW_Btn":@"PUW_Btn_Upgrade_Permanent"}];
  969. }
  970. - (IBAction)buttonItemClicked_AboutSubscriptions:(id)sender {
  971. NSString *tMessage = [NSString stringWithFormat:@"%@\n%@\n\n%@\n%@\n%@\n%@\n%@\n\n%@\n%@\n\n",
  972. @"Subscription plans: ",
  973. @"Subscriptions: USD $39.99/(6 months), USD $79.99/(one-time purchase) ",
  974. @"- Subscriptions will be charged through your iTunes account at the confirmation of purchase. ",
  975. @"- Your subscriptions will automatically renew unless cancelled at least 24 hours before the end of current subscription period. ",
  976. @"- 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. ",
  977. @"- You may manage your subscriptions in your iTunes Account Settings after purchase. ",
  978. @"- No cancellation of the current subscription is allowed during an active subscription period. ",
  979. @"- Terms of service: \nhttps://www.pdfreaderpro.com/terms_of_service ",
  980. @"- Privacy Policy: \nhttps://www.pdfreaderpro.com/privacy-policy "];
  981. NSAlert *alert = [[NSAlert alloc] init];
  982. [alert setAlertStyle:NSAlertStyleInformational];
  983. [alert setMessageText:NSLocalizedString(tMessage, nil)];
  984. [alert runModal];
  985. }
  986. - (IBAction)buttonItemClicked_CloseWindow:(id)sender {
  987. [self close];
  988. }
  989. - (void)switchAction:(NSButton *)sender {
  990. // NSControlStateValue state = self.switchBtn.state;
  991. BOOL isSwitch = self.isPurchaseSwitch;
  992. if (isSwitch) {
  993. // self.switchBtn.state = NSControlStateValueOff;
  994. self.isPurchaseSwitch = false;
  995. // self.switchCircleLeftConst.constant = 4;
  996. } else {
  997. // self.switchBtn.state = NSControlStateValueOn;
  998. self.isPurchaseSwitch = true;
  999. // self.switchCircleLeftConst.constant = 22;
  1000. }
  1001. // if (self.isPurchaseSwitch) { // 一年
  1002. //
  1003. // } else { // 半年
  1004. //
  1005. // }
  1006. [self reloadDataContent];
  1007. [self reloadData];
  1008. }
  1009. #pragma mark - NSTableViewDataSource Methods
  1010. - (NSInteger)numberOfRowsInTableView:(NSTableView *)aTableView {
  1011. return self.dataSource.count;
  1012. }
  1013. - (id)tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row {
  1014. id object = [self.dataSource objectAtIndex:row];
  1015. if ([object isKindOfClass:[NSString class]]) {
  1016. KMPurchaseCompareHeaderCell *cellView = [tableView makeViewWithIdentifier:KMPurchaseCompareHeaderCellIdentifier owner:self];
  1017. cellView.textField.stringValue = NSLocalizedString(object, nil);
  1018. return cellView;
  1019. } else if ([object isKindOfClass:[NSArray class]]) {
  1020. KMPurchaseCompareCell *cellView = [tableView makeViewWithIdentifier:KMPurchaseCompareCellIdentifier owner:self];
  1021. NSString *value = [(NSArray *)object count] > 0 ? object[0] : @"";
  1022. NSString *value1 = [(NSArray *)object count] > 1 ? object[1] : @"";
  1023. NSString *value2 = [(NSArray *)object count] > 2 ? object[2] : @"";
  1024. NSString *value3 = [(NSArray *)object count] > 3 ? object[3] : @"";
  1025. NSString *value4 = [(NSArray *)object count] > 4 ? object[4] : @"";
  1026. cellView.textField.stringValue = NSLocalizedString(value, nil);
  1027. cellView.lineBox.hidden = NO;
  1028. if (row + 1 == (NSInteger)self.dataSource.count) {
  1029. cellView.lineBox.hidden = YES;
  1030. } else {
  1031. id nextobject = [self.dataSource objectAtIndex:row+1];
  1032. if ([nextobject isKindOfClass:[NSString class]]) {
  1033. cellView.lineBox.hidden = YES;
  1034. }
  1035. }
  1036. if (row + 2 == (NSInteger)self.dataSource.count) {
  1037. cellView.boxBottomConst.constant = 0;
  1038. } else {
  1039. cellView.boxBottomConst.constant = -4;
  1040. }
  1041. if ([value1 isEqualToString:@"X"]) {
  1042. cellView.value1Label.stringValue = @"";
  1043. cellView.value1ImageView.image = [NSImage imageNamed:@"compare_nosupport"];
  1044. } else if ([value1 isEqualToString:@"✓"]) {
  1045. cellView.value1Label.stringValue = @"";
  1046. cellView.value1ImageView.image = [NSImage imageNamed:@"compare_support"];
  1047. } else if ([value1 isEqualToString:@"∞"]) {
  1048. cellView.value1Label.stringValue = @"";
  1049. cellView.value1ImageView.image = [NSImage imageNamed:@"compare_00"];
  1050. } else {
  1051. cellView.value1Label.stringValue = NSLocalizedString(value1, nil);
  1052. cellView.value1ImageView.image = nil;
  1053. }
  1054. if ([value2 isEqualToString:@"X"]) {
  1055. cellView.value2Label.stringValue = @"";
  1056. cellView.value2ImageView.image = [NSImage imageNamed:@"compare_nosupport"];
  1057. } else if ([value2 isEqualToString:@"✓"]) {
  1058. cellView.value2Label.stringValue = @"";
  1059. cellView.value2ImageView.image = [NSImage imageNamed:@"compare_support"];
  1060. } else if ([value2 isEqualToString:@"∞"]) {
  1061. cellView.value2Label.stringValue = @"";
  1062. cellView.value2ImageView.image = [NSImage imageNamed:@"compare_00"];
  1063. } else {
  1064. cellView.value2Label.stringValue = NSLocalizedString(value2, nil);
  1065. cellView.value2ImageView.image = nil;
  1066. }
  1067. if ([value3 isEqualToString:@"X"]) {
  1068. cellView.value3Label.stringValue = @"";
  1069. cellView.value3ImageView.image = [NSImage imageNamed:@"compare_nosupport"];
  1070. } else if ([value3 isEqualToString:@"✓"]) {
  1071. cellView.value3Label.stringValue = @"";
  1072. cellView.value3ImageView.image = [NSImage imageNamed:@"compare_support"];
  1073. } else if ([value3 isEqualToString:@"∞"]) {
  1074. cellView.value3Label.stringValue = @"";
  1075. cellView.value3ImageView.image = [NSImage imageNamed:@"compare_00"];
  1076. } else {
  1077. cellView.value3Label.stringValue = NSLocalizedString(value3, nil);
  1078. cellView.value3ImageView.image = nil;
  1079. }
  1080. if ([value4 isEqualToString:@"X"]) {
  1081. cellView.value4Label.stringValue = @"";
  1082. cellView.value4ImageView.image = [NSImage imageNamed:@"compare_nosupport"];
  1083. } else if ([value4 isEqualToString:@"✓"]) {
  1084. cellView.value4Label.stringValue = @"";
  1085. cellView.value4ImageView.image = [NSImage imageNamed:@"compare_support"];
  1086. } else if ([value4 isEqualToString:@"∞"]) {
  1087. cellView.value4Label.stringValue = @"";
  1088. cellView.value4ImageView.image = [NSImage imageNamed:@"compare_00"];
  1089. } else {
  1090. cellView.value4Label.stringValue = NSLocalizedString(value4, nil);
  1091. cellView.value4ImageView.image = nil;
  1092. }
  1093. return cellView;
  1094. } else if ([object isKindOfClass:[NSDictionary class]]) {
  1095. KMPurchaseCompareEmptyCell *cellView = [tableView makeViewWithIdentifier:KMPurchaseCompareEmptyCellIdentifier owner:self];
  1096. return cellView;
  1097. }
  1098. return nil;
  1099. }
  1100. - (CGFloat)tableView:(NSTableView *)tableView heightOfRow:(NSInteger)row {
  1101. NSTableCellView *cellView = nil;
  1102. id object = [self.dataSource objectAtIndex:row];
  1103. if ([object isKindOfClass:[NSString class]]) {
  1104. cellView = [tableView makeViewWithIdentifier:KMPurchaseCompareHeaderCellIdentifier owner:self];
  1105. cellView.textField.stringValue = NSLocalizedString(object, nil);
  1106. } else if ([object isKindOfClass:[NSArray class]]) {
  1107. cellView = [tableView makeViewWithIdentifier:KMPurchaseCompareCellIdentifier owner:self];
  1108. cellView.textField.stringValue = NSLocalizedString(object[0], nil);
  1109. } else if ([object isKindOfClass:[NSDictionary class]]) {
  1110. return 40;
  1111. }
  1112. if (cellView) {
  1113. [cellView layoutSubtreeIfNeeded];
  1114. return cellView.frame.size.height;
  1115. } else {
  1116. return 0;
  1117. }
  1118. }
  1119. #pragma mark - InAppPurchaseManager Notification
  1120. - (void)IAPProductFailedNotification:(NSNotification*)notification {
  1121. [self removeWaitingView:self.window.contentView];
  1122. }
  1123. - (void)IAPProductPurchasedNotification:(NSNotification*)notification {
  1124. [self removeWaitingView:self.window.contentView];
  1125. [self reloadData];
  1126. if (IAPProductsManager.defaultManager.newlyMonthProduct.isSubscribed) {
  1127. if (self.kEventTag == 1) {
  1128. [self trackEvent_freeWithEventName:@"PromotionalOffer" params:@{@"PUW_Btn" : @"PUW_7OffUpgrade_6MonthPaid"} platform:KMAnalyticsPlatformAppCenter];
  1129. }
  1130. } else if (IAPProductsManager.defaultManager.yearProduct.isSubscribed) {
  1131. if (self.kEventTag == 1) {
  1132. [self trackEvent_freeWithEventName:@"PromotionalOffer" params:@{@"PUW_Btn" : @"PUW_7OffUpgrade_12MonthPaid"} platform:KMAnalyticsPlatformAppCenter];
  1133. }
  1134. }
  1135. }
  1136. - (void)IAPProductLoadedNotification:(NSNotification*)notification {
  1137. [self reloadData];
  1138. }
  1139. - (void)IAPProductRestoreFinishedNotification:(NSNotification *)notification {
  1140. [self removeWaitingView:self.window.contentView];
  1141. [self reloadData];
  1142. }
  1143. - (void)IAPProductRestoreFailedNotification:(NSNotification *)notification {
  1144. [self removeWaitingView:self.window.contentView];
  1145. }
  1146. - (void)IAPSubscriptionLoadedNotification:(NSNotification *)notification {
  1147. [self removeWaitingView:self.window.contentView];
  1148. [self reloadData];
  1149. }
  1150. @end