KMVerificationMessageViewController.m 56 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310
  1. //
  2. // KMVerificationMessageViewController.m
  3. // PDF Reader Pro Edition
  4. //
  5. // Created by 王帅 on 2018/5/9.
  6. //
  7. #import "KMVerificationMessageViewController.h"
  8. #import <PDF_Reader_Pro-Swift.h>
  9. #import "VerificationManager.h"
  10. #import "AIInfoManager.h"
  11. #import "KMVerificationWindowController.h"
  12. #import "KMUnlockAlertViewController.h"
  13. #import "KMMessageModel.h"
  14. #import "KMMessageItemView.h"
  15. #define kbottomGap 0
  16. @interface KMVerificationMessageViewController ()<
  17. NSPopoverDelegate>
  18. @property (nonatomic, assign) IBOutlet NSTextField *label;
  19. @property (nonatomic, assign) IBOutlet NSButton *button;
  20. @property (nonatomic, assign) IBOutlet NSButton *secondTrialBtn;
  21. @property (assign) IBOutlet NSView *labelContentView;
  22. @property (assign) IBOutlet NSImageView *bgImg;
  23. @property (assign) IBOutlet NSView *aiContendView;
  24. @property (assign) IBOutlet NSImageView *aiIconImg;
  25. @property (assign) IBOutlet NSTextField *aiLabel;
  26. @property (weak) IBOutlet NSButton *userButton;
  27. @property (assign) IBOutlet NSView *signUpView;
  28. @property (assign) IBOutlet NSImageView *signUpImg;
  29. @property (assign) IBOutlet NSTextField *signUpLabel;
  30. @property (weak) IBOutlet NSButton *officeButton;
  31. @property (assign) IBOutlet NSImageView *officeImg;
  32. @property (nonatomic, retain) NSTrackingArea *trackingArea;
  33. @property (nonatomic, retain) NSPopover *popover;
  34. @property (nonatomic, assign) BOOL isPopoverShow;
  35. @property (nonatomic, assign) BOOL checkValue;
  36. @property (nonatomic, assign) BOOL stopPopOverHide;
  37. @property (nonatomic, retain) KMUnlockAlertViewController *testVC;
  38. @property (nonatomic, retain) NSMenu *userMenu;
  39. // 远程按钮 最大宽度限制 100
  40. @property (nonatomic, assign) CGFloat remoteButtonMaxWidth;
  41. @property (nonatomic, strong) NSMutableArray *datas;
  42. @property (nonatomic, strong) KMMessageDiscountItemView *userGiftView;
  43. @property (nonatomic, strong) KMMessageDiscountItemView *discountItemView;
  44. @end
  45. @implementation KMVerificationMessageViewController
  46. #pragma mark Init Methods
  47. - (instancetype)init {
  48. if (self = [super initWithNibName:@"KMVerificationMessageViewController" bundle:nil]) {
  49. self.remoteButtonMaxWidth = 200;
  50. #if VERSION_DMG
  51. [[NSNotificationCenter defaultCenter] addObserver:self
  52. selector:@selector(deviceActivateStatusChangeNotification:)
  53. name:kDeviceActivateStatusChangeNotification
  54. object:nil];
  55. [[NSNotificationCenter defaultCenter] addObserver:self
  56. selector:@selector(deviceActivateStatusChangeNotification:)
  57. name:KMIAPSubscriptionLoadedNotification
  58. object:nil];
  59. #else
  60. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(IAPProductLoaded:) name:KMIAPProductLoadedNotification object:nil];
  61. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(IAPResultReceived:) name:KMIAPSubscriptionLoadedNotification object:nil];
  62. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(IAPPurchaseSuccess:) name:KMIAPProductPurchasedNotification object:nil];
  63. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(IAPRestoreFinish:) name:KMIAPProductRestoreFinishedNotification object:nil];
  64. #endif
  65. _datas = [NSMutableArray arrayWithCapacity:4];
  66. }
  67. return self;
  68. }
  69. - (void)dealloc {
  70. [[NSNotificationCenter defaultCenter] removeObserver:self];
  71. if (self.trackingArea) {
  72. [self.button removeTrackingArea:self.trackingArea];
  73. }
  74. }
  75. #pragma mark Setter Methods
  76. - (void)loadView {
  77. [super loadView];
  78. // Do view setup here.
  79. self.button.wantsLayer = YES;
  80. self.button.layer.masksToBounds = YES;
  81. self.button.layer.cornerRadius = 4.0;
  82. self.button.font = [NSFont SFProTextSemiboldFont:11];
  83. self.button.layer.backgroundColor = [NSColor colorWithDeviceRed:121.0/255.0 green:196.0/255.0 blue:66.0/255.0 alpha:1.0].CGColor;
  84. [self.button setAlignment:NSTextAlignmentCenter];
  85. self.userButton.font = [NSFont SFProTextSemiboldFont:11];
  86. self.secondTrialBtn.wantsLayer = YES;
  87. self.secondTrialBtn.layer.masksToBounds = YES;
  88. self.secondTrialBtn.layer.cornerRadius = 4.0;
  89. self.secondTrialBtn.font = [NSFont SFProTextSemiboldFont:11];
  90. self.secondTrialBtn.layer.backgroundColor = [NSColor colorWithDeviceRed:121.0/255.0 green:196.0/255.0 blue:66.0/255.0 alpha:1.0].CGColor;
  91. [self.secondTrialBtn setAlignment:NSTextAlignmentCenter];
  92. NSString *tTips = NSLocalizedString(@"Upgrade to Pro", nil);
  93. #if VERSION_DMG
  94. tTips = @"";
  95. #else
  96. tTips = [NSString stringWithFormat:@"%@", NSLocalizedString(@"Subscribe to All Access Pack to enjoy more expanded features.", nil)];
  97. #endif
  98. self.button.toolTip = tTips;
  99. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Upgrade", nil)];
  100. [self.button setTitleColor:[NSColor whiteColor]];
  101. [self.button setAlignment:NSTextAlignmentCenter];
  102. self.secondTrialBtn.toolTip = tTips;
  103. self.secondTrialBtn.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Free Trial", nil)];
  104. [self.secondTrialBtn setTitleColor:[NSColor whiteColor]];
  105. [self.secondTrialBtn setAlignment:NSTextAlignmentCenter];
  106. self.secondTrialBtn.hidden = YES;
  107. self.labelContentView.hidden = self.bgImg.hidden = self.button.hidden = NO;
  108. self.bgImg.wantsLayer = YES;
  109. self.bgImg.image = [NSImage imageNamed:@"Upgarde_bg_icon"];
  110. self.bgImg.layer.masksToBounds = YES;
  111. self.bgImg.layer.cornerRadius = 4.;
  112. self.bgImg.hidden = YES;
  113. self.aiLabel.font = [NSFont SFProTextSemiboldFont:11];
  114. self.aiLabel.textColor = [NSColor whiteColor];
  115. self.signUpView.wantsLayer = true;
  116. self.signUpView.layer.cornerRadius = 4;
  117. self.userGiftView = [[KMMessageDiscountItemView alloc] init];
  118. self.userGiftView.gradientColors = @[[NSColor colorWithRed:248/255.0 green:150/255.0 blue:90/255.0 alpha:1.0],
  119. [NSColor colorWithRed:253/255.0 green:113/255.0 blue:113/255.0 alpha:1.0]];
  120. self.userGiftView.radius = 4;
  121. self.userGiftView.titleLabel.font = [NSFont SFProTextBoldFont:11];
  122. self.userGiftView.titleLabel.textColor = NSColor.whiteColor;
  123. self.userGiftView.hidden = true;
  124. self.userGiftView.leftImageView.image = [NSImage imageNamed:@"NewUserGift"];
  125. self.userGiftView.kTarget = self;
  126. self.userGiftView.kAction = @selector(userGiftAction:);
  127. _discountItemView = [[KMMessageDiscountItemView alloc] init];
  128. _discountItemView.gradientColors = @[[NSColor colorWithRed:248/255.0 green:150/255.0 blue:90/255.0 alpha:1.0],
  129. [NSColor colorWithRed:253/255.0 green:113/255.0 blue:113/255.0 alpha:1.0]];
  130. _discountItemView.radius = 4;
  131. _discountItemView.titleLabel.font = [NSFont SFProTextBoldFont:11];
  132. _discountItemView.titleLabel.textColor = NSColor.whiteColor;
  133. _discountItemView.hidden = true;
  134. _discountItemView.leftImageView.image = [NSImage imageNamed:@"KMImageNameCancelSubscribeDiscount"];
  135. _discountItemView.kTarget = self;
  136. _discountItemView.kAction = @selector(discountAction:);
  137. [self reloadData];
  138. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(popoverShowNoti:) name:@"KMVerificationMessagePopShowNoti" object:nil];
  139. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(loginSuccessNotification:) name:@"MemberCenterLoginSuccess" object:nil];
  140. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(logoutSuccessNotification:) name:@"MemberCenterLogoutSuccess" object:nil];
  141. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(expandPersonalCenterNotification:) name:@"ExpandPersonalCenter" object:nil];
  142. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(closeMenu:) name:@"CloseMenuNotification" object:nil];
  143. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(memberInfoChangeNotification:) name:KMMemberInfoChangeNotification object:nil];
  144. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(subscriptionLoadedNotification:) name:KMIAPSubscriptionLoadedNotification object:nil];
  145. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(trailCancelStateDidChange:) name:@"KMTrailCancelStateDidChangeNotificationName" object:nil];
  146. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(advertisementDidLoaded:) name:@"KMAdvertisementDidLoadedNotification" object:nil];
  147. }
  148. // MARK: - Private Methods
  149. - (NSString *)_getAppStoreFreeVersionBuyNowTitle {
  150. return [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Purchase without Login", nil)];
  151. }
  152. - (NSString *)_getDiscountTitle {
  153. #if VERSION_DMG
  154. if ([NSLocalizedString(@"USD", "") isEqualToString:@"USD"]) {
  155. return [NSString stringWithFormat:NSLocalizedString(@"%@ Coupons", @""), @"$60"];
  156. } else {
  157. return [NSString stringWithFormat:NSLocalizedString(@"%@ Coupons", @""), @"¥360"];
  158. }
  159. #else
  160. BOOL showCNY = false;
  161. #if VERSION_FREE
  162. NSString *localeId = [IAPProductsManager defaultManager].allAccessPackPermanent_lite.product.priceLocale.localeIdentifier;
  163. if ([localeId containsString:@"zh_CN"] || [localeId containsString:@"zh_TW"] || [localeId containsString:@"zh-TW"]) {
  164. showCNY = true;
  165. }
  166. #endif
  167. if ([[KMCheckInManager default] trailCancel] || [[KMCheckInManager default] advancedYearSubscribeTrailCancelForLocal]) {
  168. if (showCNY == false) {
  169. // if ([NSLocalizedString(@"USD", "") isEqualToString:@"USD"]) {
  170. return [NSString stringWithFormat:NSLocalizedString(@"%@ Coupons", @""), @"USD 60"];
  171. } else {
  172. return [NSString stringWithFormat:NSLocalizedString(@"%@ Coupons", @""), @"¥360"];
  173. }
  174. } else {
  175. if ([[KMMemberInfo shared] isFreeAccount]) {
  176. if (showCNY == false) {
  177. // if ([NSLocalizedString(@"USD", "") isEqualToString:@"USD"]) {
  178. return [NSString stringWithFormat:NSLocalizedString(@"%@ Coupons", @""), @"USD 30"];
  179. } else {
  180. return [NSString stringWithFormat:NSLocalizedString(@"%@ Coupons", @""), @"¥180"];
  181. }
  182. } else {
  183. return @"";
  184. }
  185. }
  186. #endif
  187. }
  188. - (CGFloat)_calTextWidth:(NSString *)textString font:(NSFont *)font {
  189. NSMutableDictionary *attri = [NSMutableDictionary dictionary];
  190. if (font != nil) {
  191. [attri setObject:font forKey:NSFontAttributeName];
  192. }
  193. NSRect rect = [textString boundingRectWithSize:CGSizeMake(MAXFLOAT, 30) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading attributes:attri];
  194. return rect.size.width;
  195. }
  196. // 是否定向跳转比较表
  197. - (BOOL)_isNowGotoPurcahseTable {
  198. #if VERSION_FREE
  199. #if VERSION_DMG
  200. return false;
  201. #else
  202. // AppStore 免费版 有特定需求
  203. // 无本机权益 true,否则 false
  204. return IAPProductsManager.defaultManager.isAvailableAllFunction == false;
  205. #endif
  206. #else
  207. return false;
  208. #endif
  209. }
  210. - (CGFloat)_dealDiscountViewWithMessageType:(KMMessageType)messageType {
  211. KMMessageModel *newUserGiftModel = nil;
  212. KMMessageModel *discountModel = nil;
  213. for (KMMessageModel *model in self.datas) {
  214. if (model.type == KMMessageTypeNewUserGift) {
  215. newUserGiftModel = model;
  216. }
  217. if (model.type == KMMessageTypeDiscount) {
  218. discountModel = model;
  219. }
  220. }
  221. CGFloat discountWidth = 0;
  222. if (newUserGiftModel != nil && newUserGiftModel.show) {
  223. if (self.userGiftView.superview == nil) {
  224. [self.view addSubview:self.userGiftView positioned:NSWindowAbove relativeTo:self.button];
  225. }
  226. [self.userGiftView mas_remakeConstraints:^(MASConstraintMaker *make) {
  227. if (messageType == KMMessageTypeFreeTrail || messageType == KMMessageTypePurchaseWithoutLogin) {
  228. make.trailing.equalTo(self.button.mas_leading).mas_offset(-4);;
  229. } else {
  230. make.trailing.equalTo(self.button);
  231. }
  232. make.top.mas_equalTo(0);
  233. make.width.mas_equalTo(newUserGiftModel.viewWidth);
  234. make.height.equalTo(self.view);
  235. }];
  236. discountWidth = newUserGiftModel.viewWidth + 4;
  237. self.userGiftView.hidden = false;
  238. self.userGiftView.titleLabel.stringValue = newUserGiftModel.titleText;
  239. } else if (discountModel != nil && discountModel.show) {
  240. if (self.discountItemView.superview == nil) {
  241. [self.view addSubview:self.discountItemView positioned:NSWindowAbove relativeTo:self.button];
  242. }
  243. [self.discountItemView mas_remakeConstraints:^(MASConstraintMaker *make) {
  244. if (messageType == KMMessageTypeFreeTrail || messageType == KMMessageTypePurchaseWithoutLogin) {
  245. make.trailing.equalTo(self.button.mas_leading).mas_offset(-4);
  246. } else {
  247. make.trailing.equalTo(self.button);
  248. }
  249. make.top.mas_equalTo(0);
  250. make.width.mas_equalTo(discountModel.viewWidth);
  251. make.height.equalTo(self.view);
  252. }];
  253. discountWidth = discountModel.viewWidth + 4;
  254. self.discountItemView.hidden = false;
  255. _discountItemView.titleLabel.stringValue = discountModel.titleText;
  256. }
  257. return discountWidth;
  258. }
  259. - (KMMessageModel *)_createDiscountModelWithType:(KMMessageType)type {
  260. NSString *titleText = @"";
  261. if (type == KMMessageTypeNewUserGift) {
  262. titleText = NSLocalizedString(@"Welcome Gifts", @"");
  263. } else if (type == KMMessageTypeDiscount) {
  264. titleText = [self _getDiscountTitle];
  265. }
  266. NSString *calTitleText = [NSString stringWithFormat:@" %@",titleText];
  267. CGFloat width = [self _calTextWidth:calTitleText font:nil];
  268. KMMessageModel *model = [[KMMessageModel alloc] init];
  269. model.type = type;
  270. model.show = true;
  271. model.titleText = titleText;
  272. model.viewWidth = width + 10;
  273. return model;
  274. }
  275. - (void)_trackButtonEvent {
  276. if (self.button.tag == KMMessageTypePurchaseWithoutLogin) {
  277. #if VERSION_FREE
  278. #if VERSION_DMG
  279. #else
  280. [FMTrackEventManager.defaultManager trackEventWithEvent:@"Tbr" withProperties:@{@"Tbr_Btn" : @"Btn_Tbr_PurchasewithoutLogin"}];
  281. #endif
  282. #endif
  283. } else if (self.button.tag == KMMessageTypeFreeTrail) {
  284. [FMTrackEventManager.defaultManager trackEventWithEvent:@"Tbr" withProperties:@{@"Tbr_Btn" : @"Btn_Tbr_FreeTrial"}];
  285. }
  286. }
  287. - (CGFloat)dealSignUpView {
  288. self.signUpLabel.stringValue = NSLocalizedStringFromTable(@"Sign in", @"MemberCenterLocalizable", nil);
  289. self.signUpLabel.font = [NSFont SFProTextSemiboldFont:11];
  290. [self.signUpLabel sizeToFit];
  291. CGFloat signUpWidth = self.signUpLabel.frame.size.width;
  292. signUpWidth += 4;
  293. signUpWidth += 8;
  294. signUpWidth += 8;
  295. signUpWidth += 12;
  296. self.signUpImg.frame = CGRectMake(8, CGRectGetHeight(self.view.frame)/2.-6, 12, 12);
  297. CGRect signUplabelRect = self.signUpLabel.frame;
  298. signUplabelRect.origin.x = CGRectGetMaxX(self.signUpImg.frame) + 4;
  299. self.signUpLabel.frame = signUplabelRect;
  300. return signUpWidth;
  301. }
  302. - (void)reloadData {
  303. [self.datas removeAllObjects];
  304. // [self.userGiftView removeFromSuperview];
  305. self.userGiftView.hidden = true;
  306. self.discountItemView.hidden = true;
  307. self.label.textColor = [NSColor blackColor];
  308. self.label.hidden = NO;
  309. self.secondTrialBtn.hidden = YES;
  310. CGFloat totalWidth = 8;
  311. self.button.hidden = NO;
  312. self.officeButton.hidden = NO;
  313. self.bgImg.hidden = NO;
  314. self.officeImg.hidden = NO;
  315. self.label.hidden = YES;
  316. self.secondTrialBtn.hidden = YES;
  317. self.labelContentView.hidden = YES;
  318. self.aiContendView.hidden = YES;
  319. self.userButton.hidden = YES;
  320. self.signUpView.hidden = YES;
  321. CGFloat signUpWidth = [self dealSignUpView];
  322. self.button.layer.backgroundColor = [NSColor clearColor].CGColor;
  323. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Upgrade to Pro", nil)];
  324. [self.button setTitleColor:[NSColor whiteColor]];
  325. self.button.tag = KMMessageTypeNone;
  326. self.officeButton.layer.backgroundColor = [NSColor clearColor].CGColor;
  327. self.officeButton.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"PDF to Office", nil)];
  328. [self.officeButton setTitleColor:[NSColor whiteColor]];
  329. self.aiLabel.stringValue = NSLocalizedStringFromTable(@"Free Use 1-Year AI Tools", @"MemberCenterLocalizable", nil);
  330. [self.aiLabel sizeToFit];
  331. CGFloat aiWidth = self.aiLabel.frame.size.width;
  332. aiWidth += 4;
  333. aiWidth += 16;
  334. aiWidth += 16;
  335. self.aiIconImg.frame = CGRectMake(8, CGRectGetHeight(self.view.frame)/2.-8, 16, 16);
  336. self.aiContendView.frame = CGRectMake(totalWidth, 0, aiWidth, self.view.frame.size.height);
  337. CGRect ailabelRect = self.aiLabel.frame;
  338. ailabelRect.origin.x = CGRectGetMaxX(self.aiIconImg.frame) + 4;
  339. self.aiLabel.frame = ailabelRect;
  340. // totalWidth+=aiWidth;
  341. // totalWidth+=4;
  342. // self.aiContendView.hidden = NO;
  343. CGFloat userImageWidth = 24;
  344. if ([KMMemberInfo shared].isLogin) {
  345. self.userButton.image = [NSImage imageNamed:@"UserProfilePicture"];
  346. } else {
  347. self.userButton.image = [NSImage imageNamed:@"UserProfilePicture1"];
  348. }
  349. CGFloat buttonWidth = CGRectGetMaxX(self.button.frame);
  350. NSRect btnRect = [self.button.attributedTitle boundingRectWithSize:CGSizeMake(MAXFLOAT, CGRectGetHeight(self.button.frame)) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading];
  351. // if (fabs(buttonWidth-btnRect.size.width)>50) {
  352. buttonWidth = btnRect.size.width + 10;
  353. // buttonWidth += 10;
  354. // }
  355. CGFloat officeWidth = CGRectGetMaxX(self.officeButton.frame);
  356. NSRect officeRect = [self.officeButton.attributedTitle boundingRectWithSize:CGSizeMake(MAXFLOAT, CGRectGetHeight(self.officeButton.frame)) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading];
  357. if (fabs(officeWidth-officeRect.size.width)>50) {
  358. officeWidth = officeRect.size.width + 10;
  359. }
  360. #if VERSION_DMG
  361. self.button.hidden = YES;
  362. self.officeButton.hidden = YES;
  363. self.bgImg.hidden = YES;
  364. self.officeImg.hidden = YES;
  365. if ([[KMMemberInfo shared].isHaveAIDiscount isEqualToString:@"1"]) {
  366. self.aiContendView.hidden = NO;
  367. totalWidth+=aiWidth;
  368. totalWidth+=4;
  369. }
  370. KMUserScenarioType type = [KMMemberInfo shared].userScenarioType;
  371. KMMessageType messageType = KMMessageTypeNone;
  372. if (type == KMUserScenarioTypeDmg_type1 ||
  373. type == KMUserScenarioTypeDmg_type2 ||
  374. type == KMUserScenarioTypeDmg_type3 ||
  375. type == KMUserScenarioTypeDmg_type5 ||
  376. type == KMUserScenarioTypeDmg_type6 ||
  377. type == KMUserScenarioTypeDmg_type7 ||
  378. type == KMUserScenarioTypeDmg_type28 ||
  379. type == KMUserScenarioTypeDmg_type29 ||
  380. type == KMUserScenarioTypeDmg_type30 ||
  381. type == KMUserScenarioTypeDmg_type43 ||
  382. type == KMUserScenarioTypeDmg_type44 ||
  383. type == KMUserScenarioTypeDmg_type45) {
  384. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Upgrade", nil)];
  385. messageType = KMMessageTypeUpgrade;
  386. } else if (type == KMUserScenarioTypeDmg_type4 ) {
  387. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Free Trial", nil)];
  388. messageType = KMMessageTypeFreeTrail;
  389. self.button.tag = KMMessageTypeFreeTrail;
  390. } else if (type == KMUserScenarioTypeDmg_type11 ||
  391. type == KMUserScenarioTypeDmg_type19 ||
  392. type == KMUserScenarioTypeDmg_type22 ||
  393. type == KMUserScenarioTypeDmg_type34 ||
  394. type == KMUserScenarioTypeDmg_type37 ) {
  395. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedStringFromTable(@"Buy Now", @"MemberCenterLocalizable", nil)];
  396. messageType = KMMessageTypeBuyNow;
  397. } else if (type == KMUserScenarioTypeDmg_type18 ||
  398. type == KMUserScenarioTypeDmg_type33 ||
  399. type == KMUserScenarioTypeDmg_type48) {
  400. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedStringFromTable(@"Renew now", @"MemberCenterLocalizable", nil)];
  401. messageType = KMMessageTypeRenew;
  402. }
  403. if (type == KMUserScenarioTypeDmg_type2 ||
  404. type == KMUserScenarioTypeDmg_type19 ||
  405. type == KMUserScenarioTypeDmg_type20 ||
  406. type == KMUserScenarioTypeDmg_type21 ||
  407. type == KMUserScenarioTypeDmg_type22 ||
  408. type == KMUserScenarioTypeDmg_type30 ||
  409. type == KMUserScenarioTypeDmg_type31 ||
  410. type == KMUserScenarioTypeDmg_type32 ||
  411. type == KMUserScenarioTypeDmg_type33) {
  412. [self.officeButton setTitleColor:[NSColor whiteColor]];
  413. self.officeButton.hidden = NO;
  414. self.officeImg.hidden = NO;
  415. self.officeButton.frame = CGRectMake(totalWidth, kbottomGap, officeWidth, self.view.frame.size.height -2 *kbottomGap);
  416. CGRect officeRect = self.officeButton.frame;
  417. self.officeImg.frame = officeRect;
  418. totalWidth+=CGRectGetWidth(self.officeButton.bounds);
  419. totalWidth+=4;
  420. }
  421. if (type == KMUserScenarioTypeDmg_type1 ||
  422. type == KMUserScenarioTypeDmg_type2 ||
  423. type == KMUserScenarioTypeDmg_type3 ||
  424. type == KMUserScenarioTypeDmg_type4 ||
  425. type == KMUserScenarioTypeDmg_type5 ||
  426. type == KMUserScenarioTypeDmg_type6 ||
  427. type == KMUserScenarioTypeDmg_type7 ||
  428. type == KMUserScenarioTypeDmg_type11 ||
  429. type == KMUserScenarioTypeDmg_type18 ||
  430. type == KMUserScenarioTypeDmg_type19 ||
  431. type == KMUserScenarioTypeDmg_type22 ||
  432. type == KMUserScenarioTypeDmg_type28 ||
  433. type == KMUserScenarioTypeDmg_type29 ||
  434. type == KMUserScenarioTypeDmg_type30 ||
  435. type == KMUserScenarioTypeDmg_type33 ||
  436. type == KMUserScenarioTypeDmg_type34 ||
  437. type == KMUserScenarioTypeDmg_type37 ||
  438. type == KMUserScenarioTypeDmg_type43 ||
  439. type == KMUserScenarioTypeDmg_type44 ||
  440. type == KMUserScenarioTypeDmg_type45 ||
  441. type == KMUserScenarioTypeDmg_type48 ||
  442. type == KMUserScenarioTypeDmg_type13) {
  443. [self.button setTitleColor:[NSColor whiteColor]];
  444. KMAdvertisementItem *advertiseItem = KMAdvertisementManager.manager.info.topRightInfoContent;
  445. if (advertiseItem != nil && advertiseItem.content.firstObject != nil) {
  446. KMAdvertisementItemInfo *info = KMAdvertisementManager.manager.info.topRightInfoContent.content.firstObject;
  447. NSString *name = [KMAdvertisementModelTransition transitionLanguageWithLangeuage:info.name];
  448. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(name, nil)];
  449. NSURL *url = [NSURL URLWithString: [KMAdvertisementModelTransition transitionImagePathWithImage:info.image highlight: YES]];
  450. __weak typeof(self)weakSelf = self;
  451. NSImage * img = [KMAdvertisementImage imageWithURLWithUrl:url completion:^(NSImage *image) {
  452. if (image != nil) {
  453. weakSelf.bgImg.image = image;
  454. }
  455. }];
  456. } else {
  457. KMMemberInfo *member = [KMMemberInfo shared];
  458. KMNewUserGiftManager *man = [KMNewUserGiftManager default];
  459. if ([man needShow] && [member isLogin] == false && member.isMemberAllFunction == false) { // 未登陆的新用户
  460. NSString *titleText = NSLocalizedString(@"Welcome Gifts", @"");
  461. NSString *calTitleText = [NSString stringWithFormat:@" %@",titleText];
  462. if (messageType != KMMessageTypeFreeTrail) {
  463. self.button.stringValue = calTitleText;
  464. }
  465. [self.datas addObject:[self _createDiscountModelWithType:KMMessageTypeNewUserGift]];
  466. } else {
  467. if ([man needShow] && [member isFreeAccount]) {
  468. NSString *titleText = [self _getDiscountTitle];
  469. NSString *calTitleText = [NSString stringWithFormat:@" %@",titleText];
  470. if (messageType != KMMessageTypeFreeTrail) {
  471. self.button.stringValue = calTitleText;
  472. }
  473. [self.datas addObject:[self _createDiscountModelWithType:KMMessageTypeDiscount]];
  474. } else if (([member isMemberAllFunction] == false || type == KMUserScenarioTypeDmg_type13) && [[KMCheckInManager default] trailCancel]) {
  475. NSString *titleText = [self _getDiscountTitle];
  476. NSString *calTitleText = [NSString stringWithFormat:@" %@",titleText];
  477. if (messageType != KMMessageTypeFreeTrail) {
  478. self.button.stringValue = calTitleText;
  479. }
  480. [self.datas addObject:[self _createDiscountModelWithType:KMMessageTypeDiscount]];
  481. }
  482. }
  483. CGFloat discountWidth = [self _dealDiscountViewWithMessageType:messageType];
  484. totalWidth += discountWidth;
  485. }
  486. if (type != KMUserScenarioTypeDmg_type13 || self.datas.count > 0) {
  487. buttonWidth = CGRectGetWidth(self.button.frame);
  488. NSRect btnRect = [self.button.attributedTitle boundingRectWithSize:CGSizeMake(MAXFLOAT, CGRectGetHeight(self.button.frame)) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading];
  489. buttonWidth = btnRect.size.width + 10;
  490. self.bgImg.hidden = NO;
  491. self.button.hidden = NO;
  492. self.button.frame = CGRectMake(totalWidth, kbottomGap, buttonWidth, self.view.frame.size.height -2 *kbottomGap);
  493. CGRect rect = self.button.frame;
  494. self.bgImg.frame = rect;
  495. totalWidth+=CGRectGetWidth(self.button.bounds);
  496. totalWidth+=4;
  497. }
  498. }
  499. #else
  500. if ([[KMMemberInfo shared].isHaveAIDiscount isEqualToString:@"1"]) {
  501. #if VERSION_FREE
  502. if(IAPProductsManager.defaultManager.aiAllAccessPack12month_lite.isTrialPeriod == false) {
  503. self.aiContendView.hidden = NO;
  504. totalWidth+=aiWidth;
  505. totalWidth+=4;
  506. }
  507. #else
  508. if(IAPProductsManager.defaultManager.aiAllAccessPack12month_pro.isTrialPeriod == false) {
  509. self.aiContendView.hidden = NO;
  510. totalWidth+=aiWidth;
  511. totalWidth+=4;
  512. }
  513. #endif
  514. }
  515. KMUserScenarioType type = [KMMemberInfo shared].userScenarioType;
  516. BOOL buttonHiddenFlag = false;
  517. KMMessageType messageType = KMMessageTypeNone;
  518. if (type == KMUserScenarioTypeLite_type1 ||
  519. type == KMUserScenarioTypeLite_type3 ||
  520. type == KMUserScenarioTypeLite_type5 ||
  521. type == KMUserScenarioTypeLite_type7 ||
  522. type == KMUserScenarioTypeLite_type9 ||
  523. type == KMUserScenarioTypeLite_type11 ||
  524. type == KMUserScenarioTypePro_type1 ||
  525. type == KMUserScenarioTypePro_type3 ||
  526. type == KMUserScenarioTypePro_type4 || type == KMUserScenarioTypeLite_type8) {
  527. if (type == KMUserScenarioTypeLite_type1) { //免费用户
  528. #if !VERSION_DMG
  529. if(KMMemberInfo.shared.isLogin == NO) {
  530. #if VERSION_FREE
  531. if (IAPProductsManager.defaultManager.isAvailableAllFunction) {
  532. if (IAPProductsManager.defaultManager.isAvailableAdvancedPDFToOffice) {
  533. self.button.title = @"";
  534. buttonHiddenFlag = true;
  535. } else {
  536. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Upgrade", nil)];
  537. messageType = KMMessageTypeUpgrade;
  538. }
  539. } else {
  540. self.button.title = [self _getAppStoreFreeVersionBuyNowTitle];
  541. if ([[KMNewUserGiftManager default] needShow]) {
  542. [self.datas addObject:[self _createDiscountModelWithType:KMMessageTypeNewUserGift]];
  543. } else if ([[KMCheckInManager default] advancedYearSubscribeTrailCancelForLocal]) {
  544. [self.datas addObject:[self _createDiscountModelWithType:KMMessageTypeDiscount]];
  545. }
  546. messageType = KMMessageTypePurchaseWithoutLogin;
  547. self.button.tag = KMMessageTypePurchaseWithoutLogin;
  548. }
  549. #else
  550. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Upgrade", nil)];
  551. messageType = KMMessageTypeUpgrade;
  552. #endif
  553. } else {
  554. if(IAPProductsManager.defaultManager.fourDevicesAllAccessPackNew12months_lite.isTrialPeriod == YES) { //是否有试用
  555. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedStringFromTable(@"Buy Now",@"MemberCenterLocalizable", nil)];
  556. messageType = KMMessageTypeBuyNow;
  557. } else {
  558. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Free Trial", nil)];
  559. messageType = KMMessageTypeFreeTrail;
  560. self.button.tag = KMMessageTypeFreeTrail;
  561. }
  562. KMMemberInfo *member = [KMMemberInfo shared];
  563. KMNewUserGiftManager *man = [KMNewUserGiftManager default];
  564. if ([man needShow] && [member isFreeAccount]) {
  565. NSString *titleText = [self _getDiscountTitle];
  566. NSString *calTitleText = [NSString stringWithFormat:@" %@",titleText];
  567. if (messageType != KMMessageTypeFreeTrail) {
  568. self.button.stringValue = calTitleText;
  569. }
  570. [self.datas addObject:[self _createDiscountModelWithType:KMMessageTypeDiscount]];
  571. } else if (man.progressState != KMProgressStateNone && member.isMemberAllFunction == false && [[KMCheckInManager default] trailCancel]) {
  572. NSString *titleText = [self _getDiscountTitle];
  573. NSString *calTitleText = [NSString stringWithFormat:@" %@",titleText];
  574. if (messageType != KMMessageTypeFreeTrail) {
  575. self.button.stringValue = calTitleText;
  576. }
  577. [self.datas addObject:[self _createDiscountModelWithType:KMMessageTypeDiscount]];
  578. }
  579. }
  580. #else
  581. #endif
  582. } else if (type == KMUserScenarioTypeLite_type3 ) {
  583. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedStringFromTable(@"Buy Now", @"MemberCenterLocalizable", nil)];
  584. messageType = KMMessageTypeBuyNow;
  585. } else if (type == KMUserScenarioTypeLite_type5) {
  586. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Upgrade", nil)];
  587. messageType = KMMessageTypeUpgrade;
  588. } else if (type == KMUserScenarioTypeLite_type7) {
  589. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedStringFromTable(@"Renew now", @"MemberCenterLocalizable", nil)];
  590. messageType = KMMessageTypeRenew;
  591. } else if (type == KMUserScenarioTypeLite_type8) {
  592. KMMemberInfo *member = [KMMemberInfo shared];
  593. KMNewUserGiftManager *man = [KMNewUserGiftManager default];
  594. if (man.progressState != KMProgressStateNone && [[KMCheckInManager default] trailCancel]) {
  595. NSString *titleText = [self _getDiscountTitle];
  596. NSString *calTitleText = [NSString stringWithFormat:@" %@",titleText];
  597. if (messageType != KMMessageTypeFreeTrail) {
  598. self.button.stringValue = calTitleText;
  599. }
  600. [self.datas addObject:[self _createDiscountModelWithType:KMMessageTypeDiscount]];
  601. }
  602. if (self.datas.count > 1) {
  603. } else {
  604. self.button.title = @"";
  605. buttonHiddenFlag = true;
  606. }
  607. } else if (type == KMUserScenarioTypeLite_type9) {
  608. if([KMMemberInfo shared].vip_status == 2) {
  609. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedStringFromTable(@"Renew now",@"MemberCenterLocalizable", nil)];
  610. messageType = KMMessageTypeRenew;
  611. } else if ([KMMemberInfo shared].vip_status == 4) {
  612. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedStringFromTable(@"Buy Now",@"MemberCenterLocalizable", nil)];
  613. messageType = KMMessageTypeBuyNow;
  614. } else {
  615. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Upgrade", nil)];
  616. messageType = KMMessageTypeUpgrade;
  617. }
  618. } else if (type == KMUserScenarioTypeLite_type11) {
  619. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Upgrade", nil)];
  620. messageType = KMMessageTypeUpgrade;
  621. } else if (type == KMUserScenarioTypePro_type3) {
  622. if([KMMemberInfo shared].vip_status == 2) {
  623. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedStringFromTable(@"Renew now",@"MemberCenterLocalizable", nil)];
  624. messageType = KMMessageTypeRenew;
  625. } else {
  626. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Upgrade", nil)];
  627. messageType = KMMessageTypeUpgrade;
  628. }
  629. }
  630. #if !VERSION_FREE
  631. BOOL isNoSupportMemberUpgrade = YES;
  632. if ([KMMemberInfo shared].vip_status == 1) { //订阅+永久
  633. isNoSupportMemberUpgrade = NO;
  634. }
  635. if (![IAPProductsManager defaultManager].isAvailableAdvancedPDFToOffice && isNoSupportMemberUpgrade) {
  636. [self.officeButton setTitleColor:[NSColor whiteColor]];
  637. self.officeButton.hidden = NO;
  638. self.officeImg.hidden = NO;
  639. self.officeButton.frame = CGRectMake(totalWidth, kbottomGap, officeWidth, self.view.frame.size.height -2 *kbottomGap);
  640. CGRect officeRect = self.officeButton.frame;
  641. self.officeImg.frame = officeRect;
  642. totalWidth+=CGRectGetWidth(self.officeButton.bounds);
  643. totalWidth+=4;
  644. } else {
  645. self.officeButton.hidden = YES;
  646. self.officeImg.hidden = YES;
  647. }
  648. #else
  649. self.officeButton.hidden = YES;
  650. self.officeImg.hidden = YES;
  651. #endif
  652. KMAdvertisementItem *advertiseItem = KMAdvertisementManager.manager.info.topRightInfoContent;
  653. if (advertiseItem != nil && advertiseItem.content.firstObject != nil) {
  654. KMAdvertisementItemInfo *info = KMAdvertisementManager.manager.info.topRightInfoContent.content.firstObject;
  655. NSString *name = [KMAdvertisementModelTransition transitionLanguageWithLangeuage:info.name];
  656. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(name, nil)];
  657. NSURL *url = [NSURL URLWithString: [KMAdvertisementModelTransition transitionImagePathWithImage:info.image highlight: YES]];
  658. __weak typeof(self)weakSelf = self;
  659. NSImage * img = [KMAdvertisementImage imageWithURLWithUrl:url completion:^(NSImage *image) {
  660. if (image != nil) {
  661. weakSelf.bgImg.image = image;
  662. }
  663. }];
  664. } else {
  665. CGFloat discountWidth = [self _dealDiscountViewWithMessageType:messageType];
  666. totalWidth += discountWidth;
  667. }
  668. [self.button setTitleColor:[NSColor whiteColor]];
  669. self.bgImg.hidden = NO;
  670. self.button.hidden = NO;
  671. BOOL isOldSubscribed = NO;
  672. #if VERSION_FREE
  673. #if !VERSION_DMG
  674. isOldSubscribed = (IAPProductsManager.defaultManager.allAccessPack6months_lite.isSubscribed == YES || IAPProductsManager.defaultManager.allAccessPack12months_lite.isSubscribed == YES);
  675. #endif
  676. #endif
  677. // 单平台高级版永久 未登录时 也不显示升级(因为点了也得先登录),但是登录后的卡片里是有升级按钮的,可以升级成全平台高级版年订阅
  678. //原来是订阅的,不需要升级,因为目前不支持订阅升级订阅这种场景
  679. if(type == KMUserScenarioTypeLite_type9 ||
  680. type == KMUserScenarioTypeLite_type10 ||
  681. type == KMUserScenarioTypeLite_type11) {
  682. if([KMMemberInfo shared].isLogin == NO) { //未登录
  683. self.button.hidden = YES;
  684. self.bgImg.hidden = YES;
  685. } else {
  686. if(isOldSubscribed) { //老版本付费功能是订阅包
  687. self.button.hidden = YES;
  688. self.bgImg.hidden = YES;
  689. } else {
  690. if((KMMemberInfo.shared.vip_status == 1) && [KMMemberInfo.shared.vip_paymentModel isEqualToString:@"1"]) { //会员订阅中
  691. self.button.hidden = YES;
  692. self.bgImg.hidden = YES;
  693. }
  694. }
  695. }
  696. }
  697. #if VERSION_FREE
  698. #if !VERSION_DMG
  699. if (buttonHiddenFlag) {
  700. self.bgImg.hidden = YES;
  701. self.button.hidden = YES;
  702. }
  703. #endif
  704. #endif
  705. buttonWidth = CGRectGetWidth(self.button.frame);
  706. NSRect btnRect = [self.button.attributedTitle boundingRectWithSize:CGSizeMake(MAXFLOAT, CGRectGetHeight(self.button.frame)) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading];
  707. // if (fabs(buttonWidth-btnRect.size.width)>50) {
  708. buttonWidth = btnRect.size.width + 10;
  709. // buttonWidth += 10;
  710. // }
  711. if (KMAdvertisementManager.manager.info.topRightInfoContent != nil) {
  712. if (KMAdvertisementManager.manager.info.topRightInfoContent.content.firstObject != nil) {
  713. buttonWidth += 10;
  714. buttonWidth = MIN(buttonWidth, self.remoteButtonMaxWidth);
  715. }
  716. }
  717. self.button.frame = CGRectMake(totalWidth, kbottomGap, buttonWidth, self.view.frame.size.height -2 *kbottomGap);
  718. CGRect rect = self.button.frame;
  719. self.bgImg.frame = rect;
  720. totalWidth+=CGRectGetWidth(self.button.bounds);
  721. totalWidth+=4;
  722. } else if (type == KMUserScenarioTypeLite_type12 ||
  723. type == KMUserScenarioTypeLite_type13 ||
  724. type == KMUserScenarioTypeLite_type2 ||
  725. type == KMUserScenarioTypeLite_type4 ||
  726. type == KMUserScenarioTypeLite_type6 ||
  727. type == KMUserScenarioTypeLite_type8 ||
  728. type == KMUserScenarioTypePro_type2 ||
  729. type == KMUserScenarioTypePro_type5) {
  730. self.button.hidden = YES;
  731. self.bgImg.hidden = YES;
  732. #if !VERSION_FREE
  733. BOOL isNoSupportMemberUpgrade = YES;
  734. if ([KMMemberInfo shared].vip_status == 1) { //订阅+永久
  735. isNoSupportMemberUpgrade = NO;
  736. }
  737. if (![IAPProductsManager defaultManager].isAvailableAdvancedPDFToOffice && isNoSupportMemberUpgrade) {
  738. [self.officeButton setTitleColor:[NSColor whiteColor]];
  739. self.officeButton.hidden = NO;
  740. self.officeImg.hidden = NO;
  741. self.officeButton.frame = CGRectMake(totalWidth, kbottomGap, officeWidth, self.view.frame.size.height -2 *kbottomGap);
  742. CGRect officeRect = self.officeButton.frame;
  743. self.officeImg.frame = officeRect;
  744. totalWidth+=CGRectGetWidth(self.officeButton.bounds);
  745. totalWidth+=4;
  746. } else {
  747. self.officeButton.hidden = YES;
  748. self.officeImg.hidden = YES;
  749. }
  750. #else
  751. self.officeButton.hidden = YES;
  752. self.officeImg.hidden = YES;
  753. #endif
  754. }
  755. #endif
  756. if ([KMMemberInfo shared].isLogin) {
  757. self.userButton.hidden = NO;
  758. self.userButton.frame = CGRectMake(totalWidth, 0, userImageWidth, userImageWidth);
  759. totalWidth += userImageWidth;
  760. totalWidth += 8;
  761. } else {
  762. self.signUpView.hidden = NO;
  763. self.signUpView.frame = CGRectMake(totalWidth, 0, signUpWidth, self.view.frame.size.height);
  764. totalWidth+=CGRectGetWidth(self.signUpView.bounds);
  765. }
  766. self.view.frame = CGRectMake(MAX(0, CGRectGetWidth(self.view.superview.frame)-totalWidth - 8), (CGRectGetHeight(self.view.superview.frame)-CGRectGetHeight(self.view.frame))/2., totalWidth, self.view.frame.size.height);
  767. if (self.frameUpdateHandle) {
  768. self.frameUpdateHandle(self.view.frame);
  769. }
  770. }
  771. #pragma mark - Button Actions
  772. - (IBAction)secondTrialAction:(NSButton *)sender {
  773. if ([VerificationManager manager].secondTrialEnabled) {
  774. KMVerificationWindowController *vc = [KMVerificationWindowController verificationWithType:KMVerificationTypeRepeatTrialGuide];
  775. [vc showWindow:nil];
  776. } else {
  777. [[KMMemberInfo shared] advancedFunctionUsageWithType:KMSubscribeWaterMarkTypeNone];
  778. }
  779. }
  780. - (IBAction)buttonAction:(id)sender {
  781. if (KMAdvertisementManager.manager.info.topRightInfoContent != nil) {
  782. if (KMAdvertisementManager.manager.info.topRightInfoContent.content.firstObject != nil) {
  783. #if VERSION_FREE
  784. #if VERSION_DMG
  785. #else
  786. [FMTrackEventManager.defaultManager trackEventWithEvent:@"Tbr" withProperties:@{@"Tbr_Btn" : @"Btn_Tbr_Sale"}];
  787. #endif
  788. #endif
  789. if ([KMMemberInfo shared].isLogin) {
  790. if ([[KMMemberInfo shared].vip_levels isEqualToString:@"1"]) {
  791. [[KMProductCompareWC shared] setOrientation:YES];
  792. #if VERSION_FREE
  793. #if VERSION_DMG
  794. // DMG
  795. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeDmg_Base];
  796. #else
  797. // AppStore 免费版本
  798. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeLite_Base];
  799. #endif
  800. #else
  801. // AppStore 付费版
  802. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypePro_Base];
  803. #endif
  804. [[KMProductCompareWC shared] showWindow:nil];
  805. } else {
  806. [[KMMemberInfo shared] advancedFunctionUsageWithType:KMSubscribeWaterMarkTypeNone];
  807. }
  808. } else {
  809. if ([self _isNowGotoPurcahseTable]) {
  810. KMProductCompareWC *winC = [KMProductCompareWC shared];
  811. // 定向跳转
  812. winC.orientation = true;
  813. // App Store 免费版 基础比较表
  814. winC.orientationType = KMCompareTableTypeLite_Base;
  815. [winC showWindow:nil];
  816. } else {
  817. [[KMLoginWindowsController shared] openWindow:^(BOOL success) {
  818. if (success) {
  819. if ([[KMMemberInfo shared].vip_levels isEqualToString:@"1"]) {
  820. [[KMProductCompareWC shared] setOrientation:YES];
  821. #if VERSION_FREE
  822. #if VERSION_DMG
  823. // DMG
  824. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeDmg_Base];
  825. #else
  826. // AppStore 免费版本
  827. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeLite_Base];
  828. #endif
  829. #else
  830. // AppStore 付费版
  831. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypePro_Base];
  832. #endif
  833. [[KMProductCompareWC shared] showWindow:nil];
  834. } else {
  835. [[KMMemberInfo shared] advancedFunctionUsageWithType:KMSubscribeWaterMarkTypeNone];
  836. }
  837. }
  838. }];
  839. }
  840. }
  841. } else {
  842. [self _trackButtonEvent];
  843. KMUserScenarioType type = [KMMemberInfo shared].userScenarioType;
  844. if (type == KMUserScenarioTypeDmg_type4) {
  845. if ([KMMemberInfo shared].isLogin) {
  846. [[KMProductCompareWC shared] setOrientation:YES];
  847. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeTrial];
  848. // [[KMProductCompareWC shared] showWindow:nil];
  849. [[KMProductCompareWC shared] openWindowWithDiscountType:KMDiscountTypeFreeTrail];
  850. } else {
  851. [[KMLoginWindowsController shared] openWindow:^(BOOL success) {
  852. if (success) {
  853. [[KMProductCompareWC shared] setOrientation:YES];
  854. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeTrial];
  855. [[KMProductCompareWC shared] showWindow:nil];
  856. }
  857. }];
  858. }
  859. } else {
  860. if ([self _isNowGotoPurcahseTable] &&
  861. ![KMMemberInfo shared].isLogin) { //本机(Apple ID)无权益,且未未登录时,直接跳购买
  862. [self _doNowGotoPurcahseTable];
  863. } else {
  864. [[KMMemberInfo shared] advancedFunctionUsageWithType:KMSubscribeWaterMarkTypeInvalid];
  865. }
  866. }
  867. }
  868. } else {
  869. [self _trackButtonEvent];
  870. KMUserScenarioType type = [KMMemberInfo shared].userScenarioType;
  871. if (type == KMUserScenarioTypeDmg_type4) {
  872. if ([KMMemberInfo shared].isLogin) {
  873. [[KMProductCompareWC shared] setOrientation:YES];
  874. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeTrial];
  875. // [[KMProductCompareWC shared] showWindow:nil];
  876. [[KMProductCompareWC shared] openWindowWithDiscountType:KMDiscountTypeFreeTrail];
  877. } else {
  878. [[KMLoginWindowsController shared] openWindow:^(BOOL success) {
  879. if (success) {
  880. [[KMProductCompareWC shared] setOrientation:YES];
  881. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeTrial];
  882. [[KMProductCompareWC shared] showWindow:nil];
  883. }
  884. }];
  885. }
  886. } else {
  887. if ([self _isNowGotoPurcahseTable] && ![KMMemberInfo shared].isLogin) { //本机(Apple ID)无权益,且未未登录时,直接跳购买
  888. [self _doNowGotoPurcahseTable];
  889. } else {
  890. [[KMMemberInfo shared] advancedFunctionUsageWithType:KMSubscribeWaterMarkTypeInvalid];
  891. }
  892. }
  893. }
  894. }
  895. - (void)_doNowGotoPurcahseTable {
  896. KMProductCompareWC *winC = [KMProductCompareWC shared];
  897. // 定向跳转
  898. winC.orientation = true;
  899. // App Store 免费版 基础比较表
  900. winC.orientationType = KMCompareTableTypeLite_Base;
  901. if ([[KMMemberInfo shared] isLogin] && self.button.tag == KMMessageTypeFreeTrail) { // 免费试用
  902. [winC openWindowWithDiscountType:KMDiscountTypeFreeTrail];
  903. } else if (self.userGiftView.isHidden == false) { // 新手礼
  904. KMMessageModel *model = nil;
  905. for (KMMessageModel *m in self.datas) {
  906. if (m.type == KMMessageTypeNewUserGift) {
  907. model = m;
  908. break;
  909. }
  910. }
  911. if (model != nil) { // 检查数据
  912. if ([[KMNewUserGiftManager default] needShow]) { // 检查条件
  913. [winC openWindowWithDiscountType:KMDiscountTypeNewUserGift];
  914. } else {
  915. [winC showWindow:nil];
  916. }
  917. } else {
  918. [winC showWindow:nil];
  919. }
  920. } else if (self.discountItemView.isHidden == false) { // 优惠卷 (新手礼 & 试用退订)
  921. KMMessageModel *model = nil;
  922. for (KMMessageModel *m in self.datas) {
  923. if (m.type == KMMessageTypeDiscount) {
  924. model = m;
  925. }
  926. }
  927. if (model != nil) { // 检查数据
  928. if ([[KMCheckInManager default] trailCancel] || [[KMCheckInManager default] advancedYearSubscribeTrailCancelForLocal]) { // 检查条件
  929. [winC openWindowWithDiscountType:KMDiscountTypeAdvancedYearSubscribeTrialingCancel];
  930. } else if ([[KMNewUserGiftManager default] needShow]) { // 检查条件
  931. [winC openWindowWithDiscountType:KMDiscountTypeNewUserGift];
  932. } else {
  933. [winC showWindow:nil];
  934. }
  935. } else {
  936. [winC showWindow:nil];
  937. }
  938. } else {
  939. [winC showWindow:nil];
  940. }
  941. }
  942. - (IBAction)officeButtonAction:(id)sender {
  943. #if VERSION_FREE
  944. #if VERSION_DMG
  945. DMGEmbeddedOldWC *embeddedWC = [DMGEmbeddedOldWC currentFirstTrialWC:@"com.brother.pdfreaderpro.mac.product_2"];
  946. [embeddedWC showWindow:nil];
  947. [embeddedWC.window center];
  948. #endif
  949. #else
  950. if ([KMMemberInfo shared].isLogin) {
  951. [[KMMemberInfo shared] productCompareShow];
  952. } else {
  953. [[KMLoginWindowsController shared] openWindow:^(BOOL success) {
  954. if (success) {
  955. [[KMMemberInfo shared] productCompareShow];
  956. }
  957. }];
  958. }
  959. #endif
  960. }
  961. - (NSAttributedString *)numberConvertColor:(NSColor*)color String:(NSString *)string {
  962. NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:string];
  963. NSString *temp = nil;
  964. for (NSUInteger i = 0; i <string.length; i++) {
  965. temp = [string substringWithRange:NSMakeRange(i, 1)];
  966. if ([self isPureInt:temp]) {
  967. [attributedString setAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
  968. color, NSForegroundColorAttributeName, nil] range:NSMakeRange(i, 1)];
  969. }
  970. }
  971. return attributedString;
  972. }
  973. - (BOOL)isPureInt:(NSString *)string {
  974. NSScanner *scan = [NSScanner scannerWithString:string];
  975. int value;
  976. return [scan scanInt:&value] && [scan isAtEnd];
  977. }
  978. - (IBAction)AIButtonAction:(NSButton *)sender {
  979. if ([[[KMMemberInfo shared] validFlag] isEqualToString:@"5"]) {
  980. [[KMMemberPromptWC shared] showWindow:sender];
  981. [KMMemberPromptWC shared].tipType = KMMemberTipTypeSignouting;
  982. } else {
  983. #if VERSION_FREE
  984. #if VERSION_DMG
  985. KMPurchaseEmbeddedWindowController *winC = [KMPurchaseEmbeddedWindowController currentCode:KMAISubscriptionYearTrailCodeKey_DMG];
  986. [winC showWindow:nil];
  987. [winC.window center];
  988. #else
  989. [[KMFreeGetAIWC shared] showWindow:nil];
  990. #endif
  991. #else
  992. [[KMFreeGetAIWC shared] showWindow:nil];
  993. #endif
  994. }
  995. }
  996. - (IBAction)userButtonAction:(NSButton *)sender {
  997. if ([KMMemberInfo shared].isLogin) {
  998. [self personalCenterAction:sender];
  999. } else {
  1000. [KMLoginWindowsController.shared showWindow:nil];
  1001. }
  1002. }
  1003. - (IBAction)personalCenterAction:(NSButton *)sender {
  1004. if (![KMCloudServer isConnectionAvailable]) {
  1005. NSAlert *alert = [NSAlert alertWithMessageText:NSLocalizedString(@"Connection Error", nil)
  1006. defaultButton:NSLocalizedString(@"OK", nil)
  1007. alternateButton:nil
  1008. otherButton:nil
  1009. informativeTextWithFormat:NSLocalizedString(@"Please make sure your internet connection is available.", nil), nil];
  1010. [alert runModal];
  1011. return;
  1012. }
  1013. // 用户头像点击事件
  1014. self.userMenu = [[NSMenu alloc] init];
  1015. KMUserInfoViewController *userInfo = [[KMUserInfoViewController alloc] init];
  1016. NSMenuItem *item = [self.userMenu addItemWithTitle:@"" action:nil target:@""];
  1017. item.target = self;
  1018. item.representedObject = userInfo;
  1019. item.view = userInfo.view;
  1020. [self.userMenu popUpMenuPositioningItem:nil atLocation:NSMakePoint(-130, 30) inView:sender];
  1021. }
  1022. - (IBAction)signUpAction:(NSButton *)sender {
  1023. #if VERSION_FREE
  1024. #if VERSION_DMG
  1025. #else
  1026. [FMTrackEventManager.defaultManager trackEventWithEvent:@"Tbr" withProperties:@{@"Tbr_Btn" : @"Btn_Tbr_Login"}];
  1027. #endif
  1028. #endif
  1029. [KMLoginWindowsController.shared showWindow:nil];
  1030. }
  1031. - (void)userGiftAction:(id)sender {
  1032. [FMTrackEventManager.defaultManager trackEventWithEvent:@"Tbr" withProperties:@{@"Tbr_Btn" : @"Btn_Tbr_WelcomGift"}];
  1033. [[KMNewUserGiftWindowController shared] openWindow];
  1034. }
  1035. - (void)discountAction:(id)sender {
  1036. [FMTrackEventManager.defaultManager trackEventWithEvent:@"Tbr" withProperties:@{@"Tbr_Btn" : @"Btn_Tbr_Conpon"}];
  1037. #if VERSION_FREE
  1038. if ([[KMCheckInManager default] trailCancel] || [[KMCheckInManager default] advancedYearSubscribeTrailCancelForLocal]) {
  1039. [[KMProductCompareWC shared] setOrientation:true];
  1040. #if VERSION_DMG
  1041. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeDmg_Base];
  1042. #else
  1043. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeLite_Base];
  1044. #endif
  1045. [[KMProductCompareWC shared] openWindowWithDiscountType:KMDiscountTypeAdvancedYearSubscribeTrialingCancel];
  1046. } else {
  1047. [[KMProductCompareWC shared] setOrientation:true];
  1048. #if VERSION_DMG
  1049. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeDmg_Base];
  1050. #else
  1051. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeLite_Base];
  1052. #endif
  1053. [[KMProductCompareWC shared] openWindowWithDiscountType:KMDiscountTypeNewUserGift];
  1054. }
  1055. #endif
  1056. }
  1057. #pragma mark - NSNotification Methods
  1058. - (void)deviceActivateStatusChangeNotification:(NSNotification *)notification {
  1059. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.4 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  1060. [self reloadData];
  1061. });
  1062. }
  1063. - (void)IAPProductLoaded:(NSNotification *)notification {
  1064. dispatch_async(dispatch_get_main_queue(), ^{
  1065. [self reloadData];
  1066. });
  1067. }
  1068. - (void)IAPResultReceived:(NSNotification *)notification {
  1069. dispatch_async(dispatch_get_main_queue(), ^{
  1070. [self reloadData];
  1071. });
  1072. }
  1073. - (void)IAPPurchaseSuccess:(NSNotification *)notification {
  1074. dispatch_async(dispatch_get_main_queue(), ^{
  1075. [self reloadData];
  1076. #if VERSION_FREE
  1077. #if VERSION_DMG
  1078. #else
  1079. [[KMProductCompareWC shared] closeAction];
  1080. #endif
  1081. #endif
  1082. });
  1083. }
  1084. - (void)IAPRestoreFinish:(NSNotification *)notification {
  1085. dispatch_async(dispatch_get_main_queue(), ^{
  1086. [self reloadData];
  1087. });
  1088. }
  1089. - (void)trailCancelStateDidChange:(NSNotification *)noti {
  1090. dispatch_async(dispatch_get_main_queue(), ^{
  1091. [self reloadData];
  1092. });
  1093. }
  1094. - (void)advertisementDidLoaded:(NSNotification *)noti {
  1095. dispatch_async(dispatch_get_main_queue(), ^{
  1096. [self reloadData];
  1097. });
  1098. }
  1099. #pragma mark - Event
  1100. - (void)mouseEntered:(NSEvent *)event {
  1101. if (ActivityStatusTrialExpire == [VerificationManager manager].status ||
  1102. ActivityStatusTrial == [VerificationManager manager].status) {
  1103. [[self class] cancelPreviousPerformRequestsWithTarget:self];
  1104. if (!self.popover.isShown) {
  1105. [self buttonAction:self.button];
  1106. }
  1107. }
  1108. }
  1109. - (void)mouseExited:(NSEvent *)event {
  1110. [super mouseExited:event];
  1111. [self performSelector:@selector(popOverCloseAction) withObject:nil afterDelay:0.35];
  1112. }
  1113. - (void)popoverDidClose:(NSNotification *)notification {
  1114. self.stopPopOverHide = NO;
  1115. }
  1116. - (void)popoverShowNoti:(NSNotification *)noti {
  1117. if (self.popover) {
  1118. [self.popover close];
  1119. self.stopPopOverHide = NO;
  1120. }
  1121. }
  1122. - (void)loginSuccessNotification:(NSNotification *)noti {
  1123. dispatch_async(dispatch_get_main_queue(), ^{
  1124. self.userButton.image = [NSImage imageNamed:@"UserProfilePicture"];
  1125. [self reloadData];
  1126. });
  1127. }
  1128. - (void)logoutSuccessNotification:(NSNotification *)noti {
  1129. dispatch_async(dispatch_get_main_queue(), ^{
  1130. self.userButton.image = [NSImage imageNamed:@"UserProfilePicture1"];
  1131. [self reloadData];
  1132. });
  1133. }
  1134. - (void)expandPersonalCenterNotification:(NSNotification *)noti {
  1135. if (self.userMenu != nil) {
  1136. [self personalCenterAction:_userButton];
  1137. }
  1138. }
  1139. - (void)closeMenu:(NSNotification *)noti {
  1140. if (self.userMenu != nil) {
  1141. [self.userMenu cancelTracking];
  1142. self.userMenu = nil;
  1143. }
  1144. }
  1145. - (void)subscriptionLoadedNotification:(NSNotification *)noti {
  1146. dispatch_async(dispatch_get_main_queue(), ^{
  1147. [self reloadData];
  1148. });
  1149. }
  1150. - (void)memberInfoChangeNotification:(NSNotification *)noti {
  1151. dispatch_async(dispatch_get_main_queue(), ^{
  1152. [self reloadData];
  1153. });
  1154. }
  1155. - (void)popOverCloseAction {
  1156. if (self.stopPopOverHide == NO) {
  1157. if (ActivityStatusTrialExpire == [VerificationManager manager].status ||
  1158. ActivityStatusTrial == [VerificationManager manager].status) {
  1159. if (self.popover.isShown) {
  1160. [self.popover close];
  1161. self.stopPopOverHide = NO;
  1162. }
  1163. }
  1164. }
  1165. }
  1166. @end