KMVerificationMessageViewController.m 57 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315
  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. }
  862. }];
  863. }
  864. } else {
  865. if ([self _isNowGotoPurcahseTable] &&
  866. ![KMMemberInfo shared].isLogin) { //本机(Apple ID)无权益,且未未登录时,直接跳购买
  867. [self _doNowGotoPurcahseTable];
  868. } else {
  869. [[KMMemberInfo shared] advancedFunctionUsageWithType:KMSubscribeWaterMarkTypeInvalid];
  870. }
  871. }
  872. }
  873. } else {
  874. [self _trackButtonEvent];
  875. KMUserScenarioType type = [KMMemberInfo shared].userScenarioType;
  876. if (type == KMUserScenarioTypeDmg_type4) {
  877. if ([KMMemberInfo shared].isLogin) {
  878. [[KMProductCompareWC shared] setOrientation:YES];
  879. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeTrial];
  880. // [[KMProductCompareWC shared] showWindow:nil];
  881. [[KMProductCompareWC shared] openWindowWithDiscountType:KMDiscountTypeFreeTrail];
  882. } else {
  883. [[KMLoginWindowsController shared] openWindow:^(BOOL success) {
  884. if (success) {
  885. [[KMProductCompareWC shared] setOrientation:YES];
  886. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeTrial];
  887. [[KMProductCompareWC shared] showWindow:nil];
  888. }
  889. }];
  890. }
  891. } else {
  892. if ([self _isNowGotoPurcahseTable] && ![KMMemberInfo shared].isLogin) { //本机(Apple ID)无权益,且未未登录时,直接跳购买
  893. [self _doNowGotoPurcahseTable];
  894. } else {
  895. [[KMMemberInfo shared] advancedFunctionUsageWithType:KMSubscribeWaterMarkTypeInvalid];
  896. }
  897. }
  898. }
  899. }
  900. - (void)_doNowGotoPurcahseTable {
  901. KMProductCompareWC *winC = [KMProductCompareWC shared];
  902. // 定向跳转
  903. winC.orientation = true;
  904. // App Store 免费版 基础比较表
  905. winC.orientationType = KMCompareTableTypeLite_Base;
  906. if ([[KMMemberInfo shared] isLogin] && self.button.tag == KMMessageTypeFreeTrail) { // 免费试用
  907. [winC openWindowWithDiscountType:KMDiscountTypeFreeTrail];
  908. } else if (self.userGiftView.isHidden == false) { // 新手礼
  909. KMMessageModel *model = nil;
  910. for (KMMessageModel *m in self.datas) {
  911. if (m.type == KMMessageTypeNewUserGift) {
  912. model = m;
  913. break;
  914. }
  915. }
  916. if (model != nil) { // 检查数据
  917. if ([[KMNewUserGiftManager default] needShow]) { // 检查条件
  918. [winC openWindowWithDiscountType:KMDiscountTypeNewUserGift];
  919. } else {
  920. [winC showWindow:nil];
  921. }
  922. } else {
  923. [winC showWindow:nil];
  924. }
  925. } else if (self.discountItemView.isHidden == false) { // 优惠卷 (新手礼 & 试用退订)
  926. KMMessageModel *model = nil;
  927. for (KMMessageModel *m in self.datas) {
  928. if (m.type == KMMessageTypeDiscount) {
  929. model = m;
  930. }
  931. }
  932. if (model != nil) { // 检查数据
  933. if ([[KMCheckInManager default] trailCancel] || [[KMCheckInManager default] advancedYearSubscribeTrailCancelForLocal]) { // 检查条件
  934. [winC openWindowWithDiscountType:KMDiscountTypeAdvancedYearSubscribeTrialingCancel];
  935. } else if ([[KMNewUserGiftManager default] needShow]) { // 检查条件
  936. [winC openWindowWithDiscountType:KMDiscountTypeNewUserGift];
  937. } else {
  938. [winC showWindow:nil];
  939. }
  940. } else {
  941. [winC showWindow:nil];
  942. }
  943. } else {
  944. [winC showWindow:nil];
  945. }
  946. }
  947. - (IBAction)officeButtonAction:(id)sender {
  948. #if VERSION_FREE
  949. #if VERSION_DMG
  950. DMGEmbeddedOldWC *embeddedWC = [DMGEmbeddedOldWC currentFirstTrialWC:@"com.brother.pdfreaderpro.mac.product_2"];
  951. [embeddedWC showWindow:nil];
  952. [embeddedWC.window center];
  953. #endif
  954. #else
  955. if ([KMMemberInfo shared].isLogin) {
  956. [[KMMemberInfo shared] productCompareShow];
  957. } else {
  958. [[KMLoginWindowsController shared] openWindow:^(BOOL success) {
  959. if (success) {
  960. [[KMMemberInfo shared] productCompareShow];
  961. }
  962. }];
  963. }
  964. #endif
  965. }
  966. - (NSAttributedString *)numberConvertColor:(NSColor*)color String:(NSString *)string {
  967. NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:string];
  968. NSString *temp = nil;
  969. for (NSUInteger i = 0; i <string.length; i++) {
  970. temp = [string substringWithRange:NSMakeRange(i, 1)];
  971. if ([self isPureInt:temp]) {
  972. [attributedString setAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
  973. color, NSForegroundColorAttributeName, nil] range:NSMakeRange(i, 1)];
  974. }
  975. }
  976. return attributedString;
  977. }
  978. - (BOOL)isPureInt:(NSString *)string {
  979. NSScanner *scan = [NSScanner scannerWithString:string];
  980. int value;
  981. return [scan scanInt:&value] && [scan isAtEnd];
  982. }
  983. - (IBAction)AIButtonAction:(NSButton *)sender {
  984. if ([[[KMMemberInfo shared] validFlag] isEqualToString:@"5"]) {
  985. [[KMMemberPromptWC shared] showWindow:sender];
  986. [KMMemberPromptWC shared].tipType = KMMemberTipTypeSignouting;
  987. } else {
  988. #if VERSION_FREE
  989. #if VERSION_DMG
  990. KMPurchaseEmbeddedWindowController *winC = [KMPurchaseEmbeddedWindowController currentCode:KMAISubscriptionYearTrailCodeKey_DMG];
  991. [winC showWindow:nil];
  992. [winC.window center];
  993. #else
  994. [[KMFreeGetAIWC shared] showWindow:nil];
  995. #endif
  996. #else
  997. [[KMFreeGetAIWC shared] showWindow:nil];
  998. #endif
  999. }
  1000. }
  1001. - (IBAction)userButtonAction:(NSButton *)sender {
  1002. if ([KMMemberInfo shared].isLogin) {
  1003. [self personalCenterAction:sender];
  1004. } else {
  1005. [KMLoginWindowsController.shared showWindow:nil];
  1006. }
  1007. }
  1008. - (IBAction)personalCenterAction:(NSButton *)sender {
  1009. if (![KMCloudServer isConnectionAvailable]) {
  1010. NSAlert *alert = [NSAlert alertWithMessageText:NSLocalizedString(@"Connection Error", nil)
  1011. defaultButton:NSLocalizedString(@"OK", nil)
  1012. alternateButton:nil
  1013. otherButton:nil
  1014. informativeTextWithFormat:NSLocalizedString(@"Please make sure your internet connection is available.", nil), nil];
  1015. [alert runModal];
  1016. return;
  1017. }
  1018. // 用户头像点击事件
  1019. self.userMenu = [[NSMenu alloc] init];
  1020. KMUserInfoViewController *userInfo = [[KMUserInfoViewController alloc] init];
  1021. NSMenuItem *item = [self.userMenu addItemWithTitle:@"" action:nil target:@""];
  1022. item.target = self;
  1023. item.representedObject = userInfo;
  1024. item.view = userInfo.view;
  1025. [self.userMenu popUpMenuPositioningItem:nil atLocation:NSMakePoint(-130, 30) inView:sender];
  1026. }
  1027. - (IBAction)signUpAction:(NSButton *)sender {
  1028. #if VERSION_FREE
  1029. #if VERSION_DMG
  1030. #else
  1031. [FMTrackEventManager.defaultManager trackEventWithEvent:@"Tbr" withProperties:@{@"Tbr_Btn" : @"Btn_Tbr_Login"}];
  1032. #endif
  1033. #endif
  1034. [KMLoginWindowsController.shared showWindow:nil];
  1035. }
  1036. - (void)userGiftAction:(id)sender {
  1037. [FMTrackEventManager.defaultManager trackEventWithEvent:@"Tbr" withProperties:@{@"Tbr_Btn" : @"Btn_Tbr_WelcomGift"}];
  1038. [[KMNewUserGiftWindowController shared] openWindow];
  1039. }
  1040. - (void)discountAction:(id)sender {
  1041. [FMTrackEventManager.defaultManager trackEventWithEvent:@"Tbr" withProperties:@{@"Tbr_Btn" : @"Btn_Tbr_Conpon"}];
  1042. #if VERSION_FREE
  1043. if ([[KMCheckInManager default] trailCancel] || [[KMCheckInManager default] advancedYearSubscribeTrailCancelForLocal]) {
  1044. [[KMProductCompareWC shared] setOrientation:true];
  1045. #if VERSION_DMG
  1046. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeDmg_Base];
  1047. #else
  1048. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeLite_Base];
  1049. #endif
  1050. [[KMProductCompareWC shared] openWindowWithDiscountType:KMDiscountTypeAdvancedYearSubscribeTrialingCancel];
  1051. } else {
  1052. [[KMProductCompareWC shared] setOrientation:true];
  1053. #if VERSION_DMG
  1054. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeDmg_Base];
  1055. #else
  1056. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeLite_Base];
  1057. #endif
  1058. [[KMProductCompareWC shared] openWindowWithDiscountType:KMDiscountTypeNewUserGift];
  1059. }
  1060. #endif
  1061. }
  1062. #pragma mark - NSNotification Methods
  1063. - (void)deviceActivateStatusChangeNotification:(NSNotification *)notification {
  1064. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.4 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  1065. [self reloadData];
  1066. });
  1067. }
  1068. - (void)IAPProductLoaded:(NSNotification *)notification {
  1069. dispatch_async(dispatch_get_main_queue(), ^{
  1070. [self reloadData];
  1071. });
  1072. }
  1073. - (void)IAPResultReceived:(NSNotification *)notification {
  1074. dispatch_async(dispatch_get_main_queue(), ^{
  1075. [self reloadData];
  1076. });
  1077. }
  1078. - (void)IAPPurchaseSuccess:(NSNotification *)notification {
  1079. dispatch_async(dispatch_get_main_queue(), ^{
  1080. [self reloadData];
  1081. #if VERSION_FREE
  1082. #if VERSION_DMG
  1083. #else
  1084. [[KMProductCompareWC shared] closeAction];
  1085. #endif
  1086. #endif
  1087. });
  1088. }
  1089. - (void)IAPRestoreFinish:(NSNotification *)notification {
  1090. dispatch_async(dispatch_get_main_queue(), ^{
  1091. [self reloadData];
  1092. });
  1093. }
  1094. - (void)trailCancelStateDidChange:(NSNotification *)noti {
  1095. dispatch_async(dispatch_get_main_queue(), ^{
  1096. [self reloadData];
  1097. });
  1098. }
  1099. - (void)advertisementDidLoaded:(NSNotification *)noti {
  1100. dispatch_async(dispatch_get_main_queue(), ^{
  1101. [self reloadData];
  1102. });
  1103. }
  1104. #pragma mark - Event
  1105. - (void)mouseEntered:(NSEvent *)event {
  1106. if (ActivityStatusTrialExpire == [VerificationManager manager].status ||
  1107. ActivityStatusTrial == [VerificationManager manager].status) {
  1108. [[self class] cancelPreviousPerformRequestsWithTarget:self];
  1109. if (!self.popover.isShown) {
  1110. [self buttonAction:self.button];
  1111. }
  1112. }
  1113. }
  1114. - (void)mouseExited:(NSEvent *)event {
  1115. [super mouseExited:event];
  1116. [self performSelector:@selector(popOverCloseAction) withObject:nil afterDelay:0.35];
  1117. }
  1118. - (void)popoverDidClose:(NSNotification *)notification {
  1119. self.stopPopOverHide = NO;
  1120. }
  1121. - (void)popoverShowNoti:(NSNotification *)noti {
  1122. if (self.popover) {
  1123. [self.popover close];
  1124. self.stopPopOverHide = NO;
  1125. }
  1126. }
  1127. - (void)loginSuccessNotification:(NSNotification *)noti {
  1128. dispatch_async(dispatch_get_main_queue(), ^{
  1129. self.userButton.image = [NSImage imageNamed:@"UserProfilePicture"];
  1130. [self reloadData];
  1131. });
  1132. }
  1133. - (void)logoutSuccessNotification:(NSNotification *)noti {
  1134. dispatch_async(dispatch_get_main_queue(), ^{
  1135. self.userButton.image = [NSImage imageNamed:@"UserProfilePicture1"];
  1136. [self reloadData];
  1137. });
  1138. }
  1139. - (void)expandPersonalCenterNotification:(NSNotification *)noti {
  1140. if (self.userMenu != nil) {
  1141. [self personalCenterAction:_userButton];
  1142. }
  1143. }
  1144. - (void)closeMenu:(NSNotification *)noti {
  1145. if (self.userMenu != nil) {
  1146. [self.userMenu cancelTracking];
  1147. self.userMenu = nil;
  1148. }
  1149. }
  1150. - (void)subscriptionLoadedNotification:(NSNotification *)noti {
  1151. dispatch_async(dispatch_get_main_queue(), ^{
  1152. [self reloadData];
  1153. });
  1154. }
  1155. - (void)memberInfoChangeNotification:(NSNotification *)noti {
  1156. dispatch_async(dispatch_get_main_queue(), ^{
  1157. [self reloadData];
  1158. });
  1159. }
  1160. - (void)popOverCloseAction {
  1161. if (self.stopPopOverHide == NO) {
  1162. if (ActivityStatusTrialExpire == [VerificationManager manager].status ||
  1163. ActivityStatusTrial == [VerificationManager manager].status) {
  1164. if (self.popover.isShown) {
  1165. [self.popover close];
  1166. self.stopPopOverHide = NO;
  1167. }
  1168. }
  1169. }
  1170. }
  1171. @end