KMVerificationMessageViewController.m 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572
  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. #define kbottomGap 0
  14. @interface KMVerificationMessageViewController ()<
  15. NSPopoverDelegate>
  16. @property (nonatomic, assign) IBOutlet NSTextField *label;
  17. @property (nonatomic, assign) IBOutlet NSButton *button;
  18. @property (nonatomic, assign) IBOutlet NSButton *secondTrialBtn;
  19. @property (assign) IBOutlet NSView *labelContentView;
  20. @property (assign) IBOutlet NSImageView *bgImg;
  21. @property (assign) IBOutlet NSView *aiContendView;
  22. @property (assign) IBOutlet NSImageView *aiIconImg;
  23. @property (assign) IBOutlet NSTextField *aiLabel;
  24. @property (weak) IBOutlet NSButton *userButton;
  25. @property (assign) IBOutlet NSView *signUpView;
  26. @property (assign) IBOutlet NSImageView *signUpImg;
  27. @property (assign) IBOutlet NSTextField *signUpLabel;
  28. @property (nonatomic, retain) NSTrackingArea *trackingArea;
  29. @property (nonatomic, retain) NSPopover *popover;
  30. @property (nonatomic, assign) BOOL isPopoverShow;
  31. @property (nonatomic, assign) BOOL checkValue;
  32. @property (nonatomic, assign) BOOL stopPopOverHide;
  33. @property (nonatomic, retain) KMUnlockAlertViewController *testVC;
  34. @property (nonatomic, retain) NSMenu *userMenu;
  35. @end
  36. @implementation KMVerificationMessageViewController
  37. #pragma mark Init Methods
  38. - (instancetype)init {
  39. if (self = [super initWithNibName:@"KMVerificationMessageViewController" bundle:nil]) {
  40. #if VERSION_DMG
  41. [[NSNotificationCenter defaultCenter] addObserver:self
  42. selector:@selector(deviceActivateStatusChangeNotification:)
  43. name:kDeviceActivateStatusChangeNotification
  44. object:nil];
  45. #else
  46. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(IAPResultReceived:) name:KMIAPSubscriptionLoadedNotification object:nil];
  47. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(IAPPurchaseSuccess:) name:KMIAPProductPurchasedNotification object:nil];
  48. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(IAPRestoreFinish:) name:KMIAPProductRestoreFinishedNotification object:nil];
  49. #endif
  50. }
  51. return self;
  52. }
  53. - (void)dealloc {
  54. [[NSNotificationCenter defaultCenter] removeObserver:self];
  55. if (self.trackingArea) {
  56. [self.button removeTrackingArea:self.trackingArea];
  57. }
  58. }
  59. #pragma mark Setter Methods
  60. - (void)loadView {
  61. [super loadView];
  62. // Do view setup here.
  63. self.button.wantsLayer = YES;
  64. self.button.layer.masksToBounds = YES;
  65. self.button.layer.cornerRadius = 4.0;
  66. self.button.font = [NSFont SFProTextSemiboldFont:11];
  67. self.button.layer.backgroundColor = [NSColor colorWithDeviceRed:121.0/255.0 green:196.0/255.0 blue:66.0/255.0 alpha:1.0].CGColor;
  68. [self.button setAlignment:NSTextAlignmentCenter];
  69. self.secondTrialBtn.wantsLayer = YES;
  70. self.secondTrialBtn.layer.masksToBounds = YES;
  71. self.secondTrialBtn.layer.cornerRadius = 4.0;
  72. self.secondTrialBtn.font = [NSFont SFProTextSemiboldFont:11];
  73. self.secondTrialBtn.layer.backgroundColor = [NSColor colorWithDeviceRed:121.0/255.0 green:196.0/255.0 blue:66.0/255.0 alpha:1.0].CGColor;
  74. [self.secondTrialBtn setAlignment:NSTextAlignmentCenter];
  75. NSString *tTips = NSLocalizedString(@"Upgrade to Pro", nil);
  76. #if VERSION_DMG
  77. tTips = [NSString stringWithFormat:@"%@\n%@", NSLocalizedString(@"Upgrade to Permanent License with one time purchase", nil), NSLocalizedString(@"Complete the purchase in your web browser to get a license", nil)];
  78. #else
  79. tTips = [NSString stringWithFormat:@"%@\n%@", NSLocalizedString(@"Subscribe to All Access Pack to enjoy more expanded features.", nil), NSLocalizedString(@"Choose your favorite payment and enjoy flexible upgrades.", nil)];
  80. #endif
  81. self.button.toolTip = tTips;
  82. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Upgrade", nil)];
  83. [self.button setTitleColor:[NSColor whiteColor]];
  84. [self.button setAlignment:NSTextAlignmentCenter];
  85. self.secondTrialBtn.toolTip = tTips;
  86. self.secondTrialBtn.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Free Trial", nil)];
  87. [self.secondTrialBtn setTitleColor:[NSColor whiteColor]];
  88. [self.secondTrialBtn setAlignment:NSTextAlignmentCenter];
  89. self.secondTrialBtn.hidden = YES;
  90. self.labelContentView.hidden = self.bgImg.hidden = self.button.hidden = NO;
  91. self.bgImg.wantsLayer = YES;
  92. self.bgImg.image = [NSImage imageNamed:@"Upgarde_bg_icon"];
  93. self.bgImg.layer.masksToBounds = YES;
  94. self.bgImg.layer.cornerRadius = 4.;
  95. self.bgImg.hidden = YES;
  96. self.aiLabel.font = [NSFont SFProTextSemiboldFont:11];
  97. self.aiLabel.textColor = [NSColor whiteColor];
  98. [self reloadData];
  99. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(popoverShowNoti:) name:@"KMVerificationMessagePopShowNoti" object:nil];
  100. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(loginSuccessNotification:) name:@"MemberCenterLoginSuccess" object:nil];
  101. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(logoutSuccessNotification:) name:@"MemberCenterLogoutSuccess" object:nil];
  102. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(expandPersonalCenterNotification:) name:@"ExpandPersonalCenter" object:nil];
  103. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(closeMenu:) name:@"CloseMenuNotification" object:nil];
  104. }
  105. - (void)reloadData {
  106. self.label.textColor = [NSColor blackColor];
  107. self.label.hidden = NO;
  108. self.secondTrialBtn.hidden = YES;
  109. if (self.frameUpdateHandle) {
  110. self.frameUpdateHandle(self.view.frame);
  111. }
  112. CGFloat totalWidth = 8;
  113. self.button.hidden = NO;
  114. self.bgImg.hidden = NO;
  115. self.label.hidden = YES;
  116. self.secondTrialBtn.hidden = YES;
  117. self.labelContentView.hidden = YES;
  118. self.aiContendView.hidden = YES;
  119. self.userButton.hidden = YES;
  120. self.signUpView.hidden = YES;
  121. self.signUpLabel.stringValue = NSLocalizedStringFromTable(@"Sign in", @"MemberCenterLocalizable", nil);
  122. [self.signUpLabel sizeToFit];
  123. CGFloat signUpWidth = self.signUpLabel.frame.size.width;
  124. signUpWidth += 4;
  125. signUpWidth += 8;
  126. signUpWidth += 8;
  127. signUpWidth += 12;
  128. self.signUpImg.frame = CGRectMake(8, CGRectGetHeight(self.view.frame)/2.-6, 12, 12);
  129. CGRect signUplabelRect = self.signUpLabel.frame;
  130. signUplabelRect.origin.x = CGRectGetMaxX(self.signUpImg.frame) + 4;
  131. self.signUpLabel.frame = signUplabelRect;
  132. self.button.layer.backgroundColor = [NSColor clearColor].CGColor;
  133. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Upgrade to Pro", nil)];
  134. [self.button setTitleColor:[NSColor whiteColor]];
  135. self.aiLabel.stringValue = NSLocalizedStringFromTable(@"Free Use 1-Year AI Tools", @"MemberCenterLocalizable", nil);
  136. [self.aiLabel sizeToFit];
  137. CGFloat aiWidth = self.aiLabel.frame.size.width;
  138. aiWidth += 4;
  139. aiWidth += 16;
  140. aiWidth += 16;
  141. self.aiIconImg.frame = CGRectMake(8, CGRectGetHeight(self.view.frame)/2.-8, 16, 16);
  142. self.aiContendView.frame = CGRectMake(totalWidth, 0, aiWidth, self.view.frame.size.height);
  143. CGRect ailabelRect = self.aiLabel.frame;
  144. ailabelRect.origin.x = CGRectGetMaxX(self.aiIconImg.frame) + 4;
  145. self.aiLabel.frame = ailabelRect;
  146. // totalWidth+=aiWidth;
  147. // totalWidth+=4;
  148. // self.aiContendView.hidden = NO;
  149. CGFloat userImageWidth = 24;
  150. if ([KMMemberInfo shared].isLogin) {
  151. self.userButton.image = [NSImage imageNamed:@"UserProfilePicture"];
  152. } else {
  153. self.userButton.image = [NSImage imageNamed:@"UserProfilePicture1"];
  154. }
  155. CGFloat buttonWidth = CGRectGetMaxX(self.button.frame);
  156. NSRect btnRect = [self.button.attributedTitle boundingRectWithSize:CGSizeMake(MAXFLOAT, CGRectGetHeight(self.button.frame)) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading];
  157. if (fabs(buttonWidth-btnRect.size.width)>50) {
  158. buttonWidth = btnRect.size.width + 10;
  159. }
  160. if ([[KMMemberInfo shared].isHaveAIDiscount isEqualToString:@"1"]) {
  161. if(IAPProductsManager.defaultManager.aiAllAccessPack12month_pro.isTrialPeriod == false) {
  162. self.aiContendView.hidden = NO;
  163. totalWidth+=aiWidth;
  164. totalWidth+=4;
  165. }
  166. }
  167. KMUserScenarioType type = [KMMemberInfo shared].userScenarioType;
  168. if (type == KMUserScenarioTypeLite_type1 ||
  169. type == KMUserScenarioTypeLite_type3 ||
  170. type == KMUserScenarioTypeLite_type5 ||
  171. type == KMUserScenarioTypeLite_type7 ||
  172. type == KMUserScenarioTypeLite_type9 ||
  173. type == KMUserScenarioTypeLite_type11 ||
  174. type == KMUserScenarioTypePro_type1 ||
  175. type == KMUserScenarioTypePro_type3 ||
  176. type == KMUserScenarioTypePro_type4) {
  177. if (type == KMUserScenarioTypeLite_type1) { //免费用户
  178. #if !VERSION_DMG
  179. if(IAPProductsManager.defaultManager.fourDevicesAllAccessPackNew12months_lite.isTrialPeriod == YES) { //是否有试用
  180. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Upgrade", nil)];
  181. } else {
  182. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Free Trial", nil)];
  183. }
  184. #else
  185. #endif
  186. } else if (type == KMUserScenarioTypeLite_type3 ) {
  187. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedStringFromTable(@"Buy Now", @"MemberCenterLocalizable", nil)];
  188. } else if (type == KMUserScenarioTypeLite_type5) {
  189. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Upgrade", nil)];
  190. } else if (type == KMUserScenarioTypeLite_type7) {
  191. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedStringFromTable(@"Renew now", @"MemberCenterLocalizable", nil)];
  192. } else if (type == KMUserScenarioTypeLite_type9) {
  193. if([KMMemberInfo shared].vip_status == 2) {
  194. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedStringFromTable(@"Renew now",@"MemberCenterLocalizable", nil)];
  195. } else if ([KMMemberInfo shared].vip_status == 4) {
  196. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedStringFromTable(@"Buy Now",@"MemberCenterLocalizable", nil)];
  197. } else {
  198. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Upgrade", nil)];
  199. }
  200. } else if (type == KMUserScenarioTypeLite_type11) {
  201. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Upgrade", nil)];
  202. }
  203. if (type == KMUserScenarioTypeLite_type1 ||
  204. type == KMUserScenarioTypeLite_type3 ||
  205. type == KMUserScenarioTypeLite_type7 ||
  206. type == KMUserScenarioTypeLite_type11) {
  207. if (KMAdvertisementManager.manager.info.topRightInfoContent != nil) {
  208. if (KMAdvertisementManager.manager.info.topRightInfoContent.content.firstObject != nil) {
  209. KMAdvertisementItemInfo *info = KMAdvertisementManager.manager.info.topRightInfoContent.content.firstObject;
  210. NSString *name = [KMAdvertisementModelTransition transitionLanguageWithLangeuage:info.name];
  211. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(name, nil)];
  212. NSURL *url = [NSURL URLWithString: [KMAdvertisementModelTransition transitionImagePathWithImage:info.image highlight: YES]];
  213. __weak typeof(self)weakSelf = self;
  214. weakSelf.bgImg.image = [KMAdvertisementImage imageWithURLWithUrl:url completion:^(NSImage *image) {
  215. weakSelf.bgImg.image = image;
  216. }];
  217. }
  218. }
  219. }
  220. [self.button setTitleColor:[NSColor whiteColor]];
  221. self.bgImg.hidden = NO;
  222. self.button.hidden = NO;
  223. BOOL isOldSubscribed = NO;
  224. #if VERSION_FREE
  225. #if !VERSION_DMG
  226. isOldSubscribed = (IAPProductsManager.defaultManager.allAccessPack6months_lite.isSubscribed == YES || IAPProductsManager.defaultManager.allAccessPack12months_lite.isSubscribed == YES);
  227. #endif
  228. #endif
  229. // 单平台高级版永久 未登录时 也不显示升级(因为点了也得先登录),但是登录后的卡片里是有升级按钮的,可以升级成全平台高级版年订阅
  230. //原来是订阅的,不需要升级,因为目前不支持订阅升级订阅这种场景
  231. if(type == KMUserScenarioTypeLite_type9 ||
  232. type == KMUserScenarioTypeLite_type10 ||
  233. type == KMUserScenarioTypeLite_type11) {
  234. if([KMMemberInfo shared].isLogin == NO) { //未登录
  235. self.button.hidden = YES;
  236. self.bgImg.hidden = YES;
  237. } else {
  238. if(isOldSubscribed) { //老版本付费功能是订阅包
  239. self.button.hidden = YES;
  240. self.bgImg.hidden = YES;
  241. } else {
  242. if((KMMemberInfo.shared.vip_status == 1) && [KMMemberInfo.shared.vip_paymentModel isEqualToString:@"1"]) { //会员订阅中
  243. self.button.hidden = YES;
  244. self.bgImg.hidden = YES;
  245. }
  246. }
  247. }
  248. } else if (type == KMUserScenarioTypeLite_type12 ||
  249. type == KMUserScenarioTypeLite_type13 ||
  250. type == KMUserScenarioTypeLite_type2 ||
  251. type == KMUserScenarioTypeLite_type4 ||
  252. type == KMUserScenarioTypeLite_type6 ||
  253. type == KMUserScenarioTypeLite_type8 ||
  254. type == KMUserScenarioTypePro_type2 ||
  255. type == KMUserScenarioTypePro_type5) {
  256. self.button.hidden = YES;
  257. self.bgImg.hidden = YES;
  258. }
  259. self.button.frame = CGRectMake(totalWidth, kbottomGap, buttonWidth, self.view.frame.size.height -2 *kbottomGap);
  260. CGRect rect = self.button.frame;
  261. self.bgImg.frame = rect;
  262. totalWidth+=CGRectGetWidth(self.button.bounds);
  263. totalWidth+=4;
  264. }
  265. if ([KMMemberInfo shared].isLogin) {
  266. self.userButton.hidden = NO;
  267. self.userButton.frame = CGRectMake(totalWidth, 0, userImageWidth, userImageWidth);
  268. totalWidth += userImageWidth;
  269. totalWidth += 8;
  270. } else {
  271. self.signUpView.hidden = NO;
  272. self.signUpView.frame = CGRectMake(totalWidth, 0, signUpWidth, self.view.frame.size.height);
  273. totalWidth+=CGRectGetWidth(self.signUpView.bounds);
  274. }
  275. if (self.view.superview) {
  276. 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);
  277. } else {
  278. // if (self.button.hidden) {
  279. // self.view.frame = CGRectMake(0,0, CGRectGetMaxX(self.aiLabel.frame) + 20 ,self.view.frame.size.height);
  280. // } else {
  281. // self.view.frame = CGRectMake(0,0, CGRectGetMaxX(self.button.frame) ,self.view.frame.size.height);
  282. // }
  283. 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);
  284. }
  285. }
  286. #pragma mark - Button Actions
  287. - (IBAction)secondTrialAction:(NSButton *)sender {
  288. if ([VerificationManager manager].secondTrialEnabled) {
  289. KMVerificationWindowController *vc = [KMVerificationWindowController verificationWithType:KMVerificationTypeRepeatTrialGuide];
  290. [vc showWindow:nil];
  291. } else {
  292. [[KMProductCompareWC shared] setOrientation:NO];
  293. [[KMProductCompareWC shared] showWindow:nil];
  294. }
  295. }
  296. - (IBAction)buttonAction:(id)sender {
  297. if ([KMMemberInfo shared].isLogin) {
  298. [[KMProductCompareWC shared] setOrientation:YES];
  299. if ([KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type1) {
  300. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeTrial];
  301. } else if ([KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type3 ||
  302. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type7 ||
  303. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type8) {
  304. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeLite_Base];
  305. } else if ([KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type4 ||
  306. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type5 ||
  307. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type9 ||
  308. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type11 ||
  309. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type13) {
  310. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeLite_MacWindows];
  311. } else if ([KMMemberInfo shared].userScenarioType == KMUserScenarioTypePro_type1 ||
  312. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypePro_type4) {
  313. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypePro_Advanced];
  314. } else if ([KMMemberInfo shared].userScenarioType == KMUserScenarioTypePro_type3) {
  315. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypePro_Base];
  316. }
  317. [[KMProductCompareWC shared] showWindow:nil];
  318. } else {
  319. [KMLoginWindowsController.shared openWindow:^(BOOL success) {
  320. if (success) {
  321. [[KMProductCompareWC shared] setOrientation:YES];
  322. if ([KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type1) {
  323. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeTrial];
  324. } else if ([KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type3 ||
  325. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type7 ||
  326. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type8) {
  327. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeLite_Base];
  328. } else if ([KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type4 ||
  329. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type5 ||
  330. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type9 ||
  331. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type11 ||
  332. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type13) {
  333. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeLite_MacWindows];
  334. } else if ([KMMemberInfo shared].userScenarioType == KMUserScenarioTypePro_type1 ||
  335. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypePro_type4) {
  336. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypePro_Advanced];
  337. } else if ([KMMemberInfo shared].userScenarioType == KMUserScenarioTypePro_type3) {
  338. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypePro_Base];
  339. }
  340. [[KMProductCompareWC shared] showWindow:nil];
  341. }
  342. }];
  343. }
  344. }
  345. - (NSAttributedString *)numberConvertColor:(NSColor*)color String:(NSString *)string {
  346. NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:string];
  347. NSString *temp = nil;
  348. for (NSUInteger i = 0; i <string.length; i++) {
  349. temp = [string substringWithRange:NSMakeRange(i, 1)];
  350. if ([self isPureInt:temp]) {
  351. [attributedString setAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
  352. color, NSForegroundColorAttributeName, nil] range:NSMakeRange(i, 1)];
  353. }
  354. }
  355. return attributedString;
  356. }
  357. - (BOOL)isPureInt:(NSString *)string {
  358. NSScanner *scan = [NSScanner scannerWithString:string];
  359. int value;
  360. return [scan scanInt:&value] && [scan isAtEnd];
  361. }
  362. - (IBAction)AIButtonAction:(NSButton *)sender {
  363. __block typeof(self) blockSelf = self;
  364. // [[FMTrackEventManager defaultManager] trackEventWithEvent:@"Tbr" withProperties:@{@"Tbr_Btn":@"Btn_Tbr_AICredit"}];
  365. // [[AIInfoManager defaultManager] fetchAIInfoWithComplention:^(NSDictionary *info, NSError *error) {
  366. //
  367. // }];
  368. // AIUserInfoController *controller = [[AIUserInfoController alloc] init];
  369. // controller.purchaseHandle = ^(AIUserInfoController * _Nonnull vc) {
  370. //#if VERSION_DMG
  371. // KMPurchaseEmbeddedWindowController *embeddedWC = [KMPurchaseEmbeddedWindowController currentFirstTrialWC:@"com.brother.pdfreaderpro.ai.product_1"];
  372. // [embeddedWC showWindow:nil];
  373. // [[embeddedWC window] center];
  374. //#else
  375. //
  376. // [[AIPurchaseWindowController currentWC] showWindow:nil];
  377. //#endif
  378. // [[FMTrackEventManager defaultManager] trackEventWithEvent:@"Tbr" withProperties:@{@"Tbr_Btn":@"Btn_Tbr_AICredit_BuyNow"}];
  379. // };
  380. // controller.enterLicenseHandle = ^(AIUserInfoController * _Nonnull vc) {
  381. // KMVerificationWindowController *verifyVC = [KMVerificationWindowController verificationWithType:KMVerificationTypeActivateAIInfo];
  382. // verifyVC.callback = ^{
  383. //
  384. // };
  385. // [verifyVC showWindow:nil];
  386. // };
  387. //
  388. // controller.guideHandle = ^(AIUserInfoController * _Nonnull vc) {
  389. // if (!blockSelf.guideWindowVC) {
  390. // KMFunctionGuideWindowController *guideWindowVC = [[KMFunctionGuideWindowController alloc] initWithWindowNibName:@"KMFunctionGuideWindowController"];
  391. // blockSelf.guideWindowVC = guideWindowVC;
  392. // }
  393. // ((KMFunctionGuideWindowController *)(blockSelf.guideWindowVC)).type = KMGuideInfoTypeFunctionMulti;
  394. // [blockSelf.guideWindowVC showWindow:nil];
  395. // [KMFunctionGuideWindowController setDidShowFor:KMGuideInfoTypeFunctionMultiAIGuide];
  396. // [blockSelf.guideWindowVC.window orderFront:nil];
  397. // };
  398. //
  399. // NSPopover *popover = [[NSPopover alloc] init];
  400. // popover.contentViewController = controller;
  401. // popover.animates = YES;
  402. // popover.behavior = NSPopoverBehaviorTransient;
  403. // [popover showRelativeToRect:[sender bounds] ofView:sender preferredEdge:NSMinYEdge];
  404. [[KMFreeGetAIWC shared] showWindow:nil];
  405. }
  406. - (IBAction)userButtonAction:(NSButton *)sender {
  407. if ([KMMemberInfo shared].isLogin) {
  408. [self personalCenterAction:sender];
  409. } else {
  410. [KMLoginWindowsController.shared showWindow:nil];
  411. }
  412. }
  413. - (IBAction)personalCenterAction:(NSButton *)sender {
  414. // 用户头像点击事件
  415. self.userMenu = [[NSMenu alloc] init];
  416. KMUserInfoViewController *userInfo = [[KMUserInfoViewController alloc] init];
  417. NSMenuItem *item = [self.userMenu addItemWithTitle:@"" action:nil target:@""];
  418. item.target = self;
  419. item.representedObject = userInfo;
  420. item.view = userInfo.view;
  421. [self.userMenu popUpMenuPositioningItem:nil atLocation:NSMakePoint(-130, 30) inView:sender];
  422. }
  423. - (IBAction)signUpAction:(NSButton *)sender {
  424. [KMLoginWindowsController.shared showWindow:nil];
  425. }
  426. #pragma mark - NSNotification Methods
  427. - (void)deviceActivateStatusChangeNotification:(NSNotification *)notification {
  428. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.4 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  429. [self reloadData];
  430. });
  431. }
  432. - (void)IAPResultReceived:(NSNotification *)notification {
  433. dispatch_async(dispatch_get_main_queue(), ^{
  434. [self reloadData];
  435. });
  436. }
  437. - (void)IAPPurchaseSuccess:(NSNotification *)notification {
  438. dispatch_async(dispatch_get_main_queue(), ^{
  439. [self reloadData];
  440. });
  441. }
  442. - (void)IAPRestoreFinish:(NSNotification *)notification {
  443. dispatch_async(dispatch_get_main_queue(), ^{
  444. [self reloadData];
  445. });
  446. }
  447. #pragma mark - Event
  448. - (void)mouseEntered:(NSEvent *)event {
  449. if (ActivityStatusTrialExpire == [VerificationManager manager].status ||
  450. ActivityStatusTrial == [VerificationManager manager].status) {
  451. [[self class] cancelPreviousPerformRequestsWithTarget:self];
  452. if (!self.popover.isShown) {
  453. [self buttonAction:self.button];
  454. }
  455. }
  456. }
  457. - (void)mouseExited:(NSEvent *)event {
  458. [super mouseExited:event];
  459. [self performSelector:@selector(popOverCloseAction) withObject:nil afterDelay:0.35];
  460. }
  461. - (void)popoverDidClose:(NSNotification *)notification {
  462. self.stopPopOverHide = NO;
  463. }
  464. - (void)popoverShowNoti:(NSNotification *)noti {
  465. if (self.popover) {
  466. [self.popover close];
  467. self.stopPopOverHide = NO;
  468. }
  469. }
  470. - (void)loginSuccessNotification:(NSNotification *)noti {
  471. _userButton.image = [NSImage imageNamed:@"UserProfilePicture"];
  472. [self reloadData];
  473. }
  474. - (void)logoutSuccessNotification:(NSNotification *)noti {
  475. _userButton.image = [NSImage imageNamed:@"UserProfilePicture1"];
  476. [self reloadData];
  477. }
  478. - (void)expandPersonalCenterNotification:(NSNotification *)noti {
  479. if (self.userMenu != nil) {
  480. [self personalCenterAction:_userButton];
  481. }
  482. }
  483. - (void)closeMenu:(NSNotification *)noti {
  484. if (self.userMenu != nil) {
  485. [self.userMenu cancelTracking];
  486. self.userMenu = nil;
  487. }
  488. }
  489. - (void)popOverCloseAction {
  490. if (self.stopPopOverHide == NO) {
  491. if (ActivityStatusTrialExpire == [VerificationManager manager].status ||
  492. ActivityStatusTrial == [VerificationManager manager].status) {
  493. if (self.popover.isShown) {
  494. [self.popover close];
  495. self.stopPopOverHide = NO;
  496. }
  497. }
  498. }
  499. }
  500. @end