KMVerificationMessageViewController.m 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574
  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 = YES;
  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. BOOL isFree = NO;
  109. self.secondTrialBtn.hidden = YES;
  110. self.bgImg.hidden = YES;
  111. if (self.frameUpdateHandle) {
  112. self.frameUpdateHandle(self.view.frame);
  113. }
  114. CGFloat totalWidth = 8;
  115. self.button.hidden = YES;
  116. self.label.hidden = YES;
  117. self.secondTrialBtn.hidden = YES;
  118. self.labelContentView.hidden = YES;
  119. self.bgImg.hidden = YES;
  120. self.aiContendView.hidden = YES;
  121. self.userButton.hidden = YES;
  122. self.signUpView.hidden = YES;
  123. self.signUpLabel.stringValue = NSLocalizedStringFromTable(@"Sign in", @"MemberCenterLocalizable", nil);
  124. [self.signUpLabel sizeToFit];
  125. CGFloat signUpWidth = self.signUpLabel.frame.size.width;
  126. signUpWidth += 4;
  127. signUpWidth += 8;
  128. signUpWidth += 8;
  129. signUpWidth += 12;
  130. self.signUpImg.frame = CGRectMake(8, CGRectGetHeight(self.view.frame)/2.-6, 12, 12);
  131. CGRect signUplabelRect = self.signUpLabel.frame;
  132. signUplabelRect.origin.x = CGRectGetMaxX(self.signUpImg.frame) + 4;
  133. self.signUpLabel.frame = signUplabelRect;
  134. self.button.layer.backgroundColor = [NSColor clearColor].CGColor;
  135. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Upgrade to Pro", nil)];
  136. [self.button setTitleColor:[NSColor whiteColor]];
  137. self.aiLabel.stringValue = NSLocalizedStringFromTable(@"Free to receive 1 year of AI", @"MemberCenterLocalizable", nil);
  138. [self.aiLabel sizeToFit];
  139. CGFloat aiWidth = self.aiLabel.frame.size.width;
  140. aiWidth += 4;
  141. aiWidth += 16;
  142. aiWidth += 16;
  143. self.aiIconImg.frame = CGRectMake(8, CGRectGetHeight(self.view.frame)/2.-8, 16, 16);
  144. self.aiContendView.frame = CGRectMake(totalWidth, 0, aiWidth, self.view.frame.size.height);
  145. CGRect ailabelRect = self.aiLabel.frame;
  146. ailabelRect.origin.x = CGRectGetMaxX(self.aiIconImg.frame) + 4;
  147. self.aiLabel.frame = ailabelRect;
  148. // totalWidth+=aiWidth;
  149. // totalWidth+=4;
  150. // self.aiContendView.hidden = NO;
  151. CGFloat userImageWidth = 24;
  152. if ([KMMemberInfo shared].isLogin) {
  153. self.userButton.image = [NSImage imageNamed:@"UserProfilePicture"];
  154. } else {
  155. self.userButton.image = [NSImage imageNamed:@"UserProfilePicture1"];
  156. }
  157. CGFloat buttonWidth = CGRectGetMaxX(self.button.frame);
  158. NSRect btnRect = [self.button.attributedTitle boundingRectWithSize:CGSizeMake(MAXFLOAT, CGRectGetHeight(self.button.frame)) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading];
  159. if (fabs(buttonWidth-btnRect.size.width)>50) {
  160. buttonWidth = btnRect.size.width + 10;
  161. }
  162. if ([[KMMemberInfo shared].isHaveAIDiscount isEqualToString:@"1"]) {
  163. if(IAPProductsManager.defaultManager.aiAllAccessPack12month_pro.isTrialPeriod == false) {
  164. self.aiContendView.hidden = NO;
  165. totalWidth+=aiWidth;
  166. totalWidth+=4;
  167. }
  168. }
  169. if ([KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type1 ||
  170. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type3 ||
  171. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type5 ||
  172. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type7 ||
  173. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type8 ||
  174. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type9 ||
  175. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type13 ||
  176. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type11 ||
  177. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypePro_type1 ||
  178. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypePro_type3 ||
  179. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypePro_type4) {
  180. if ([KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type1) {
  181. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Free Trial", nil)];
  182. if (KMAdvertisementManager.manager.info.topRightInfoContent != nil) {
  183. if (KMAdvertisementManager.manager.info.topRightInfoContent.content.firstObject != nil) {
  184. KMAdvertisementItemInfo *info = KMAdvertisementManager.manager.info.topRightInfoContent.content.firstObject;
  185. NSString *name = [KMAdvertisementModelTransition transitionLanguageWithLangeuage:info.name];
  186. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(name, nil)];
  187. NSURL *url = [NSURL URLWithString: [KMAdvertisementModelTransition transitionImagePathWithImage:info.image highlight: YES]];
  188. __weak typeof(self)weakSelf = self;
  189. weakSelf.bgImg.image = [KMAdvertisementImage imageWithURLWithUrl:url completion:^(NSImage *image) {
  190. weakSelf.bgImg.image = image;
  191. }];
  192. }
  193. }
  194. } else if ([KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type3 ||
  195. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type11) {
  196. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Renew now", nil)];
  197. } else if ([KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type5 ||
  198. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type9 ||
  199. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypePro_type1 ||
  200. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypePro_type3 ||
  201. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypePro_type4) {
  202. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Upgrade", nil)];
  203. if (KMAdvertisementManager.manager.info.topRightInfoContent != nil) {
  204. if (KMAdvertisementManager.manager.info.topRightInfoContent.content.firstObject != nil) {
  205. KMAdvertisementItemInfo *info = KMAdvertisementManager.manager.info.topRightInfoContent.content.firstObject;
  206. NSString *name = [KMAdvertisementModelTransition transitionLanguageWithLangeuage:info.name];
  207. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(name, nil)];
  208. NSURL *url = [NSURL URLWithString: [KMAdvertisementModelTransition transitionImagePathWithImage:info.image highlight: YES]];
  209. __weak typeof(self)weakSelf = self;
  210. weakSelf.bgImg.image = [KMAdvertisementImage imageWithURLWithUrl:url completion:^(NSImage *image) {
  211. weakSelf.bgImg.image = image;
  212. }];
  213. }
  214. }
  215. } else if ([KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type7 ||
  216. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type8 ||
  217. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type13) {
  218. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Renew now", nil)];
  219. }
  220. [self.button setTitleColor:[NSColor whiteColor]];
  221. self.bgImg.hidden = NO;
  222. self.button.hidden = NO;
  223. if ([KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type1) {
  224. if ([IAPProductsManager defaultManager].fourDevicesAllAccessPackNew12months_lite.isTrialPeriod) {
  225. self.bgImg.hidden = YES;
  226. self.button.hidden = YES;
  227. }
  228. }
  229. KMUserScenarioType type = [KMMemberInfo shared].userScenarioType;
  230. // 单平台高级版永久 未登录时 也不显示升级(因为点了也得先登录),但是登录后的卡片里是有升级按钮的,可以升级成全平台高级版年订阅
  231. //原来是订阅的,不需要升级,因为目前不支持订阅升级订阅这种场景
  232. if(type == KMUserScenarioTypeLite_type9 ||
  233. type == KMUserScenarioTypeLite_type10 ||
  234. type == KMUserScenarioTypeLite_type11 ||
  235. type == KMUserScenarioTypeLite_type12 ||
  236. type == KMUserScenarioTypeLite_type13 ||
  237. type == KMUserScenarioTypePro_type1 ||
  238. type == KMUserScenarioTypePro_type2 ||
  239. type == KMUserScenarioTypePro_type3 ||
  240. type == KMUserScenarioTypePro_type4 ||
  241. type == KMUserScenarioTypePro_type5) {
  242. if ([KMMemberInfo shared].isLogin == NO || ([KMMemberInfo shared].isMemberAllFunction == NO && [KMMemberInfo shared].isLogin == YES)) {
  243. self.button.hidden = YES;
  244. self.bgImg.hidden = YES;
  245. }
  246. }
  247. self.button.frame = CGRectMake(totalWidth, kbottomGap, buttonWidth, self.view.frame.size.height -2 *kbottomGap);
  248. CGRect rect = self.button.frame;
  249. self.bgImg.frame = rect;
  250. totalWidth+=CGRectGetWidth(self.button.bounds);
  251. totalWidth+=4;
  252. }
  253. if ([KMMemberInfo shared].isLogin) {
  254. self.userButton.hidden = NO;
  255. self.userButton.frame = CGRectMake(totalWidth, 0, userImageWidth, userImageWidth);
  256. totalWidth += userImageWidth;
  257. totalWidth += 8;
  258. } else {
  259. if (KMAdvertisementManager.manager.info.topRightInfoContent != nil) {
  260. if (KMAdvertisementManager.manager.info.topRightInfoContent.content.firstObject != nil) {
  261. KMAdvertisementItemInfo *info = KMAdvertisementManager.manager.info.topRightInfoContent.content.firstObject;
  262. NSString *name = [KMAdvertisementModelTransition transitionLanguageWithLangeuage:info.name];
  263. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(name, nil)];
  264. NSURL *url = [NSURL URLWithString: [KMAdvertisementModelTransition transitionImagePathWithImage:info.image highlight: YES]];
  265. __weak typeof(self)weakSelf = self;
  266. weakSelf.bgImg.image = [KMAdvertisementImage imageWithURLWithUrl:url completion:^(NSImage *image) {
  267. weakSelf.bgImg.image = image;
  268. }];
  269. }
  270. }
  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