KMVerificationMessageViewController.m 59 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352
  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. BOOL advanceFreeTrailing = [IAPReceiptTool isFreeTrailingWithModel:[IAPProductsManager defaultManager].receiptModel withProductId:[IAPProductsManager defaultManager].fourDevicesAllAccessPackNew12months_lite.product.productIdentifier];
  534. if (advanceFreeTrailing && [[KMCheckInManager default] advancedYearSubscribeTrailCancelForLocal]) {
  535. [self.datas addObject:[self _createDiscountModelWithType:KMMessageTypeDiscount]];
  536. } else {
  537. self.button.title = @"";
  538. buttonHiddenFlag = true;
  539. }
  540. } else {
  541. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Upgrade", nil)];
  542. messageType = KMMessageTypeUpgrade;
  543. }
  544. } else {
  545. self.button.title = [self _getAppStoreFreeVersionBuyNowTitle];
  546. if ([[KMNewUserGiftManager default] needShow]) {
  547. [self.datas addObject:[self _createDiscountModelWithType:KMMessageTypeNewUserGift]];
  548. } else if ([[KMCheckInManager default] advancedYearSubscribeTrailCancelForLocal]) {
  549. [self.datas addObject:[self _createDiscountModelWithType:KMMessageTypeDiscount]];
  550. }
  551. messageType = KMMessageTypePurchaseWithoutLogin;
  552. self.button.tag = KMMessageTypePurchaseWithoutLogin;
  553. }
  554. #else
  555. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Upgrade", nil)];
  556. messageType = KMMessageTypeUpgrade;
  557. #endif
  558. } else {
  559. if(IAPProductsManager.defaultManager.fourDevicesAllAccessPackNew12months_lite.isTrialPeriod == YES) { //是否有试用
  560. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedStringFromTable(@"Buy Now",@"MemberCenterLocalizable", nil)];
  561. messageType = KMMessageTypeBuyNow;
  562. } else {
  563. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Free Trial", nil)];
  564. messageType = KMMessageTypeFreeTrail;
  565. self.button.tag = KMMessageTypeFreeTrail;
  566. }
  567. KMMemberInfo *member = [KMMemberInfo shared];
  568. KMNewUserGiftManager *man = [KMNewUserGiftManager default];
  569. if ([man needShow] && [member isFreeAccount]) {
  570. NSString *titleText = [self _getDiscountTitle];
  571. NSString *calTitleText = [NSString stringWithFormat:@" %@",titleText];
  572. if (messageType != KMMessageTypeFreeTrail) {
  573. self.button.stringValue = calTitleText;
  574. }
  575. [self.datas addObject:[self _createDiscountModelWithType:KMMessageTypeDiscount]];
  576. } else if (man.progressState != KMProgressStateNone && member.isMemberAllFunction == false && [[KMCheckInManager default] trailCancel]) {
  577. NSString *titleText = [self _getDiscountTitle];
  578. NSString *calTitleText = [NSString stringWithFormat:@" %@",titleText];
  579. if (messageType != KMMessageTypeFreeTrail) {
  580. self.button.stringValue = calTitleText;
  581. }
  582. [self.datas addObject:[self _createDiscountModelWithType:KMMessageTypeDiscount]];
  583. }
  584. }
  585. #else
  586. #endif
  587. } else if (type == KMUserScenarioTypeLite_type3 ) {
  588. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedStringFromTable(@"Buy Now", @"MemberCenterLocalizable", nil)];
  589. messageType = KMMessageTypeBuyNow;
  590. } else if (type == KMUserScenarioTypeLite_type5) {
  591. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Upgrade", nil)];
  592. messageType = KMMessageTypeUpgrade;
  593. } else if (type == KMUserScenarioTypeLite_type7) {
  594. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedStringFromTable(@"Renew now", @"MemberCenterLocalizable", nil)];
  595. messageType = KMMessageTypeRenew;
  596. } else if (type == KMUserScenarioTypeLite_type8) {
  597. KMMemberInfo *member = [KMMemberInfo shared];
  598. KMNewUserGiftManager *man = [KMNewUserGiftManager default];
  599. if (man.progressState != KMProgressStateNone && [[KMCheckInManager default] trailCancel]) {
  600. NSString *titleText = [self _getDiscountTitle];
  601. NSString *calTitleText = [NSString stringWithFormat:@" %@",titleText];
  602. if (messageType != KMMessageTypeFreeTrail) {
  603. self.button.stringValue = calTitleText;
  604. }
  605. [self.datas addObject:[self _createDiscountModelWithType:KMMessageTypeDiscount]];
  606. }
  607. if (self.datas.count > 1) {
  608. } else {
  609. self.button.title = @"";
  610. buttonHiddenFlag = true;
  611. }
  612. } else if (type == KMUserScenarioTypeLite_type9) {
  613. if([KMMemberInfo shared].vip_status == 2) {
  614. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedStringFromTable(@"Renew now",@"MemberCenterLocalizable", nil)];
  615. messageType = KMMessageTypeRenew;
  616. } else if ([KMMemberInfo shared].vip_status == 4) {
  617. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedStringFromTable(@"Buy Now",@"MemberCenterLocalizable", nil)];
  618. messageType = KMMessageTypeBuyNow;
  619. } else {
  620. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Upgrade", nil)];
  621. messageType = KMMessageTypeUpgrade;
  622. }
  623. } else if (type == KMUserScenarioTypeLite_type11) {
  624. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Upgrade", nil)];
  625. messageType = KMMessageTypeUpgrade;
  626. } else if (type == KMUserScenarioTypePro_type3) {
  627. if([KMMemberInfo shared].vip_status == 2) {
  628. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedStringFromTable(@"Renew now",@"MemberCenterLocalizable", nil)];
  629. messageType = KMMessageTypeRenew;
  630. } else {
  631. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Upgrade", nil)];
  632. messageType = KMMessageTypeUpgrade;
  633. }
  634. }
  635. #if !VERSION_FREE
  636. BOOL isNoSupportMemberUpgrade = YES;
  637. if ([KMMemberInfo shared].vip_status == 1) { //订阅+永久
  638. isNoSupportMemberUpgrade = NO;
  639. }
  640. if (![IAPProductsManager defaultManager].isAvailableAdvancedPDFToOffice && isNoSupportMemberUpgrade) {
  641. [self.officeButton setTitleColor:[NSColor whiteColor]];
  642. self.officeButton.hidden = NO;
  643. self.officeImg.hidden = NO;
  644. self.officeButton.frame = CGRectMake(totalWidth, kbottomGap, officeWidth, self.view.frame.size.height -2 *kbottomGap);
  645. CGRect officeRect = self.officeButton.frame;
  646. self.officeImg.frame = officeRect;
  647. totalWidth+=CGRectGetWidth(self.officeButton.bounds);
  648. totalWidth+=4;
  649. } else {
  650. self.officeButton.hidden = YES;
  651. self.officeImg.hidden = YES;
  652. }
  653. #else
  654. self.officeButton.hidden = YES;
  655. self.officeImg.hidden = YES;
  656. #endif
  657. KMAdvertisementItem *advertiseItem = KMAdvertisementManager.manager.info.topRightInfoContent;
  658. if (advertiseItem != nil && advertiseItem.content.firstObject != nil) {
  659. KMAdvertisementItemInfo *info = KMAdvertisementManager.manager.info.topRightInfoContent.content.firstObject;
  660. NSString *name = [KMAdvertisementModelTransition transitionLanguageWithLangeuage:info.name];
  661. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(name, nil)];
  662. NSURL *url = [NSURL URLWithString: [KMAdvertisementModelTransition transitionImagePathWithImage:info.image highlight: YES]];
  663. __weak typeof(self)weakSelf = self;
  664. NSImage * img = [KMAdvertisementImage imageWithURLWithUrl:url completion:^(NSImage *image) {
  665. if (image != nil) {
  666. weakSelf.bgImg.image = image;
  667. }
  668. }];
  669. } else {
  670. CGFloat discountWidth = [self _dealDiscountViewWithMessageType:messageType];
  671. totalWidth += discountWidth;
  672. }
  673. [self.button setTitleColor:[NSColor whiteColor]];
  674. self.bgImg.hidden = NO;
  675. self.button.hidden = NO;
  676. BOOL isOldSubscribed = NO;
  677. #if VERSION_FREE
  678. #if !VERSION_DMG
  679. isOldSubscribed = (IAPProductsManager.defaultManager.allAccessPack6months_lite.isSubscribed == YES || IAPProductsManager.defaultManager.allAccessPack12months_lite.isSubscribed == YES);
  680. #endif
  681. #endif
  682. // 单平台高级版永久 未登录时 也不显示升级(因为点了也得先登录),但是登录后的卡片里是有升级按钮的,可以升级成全平台高级版年订阅
  683. //原来是订阅的,不需要升级,因为目前不支持订阅升级订阅这种场景
  684. if(type == KMUserScenarioTypeLite_type9 ||
  685. type == KMUserScenarioTypeLite_type10 ||
  686. type == KMUserScenarioTypeLite_type11) {
  687. if([KMMemberInfo shared].isLogin == NO) { //未登录
  688. self.button.hidden = YES;
  689. self.bgImg.hidden = YES;
  690. } else {
  691. if(isOldSubscribed) { //老版本付费功能是订阅包
  692. self.button.hidden = YES;
  693. self.bgImg.hidden = YES;
  694. } else {
  695. if((KMMemberInfo.shared.vip_status == 1) && [KMMemberInfo.shared.vip_paymentModel isEqualToString:@"1"]) { //会员订阅中
  696. self.button.hidden = YES;
  697. self.bgImg.hidden = YES;
  698. }
  699. }
  700. }
  701. }
  702. #if VERSION_FREE
  703. #if !VERSION_DMG
  704. if (buttonHiddenFlag) {
  705. self.bgImg.hidden = YES;
  706. self.button.hidden = YES;
  707. }
  708. #endif
  709. #endif
  710. buttonWidth = CGRectGetWidth(self.button.frame);
  711. NSRect btnRect = [self.button.attributedTitle boundingRectWithSize:CGSizeMake(MAXFLOAT, CGRectGetHeight(self.button.frame)) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading];
  712. // if (fabs(buttonWidth-btnRect.size.width)>50) {
  713. buttonWidth = btnRect.size.width + 10;
  714. // buttonWidth += 10;
  715. // }
  716. if (KMAdvertisementManager.manager.info.topRightInfoContent != nil) {
  717. if (KMAdvertisementManager.manager.info.topRightInfoContent.content.firstObject != nil) {
  718. buttonWidth += 10;
  719. buttonWidth = MIN(buttonWidth, self.remoteButtonMaxWidth);
  720. }
  721. }
  722. self.button.frame = CGRectMake(totalWidth, kbottomGap, buttonWidth, self.view.frame.size.height -2 *kbottomGap);
  723. CGRect rect = self.button.frame;
  724. self.bgImg.frame = rect;
  725. totalWidth+=CGRectGetWidth(self.button.bounds);
  726. totalWidth+=4;
  727. } else if (type == KMUserScenarioTypeLite_type12 ||
  728. type == KMUserScenarioTypeLite_type13 ||
  729. type == KMUserScenarioTypeLite_type2 ||
  730. type == KMUserScenarioTypeLite_type4 ||
  731. type == KMUserScenarioTypeLite_type6 ||
  732. type == KMUserScenarioTypeLite_type8 ||
  733. type == KMUserScenarioTypePro_type2 ||
  734. type == KMUserScenarioTypePro_type5) {
  735. self.button.hidden = YES;
  736. self.bgImg.hidden = YES;
  737. #if !VERSION_FREE
  738. BOOL isNoSupportMemberUpgrade = YES;
  739. if ([KMMemberInfo shared].vip_status == 1) { //订阅+永久
  740. isNoSupportMemberUpgrade = NO;
  741. }
  742. if (![IAPProductsManager defaultManager].isAvailableAdvancedPDFToOffice && isNoSupportMemberUpgrade) {
  743. [self.officeButton setTitleColor:[NSColor whiteColor]];
  744. self.officeButton.hidden = NO;
  745. self.officeImg.hidden = NO;
  746. self.officeButton.frame = CGRectMake(totalWidth, kbottomGap, officeWidth, self.view.frame.size.height -2 *kbottomGap);
  747. CGRect officeRect = self.officeButton.frame;
  748. self.officeImg.frame = officeRect;
  749. totalWidth+=CGRectGetWidth(self.officeButton.bounds);
  750. totalWidth+=4;
  751. } else {
  752. self.officeButton.hidden = YES;
  753. self.officeImg.hidden = YES;
  754. }
  755. #else
  756. self.officeButton.hidden = YES;
  757. self.officeImg.hidden = YES;
  758. #endif
  759. }
  760. #endif
  761. if ([KMMemberInfo shared].isLogin) {
  762. self.userButton.hidden = NO;
  763. self.userButton.frame = CGRectMake(totalWidth, 0, userImageWidth, userImageWidth);
  764. totalWidth += userImageWidth;
  765. totalWidth += 8;
  766. } else {
  767. self.signUpView.hidden = NO;
  768. self.signUpView.frame = CGRectMake(totalWidth, 0, signUpWidth, self.view.frame.size.height);
  769. totalWidth+=CGRectGetWidth(self.signUpView.bounds);
  770. }
  771. 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);
  772. if (self.frameUpdateHandle) {
  773. self.frameUpdateHandle(self.view.frame);
  774. }
  775. }
  776. #pragma mark - Button Actions
  777. - (IBAction)secondTrialAction:(NSButton *)sender {
  778. if ([VerificationManager manager].secondTrialEnabled) {
  779. KMVerificationWindowController *vc = [KMVerificationWindowController verificationWithType:KMVerificationTypeRepeatTrialGuide];
  780. [vc showWindow:nil];
  781. } else {
  782. [[KMMemberInfo shared] advancedFunctionUsageWithType:KMSubscribeWaterMarkTypeNone];
  783. }
  784. }
  785. - (IBAction)buttonAction:(id)sender {
  786. if (KMAdvertisementManager.manager.info.topRightInfoContent != nil) {
  787. if (KMAdvertisementManager.manager.info.topRightInfoContent.content.firstObject != nil) {
  788. #if VERSION_FREE
  789. #if VERSION_DMG
  790. #else
  791. [FMTrackEventManager.defaultManager trackEventWithEvent:@"Tbr" withProperties:@{@"Tbr_Btn" : @"Btn_Tbr_Sale"}];
  792. #endif
  793. #endif
  794. if ([KMMemberInfo shared].isLogin) {
  795. if ([[KMMemberInfo shared].vip_levels isEqualToString:@"1"]) {
  796. [[KMProductCompareWC shared] setOrientation:YES];
  797. #if VERSION_FREE
  798. #if VERSION_DMG
  799. // DMG
  800. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeDmg_Base];
  801. #else
  802. // AppStore 免费版本
  803. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeLite_Base];
  804. #endif
  805. #else
  806. // AppStore 付费版
  807. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypePro_Base];
  808. #endif
  809. [[KMProductCompareWC shared] showWindow:nil];
  810. } else {
  811. [[KMMemberInfo shared] advancedFunctionUsageWithType:KMSubscribeWaterMarkTypeNone];
  812. }
  813. } else {
  814. if ([self _isNowGotoPurcahseTable]) {
  815. KMProductCompareWC *winC = [KMProductCompareWC shared];
  816. // 定向跳转
  817. winC.orientation = true;
  818. // App Store 免费版 基础比较表
  819. winC.orientationType = KMCompareTableTypeLite_Base;
  820. [winC showWindow:nil];
  821. } else {
  822. [[KMLoginWindowsController shared] openWindow:^(BOOL success) {
  823. if (success) {
  824. if ([[KMMemberInfo shared].vip_levels isEqualToString:@"1"]) {
  825. [[KMProductCompareWC shared] setOrientation:YES];
  826. #if VERSION_FREE
  827. #if VERSION_DMG
  828. // DMG
  829. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeDmg_Base];
  830. #else
  831. // AppStore 免费版本
  832. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeLite_Base];
  833. #endif
  834. #else
  835. // AppStore 付费版
  836. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypePro_Base];
  837. #endif
  838. [[KMProductCompareWC shared] showWindow:nil];
  839. } else {
  840. [[KMMemberInfo shared] advancedFunctionUsageWithType:KMSubscribeWaterMarkTypeNone];
  841. }
  842. }
  843. }];
  844. }
  845. }
  846. } else {
  847. [self _trackButtonEvent];
  848. KMUserScenarioType type = [KMMemberInfo shared].userScenarioType;
  849. if (type == KMUserScenarioTypeDmg_type4) {
  850. if ([KMMemberInfo shared].isLogin) {
  851. [[KMProductCompareWC shared] setOrientation:YES];
  852. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeTrial];
  853. // [[KMProductCompareWC shared] showWindow:nil];
  854. [[KMProductCompareWC shared] openWindowWithDiscountType:KMDiscountTypeFreeTrail];
  855. } else {
  856. [[KMLoginWindowsController shared] openWindow:^(BOOL success) {
  857. if (success) {
  858. [[KMProductCompareWC shared] setOrientation:YES];
  859. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeTrial];
  860. // [[KMProductCompareWC shared] showWindow:nil];
  861. [[KMProductCompareWC shared] openWindowWithDiscountType:KMDiscountTypeFreeTrail];
  862. }
  863. }];
  864. }
  865. } else {
  866. if ([self _isNowGotoPurcahseTable] &&
  867. ![KMMemberInfo shared].isLogin) { //本机(Apple ID)无权益,且未未登录时,直接跳购买
  868. [self _doNowGotoPurcahseTable];
  869. } else {
  870. if ([[KMMemberInfo shared] isLogin] && self.button.tag == KMMessageTypeFreeTrail) { // 免费试用
  871. [[KMProductCompareWC shared] setOrientation:YES];
  872. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeTrial];
  873. [[KMProductCompareWC shared] openWindowWithDiscountType:KMDiscountTypeFreeTrail];
  874. } else {
  875. [[KMMemberInfo shared] advancedFunctionUsageWithType:KMSubscribeWaterMarkTypeInvalid];
  876. }
  877. }
  878. }
  879. }
  880. } else {
  881. [self _trackButtonEvent];
  882. KMUserScenarioType type = [KMMemberInfo shared].userScenarioType;
  883. if (type == KMUserScenarioTypeDmg_type4) {
  884. if ([KMMemberInfo shared].isLogin) {
  885. [[KMProductCompareWC shared] setOrientation:YES];
  886. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeTrial];
  887. // [[KMProductCompareWC shared] showWindow:nil];
  888. [[KMProductCompareWC shared] openWindowWithDiscountType:KMDiscountTypeFreeTrail];
  889. } else {
  890. [[KMLoginWindowsController shared] openWindow:^(BOOL success) {
  891. if (success) {
  892. [[KMProductCompareWC shared] setOrientation:YES];
  893. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeTrial];
  894. // [[KMProductCompareWC shared] showWindow:nil];
  895. [[KMProductCompareWC shared] openWindowWithDiscountType:KMDiscountTypeFreeTrail];
  896. }
  897. }];
  898. }
  899. } else {
  900. if ([self _isNowGotoPurcahseTable] && ![KMMemberInfo shared].isLogin) { //本机(Apple ID)无权益,且未未登录时,直接跳购买
  901. [self _doNowGotoPurcahseTable];
  902. } else {
  903. if ([[KMMemberInfo shared] isLogin] && self.button.tag == KMMessageTypeFreeTrail) { // 免费试用
  904. [[KMProductCompareWC shared] setOrientation:YES];
  905. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeTrial];
  906. [[KMProductCompareWC shared] openWindowWithDiscountType:KMDiscountTypeFreeTrail];
  907. } else {
  908. [[KMMemberInfo shared] advancedFunctionUsageWithType:KMSubscribeWaterMarkTypeInvalid];
  909. }
  910. }
  911. }
  912. }
  913. }
  914. - (void)_doNowGotoPurcahseTable {
  915. KMProductCompareWC *winC = [KMProductCompareWC shared];
  916. // 定向跳转
  917. winC.orientation = true;
  918. // App Store 免费版 基础比较表
  919. winC.orientationType = KMCompareTableTypeLite_Base;
  920. if ([[KMMemberInfo shared] isLogin] && self.button.tag == KMMessageTypeFreeTrail) { // 免费试用
  921. [winC openWindowWithDiscountType:KMDiscountTypeFreeTrail];
  922. } else if (self.userGiftView.isHidden == false) { // 新手礼
  923. KMMessageModel *model = nil;
  924. for (KMMessageModel *m in self.datas) {
  925. if (m.type == KMMessageTypeNewUserGift) {
  926. model = m;
  927. break;
  928. }
  929. }
  930. if (model != nil) { // 检查数据
  931. if ([[KMNewUserGiftManager default] needShow]) { // 检查条件
  932. [winC openWindowWithDiscountType:KMDiscountTypeNewUserGift];
  933. } else {
  934. [winC showWindow:nil];
  935. }
  936. } else {
  937. [winC showWindow:nil];
  938. }
  939. } else if (self.discountItemView.isHidden == false) { // 优惠卷 (新手礼 & 试用退订)
  940. KMMessageModel *model = nil;
  941. for (KMMessageModel *m in self.datas) {
  942. if (m.type == KMMessageTypeDiscount) {
  943. model = m;
  944. }
  945. }
  946. if (model != nil) { // 检查数据
  947. if ([[KMCheckInManager default] trailCancel] || [[KMCheckInManager default] advancedYearSubscribeTrailCancelForLocal]) { // 检查条件
  948. [winC openWindowWithDiscountType:KMDiscountTypeAdvancedYearSubscribeTrialingCancel];
  949. } else if ([[KMNewUserGiftManager default] needShow]) { // 检查条件
  950. [winC openWindowWithDiscountType:KMDiscountTypeNewUserGift];
  951. } else {
  952. [winC showWindow:nil];
  953. }
  954. } else {
  955. [winC showWindow:nil];
  956. }
  957. } else {
  958. [winC showWindow:nil];
  959. }
  960. }
  961. - (IBAction)officeButtonAction:(id)sender {
  962. #if VERSION_FREE
  963. #if VERSION_DMG
  964. DMGEmbeddedOldWC *embeddedWC = [DMGEmbeddedOldWC currentFirstTrialWC:@"com.brother.pdfreaderpro.mac.product_2"];
  965. [embeddedWC showWindow:nil];
  966. [embeddedWC.window center];
  967. #endif
  968. #else
  969. if ([KMMemberInfo shared].isLogin) {
  970. [[KMMemberInfo shared] productCompareShow];
  971. } else {
  972. [[KMLoginWindowsController shared] openWindow:^(BOOL success) {
  973. if (success) {
  974. [[KMMemberInfo shared] productCompareShow];
  975. }
  976. }];
  977. }
  978. #endif
  979. }
  980. - (NSAttributedString *)numberConvertColor:(NSColor*)color String:(NSString *)string {
  981. NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:string];
  982. NSString *temp = nil;
  983. for (NSUInteger i = 0; i <string.length; i++) {
  984. temp = [string substringWithRange:NSMakeRange(i, 1)];
  985. if ([self isPureInt:temp]) {
  986. [attributedString setAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
  987. color, NSForegroundColorAttributeName, nil] range:NSMakeRange(i, 1)];
  988. }
  989. }
  990. return attributedString;
  991. }
  992. - (BOOL)isPureInt:(NSString *)string {
  993. NSScanner *scan = [NSScanner scannerWithString:string];
  994. int value;
  995. return [scan scanInt:&value] && [scan isAtEnd];
  996. }
  997. - (IBAction)AIButtonAction:(NSButton *)sender {
  998. if ([[[KMMemberInfo shared] validFlag] isEqualToString:@"5"]) {
  999. [[KMMemberPromptWC shared] showWindow:sender];
  1000. [KMMemberPromptWC shared].tipType = KMMemberTipTypeSignouting;
  1001. } else {
  1002. #if VERSION_FREE
  1003. #if VERSION_DMG
  1004. KMPurchaseEmbeddedWindowController *winC = [KMPurchaseEmbeddedWindowController currentCode:KMAISubscriptionYearTrailCodeKey_DMG];
  1005. [winC showWindow:nil];
  1006. [winC.window center];
  1007. #else
  1008. [[KMFreeGetAIWC shared] showWindow:nil];
  1009. #endif
  1010. #else
  1011. [[KMFreeGetAIWC shared] showWindow:nil];
  1012. #endif
  1013. }
  1014. }
  1015. - (IBAction)userButtonAction:(NSButton *)sender {
  1016. if ([KMMemberInfo shared].isLogin) {
  1017. [self personalCenterAction:sender];
  1018. } else {
  1019. [KMLoginWindowsController.shared showWindow:nil];
  1020. }
  1021. }
  1022. - (BOOL)isConnectionAvailable {
  1023. BOOL isExistenceNetwork = YES;
  1024. Reachability *reach = [Reachability reachabilityWithHostname:@"www.apple.com"];
  1025. switch ([reach currentReachabilityStatus]) {
  1026. case NotReachable:
  1027. isExistenceNetwork = NO;
  1028. //NSLog(@"notReachable");
  1029. break;
  1030. case ReachableViaWiFi:
  1031. isExistenceNetwork = YES;
  1032. //NSLog(@"WIFI");
  1033. break;
  1034. case ReachableViaWWAN:
  1035. isExistenceNetwork = YES;
  1036. //NSLog(@"3G");
  1037. break;
  1038. }
  1039. if (NotReachable == [[Reachability reachabilityForInternetConnection] currentReachabilityStatus]) {
  1040. return NO;
  1041. }
  1042. return YES;
  1043. }
  1044. - (IBAction)personalCenterAction:(NSButton *)sender {
  1045. if (![self isConnectionAvailable]) {
  1046. NSAlert *alert = [NSAlert alertWithMessageText:NSLocalizedString(@"Connection Error", nil)
  1047. defaultButton:NSLocalizedString(@"OK", nil)
  1048. alternateButton:nil
  1049. otherButton:nil
  1050. informativeTextWithFormat:NSLocalizedString(@"Please make sure your internet connection is available.", nil), nil];
  1051. [alert runModal];
  1052. return;
  1053. }
  1054. // 用户头像点击事件
  1055. self.userMenu = [[NSMenu alloc] init];
  1056. KMUserInfoViewController *userInfo = [[KMUserInfoViewController alloc] init];
  1057. NSMenuItem *item = [self.userMenu addItemWithTitle:@"" action:nil target:@""];
  1058. item.target = self;
  1059. item.representedObject = userInfo;
  1060. item.view = userInfo.view;
  1061. [self.userMenu popUpMenuPositioningItem:nil atLocation:NSMakePoint(-130, 30) inView:sender];
  1062. }
  1063. - (IBAction)signUpAction:(NSButton *)sender {
  1064. #if VERSION_FREE
  1065. #if VERSION_DMG
  1066. #else
  1067. [FMTrackEventManager.defaultManager trackEventWithEvent:@"Tbr" withProperties:@{@"Tbr_Btn" : @"Btn_Tbr_Login"}];
  1068. #endif
  1069. #endif
  1070. [KMLoginWindowsController.shared showWindow:nil];
  1071. }
  1072. - (void)userGiftAction:(id)sender {
  1073. [FMTrackEventManager.defaultManager trackEventWithEvent:@"Tbr" withProperties:@{@"Tbr_Btn" : @"Btn_Tbr_WelcomGift"}];
  1074. [[KMNewUserGiftWindowController shared] openWindow];
  1075. }
  1076. - (void)discountAction:(id)sender {
  1077. [FMTrackEventManager.defaultManager trackEventWithEvent:@"Tbr" withProperties:@{@"Tbr_Btn" : @"Btn_Tbr_Conpon"}];
  1078. #if VERSION_FREE
  1079. if ([[KMCheckInManager default] trailCancel] || [[KMCheckInManager default] advancedYearSubscribeTrailCancelForLocal]) {
  1080. [[KMProductCompareWC shared] setOrientation:true];
  1081. #if VERSION_DMG
  1082. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeDmg_Base];
  1083. #else
  1084. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeLite_Base];
  1085. #endif
  1086. [[KMProductCompareWC shared] openWindowWithDiscountType:KMDiscountTypeAdvancedYearSubscribeTrialingCancel];
  1087. } else {
  1088. [[KMProductCompareWC shared] setOrientation:true];
  1089. #if VERSION_DMG
  1090. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeDmg_Base];
  1091. #else
  1092. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeLite_Base];
  1093. #endif
  1094. [[KMProductCompareWC shared] openWindowWithDiscountType:KMDiscountTypeNewUserGift];
  1095. }
  1096. #endif
  1097. }
  1098. #pragma mark - NSNotification Methods
  1099. - (void)deviceActivateStatusChangeNotification:(NSNotification *)notification {
  1100. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.4 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  1101. [self reloadData];
  1102. });
  1103. }
  1104. - (void)IAPProductLoaded:(NSNotification *)notification {
  1105. dispatch_async(dispatch_get_main_queue(), ^{
  1106. [self reloadData];
  1107. });
  1108. }
  1109. - (void)IAPResultReceived:(NSNotification *)notification {
  1110. dispatch_async(dispatch_get_main_queue(), ^{
  1111. [self reloadData];
  1112. });
  1113. }
  1114. - (void)IAPPurchaseSuccess:(NSNotification *)notification {
  1115. dispatch_async(dispatch_get_main_queue(), ^{
  1116. [self reloadData];
  1117. #if VERSION_FREE
  1118. #if VERSION_DMG
  1119. #else
  1120. [[KMProductCompareWC shared] closeAction];
  1121. #endif
  1122. #endif
  1123. });
  1124. }
  1125. - (void)IAPRestoreFinish:(NSNotification *)notification {
  1126. dispatch_async(dispatch_get_main_queue(), ^{
  1127. [self reloadData];
  1128. });
  1129. }
  1130. - (void)trailCancelStateDidChange:(NSNotification *)noti {
  1131. dispatch_async(dispatch_get_main_queue(), ^{
  1132. [self reloadData];
  1133. });
  1134. }
  1135. - (void)advertisementDidLoaded:(NSNotification *)noti {
  1136. dispatch_async(dispatch_get_main_queue(), ^{
  1137. [self reloadData];
  1138. });
  1139. }
  1140. #pragma mark - Event
  1141. - (void)mouseEntered:(NSEvent *)event {
  1142. if (ActivityStatusTrialExpire == [VerificationManager manager].status ||
  1143. ActivityStatusTrial == [VerificationManager manager].status) {
  1144. [[self class] cancelPreviousPerformRequestsWithTarget:self];
  1145. if (!self.popover.isShown) {
  1146. [self buttonAction:self.button];
  1147. }
  1148. }
  1149. }
  1150. - (void)mouseExited:(NSEvent *)event {
  1151. [super mouseExited:event];
  1152. [self performSelector:@selector(popOverCloseAction) withObject:nil afterDelay:0.35];
  1153. }
  1154. - (void)popoverDidClose:(NSNotification *)notification {
  1155. self.stopPopOverHide = NO;
  1156. }
  1157. - (void)popoverShowNoti:(NSNotification *)noti {
  1158. if (self.popover) {
  1159. [self.popover close];
  1160. self.stopPopOverHide = NO;
  1161. }
  1162. }
  1163. - (void)loginSuccessNotification:(NSNotification *)noti {
  1164. dispatch_async(dispatch_get_main_queue(), ^{
  1165. self.userButton.image = [NSImage imageNamed:@"UserProfilePicture"];
  1166. [self reloadData];
  1167. });
  1168. }
  1169. - (void)logoutSuccessNotification:(NSNotification *)noti {
  1170. dispatch_async(dispatch_get_main_queue(), ^{
  1171. self.userButton.image = [NSImage imageNamed:@"UserProfilePicture1"];
  1172. [self reloadData];
  1173. });
  1174. }
  1175. - (void)expandPersonalCenterNotification:(NSNotification *)noti {
  1176. if (self.userMenu != nil) {
  1177. [self personalCenterAction:_userButton];
  1178. }
  1179. }
  1180. - (void)closeMenu:(NSNotification *)noti {
  1181. if (self.userMenu != nil) {
  1182. [self.userMenu cancelTracking];
  1183. self.userMenu = nil;
  1184. }
  1185. }
  1186. - (void)subscriptionLoadedNotification:(NSNotification *)noti {
  1187. dispatch_async(dispatch_get_main_queue(), ^{
  1188. [self reloadData];
  1189. });
  1190. }
  1191. - (void)memberInfoChangeNotification:(NSNotification *)noti {
  1192. dispatch_async(dispatch_get_main_queue(), ^{
  1193. [self reloadData];
  1194. });
  1195. }
  1196. - (void)popOverCloseAction {
  1197. if (self.stopPopOverHide == NO) {
  1198. if (ActivityStatusTrialExpire == [VerificationManager manager].status ||
  1199. ActivityStatusTrial == [VerificationManager manager].status) {
  1200. if (self.popover.isShown) {
  1201. [self.popover close];
  1202. self.stopPopOverHide = NO;
  1203. }
  1204. }
  1205. }
  1206. }
  1207. @end