KMPurchaseCompareWindowController.m 66 KB

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