KMVerificationMessageViewController.m 58 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329
  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. - (IBAction)personalCenterAction:(NSButton *)sender {
  1023. if (![KMCloudServer isConnectionAvailable]) {
  1024. NSAlert *alert = [NSAlert alertWithMessageText:NSLocalizedString(@"Connection Error", nil)
  1025. defaultButton:NSLocalizedString(@"OK", nil)
  1026. alternateButton:nil
  1027. otherButton:nil
  1028. informativeTextWithFormat:NSLocalizedString(@"Please make sure your internet connection is available.", nil), nil];
  1029. [alert runModal];
  1030. return;
  1031. }
  1032. // 用户头像点击事件
  1033. self.userMenu = [[NSMenu alloc] init];
  1034. KMUserInfoViewController *userInfo = [[KMUserInfoViewController alloc] init];
  1035. NSMenuItem *item = [self.userMenu addItemWithTitle:@"" action:nil target:@""];
  1036. item.target = self;
  1037. item.representedObject = userInfo;
  1038. item.view = userInfo.view;
  1039. [self.userMenu popUpMenuPositioningItem:nil atLocation:NSMakePoint(-130, 30) inView:sender];
  1040. }
  1041. - (IBAction)signUpAction:(NSButton *)sender {
  1042. #if VERSION_FREE
  1043. #if VERSION_DMG
  1044. #else
  1045. [FMTrackEventManager.defaultManager trackEventWithEvent:@"Tbr" withProperties:@{@"Tbr_Btn" : @"Btn_Tbr_Login"}];
  1046. #endif
  1047. #endif
  1048. [KMLoginWindowsController.shared showWindow:nil];
  1049. }
  1050. - (void)userGiftAction:(id)sender {
  1051. [FMTrackEventManager.defaultManager trackEventWithEvent:@"Tbr" withProperties:@{@"Tbr_Btn" : @"Btn_Tbr_WelcomGift"}];
  1052. [[KMNewUserGiftWindowController shared] openWindow];
  1053. }
  1054. - (void)discountAction:(id)sender {
  1055. [FMTrackEventManager.defaultManager trackEventWithEvent:@"Tbr" withProperties:@{@"Tbr_Btn" : @"Btn_Tbr_Conpon"}];
  1056. #if VERSION_FREE
  1057. if ([[KMCheckInManager default] trailCancel] || [[KMCheckInManager default] advancedYearSubscribeTrailCancelForLocal]) {
  1058. [[KMProductCompareWC shared] setOrientation:true];
  1059. #if VERSION_DMG
  1060. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeDmg_Base];
  1061. #else
  1062. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeLite_Base];
  1063. #endif
  1064. [[KMProductCompareWC shared] openWindowWithDiscountType:KMDiscountTypeAdvancedYearSubscribeTrialingCancel];
  1065. } else {
  1066. [[KMProductCompareWC shared] setOrientation:true];
  1067. #if VERSION_DMG
  1068. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeDmg_Base];
  1069. #else
  1070. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeLite_Base];
  1071. #endif
  1072. [[KMProductCompareWC shared] openWindowWithDiscountType:KMDiscountTypeNewUserGift];
  1073. }
  1074. #endif
  1075. }
  1076. #pragma mark - NSNotification Methods
  1077. - (void)deviceActivateStatusChangeNotification:(NSNotification *)notification {
  1078. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.4 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  1079. [self reloadData];
  1080. });
  1081. }
  1082. - (void)IAPProductLoaded:(NSNotification *)notification {
  1083. dispatch_async(dispatch_get_main_queue(), ^{
  1084. [self reloadData];
  1085. });
  1086. }
  1087. - (void)IAPResultReceived:(NSNotification *)notification {
  1088. dispatch_async(dispatch_get_main_queue(), ^{
  1089. [self reloadData];
  1090. });
  1091. }
  1092. - (void)IAPPurchaseSuccess:(NSNotification *)notification {
  1093. dispatch_async(dispatch_get_main_queue(), ^{
  1094. [self reloadData];
  1095. #if VERSION_FREE
  1096. #if VERSION_DMG
  1097. #else
  1098. [[KMProductCompareWC shared] closeAction];
  1099. #endif
  1100. #endif
  1101. });
  1102. }
  1103. - (void)IAPRestoreFinish:(NSNotification *)notification {
  1104. dispatch_async(dispatch_get_main_queue(), ^{
  1105. [self reloadData];
  1106. });
  1107. }
  1108. - (void)trailCancelStateDidChange:(NSNotification *)noti {
  1109. dispatch_async(dispatch_get_main_queue(), ^{
  1110. [self reloadData];
  1111. });
  1112. }
  1113. - (void)advertisementDidLoaded:(NSNotification *)noti {
  1114. dispatch_async(dispatch_get_main_queue(), ^{
  1115. [self reloadData];
  1116. });
  1117. }
  1118. #pragma mark - Event
  1119. - (void)mouseEntered:(NSEvent *)event {
  1120. if (ActivityStatusTrialExpire == [VerificationManager manager].status ||
  1121. ActivityStatusTrial == [VerificationManager manager].status) {
  1122. [[self class] cancelPreviousPerformRequestsWithTarget:self];
  1123. if (!self.popover.isShown) {
  1124. [self buttonAction:self.button];
  1125. }
  1126. }
  1127. }
  1128. - (void)mouseExited:(NSEvent *)event {
  1129. [super mouseExited:event];
  1130. [self performSelector:@selector(popOverCloseAction) withObject:nil afterDelay:0.35];
  1131. }
  1132. - (void)popoverDidClose:(NSNotification *)notification {
  1133. self.stopPopOverHide = NO;
  1134. }
  1135. - (void)popoverShowNoti:(NSNotification *)noti {
  1136. if (self.popover) {
  1137. [self.popover close];
  1138. self.stopPopOverHide = NO;
  1139. }
  1140. }
  1141. - (void)loginSuccessNotification:(NSNotification *)noti {
  1142. dispatch_async(dispatch_get_main_queue(), ^{
  1143. self.userButton.image = [NSImage imageNamed:@"UserProfilePicture"];
  1144. [self reloadData];
  1145. });
  1146. }
  1147. - (void)logoutSuccessNotification:(NSNotification *)noti {
  1148. dispatch_async(dispatch_get_main_queue(), ^{
  1149. self.userButton.image = [NSImage imageNamed:@"UserProfilePicture1"];
  1150. [self reloadData];
  1151. });
  1152. }
  1153. - (void)expandPersonalCenterNotification:(NSNotification *)noti {
  1154. if (self.userMenu != nil) {
  1155. [self personalCenterAction:_userButton];
  1156. }
  1157. }
  1158. - (void)closeMenu:(NSNotification *)noti {
  1159. if (self.userMenu != nil) {
  1160. [self.userMenu cancelTracking];
  1161. self.userMenu = nil;
  1162. }
  1163. }
  1164. - (void)subscriptionLoadedNotification:(NSNotification *)noti {
  1165. dispatch_async(dispatch_get_main_queue(), ^{
  1166. [self reloadData];
  1167. });
  1168. }
  1169. - (void)memberInfoChangeNotification:(NSNotification *)noti {
  1170. dispatch_async(dispatch_get_main_queue(), ^{
  1171. [self reloadData];
  1172. });
  1173. }
  1174. - (void)popOverCloseAction {
  1175. if (self.stopPopOverHide == NO) {
  1176. if (ActivityStatusTrialExpire == [VerificationManager manager].status ||
  1177. ActivityStatusTrial == [VerificationManager manager].status) {
  1178. if (self.popover.isShown) {
  1179. [self.popover close];
  1180. self.stopPopOverHide = NO;
  1181. }
  1182. }
  1183. }
  1184. }
  1185. @end