KMVerificationMessageViewController.m 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577
  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_type9 ||
  174. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type13 ||
  175. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type11 ||
  176. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypePro_type1 ||
  177. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypePro_type3 ||
  178. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypePro_type4) {
  179. if ([KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type1) {
  180. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Free Trial", nil)];
  181. if (KMAdvertisementManager.manager.info.topRightInfoContent != nil) {
  182. if (KMAdvertisementManager.manager.info.topRightInfoContent.content.firstObject != nil) {
  183. KMAdvertisementItemInfo *info = KMAdvertisementManager.manager.info.topRightInfoContent.content.firstObject;
  184. NSString *name = [KMAdvertisementModelTransition transitionLanguageWithLangeuage:info.name];
  185. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(name, nil)];
  186. NSURL *url = [NSURL URLWithString: [KMAdvertisementModelTransition transitionImagePathWithImage:info.image highlight: YES]];
  187. __weak typeof(self)weakSelf = self;
  188. weakSelf.bgImg.image = [KMAdvertisementImage imageWithURLWithUrl:url completion:^(NSImage *image) {
  189. weakSelf.bgImg.image = image;
  190. }];
  191. }
  192. }
  193. } else if ([KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type3 ) {
  194. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedStringFromTable(@"Buy Now", @"MemberCenterLocalizable", nil)];
  195. } else if ([KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type11) {
  196. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Upgrade", 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. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedStringFromTable(@"Renew now", @"MemberCenterLocalizable", nil)];
  217. }
  218. [self.button setTitleColor:[NSColor whiteColor]];
  219. self.bgImg.hidden = NO;
  220. self.button.hidden = NO;
  221. if ([KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type1) {
  222. if ([IAPProductsManager defaultManager].fourDevicesAllAccessPackNew12months_lite.isTrialPeriod) {
  223. self.bgImg.hidden = YES;
  224. self.button.hidden = YES;
  225. }
  226. }
  227. KMUserScenarioType type = [KMMemberInfo shared].userScenarioType;
  228. // 单平台高级版永久 未登录时 也不显示升级(因为点了也得先登录),但是登录后的卡片里是有升级按钮的,可以升级成全平台高级版年订阅
  229. //原来是订阅的,不需要升级,因为目前不支持订阅升级订阅这种场景
  230. if(type == KMUserScenarioTypeLite_type10 ||
  231. type == KMUserScenarioTypeLite_type12 ||
  232. type == KMUserScenarioTypePro_type1 ||
  233. type == KMUserScenarioTypePro_type2 ||
  234. type == KMUserScenarioTypePro_type3 ||
  235. type == KMUserScenarioTypePro_type4 ||
  236. type == KMUserScenarioTypePro_type5) {
  237. if ([KMMemberInfo shared].isLogin == NO || ([KMMemberInfo shared].isMemberAllFunction == NO && [KMMemberInfo shared].isLogin == YES)) {
  238. self.button.hidden = YES;
  239. self.bgImg.hidden = YES;
  240. }
  241. } else if(type == KMUserScenarioTypeLite_type9 || type == KMUserScenarioTypeLite_type11) { //永久版+免费版显示升级
  242. if ([KMMemberInfo shared].isLogin == NO || ([[KMMemberInfo shared].vip_paymentModel isEqualToString:@"1"] && [KMMemberInfo shared].isLogin == YES && (IAPProductsManager.defaultManager.allAccessPack6months_lite.isSubscribed == YES || IAPProductsManager.defaultManager.allAccessPack12months_lite.isSubscribed == YES))) {
  243. self.button.hidden = YES;
  244. self.bgImg.hidden = YES;
  245. }
  246. } else if(type == KMUserScenarioTypeLite_type13) {
  247. self.button.hidden = YES;
  248. self.bgImg.hidden = YES;
  249. }
  250. self.button.frame = CGRectMake(totalWidth, kbottomGap, buttonWidth, self.view.frame.size.height -2 *kbottomGap);
  251. CGRect rect = self.button.frame;
  252. self.bgImg.frame = rect;
  253. totalWidth+=CGRectGetWidth(self.button.bounds);
  254. totalWidth+=4;
  255. }
  256. if ([KMMemberInfo shared].isLogin) {
  257. self.userButton.hidden = NO;
  258. self.userButton.frame = CGRectMake(totalWidth, 0, userImageWidth, userImageWidth);
  259. totalWidth += userImageWidth;
  260. totalWidth += 8;
  261. } else {
  262. if (KMAdvertisementManager.manager.info.topRightInfoContent != nil) {
  263. if (KMAdvertisementManager.manager.info.topRightInfoContent.content.firstObject != nil) {
  264. KMAdvertisementItemInfo *info = KMAdvertisementManager.manager.info.topRightInfoContent.content.firstObject;
  265. NSString *name = [KMAdvertisementModelTransition transitionLanguageWithLangeuage:info.name];
  266. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(name, nil)];
  267. NSURL *url = [NSURL URLWithString: [KMAdvertisementModelTransition transitionImagePathWithImage:info.image highlight: YES]];
  268. __weak typeof(self)weakSelf = self;
  269. weakSelf.bgImg.image = [KMAdvertisementImage imageWithURLWithUrl:url completion:^(NSImage *image) {
  270. weakSelf.bgImg.image = image;
  271. }];
  272. }
  273. }
  274. self.signUpView.hidden = NO;
  275. self.signUpView.frame = CGRectMake(totalWidth, 0, signUpWidth, self.view.frame.size.height);
  276. totalWidth+=CGRectGetWidth(self.signUpView.bounds);
  277. }
  278. if (self.view.superview) {
  279. 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);
  280. } else {
  281. // if (self.button.hidden) {
  282. // self.view.frame = CGRectMake(0,0, CGRectGetMaxX(self.aiLabel.frame) + 20 ,self.view.frame.size.height);
  283. // } else {
  284. // self.view.frame = CGRectMake(0,0, CGRectGetMaxX(self.button.frame) ,self.view.frame.size.height);
  285. // }
  286. 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);
  287. }
  288. }
  289. #pragma mark - Button Actions
  290. - (IBAction)secondTrialAction:(NSButton *)sender {
  291. if ([VerificationManager manager].secondTrialEnabled) {
  292. KMVerificationWindowController *vc = [KMVerificationWindowController verificationWithType:KMVerificationTypeRepeatTrialGuide];
  293. [vc showWindow:nil];
  294. } else {
  295. [[KMProductCompareWC shared] setOrientation:NO];
  296. [[KMProductCompareWC shared] showWindow:nil];
  297. }
  298. }
  299. - (IBAction)buttonAction:(id)sender {
  300. if ([KMMemberInfo shared].isLogin) {
  301. [[KMProductCompareWC shared] setOrientation:YES];
  302. if ([KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type1) {
  303. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeTrial];
  304. } else if ([KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type3 ||
  305. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type7 ||
  306. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type8) {
  307. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeLite_Base];
  308. } else if ([KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type4 ||
  309. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type5 ||
  310. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type9 ||
  311. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type11 ||
  312. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type13) {
  313. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeLite_MacWindows];
  314. } else if ([KMMemberInfo shared].userScenarioType == KMUserScenarioTypePro_type1 ||
  315. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypePro_type4) {
  316. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypePro_Advanced];
  317. } else if ([KMMemberInfo shared].userScenarioType == KMUserScenarioTypePro_type3) {
  318. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypePro_Base];
  319. }
  320. [[KMProductCompareWC shared] showWindow:nil];
  321. } else {
  322. [KMLoginWindowsController.shared openWindow:^(BOOL success) {
  323. if (success) {
  324. [[KMProductCompareWC shared] setOrientation:YES];
  325. if ([KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type1) {
  326. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeTrial];
  327. } else if ([KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type3 ||
  328. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type7 ||
  329. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type8) {
  330. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeLite_Base];
  331. } else if ([KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type4 ||
  332. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type5 ||
  333. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type9 ||
  334. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type11 ||
  335. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type13) {
  336. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeLite_MacWindows];
  337. } else if ([KMMemberInfo shared].userScenarioType == KMUserScenarioTypePro_type1 ||
  338. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypePro_type4) {
  339. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypePro_Advanced];
  340. } else if ([KMMemberInfo shared].userScenarioType == KMUserScenarioTypePro_type3) {
  341. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypePro_Base];
  342. }
  343. [[KMProductCompareWC shared] showWindow:nil];
  344. }
  345. }];
  346. }
  347. }
  348. - (NSAttributedString *)numberConvertColor:(NSColor*)color String:(NSString *)string {
  349. NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:string];
  350. NSString *temp = nil;
  351. for (NSUInteger i = 0; i <string.length; i++) {
  352. temp = [string substringWithRange:NSMakeRange(i, 1)];
  353. if ([self isPureInt:temp]) {
  354. [attributedString setAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
  355. color, NSForegroundColorAttributeName, nil] range:NSMakeRange(i, 1)];
  356. }
  357. }
  358. return attributedString;
  359. }
  360. - (BOOL)isPureInt:(NSString *)string {
  361. NSScanner *scan = [NSScanner scannerWithString:string];
  362. int value;
  363. return [scan scanInt:&value] && [scan isAtEnd];
  364. }
  365. - (IBAction)AIButtonAction:(NSButton *)sender {
  366. __block typeof(self) blockSelf = self;
  367. // [[FMTrackEventManager defaultManager] trackEventWithEvent:@"Tbr" withProperties:@{@"Tbr_Btn":@"Btn_Tbr_AICredit"}];
  368. // [[AIInfoManager defaultManager] fetchAIInfoWithComplention:^(NSDictionary *info, NSError *error) {
  369. //
  370. // }];
  371. // AIUserInfoController *controller = [[AIUserInfoController alloc] init];
  372. // controller.purchaseHandle = ^(AIUserInfoController * _Nonnull vc) {
  373. //#if VERSION_DMG
  374. // KMPurchaseEmbeddedWindowController *embeddedWC = [KMPurchaseEmbeddedWindowController currentFirstTrialWC:@"com.brother.pdfreaderpro.ai.product_1"];
  375. // [embeddedWC showWindow:nil];
  376. // [[embeddedWC window] center];
  377. //#else
  378. //
  379. // [[AIPurchaseWindowController currentWC] showWindow:nil];
  380. //#endif
  381. // [[FMTrackEventManager defaultManager] trackEventWithEvent:@"Tbr" withProperties:@{@"Tbr_Btn":@"Btn_Tbr_AICredit_BuyNow"}];
  382. // };
  383. // controller.enterLicenseHandle = ^(AIUserInfoController * _Nonnull vc) {
  384. // KMVerificationWindowController *verifyVC = [KMVerificationWindowController verificationWithType:KMVerificationTypeActivateAIInfo];
  385. // verifyVC.callback = ^{
  386. //
  387. // };
  388. // [verifyVC showWindow:nil];
  389. // };
  390. //
  391. // controller.guideHandle = ^(AIUserInfoController * _Nonnull vc) {
  392. // if (!blockSelf.guideWindowVC) {
  393. // KMFunctionGuideWindowController *guideWindowVC = [[KMFunctionGuideWindowController alloc] initWithWindowNibName:@"KMFunctionGuideWindowController"];
  394. // blockSelf.guideWindowVC = guideWindowVC;
  395. // }
  396. // ((KMFunctionGuideWindowController *)(blockSelf.guideWindowVC)).type = KMGuideInfoTypeFunctionMulti;
  397. // [blockSelf.guideWindowVC showWindow:nil];
  398. // [KMFunctionGuideWindowController setDidShowFor:KMGuideInfoTypeFunctionMultiAIGuide];
  399. // [blockSelf.guideWindowVC.window orderFront:nil];
  400. // };
  401. //
  402. // NSPopover *popover = [[NSPopover alloc] init];
  403. // popover.contentViewController = controller;
  404. // popover.animates = YES;
  405. // popover.behavior = NSPopoverBehaviorTransient;
  406. // [popover showRelativeToRect:[sender bounds] ofView:sender preferredEdge:NSMinYEdge];
  407. [[KMFreeGetAIWC shared] showWindow:nil];
  408. }
  409. - (IBAction)userButtonAction:(NSButton *)sender {
  410. if ([KMMemberInfo shared].isLogin) {
  411. [self personalCenterAction:sender];
  412. } else {
  413. [KMLoginWindowsController.shared showWindow:nil];
  414. }
  415. }
  416. - (IBAction)personalCenterAction:(NSButton *)sender {
  417. // 用户头像点击事件
  418. self.userMenu = [[NSMenu alloc] init];
  419. KMUserInfoViewController *userInfo = [[KMUserInfoViewController alloc] init];
  420. NSMenuItem *item = [self.userMenu addItemWithTitle:@"" action:nil target:@""];
  421. item.target = self;
  422. item.representedObject = userInfo;
  423. item.view = userInfo.view;
  424. [self.userMenu popUpMenuPositioningItem:nil atLocation:NSMakePoint(-130, 30) inView:sender];
  425. }
  426. - (IBAction)signUpAction:(NSButton *)sender {
  427. [KMLoginWindowsController.shared showWindow:nil];
  428. }
  429. #pragma mark - NSNotification Methods
  430. - (void)deviceActivateStatusChangeNotification:(NSNotification *)notification {
  431. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.4 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  432. [self reloadData];
  433. });
  434. }
  435. - (void)IAPResultReceived:(NSNotification *)notification {
  436. dispatch_async(dispatch_get_main_queue(), ^{
  437. [self reloadData];
  438. });
  439. }
  440. - (void)IAPPurchaseSuccess:(NSNotification *)notification {
  441. dispatch_async(dispatch_get_main_queue(), ^{
  442. [self reloadData];
  443. });
  444. }
  445. - (void)IAPRestoreFinish:(NSNotification *)notification {
  446. dispatch_async(dispatch_get_main_queue(), ^{
  447. [self reloadData];
  448. });
  449. }
  450. #pragma mark - Event
  451. - (void)mouseEntered:(NSEvent *)event {
  452. if (ActivityStatusTrialExpire == [VerificationManager manager].status ||
  453. ActivityStatusTrial == [VerificationManager manager].status) {
  454. [[self class] cancelPreviousPerformRequestsWithTarget:self];
  455. if (!self.popover.isShown) {
  456. [self buttonAction:self.button];
  457. }
  458. }
  459. }
  460. - (void)mouseExited:(NSEvent *)event {
  461. [super mouseExited:event];
  462. [self performSelector:@selector(popOverCloseAction) withObject:nil afterDelay:0.35];
  463. }
  464. - (void)popoverDidClose:(NSNotification *)notification {
  465. self.stopPopOverHide = NO;
  466. }
  467. - (void)popoverShowNoti:(NSNotification *)noti {
  468. if (self.popover) {
  469. [self.popover close];
  470. self.stopPopOverHide = NO;
  471. }
  472. }
  473. - (void)loginSuccessNotification:(NSNotification *)noti {
  474. _userButton.image = [NSImage imageNamed:@"UserProfilePicture"];
  475. [self reloadData];
  476. }
  477. - (void)logoutSuccessNotification:(NSNotification *)noti {
  478. _userButton.image = [NSImage imageNamed:@"UserProfilePicture1"];
  479. [self reloadData];
  480. }
  481. - (void)expandPersonalCenterNotification:(NSNotification *)noti {
  482. if (self.userMenu != nil) {
  483. [self personalCenterAction:_userButton];
  484. }
  485. }
  486. - (void)closeMenu:(NSNotification *)noti {
  487. if (self.userMenu != nil) {
  488. [self.userMenu cancelTracking];
  489. self.userMenu = nil;
  490. }
  491. }
  492. - (void)popOverCloseAction {
  493. if (self.stopPopOverHide == NO) {
  494. if (ActivityStatusTrialExpire == [VerificationManager manager].status ||
  495. ActivityStatusTrial == [VerificationManager manager].status) {
  496. if (self.popover.isShown) {
  497. [self.popover close];
  498. self.stopPopOverHide = NO;
  499. }
  500. }
  501. }
  502. }
  503. @end